Debug cpp Modules Imported by Python
Problem
I found a bug when building my model with mxnet
, see here. It seems mxnet
people are busy doing other things, therefore I have to solve this by myself. When I am trying to debug mxnet
package using lldb
with the following command:
1 | lldb -- python test.py |
and the following command to set a breakpoint in file:
1 | b file:line |
lldb
cannot successfully set the breakpoint. It seems the python module is not loaded at that time and lldb
cannot find the breakpoint.
Solution
If the problem is on the module loading, we can set a breakpoint in python using
1 | pdb.set_trace() |
and open another term, attach lldb
to the python process using
1 | attach --pid XXXX |
then set the breakpoint, using the absolute path
1 | b \Users\odin\local\mxnet\src\imperative\imperative.cc:300 |
and continue in pdb
.
The breakpoint is then successfully set.