gdb:在由python加载的共享库中中断 [英] gdb: break in shared library loaded by python

查看:198
本文介绍了gdb:在由python加载的共享库中中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调试位于共享库中的c / c ++代码,这些代码由python中的ctypes.cdll.LoadLibrary()加载,然后从python调用特定的函数。
python代码派生子进程,所以我需要能够打破是否从python父进程或子进程调用c函数。
一个简单的例子: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)
printi =%dj =%d \\\
%(i,j)


$ gcc -g -O0 test.c -shared -o test.so
$ gdb --args python-dbg test.py
(gdb)break test.c call1
未定义函数test.c call1。
在将来的共享库加载时使断点处于待处理状态? (y或[n])y
断点1(test.c call1)挂起。
(gdb)信息断点
数字类型Disp Enb地址什么
1断点保持y< PENDING> test.c call1
(gdb)run
启动程序:/ usr / bin / python-dbg test.py
[使用libthread_db启用线程调试]
使用主机libthread_db库 /lib/x86_64-linux-gnu/libthread_db.so.1\" 。
i = 20 j = 40

[23744 refs]
[下1(进程44079)正常退出]

您可以从我的终端日志中看到,当python加载库时,gdb没有看到断点。我看到了与我的应用程序相同的行为。

解决方案

break on call1 而不是

 (gdb)break call1 

这也应该可以工作

 (gdb)break test.c:call1 


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

这篇关于gdb:在由python加载的共享库中中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆