简体   繁体   中英

How to jump into python code in c++ call through GDB debugger?

I have a C++ project which was written by others, which calls python code at the end of the execution.

In the C++ initializer, it defines a pHandle:

pHandle_ = PyObject_CallObject(pLoad_, NULL);
PyGILState_Release(gstate);

Then it calls python code this way:

PyObject *pyValue = PyObject_CallObject(pProcess_, pArgs);

pProcess_ and pArgs are created earlier. The python code's file name is 'runLogic.py' and the function executed in runLogic.py is 'process()'.

Is there a way to break into the python's process() function while I debug in c++ through GDB? In C++ code, I can step through until the line above, copied again below: PyObject *pyValue = PyObject_CallObject(pProcess_, pArgs);

Then I don't know how to jump into the Python's function.

Is there a way to do that? I want to trace the full logic of the code, in addition to C++'s code.

Then I don't know how to jump into the Python's function.

Presumably you want to now step through Python code.

GDB doesn't know how to do that, but pdb can.

Assuming you can modify runLogic.py , add import pdb to the top of the file, and pdb.set_trace() in the process() function.

This will let you step through Python code. If you have breakpoints in C++ , and Python code calls back into C++ , these breakpoints will still be active, you should be able to debug both C++ and Python .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM