Skip to content

Core file from apps that catch SEGV etc

June 23, 2005

Here is an old chestnut that comes up from time to time. How do I get a core dump from a process that catches SEGV?

The trick is to use truss -S to stop the process when it receives the SEGV then you can gcore(1) the process and use your favourite debugger to work out the problem. Here is a very simple example:

: enoexec.eu FSS 55 $; cat segv.c #include <signal.h> #include <stdlib.h> #include <unistd.h>  int main(int argc, char **argv) {         char *x = 0;          signal(SIGSEGV, exit);          sleep(20);          *x = ‘a’; } : enoexec.eu FSS 56 $; make segv cc    -o segv segv.c : enoexec.eu FSS 57 $; coreadm $$ 825235: core    default : enoexec.eu FSS 58 $; ./segv : enoexec.eu FSS 59 $; ls -l core core: No such file or directory : enoexec.eu FSS 60 $; ./segv & [1]     829766 : enoexec.eu FSS 61 $; truss -t!all -S SEGV -p $!     Incurred fault #6, FLTBOUNDS  %pc = 0x00010C00       siginfo: SIGSEGV SEGV_MAPERR addr=0x00000000     Received signal #11, SIGSEGV [caught]       siginfo: SIGSEGV SEGV_MAPERR addr=0x00000000 : enoexec.eu FSS 62 $; gcore $! gcore: core.829766 dumped : enoexec.eu FSS 63 $; prun $! : enoexec.eu FSS 64 $; pstack core.829766 core ‘core.829766’ of 829766:   ./segv  00010c00 main     (1, ffbfef3c, ffbfef44, 20c00, ff3a00c0, 0) + 30  000107a0 _start   (0, 0, 0, 0, 0, 0) + 108 [1] +  Done(11)                ./segv & : enoexec.eu FSS 65 $;


Use the “-t!all” flag to truss so that it does not report every system call the process makes, you might want to do a similar thing with the -s flag if the process takes a lot of signals.

Tags: Solaris, truss

Advertisements

From → Solaris

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: