Core file from apps that catch SEGV etc

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

Comments:

Post a Comment:
Comments are closed for this entry.
About

This is the old blog of Chris Gerhard. It has mostly moved to http://chrisgerhard.wordpress.com

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today