Results 1 to 3 of 3
I want to use backtrace() function to debug a crash issue. I tried this sample code to see how backtrace works. backtrace() function always returns 0 with the below code. ...
- 07-23-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 2
Using backtrace() function in C
I want to use backtrace() function to debug a crash issue. I tried this sample code to see how backtrace works. backtrace() function always returns 0 with the below code. Is there any kernel configuration that needs to be set for proper working of backtrace?
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
/* Obtain a backtrace and print it to stdout. */
void
print_trace (void)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size);
for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);
}
/* A dummy function to make the backtrace more interesting. */
void
dummy_function (void)
{
print_trace ();
}
int
main (void)
{
dummy_function ();
return 0;
}
- 07-23-2010 #2Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
Strange... on my system, this shows there to be 5 stack frames. I doubt this is anything to do with the kernel. What distro are you using? Could you post the command-line you use to build the program?
- 07-23-2010 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 2
Using backtrace() function in C
I am using MontaVista linux on an embedded device (TI's DaVinci processor).
Command used for creating executable:
arm_v5t_le-gcc -c -g -I../inc ../src/linux_signals.c -o ../src/linux_signals.o
arm_v5t_le-gcc -o ./linux_signals.out ../src/linux_signals.o -lpthread -lrt


Reply With Quote