batuman
batuman

Reputation: 7324

Debugging c++ code behind python

I am trying to debug C++ code behind python for this library (faster rcnn).

I followed the instruction here.

Say I like to stop a break point at solver.cpp and line 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

I press Ctrl + c

then

gdb python 8504

break solver.cpp:188

then type c and enter

But never break at solver.cpp. How can I debug?

Upvotes: 1

Views: 1570

Answers (2)

n. m. could be an AI
n. m. could be an AI

Reputation: 120239

If you are not debugging the python interpreter itself, you don't need any python debugging stuff described in the linked article. You can use the regular interpreter and no extensions. You also don't want to run gdb twice. You only need to make sure you set your breakpoint early enough.

$ 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])

Answer "y".

(gdb) run

That's it.

Upvotes: 2

You probably has passed your breakpoint (before GDB got started). You should, per the instructions mentioned:

run python under gdb from the start

Try to run your python under GDB.

Read about Debugging with GDB.

You might want to use a python interpreter built with DWARF debug info, so compiled with -g (and of course your solver.cpp should also be compiled with -g). Since Python is free software recompiling it with -g should be pretty simple.

BTW, are you sure of the line position 188 of your breakpoint? Did you try to add more breakpoints in solver.cpp at other positions, or to break at function names?

Upvotes: 0

Related Questions