Filippo, That really helps! Now a minor variation of the program does not throw a full backtrace and stops short after showing the c library call. Again on x86 host machine it correctly shows a deep backtrace.
Attached is the file. I am calling "func1()" which crashes inside snprintf library call implementation. ARMv7a# ./crash_test Trying to construct invalid buffer! SIGSEGV Handler! Got Backtrace Size=3 0x000087bc 0x0000887c 0xb6f02420 ARMv7a # I think we need to add unwind-tables or -finstrument-functions for uClibc as well. I am using buildroot for the toolchain. Any ideas? /Thanks -----Original Message----- From: Filippo ARCIDIACONO [mailto:filippo.arcidiac...@st.com] Sent: Thursday, September 12, 2013 10:14 AM To: Rajendra Dendukuri Cc: SHREYAS JOSHI; uclibc@uclibc.org Subject: Re: backtrace() not working on ARMv7a On 9/12/2013 2:49 PM, Rajendra Dendukuri wrote: > Thanks Shreyas for the tip. But it is not working even with "-fexceptions" or > "-fasynchronous-unwind-tables" options. > > Forum, > Anyone faced this issue before? Yes. I got the same behavior using your test. Doing some googling , see http://stackoverflow.com/questions/9229702/gcc-return-address-of-calling-function-in-arm-architecture on ARM arch the gcc __builtin_return_address() function does not work beyond the current function|||| (only __builtin_return_address(0) works), this explain because we don't obtain a full backtrace. Using -finstrument-function compiler option (see gcc documentation at http://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/Code-Gen-Options.html#Code-Gen-Options) I got a full backtrace: root@arcidiaf:/home/filippo# gcc -o crash_test -O0 -fexceptions -finstrument-functions crash_tst.c root@arcidiaf:/home/filippo# ./crash_test Trying to access NULL pointer! SIGSEGV Handler! Got Backtrace Size=6 0x00008854 0x0000894c 0x76ef1c24 0x000089b4 0x00008b18 0x76f3c7bc || > > /Thanks > > From: SHREYAS JOSHI [mailto:dexterous.m...@yahoo.com] > Sent: Thursday, September 12, 2013 2:33 AM > To: Rajendra Dendukuri; uclibc@uclibc.org > Subject: Re: backtrace() not working on ARMv7a > > Try -fexceptions. > > For further details, check the following link. > > http://www.tune2wizard.com/backtrace/ > > > Thanks & regards, > Shreyas Joshi > > > ________________________________ > From: Rajendra Dendukuri <rajen...@broadcom.com<mailto:rajen...@broadcom.com>> > To: "uclibc@uclibc.org<mailto:uclibc@uclibc.org>" > <uclibc@uclibc.org<mailto:uclibc@uclibc.org>> > Sent: Wednesday, September 11, 2013 10:01 PM > Subject: backtrace() not working on ARMv7a > > Hi uclibc list, > > I am trying to generate a call stack trace using backtrace() API which is > part of libubacktrace. The idea is to catch a SIGSEGV signal and call > backtrace() to print all the address values and compare the obtained > addresses from objdump -D of executable. Attached is a simplified version of > the application. Following is the output seen on ARMv7a platform with > buildroot cross-toolchain (gcc- 4.6.3, uClibc-0.9.33.2, binutis-2.21.1). > > To compile the application: > ${CROSS_COMPILE}gcc -o crash_test -O0 -funwind-tables -rdynamic crash_test.c > > ARMv7a# ./crash_test > Trying to access NULL pointer! > SIGSEGV Handler! > Got Backtrace Size=2 > 0x00008724 > 0x000087c4 > ARMv7a# > > The above function call trace is only that of the signal hander > (print_back_trace, sigsegv_handler) and does not show the entire call stack > for the function where program crashed (print_back_trace, sigsegv_handler, > func2, main). > > On x86 host same program shows a deeper function call trace right up to the > main function and even beyond: > x86-RHEL5-host$./crash_test > Trying to access NULL pointer! > SIGSEGV Handler! > Got Backtrace Size=7 > 0x00400939 > 0x004009ab > 0x30930302f0 > 0x004009d3 > 0x00400a7b > 0x309301d994 > 0x00400889 > x86-RHEL5-host$ > > Can someone please comment on what is going wrong. Any special flags that > need to be used while compiling/linking the program. > > /Thanks > > _______________________________________________ > uClibc mailing list > uClibc@uclibc.org<mailto:uClibc@uclibc.org> > http://lists.busybox.net/mailman/listinfo/uclibc > _______________________________________________ > uClibc mailing list > uClibc@uclibc.org > http://lists.busybox.net/mailman/listinfo/uclibc > >
#include <termios.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h> #include <signal.h> #include <stdio.h> #include <string.h> void print_back_trace() { void *array[32]; int index, size; size = backtrace (array, 32); printf("Got Backtrace Size=%d\n", size); for (index = 0; index < size; index++) { printf ("0x%08lx\n", (unsigned long) array[index]); } } static void sigsegv_handler (int sig, siginfo_t * info, void *v) { printf("SIGSEGV Handler!\n"); print_back_trace(); exit (0); } void func2() { int val; unsigned int *ptr; ptr = 0; printf("Trying to access NULL pointer!\n"); val = *ptr; printf ("Read 0x%x from %p\n", val, ptr); } void func1() { int val; char buf[256]; val = 100; printf("\nTrying to construct invalid buffer!\n"); snprintf(buf, sizeof (buf), "%s", val); printf("The content of buf: %s\n", buf); } int main() { struct sigaction sig_act; int rc; sig_act.sa_sigaction = sigsegv_handler; rc = sigaction (SIGSEGV, &sig_act, 0); func1(); return 0; }
_______________________________________________ uClibc mailing list uClibc@uclibc.org http://lists.busybox.net/mailman/listinfo/uclibc