How do you debug the C++ core while launching from Python?

Hello,

Although TVM has a wide set of Python APIs for the core functionality which is implemented in C++. In some cases it would be very beneficial to be able to set a breakpoint in a C++ file and have a Python script launch and have the debbuger stop at that line.

Obviously this requires compiling the tvm library with debug flags, but it also requires more than this.

Anyone want to share their way of doing the mixed Python/C++ debugging?

You can use gdb to do this – make sure you compiled with debug mode enabled, then run

gdb --args python3 /path/to/your/file

Then gdb will open and you can set breakpoints if you want. Then enter “run” and your python program will run but you can see where failures occur in C++.

You might need to install some packages before this works. See this page for more info: https://wiki.python.org/moin/DebuggingWithGdb

Thanks for the hints.

Any way of doing debug with the VSCode/Pycharm visual representation? command line gdb is an art that I dont really master

I do this using CLion (which supports Python as well as C++). You can set up two different launch configurations for your program, one that launches it as a Python app and the other as a C++ app. Then if I need to debug the C++, I can launch it in debug using the C++ config and the graphical debugger will attach. The only downside is you can’t step between Python and C++, but I’m not aware of any tool that lets you do that.