Date: Sat, 6 Apr 2013 02:21:47 +1100 (EST) From: Bruce Evans <brde@optusnet.com.au> To: Alexander Motin <mav@FreeBSD.org> Cc: svn-src-head@FreeBSD.org, Adrian Chadd <adrian@FreeBSD.org>, src-committers@FreeBSD.org, svn-src-all@FreeBSD.org Subject: Re: svn commit: r249105 - in head/sys/cam: ata scsi Message-ID: <20130406020010.P1319@besplex.bde.org> In-Reply-To: <515DE949.6050309@FreeBSD.org> References: <201304041904.r34J4F2I065527@svn.freebsd.org> <CAJ-Vmo=p04MaqjYZhA3aKz%2BnQ9=diyMfaVJ4kNAjRVPFyHLRkg@mail.gmail.com> <515DE949.6050309@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 4 Apr 2013, Alexander Motin wrote: > On 04.04.2013 23:53, Adrian Chadd wrote: >> Hi, >> >> Isn't this a prime candidate to replace with KASSERT()? > > It could be, but NULL dereference attempt will crash system no less reliably > then KASSERT. Much more reliably: - if INAVRIANTS is not configured, then the NULL dereference still crashes properly - if INAVRIANTS is configured, then the NULL dereference gives a nice (restartable) fault, while KASSERT() calls panic() and there is no way to get back to the original context so as to to restart or debug it more easily. KASSERT() could be improved by replacing it by a a null dereference or other restartable fault, at least before calling panic() or taking any other unrestartable actions. The panic() call would still prevent restarting very easily -- you would have to back out to before the KASSERT() and fix up all the asserted conditions (usually more than a single null pointer). This method works well in userland too. Instead of assert() or abort(), use an null dereference, or more portably, a signal, or less portably, an asm with a breakpoint instruction or with the null pointer dereference (so that the compiler can't see that it gives undefined behaviour and optimize it away). I use this more to debug than to restart. Even if optimization or the debugger doesn't lose the local variables when assert() or abort() is called, it is easier to debug if you don't have to go up several frames to see the variables. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130406020010.P1319>