Вопрос

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.

Это было полезно?

Решение

break on call1 instead

(gdb) break call1

this should work too

(gdb) break test.c:call1
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top