[uClibc]gdb problems

Erik Andersen andersen at codepoet.org
Sat Mar 1 08:39:00 UTC 2003

On Thu Feb 27, 2003 at 11:10:25AM +0100, azarate at saincotrafico.com wrote:
> Hello, I'm testing the uclibc with pthreads in a i386 linux box (installed
> RedHat 7.3) and it works well with uclibc-0.9.18.
> The problem i have is when i want to debug my test program. The gdb can't
> debug threads???

After several days of effort trying to track down what was wrong,
I was finally able to locate and fix the problem causing this
failure in uClibc's shared library loader.  If you update uClibc
to the latest and greatest, it should work.  Be aware though that
you will need to either recompile gdb vs uClibc to debug threaded
uClibc applications, or you will need to debug your applications
staticly linked and using gdb 5.3 with a patch from gdb in debian

The deal is that for gdb to find out what is happening with all
the thread on the system, gdb will try to dlopen a library named
"libthread_db.so.1".  The libthread_db library needs to be
compiled vs uClibc for it to work properly.

If you try to debug threaded uClibc apps using your RedHat
system's gdb, it will dlopen the system's libthread_db library,
which will cause gdb crash, and generally do not work properly.
And of course trying to use something like LD_LIBRARY_PATH to
force your system gdb to load uClibc's libthread_db library will
also cause gdb to crash.

So in addition to rebuildng uClibc, to debug threaded uClibc
programs you will also need to compile gdb against uClibc, which
will allow gdb to safely dlopen and use uClibc's libthread_db

[andersen at dillweed pthread]$ ldd ./gdb
        libncurses.so.5 => /usr/i386-linux-uclibc/lib/libncurses.so.5 (0x0x40006000)
        libm.so.0 => /usr/i386-linux-uclibc/lib/libm.so.0 (0x0x40043000)
        libdl.so.0 => /usr/i386-linux-uclibc/lib/libdl.so.0 (0x0x40051000)
        libc.so.0 => /usr/i386-linux-uclibc/lib/libc.so.0 (0x0x40054000)
        ld-uClibc.so.0 => /usr/i386-linux-uclibc/lib/ld-uClibc.so.0 (0x0x40000000)

[andersen at dillweed pthread]$ ldd ./ex7
        libpthread.so.0 => /usr/i386-linux-uclibc/lib/libpthread.so.0 (0x0x40006000)
        libc.so.0 => /usr/i386-linux-uclibc/lib/libc.so.0 (0x0x40018000)
        ld-uClibc.so.0 => /usr/i386-linux-uclibc/lib/ld-uClibc.so.0 (0x0x40000000)

[andersen at dillweed pthread]$ ./gdb ./ex7
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-linux"...
(gdb) b 29
Breakpoint 1 at 0x804852f: file ex7.c, line 29.
(gdb) r
Starting program: /home/andersen/CVS/uClibc/test/pthread/ex7 
[New Thread 1024 (LWP 3969)]
[New Thread 2049 (LWP 3970)]
[New Thread 1026 (LWP 3971)]
main: waiting for thread to finish
test_thread: sleeping for 10 seconds
[Switching to Thread 1024 (LWP 3969)]

Breakpoint 1, main () at ex7.c:29
29          pthread_join(thread, (void *)&status);
(gdb) info threads 
  3 Thread 1026 (LWP 3971)  0x40044b71 in __libc_nanosleep (req=0xbf7ffd10, rem=0xbf7ffd10) at syscalls.c:1594
  2 Thread 2049 (LWP 3970)  0x40044cf8 in poll (fds=0x804fe94, nfds=1, timeout=2000) at syscalls.c:1659
* 1 Thread 1024 (LWP 3969)  main () at ex7.c:29


Erik B. Andersen             http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--

More information about the uClibc mailing list