Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Aug 2000 21:30:50 -0700
From:      "Brian O'Shea" <boshea@ricochet.net>
To:        Nicolas Leonard <nicolas.leonard@animaths.com>
Cc:        Samuel Tardieu <sam@inf.enst.fr>, hackers@FreeBSD.ORG
Subject:   Re: How to generate a core dump explicily
Message-ID:  <20000808213050.J351@beastie.localdomain>
In-Reply-To: <011301c00146$c709f170$0f0210ac@masa.com>; from Nicolas Leonard on Tue, Aug 08, 2000 at 04:41:46PM %2B0200
References:  <00f101c00140$2a4b5a50$0f0210ac@masa.com> <2000-08-08-15-56-50%2Btrackit%2Bsam@inf.enst.fr> <011301c00146$c709f170$0f0210ac@masa.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h>
#include <signal.h>
#include <sys/cdefs.h>

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
<snip>
(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




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