【问题标题】:Debugging c++ code behind python在python后面调试c++代码
【发布时间】:2018-05-25 18:27:44
【问题描述】:

我正在尝试为这个库 (faster rcnn) 调试 Python 后面的 C++ 代码。

我遵循了here的指示。

假设我想在solver.cpp和第188行停止一个断点。

gdb -ex r --args python ./tools/train_faster_rcnn_alt_opt.py --gpu 0 --net_name headhand --weights data/imagenet_models/VGG_CNN_M_1024.v2.caffemodel --imdb headhand_train --cfg experiments/cfgs/config.yml

我按Ctrl + c

然后

gdb python 8504

break solver.cpp:188

然后type c and enter

但永远不要在solver.cpp 中断。如何调试?

【问题讨论】:

    标签: python c++ python-2.7 gdb


    【解决方案1】:

    如果您不调试 python 解释器本身,则不需要链接文章中描述的任何 python 调试内容。您可以使用常规解释器而无需扩展。您也不想运行 gdb 两次。您只需要确保足够早地设置断点。

    $ gdb python --args <your-args> # no -x r 
    (gdb) break <your-breakpoint>
    No symbol table is loaded. Use the "file" comand.
    Make breakpoint pending on future shared library load? (y or [n])
    

    回答“是”。

    (gdb) run
    

    就是这样。

    【讨论】:

    • 我按照你提到的做了,我已经(gdb)运行了启动程序:--gpu 0 --net_name headhand --weights data/imagenet_models/VGG_CNN_M_1024.v2.caffemodel --imdb headhand_train -- cfg Experiments/cfgs/config.yml 未指定可执行文件。使用“file”或“exec-file”命令。
    【解决方案2】:

    您可能已经通过了断点(在 GDB 启动之前)。根据提到的instructions,您应该:

    从一开始就在gdb下运行python

    在GDB下尝试run你的python

    了解Debugging with GDB

    您可能希望使用使用DWARF 调试信息构建的python 解释器,因此使用-g 编译(当然您的solver.cpp 也应该使用-g 编译)。由于 Python 是 free software,用 -g 重新编译它应该很简单。

    顺便说一句,您确定断点的第 188 行位置吗?您是否尝试在 solver.cpp 的其他位置添加更多断点,或者在函数名称处添加断点?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 2012-10-22
      • 2021-06-14
      • 2016-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多