Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a python - c++ program

I got a quite complex distributed programming framework where there are:

  1. a Controller, BC, written in Python as a twisted plugin, which is running on some machine;
  2. N Daemons, BM, written in Python but wrapping a C++ core as a shared library, in the following way:

import imp handle = imp.load_dynamic('mylib', '../libmy.so')

Then each BM talks to the BC via a jsonrpc interaction, but we don't care about this.

What I would do is to debug, possibly in a step into/step over/step debug fashion but not limited to, a BM process, which at the front-end appears as a homogeneous stream of characters in a single terminal.

I'm strongly interested into the C++ part, considering the Python code almost final to release and working well.

Due to this language mixture I'm a bit confused about what type of tool may be useful.

like image 826
Patrizio Bertoni Avatar asked Apr 20 '15 13:04

Patrizio Bertoni


1 Answers

You can use gdb on any C/C++ extensions loaded through Python. The way this is done is:

(gdb) target exec python
(gdb) run
 >>> import your_extension as ye
 >>> ye.do_something ()
 >>> # do your python here
 >>> # or just run your python script from here
(gdb) do debugging stuff

You can also add breakpoints/do full C/C++ debugging via gdb. Tip from boost::python docs

like image 186
WakkaDojo Avatar answered Oct 19 '22 15:10

WakkaDojo