From owner-freebsd-arch@freebsd.org Mon May 28 18:24:11 2018 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3D399F7594F for ; Mon, 28 May 2018 18:24:11 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id CE3807A5BF for ; Mon, 28 May 2018 18:24:10 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: by mailman.ysv.freebsd.org (Postfix) id 89D67F7594E; Mon, 28 May 2018 18:24:10 +0000 (UTC) Delivered-To: arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 776B2F7594D for ; Mon, 28 May 2018 18:24:10 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) by mx1.freebsd.org (Postfix) with ESMTP id 0E5577A5BD; Mon, 28 May 2018 18:24:09 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (unknown [192.168.55.3]) by phk.freebsd.dk (Postfix) with ESMTP id 07BB514888; Mon, 28 May 2018 18:24:07 +0000 (UTC) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.15.2/8.15.2) with ESMTPS id w4SIO7Wp022471 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 28 May 2018 18:24:07 GMT (envelope-from phk@critter.freebsd.dk) Received: (from phk@localhost) by critter.freebsd.dk (8.15.2/8.15.2/Submit) id w4SIO6af022470; Mon, 28 May 2018 18:24:06 GMT (envelope-from phk) To: Ravi Pokala cc: arch@freebsd.org Subject: Re: To assert() or not to assert(), that is not really a question... In-reply-to: <4427091E-3B0E-4C34-B4C6-3557DD7B55E4@panasas.com> From: "Poul-Henning Kamp" References: <4514.1527319154@critter.freebsd.dk> <4427091E-3B0E-4C34-B4C6-3557DD7B55E4@panasas.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22468.1527531846.1@critter.freebsd.dk> Content-Transfer-Encoding: quoted-printable Date: Mon, 28 May 2018 18:24:06 +0000 Message-ID: <22469.1527531846@critter.freebsd.dk> X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 May 2018 18:24:11 -0000 -------- In message <4427091E-3B0E-4C34-B4C6-3557DD7B55E4@panasas.com>, Ravi Pokala= writ es: >> 1. "Regular asserts" - things which are just plain wrong, which >> probably means we have a genuine bug somewhere. Examples could >> be null pointers where previous checks should have ensured this >> not be so. Also error situations for which there is no saner >> handling that killing the projcess. >> = >> ... >> = >> 3. "wrong asserts" - Internal state is messed up, program flow >> has taken a "impossible" branch. A good example is the >> default branch of a switch on a finite input set. > >Hi Poul-Henning, > >I am in strong overall agreement with your argument. I am however >confused as to how (1) and (3) are different; they're both irrevocably >bad internal state. The regular assert is assert() as we know and love it, and if it triggers it reports the C-source of the failing condition. The WRONG macro always triggers, and reports its string argument. Here is a random snippet of varnish code showing both: /* Per specification */ assert(sizeof vpx1_sig =3D=3D 5); assert(sizeof vpx2_sig =3D=3D 12); [...] p =3D req->htc->rxbuf_b; if (p[0] =3D=3D vpx1_sig[0]) i =3D vpx_proto1(wrk, req); else if (p[0] =3D=3D vpx2_sig[0]) i =3D vpx_proto2(wrk, req); else WRONG("proxy sig mismatch"); Poul-Henning PS: You can explore the Varnish source code here: https://github.com/varnishcache/varnish-cache Asserts defined in: .../include/vas.h Custom backtrace/state dump in: .../bin/varnishd/cache/cache_panic.c Code coverage results: http://varnish-cache.org/gcov/ You may also find the void-pointer paranoia interesting: .../include/miniobj.h -- = Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe = Never attribute to malice what can adequately be explained by incompetence= .