From owner-freebsd-hackers Tue Aug 8 21:30:39 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from mail1.rdc1.sfba.home.com (mail1.rdc1.sfba.home.com [24.0.0.74]) by hub.freebsd.org (Postfix) with ESMTP id 6224337B548 for ; Tue, 8 Aug 2000 21:30:25 -0700 (PDT) (envelope-from boshea@ricochet.net) Received: from beastie.localdomain ([24.19.158.41]) by mail1.rdc1.sfba.home.com (InterMail vM.4.01.03.00 201-229-121) with ESMTP id <20000809043023.WMBM28364.mail1.rdc1.sfba.home.com@beastie.localdomain>; Tue, 8 Aug 2000 21:30:23 -0700 Received: (from brian@localhost) by beastie.localdomain (8.9.3/8.8.7) id VAA97789; Tue, 8 Aug 2000 21:30:50 -0700 (PDT) (envelope-from brian) Date: Tue, 8 Aug 2000 21:30:50 -0700 From: "Brian O'Shea" To: Nicolas Leonard Cc: Samuel Tardieu , hackers@FreeBSD.ORG Subject: Re: How to generate a core dump explicily Message-ID: <20000808213050.J351@beastie.localdomain> Reply-To: boshea@ricochet.net Mail-Followup-To: Nicolas Leonard , Samuel Tardieu , hackers@FreeBSD.ORG References: <00f101c00140$2a4b5a50$0f0210ac@masa.com> <2000-08-08-15-56-50+trackit+sam@inf.enst.fr> <011301c00146$c709f170$0f0210ac@masa.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.4i In-Reply-To: <011301c00146$c709f170$0f0210ac@masa.com>; from Nicolas Leonard on Tue, Aug 08, 2000 at 04:41:46PM +0200 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, Aug 08, 2000 at 04:41:46PM +0200, Nicolas Leonard wrote: > Sorry, I wasn't precise enough . > > In fact, I caught the SIGABRT signal (and the others signals which are > ending the program) > and I'm doing some ending stuff, and after that, I would like to dump a core > file. > > I could remove the handler of SIGABRT after my ending suff done, and kill > myself another > time, but I would like to know if it's possible to dump the core explicitly. > (With a dumpcore() > function or whatever ) > There's no need to remove the handler for SIGABRT, unless you exit normally inside the handler. If you would like to handle SIGABRT, and you also want abort() to terminate the process and cause it to generate a core file, just remove any calls to exit() inside the handler. After your handler returns, the process will abort and dump core. If you use the same handler for all signals, you can conditionally exit based on the signal number. This example (handler.c) illustrates: #include #include #include void sig_handler __P((int)); int main(argc, argv) int argc; char *argv[]; { sig_t handler; handler = signal(SIGABRT, sig_handler); printf("Calling abort() ...\n"); abort(); printf("NOTREACHED\n"); return 0; } void sig_handler(sig) int sig; { printf("Caught signal %d\n", sig); /* exit(0); */ return; } Note from the backtrace (included below the program output) that the program dies at line 17. This is in the kill() function (as called from abort(), which never returns), but after the handler has returned (as can be seen by the output). [beastie:/home/brian]% cc -g handler.c -o handler [beastie:/home/brian]% ./handler Calling abort() ... Caught signal 6 zsh: 97734 abort (core dumped) ./handler [beastie:/home/brian]% gdb handler handler.core (gdb) bt #0 0x28094c78 in kill () from /usr/lib/libc.so.3 #1 0x280c8e57 in abort () from /usr/lib/libc.so.3 #2 0x80484a8 in main (argc=1, argv=0xbfbfd6ec) at handler.c:17 #3 0x8048419 in _start () -brian -- Brian O'Shea boshea@ricochet.net To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message