Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Dec 2000 09:21:04 -0800 (PST)
From:      Matt Dillon <dillon@earth.backplane.com>
To:        Assar Westerlund <assar@FreeBSD.ORG>
Cc:        Aled Morris <aledm@qix.co.uk>, Jack Rusher <jar@integratus.com>, "Jacques A. Vidrine" <n@nectar.com>, Warner Losh <imp@village.org>, hackers@FreeBSD.ORG
Subject:   Re: Why not another style thread? (was Re: cvs commit: src/lib/libc/gen ..
Message-ID:  <200012201721.eBKHL4Q67705@earth.backplane.com>
References:  <Pine.BSF.4.21.0012201120480.436-100000@kai.qix.co.uk> <5ld7enduic.fsf@assaris.sics.se>

next in thread | previous in thread | raw e-mail | index | archive | help
:> 
:> 
:> Shouldn't you use "kill(0, SIGSEGV)" ?
:
:Why not err(3) or abort(3) ?
:
:/assar

    I need something gdb can latch on to.  If the program exits all the state
    required to debug the problem goes away.  When writing a program one must
    make the run-time distinction between a bug and an expectable error. 
    If it's a bug then something unexpected occured which has to be fixed,
    so the best thing to do is usually to seg fault.

    After a while of debugging like this, the bugs get worked out and the
    programs stop seg faulting.  The final result tends to be a whole lot
    more stable then if you were to try to recover from or ignore the bug.

    I actually have a DBASSERT() macro to assert conditions and force the
    seg fault.  The macro uses GCC's preprocessor's __FILE__, __LINE__,
    and __FUNCTION__ macros in a call to a routine which prints out where
    the program died and then forces the seg-fault.

    If you put reasonable, strategic assertions in the code you tend to 
    catch problems before they've propogated through dozens of routines and
    become untraceable.

    #define DBASSERT(exp)           \
	    if (!(exp)) _DBAssert(__FILE__, __LINE__, __FUNCTION__)

    ...

    void
    _DBAssert(const char *file, int line, const char *func)
    {
	fprintf(stderr, "Assertion failed %s line %d in %s\n", file, line, func);
	fflush(stderr);
    #ifndef NO_ASSERT_CORE
	*(long *)0 = 1;
    #endif
    exit(1);
    }


					-Matt



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200012201721.eBKHL4Q67705>