Hi,
I spent lot of time on debugging the code. am not sure about the libunwind internals .. but libunwind failed on to extract frame information from pthreads lib api (example pthread_cond_wait in this function the frame pointer is getting changed to some value like 0x1). Libunwind works with the examples provided by u .......
From GDB I figured out more than esp or ebp or CFI they r doing lot more stuffs to get stacktrace of a process like Prologue Analysis.
http://sources.redhat.com/gdb/onlinedocs/gdbint.html#AlgorithmsIntially I implemented stack gen code using ptrace + esp + ebp it didnt work and i tried with libwindi my bad luck libunwind also didnt work
32-bit machine
Version details--------------------address@hidden PROJECT]# ls -l /usr/lib/libunwind*
lrwxrwxrwx. 1 root root 16 Feb 14 21:30 /usr/lib/libunwind-generic.so -> libunwind-x86.solrwxrwxrwx. 1 root root 18 Feb 14 21:30 /usr/lib/libunwind.so -> libunwind.so.7.0.0
lrwxrwxrwx. 1 root root 18 Feb 14 21:28 /usr/lib/libunwind.so.7 -> libunwind.so.7.0.0-rwxr-xr-x. 1 root root 42716 Dec 4 2009 /usr/lib/libunwind.so.7.0.0
lrwxrwxrwx. 1 root root 22 Feb 14 21:30 /usr/lib/libunwind-x86.so -> libunwind-x86.so.7.0.0lrwxrwxrwx. 1 root root 22 Feb 14 21:28 /usr/lib/libunwind-x86.so.7 -> libunwind-x86.so.7.0.0
-rwxr-xr-x. 1 root root 63204 Dec 4 2009 /usr/lib/libunwind-x86.so.7.0.0address@hidden PROJECT]# gcc -v
Using built-in specs.Target: i686-redhat-linuxConfigured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch=i686 --build=i686-redhat-linux
Thread model: posixgcc version 4.4.5 20101112 (Red Hat 4.4.5-2) (GCC)
/lib/libc-2.12.2.so/lib/libpthread-2.12.2.soaddress@hidden PROJECT]# cat /etc/redhat-release
Fedora release 13 (Goddard)I attached two .c files one example program (pthread.c) for testing the libunwind functionality and bractrace_libunwind.c using unwind lib which unwinds the stack frame
How I compiled
------------------------
gcc backtrace_libunwind.c -lunwind-generic -lunwind-ptrace -g -o backtrace
gcc pthread.c -lpthread
Output
-------------
address@hidden PROJECT]#
address@hidden PROJECT]# pstack 4187
Thread 4 (Thread 0xb7848b70 (LWP 4188)):
#0 0x001d1416 in __kernel_vsyscall ()
#1 0x4cf3d22c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0
#2 0x08048923 in watch_count ()
#3 0x4cf39919 in start_thread () from /lib/libpthread.so.0
#4 0x4ce7bd4e in clone () from /lib/libc.so.6
Thread 3 (Thread 0xb6e47b70 (LWP 4189)):
#0 0x001d1416 in __kernel_vsyscall ()
#1 0x4ce3bea6 in nanosleep () from /lib/libc.so.6
#2 0x4ce3bcd0 in sleep () from /lib/libc.so.6
#3 0x080488ab in inc_count ()
#4 0x4cf39919 in start_thread () from /lib/libpthread.so.0
#5 0x4ce7bd4e in clone () from /lib/libc.so.6
Thread 2 (Thread 0xb6446b70 (LWP 4190)):
#0 0x001d1416 in __kernel_vsyscall ()
#1 0x4ce3bea6 in nanosleep () from /lib/libc.so.6
#2 0x4ce3bcd0 in sleep () from /lib/libc.so.6
#3 0x080488ab in inc_count ()
#4 0x4cf39919 in start_thread () from /lib/libpthread.so.0
#5 0x4ce7bd4e in clone () from /lib/libc.so.6
Thread 1 (Thread 0xb78496c0 (LWP 4187)):
#0 0x001d1416 in __kernel_vsyscall ()
#1 0x4cf39fdd in pthread_join () from /lib/libpthread.so.0
#2 0x08048a77 in main ()
address@hidden PROJECT]# vim backtrace_libunwind.c
address@hidden PROJECT]# gcc backtrace_libunwind.c ^C
(reverse-i-search)`': vim backtrace_^Cbunwind.c
address@hidden PROJECT]# gcc backtrace_libunwind.c -lunwind-generic -lunwind-ptrace -g -o backtrace
address@hidden PROJECT]# ./a.out ^C
address@hidden PROJECT]# ./backtrace 4187
----------tid4187----------
main
__libc_start_main
_start
----------tid4188----------
----------tid4189----------
inc_count
start_thread
clone
----------tid4190----------
inc_count
start_thread
clone
On Tue, Feb 21, 2012 at 9:50 PM, Arun Sharma
<address@hidden> wrote:
> Hi all,
>
> I am trying to unwind stack frame using lib unwind lib, but most of the
> time i could not able to get the stack trace, especially t system call
> frames and pthread lib frame ( am not sure about the other lib frames).
> A little debugging inside the code i figured out libwind failes where the
> base pointer getting changed for eg pthread_cond_wait changes the bp and
> copies it into some other register
Can you provide the version of glibc and libunwind? In theory, this
should work just fine on x64:
http://bit.ly/w5IrVK
Since gdb is able to unwind, I'm guessing that the dwarf unwind info
is present and libunwind should be able to use it too.
-Arun