11

I'm trying to debug c/c++ code located in shared libraries which are loaded by ctypes.cdll.LoadLibrary() in python and then specific functions are called from python. The python code forks child processes, so I need to be able to break whether the c function is called from a python parent or child process. A dead-simple example: test.c

// j = clib.call1(i)
int call1(int i)
{
    return i*2;
}

test.py

import os, sys, ctypes
path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "test.so"))
clib = ctypes.cdll.LoadLibrary(path)
i = 20
j = clib.call1(i)
print "i=%d j=%d\n" %(i, j)


$ gcc -g -O0 test.c -shared -o test.so
$ gdb --args python-dbg test.py
(gdb) break test.c call1
Function "test.c call1" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (test.c call1) pending.
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   <PENDING>  test.c call1
(gdb) run
Starting program: /usr/bin/python-dbg test.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
i=20 j=40

[23744 refs]
[Inferior 1 (process 44079) exited normally]

You can see from my terminal log that gdb is not seeing the breakpoint when python loads the library. I am seeing the same behavior with my application.

lightdee
  • 487
  • 4
  • 11
  • update: digging further, I noticed that "(gdb) break test.c:6" does work. why does one work and not the other? – lightdee Nov 30 '12 at 21:53

1 Answers1

6

break on call1 instead

(gdb) break call1

this should work too

(gdb) break test.c:call1
iabdalkader
  • 17,009
  • 4
  • 47
  • 74
  • So that worked for this example. Why does that work when "break test.c call1" does not? This doesn't solve the problem where I may have overloaded function names in different libraries, but I guess I can use line numbers for that. – lightdee Nov 30 '12 at 21:52
  • 1
    @lightdee it's actually filename:function (a colon not a space). – iabdalkader Nov 30 '12 at 21:54
  • thanks - I should've paid closer attention when I read the help page – lightdee Nov 30 '12 at 22:57