Wednesday, August 2, 2017

[Debug] Debugging Python and C++ exposed by boost together

During the studying of Caffe, I was curious about how Caffe provides Python interface and what kind of tool uses for wrapping. Then, the answer is Boost.Python. I think for C++ developer, it is worth time to learn and I will study it sooner. In this post, I want to introduce the debugging skill which I found in this post and I believe these are very useful such as debugging Caffe with Python Layer. Here is the link:
https://stackoverflow.com/questions/38898459/debugging-python-and-c-exposed-by-boost-together



And it provides a useful approach to deal with this kind of debugging Python and C++ together as follows: http://www.boost.org/doc/libs/1_61_0/libs/python/doc/html/faq/how_do_i_debug_my_python_extensi.html

I use its way to try debugging a little bit and it works well. Here is a simple example using Caffe Python.

$ gdb python

(gdb) target exec python
(gdb) run

>>> import caffe
>>> [C-c]   # Ctrl + C

(gdb) break caffe::set_mode_cpu()  # Please refer to $(CAFFE_ROOT)/python/caffe/_caffe.cpp
(gdb) cont
>>> 
>>> caffe.set_mode_cpu()

Breakpoint 2, 0x00007ffff0e21750 in caffe::set_mode_cpu() ()
   from /home/liudanny/git/py-faster-rcnn/caffe-fast-rcnn/python/caffe/_caffe.so
(gdb) 
Continuing.
(gdb) ... you can then do debugging stuff ...

No comments: