Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stack trace of C program core dump on solaris

Status
Not open for further replies.

powah

Programmer
Aug 31, 2006
5
US
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;
}
 
Does this help?
Code:
$ 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`[red]printf[/red]+0xd8(10c70, ff2e87dc, ff2e87fa, ff2e8368, ff2e4280, 4)
__1cN[green]coredump_func[/green]6F_i_+0x20(6, ff2e87dc, ff2e87fa, ff2e8368, ff2e4280, 6)
[blue]main[/blue]+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 [green]coredump_func[/green]() {
char *ptr = 0;
ptr = (char *) 123;
[red]printf[/red]("ptr %s\n", ptr);
return 0;
}

int [blue]main[/blue](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;
}

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top