From owner-freebsd-hackers Wed Dec 20 9:21:22 2000 From owner-freebsd-hackers@FreeBSD.ORG Wed Dec 20 09:21:19 2000 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from earth.backplane.com (placeholder-dcat-1076843399.broadbandoffice.net [64.47.83.135]) by hub.freebsd.org (Postfix) with ESMTP id 51B7237B402; Wed, 20 Dec 2000 09:21:19 -0800 (PST) Received: (from dillon@localhost) by earth.backplane.com (8.11.1/8.9.3) id eBKHL4Q67705; Wed, 20 Dec 2000 09:21:04 -0800 (PST) (envelope-from dillon) Date: Wed, 20 Dec 2000 09:21:04 -0800 (PST) From: Matt Dillon Message-Id: <200012201721.eBKHL4Q67705@earth.backplane.com> To: Assar Westerlund Cc: Aled Morris , Jack Rusher , "Jacques A. Vidrine" , Warner Losh , hackers@FreeBSD.ORG Subject: Re: Why not another style thread? (was Re: cvs commit: src/lib/libc/gen .. References: <5ld7enduic.fsf@assaris.sics.se> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG :> :> :> 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