I want to find out where (which line) my C program core dump.
How to do that?
One approach is to use stack trace of the mdb debugger, but I does not understand its output completely.
e.g.
$ CC -g coredump_fn.c
$ a.out
hello
Segmentation Fault (core dumped)
$ mdb core
Loading modules: [ libc.so.1 ld.so.1 ]
> ::stack
libc.so.1`strlen+0x18(10c76, ffbffbc4, ffbff441, 7b, 0, 0)
libc.so.1`printf+0xd8(10c70, ff2e87dc, ff2e87fa, ff2e8368, ff2e4280, 4)
__1cNcoredump_func6F_i_+0x20(6, ff2e87dc, ff2e87fa, ff2e8368, ff2e4280, 6)
main+0x20(1, ffbffcbc, ffbffcc4, 20c00, ff3301c0, ff330200)
_start+0xb8(0, 0, 0, 0, 0, 0)
>
/* coredump_fn.c : C test program for core dump generation */
#include <stdio.h>
int coredump_func() {
char *ptr = 0;
ptr = (char *) 123;
printf("ptr %s\n", ptr);
return 0;
}
int main(int argc, char *argv[])
{
int i = 0;
double x;
printf("hello\n");
coredump_func();
x = 1.0 / i;
printf("x %f\n", x);
return 0;
}
How to do that?
One approach is to use stack trace of the mdb debugger, but I does not understand its output completely.
e.g.
$ CC -g coredump_fn.c
$ a.out
hello
Segmentation Fault (core dumped)
$ mdb core
Loading modules: [ libc.so.1 ld.so.1 ]
> ::stack
libc.so.1`strlen+0x18(10c76, ffbffbc4, ffbff441, 7b, 0, 0)
libc.so.1`printf+0xd8(10c70, ff2e87dc, ff2e87fa, ff2e8368, ff2e4280, 4)
__1cNcoredump_func6F_i_+0x20(6, ff2e87dc, ff2e87fa, ff2e8368, ff2e4280, 6)
main+0x20(1, ffbffcbc, ffbffcc4, 20c00, ff3301c0, ff330200)
_start+0xb8(0, 0, 0, 0, 0, 0)
>
/* coredump_fn.c : C test program for core dump generation */
#include <stdio.h>
int coredump_func() {
char *ptr = 0;
ptr = (char *) 123;
printf("ptr %s\n", ptr);
return 0;
}
int main(int argc, char *argv[])
{
int i = 0;
double x;
printf("hello\n");
coredump_func();
x = 1.0 / i;
printf("x %f\n", x);
return 0;
}