4

For test example, I have this test C++ class which I exported to Python using boost.(from boost website)

#include <boost/python.hpp>
using namespace boost::python;

struct WorldC
{
    void set(std::string msg) { this->msg = msg; }
    std::string greet() { return msg; }
    std::string msg;
};

BOOST_PYTHON_MODULE(hello)
{
    class_<WorldC>("WorldP")
        .def("greet", &WorldC::greet)
        .def("set", &WorldC::set)
    ;
}

I compiled this code by g++ -g -shared -o hello.so -fPIC hello.cpp -lboost_python -lpython2.7 -I/usr/local/include/python2.7 and tested it ok. The test script pp1.py is like this :

import hello
a = hello.WorldP()
a.set('ahahahah')    # <-- line 3
print a.greet()
print('print1')
b = hello.WorldP()
b.set('bhbhbhbh')
print b.greet()
print('print2')
print('program done')

This code runs ok either in interacitive mode and as a script.

ckim@stph45:~/python/hello] python pp1.py
ahahahah
print1
bhbhbhbh
print2
program done

I'm using DDD for visual debugging. When I give the command ddd -pydb pp1.py, I can do Python code debugging. When I'm inside the debugger, I can give next command and see the result. But when the debugger is for example in line 3, when I give step command, it just passes the line not entering into the c++ code. How can I make this work? (I tried with just gdb, but it's the same- not entering into c++ code.)

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • you could (temporarily) try to insert `__asm__("int $3")` in the code of your C++ module, see if gdb/DDD catches it. – Jean-François Fabre Aug 16 '16 at 08:28
  • it catches the interrupt. then what can I do more? though I want to set breakpoints dynamitcally.. – Chan Kim Aug 16 '16 at 08:38
  • do you see the source? Have you tried `info shared` to see which dll is loaded and if there is a `(*)` to indicate that symbols are loaded? – Jean-François Fabre Aug 16 '16 at 08:42
  • I see the python source, but when interrupt is caught, I see the message `PYDB terminated abnormally(Trace/breakpoint trap)`. For `info shared`, I get `Undefined info command shared`. Thanks for trying to help..:) – Chan Kim Aug 16 '16 at 08:46
  • What add-on are you using with gdb to single-step python code? – Mark Plotnick Aug 16 '16 at 13:50
  • I don't know. I installed pydb1.26 which is an extended version of Python debugger pdb.py. pdb.py works with GUI frontend ddd. (I checked the README file of pydb1.26 now that you asked)`.. Hmm maybe I was not using gdb. (the README says it's trying to follow gdb command). – Chan Kim Aug 16 '16 at 14:13
  • @Jean-FrançoisFabre see my answer, now I can debug C++ while runnig python program! :) – Chan Kim Aug 18 '16 at 07:38

0 Answers0