30

When I run GDB against a program which loads a .so which is linked to pthreads, GDB reports error "Cannot find new threads: generic error".

Note that executable that I run is not linked with pthreads.

Any clues?

$ gdb --args lua -lluarocks.require
GNU gdb (GDB) 7.0-ubuntu
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
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 /usr/bin/lua...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/lua -lluarocks.require
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio> require 'ev'
[Thread debugging using libthread_db enabled]
Cannot find new threads: generic error
(gdb) q
A debugging session is active.
 Inferior 1 [process 4986] will be killed.
Quit anyway? (y or n) y

This function gets called on require 'ev':

http://github.com/brimworks/lua-ev/blob/master/lua_ev.c#L25-65

Additional information about my system:

$ uname -a
Linux localhost 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 04:38:19 UTC 2010 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.10
Release: 9.10
Codename: karmic
asked Apr 23, 2010 at 23:56
2
  • I think this may be related: thread.gmane.org/gmane.comp.gdb.devel/24205 Any workarounds? Commented Apr 24, 2010 at 0:23
  • Thanks for the question... On my ubuntu system, I could not get preload /usr/lib/i386-linux-gnu/libpthread.so to work so I compiled Lua with pthread... ;-(. Commented Mar 5, 2012 at 19:28

6 Answers 6

30

This also works:

LD_PRELOAD=/lib/libpthread.so.0 gdb --args ./app
Josh Correia
4,4003 gold badges42 silver badges67 bronze badges
answered Nov 2, 2010 at 16:01
Sign up to request clarification or add additional context in comments.

Comments

28

64 bit Ubuntu users should do this:

LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0 gdb --args ./app
answered May 20, 2011 at 22:24

Comments

15

You can also create a .gdbinit in your home directory containing this text:

set env LD_PRELOAD /lib/libpthread.so.0
DarthJDG
16.6k11 gold badges52 silver badges56 bronze badges
answered Jun 7, 2011 at 10:32

Comments

7

It appears that GDB doesn't like when application "suddenly" becomes dependent on pthreads.

The only workaround I've found is to link host application with pthreads.

Which is rather sad...

answered Apr 29, 2010 at 14:09

3 Comments

When you say "suddenly" do you mean dynamic loading at runtime ?
This solved my problem as well, my static / shared libraries depend on pthread but not my executable therefore I do not link it in. However, once linked the debugger behaves properly... I should mention that my application does not create any threads, however it does have the potential to create objects in thread local memory.
@Hassan: yes, suddenly = dynamic loading
5

I have found that gdb can attach to the process after the runtime linking to the pthreads library has completed.

answered Sep 29, 2010 at 17:43

1 Comment

Sometimes recompiling is not a realistic option so attaching after is probably the more general solution. Thanks, this thread solved my problem.
2

"If you add flag -lpthread to gcc (or g++) while linking your application to be debugged the problem vanish." Source

answered Sep 3, 2013 at 15:18

1 Comment

Well, this is more or less what I wrote as an answer three years ago: "The only workaround I've found is to link host application with pthreads." ;)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.