I had one program I'm writing and started getting these strange gdb
errors, I narrowed it down to linking with libdbi. This is the problem I
see:
csmall@elmo:~$ cat test.c
#include <stdio.h>
#include <dbi/dbi.h>
int main(int argc, char *argv[])
{
printf("Hello, World!\n");
dbi_initialize(NULL);
return 0;
}
csmall@elmo:~$ gcc -ggdb -o test test.c -ldbi
csmall@elmo:~$ gdb ./test
GNU gdb (GDB) 7.1-debian
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show
copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/csmall/test...done.
(gdb) run
Starting program: /home/csmall/test
Hello, World!
[Thread debugging using libthread_db enabled]
Cannot find new threads: generic error
(gdb) n
Cannot execute this command while the selected thread is running.
(gdb) info threads
Cannot find new threads: generic error
Hello, I had a closer look at programs using libdbi. Most of them seem to link to libpthread. Programs such as rrdtool and syslog-ng use it. So I changed my command line to build my simple test program I sent in my initial report from: gcc -o test -ldbi -ggdb test.c to: gcc -o test -ldbi -lpthread -ggdb test.c GDB now works as you expect, info threads sees threads and all is well. The question is, should gdb work fine without the program having to link to libpthread? Or is there a problem in libdbi? I built my own libdbi 0.8.3 just in case it was a problem with 0.8.2 but get the same results. - Craig
Does libdbi load libpthread dynamically?
Indirectly it does. libdbi uses database-specific backends. So, for example, libdbd-mysql.so is dlopen()ed by libdbi and that mysql specific library is dynamically linked to libpthread. - Craig
OK, thanks. That's going to be the issue then; I'm surprised to see it resurface, but GDB has historically had trouble in this situation.
And with LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 gdb sudo this suddenly starts to work. (Why is it that I only need this kludge on Debian? openSUSE also ships gdb 7.3)