Hi guys,
I'm looking at using libunwind to work around the perennial lack of
backtrace on uclibc MIPS. To test it out on the embedded system in
question I knocked together a simple application consisting of a couple of
recursive functions before calling the show_backtrace example code featured
on the website documentation.
Unfortunately the show_backtrace is unable to show anything useful,
unw_step exits with -UNW_ENOINFO. Cranking up the debug levels gives me
the following (the full code attached):
Backtracing 00400b10
>_ULmips_init_local: (cursor=0x7fe1a668)
>_ULmips_step: (cursor=0x7fe1a668)
>get_rs_cache: acquiring lock
>_ULmips_dwarf_find_proc_info: looking for IP=0x400927
>_ULmips_dwarf_callback: checking ./main, base=0x0)
>_ULmips_dwarf_callback: checking ../lib//libunwind.so.8,
base=0x770cd000)
>_ULmips_dwarf_callback: checking
../lib//libunwind-mips.so.8, base=0x77045000)
>_ULmips_dwarf_callback: checking /lib/libgcc_s.so.1,
base=0x7700e000)
>_ULmips_dwarf_callback: checking /lib/libc.so.0,
base=0x76f54000)
>_ULmips_dwarf_callback: checking /lib/ld-uClibc.so.0,
base=0x77142000)
>_ULmips_dwarf_find_proc_info: IP=0x400927 not found
>put_rs_cache: unmasking signals/interrupts and releasing
lock
>_ULmips_dwarf_step: returning -10
"Backtracing" is the result of a __builtin_return_address(0) and is correct
from my examination of the disassembly.
Other than it not working. What really concerns me is the value for IP
being unaligned to a word boundary and that it doesn't correspond to an
actual instruction (I performed a objdump -d on the executable and crossed
referenced against the proc/maps file to sanity check).
Compiler: mipsel-linux-gcc (Broadcom stbgcc-4.5.3-2.4) 4.5.3
uclibc: uClibc-0.9.32
Compile line: mipsel-linux-uclibc-gcc -g -fPIC -Ilibunwind/include
-Llibunwind/src/.libs -lunwind -lunwind-mips -Wall -W -D_REENTRANT -fPIE
-O0 -fno-inline -fno-omit-frame-pointer -o main main.c
Thanks in advance.
#include <stdio.h>
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#define NOINLINE __attribute__((noinline))
void show_backtrace (void) {
void* pc0 = __builtin_return_address(0);
printf( "Backtracing %08x\n", pc0 );
unw_cursor_t cursor;
unw_context_t uc;
unw_word_t ip, sp;
unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
while (unw_step(&cursor) > 0)
{
unw_get_reg(&cursor, UNW_REG_IP, &ip);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
printf ("ip = %lx, sp = %lx\n", (long) ip, (long) sp);
}
}
void f( int i );
void NOINLINE another( int i )
{
printf( "calling f\n");
f( i );
}
void NOINLINE f( int i )
{
printf( "eek %d\n", i );
if( i > 0 )
f( i -1 );
else
show_backtrace();
}
int main( int argc, char** argv )
{
printf( "hello world\n" );
f( 10 );
another( 5 );
pause();
return 0;
}
_______________________________________________
Libunwind-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/libunwind-devel