Hi Carsten, What you get is *expected*. When a SIGSEGV is raised you jump to the registered check_sys_sig. Since you initialize context using unw_init_local inside the signal handler, that is what you will get (not the application context you were expecting).
You will have to figure out a way to capture your application context and pass it on to the signal handler and unwind on that passed context (and not a new initialization that you are doing). Linux provides this context as an extra void* argument to the signal handler. Take a look at this thread and example I posted a while back. The thread also lists some issues with SIGSEGV raised on NULL IP (like what you are doing): http://comments.gmane.org/gmane.comp.lib.unwind.devel/1350 Thanks and Regards, Prabhat From: [email protected] [mailto:[email protected]] On Behalf Of Carsten Edenfeld Sent: Wednesday, June 13, 2012 12:18 PM To: [email protected] Subject: [Libunwind-devel] Signal SIGSEGV clears Callstack Hi, I am trying to use the libunwind library for getting a callstack while my application crashes with a segmentation fault signal. But, if the app crashes, I do not get a correct callstack, but always this output: _ZL13check_sys_sigi __restore_rt If I am using the unwind code without a (forced) exception, but instead directly calling the following function, everything works as expected: void show_backtrace (void) { char name[256]; unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp, offp; unw_getcontext(&uc); unw_init_local(&cursor, &uc); while (unw_step(&cursor) > 0) { char file[256]; int line = 0; name[0] = '\0'; int iResult = unw_get_proc_name(&cursor, name, 256, &offp); if ( iResult != UNW_ESUCCESS ) { DEBUGERROR("no proc name"); } unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); printf ("%s ip = %lx, sp = %lx\n", name, (long) ip, (long) sp); DEBUGERROR(name); //getFileAndLine((long)ip, file, 256, &line); //printf("%s in file %s line %d\n", name, file, line); } } Any clues what I am doing wrong ? I am using Suse 12.1 with libunwind version 0.98.6-39.1.2. All object files are compiled with the "-g" and "-rdynamic" flags. The signal handling is initialized with the following code: static void check_sys_sig ( int sig_nr ) { show_backtrace(); } bool register_sys_signal_handler() { sys_signal_add (SIGSEGV, check_sys_sig); } void main () { . . . register_sys_signal_handler(); // a) force crash *(int*)0=0; // <- wrong/empty callstack // OR b) using directly show_backtrace(); show_backtrace(); // <- correct callstack } Thanks, Carsten Edenfeld
_______________________________________________ Libunwind-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/libunwind-devel
