I’m debugging TVM workflows where Python frontend code calling backend C++ implementations. Specifically, I need to step through TVM’s C++ source code during execution of Python code – for example, when running python frontend code tvm.meta_schedule.tune(), I expect the debugger to jump from Python into corresponding C++ functions for line-by-line debugging.
Previously, I successfully used VSCode’s python C++ debugger plugin for this exact purpose. However, this solution has recently stopped working and I cannot restore its functionality.
Given that the python C++ debugger plugin appears to be unmaintained, I no longer consider it a sustainable approach. I would greatly appreciate insights on how others in the community achieve reliable Python-C++ mixed debugging with TVM.
Specifically:
What tools/workflows are you currently using?
Are there maintained VSCode alternatives or more robust methods?
Python-C++ Mixed Debugging Configuration in VSCode
The following .vscode/launch.json configuration enables mixed debugging of TVM’s Python frontend (Python debugger) and C++ backend (GDB) in VSCode.
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
/*
* Configuration 1: Hybrid Python + C++ Debugging for TVM.
* Purpose: Debug both Python frontend and C++ backend simultaneously.
* Mechanism: Launches Python script while attaching to C++ process.
* Use: This is a hybrid debugging approach, where users should launch
* the Python script first, and then the C++ process is automatically
* attached to.
* Note:
* - Requires `benjamin-simmonds.pythoncpp-debug` (Python C++ Debugger)
* extension for C++ debugging.
* - The following 1.1 and 1.2 configurations are subordinate to this configuration.
*/
{
"name": "Full Auto Debug (Python+C++)",
"type": "pythoncpp",
"request": "launch",
"pythonLaunchName": "Python: TVM Frontend",
"cppAttachName": "C++: TVM Backend",
},
/*
* Configuration 1.1: Python Frontend Debugger.
* Purpose: Debug Python components of TVM.
*/
{
"name": "Python: TVM Frontend",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"purpose": [
"debug-in-terminal"
],
"args": [],
"env": {},
"gevent": false
},
/*
* Configuration 1.2: C++ Backend Attach Debugger.
* Purpose: Debug TVM's C++ runtime.
* Note:
* - Customize `"program"` entry to your venv python executable path.
*/
{
"name": "C++: TVM Backend",
"type": "cppdbg",
"request": "attach",
// Customize this to your venv python executable path
"program": "/home/user/miniconda3/envs/tvm-build-venv/bin/python3",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
/*
* Configuration 2: Pure C++ Debugging.
* Purpose: Debug standalone C++ executables.
* Use: When testing C++ components without Python
* Note:
* - Customize `"program"` entry to your C++ executable path.
*/
{
"name": "Pure C++ Debug",
"type": "cppdbg",
"request": "launch",
// Customize `"program"` entry to your C++ executable path.
"program": "${workspaceFolder}/oot-tvm-example-project/build/oottvm_test",
"args": [],
"cwd": "${workspaceFolder}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
],
"environment": [
{
"name": "EXAMPLEKEY",
"value": "EXAMPLEVALUE"
}
]
},
],
}
1. Required VSCode Extensions
Before using this configuration to debug TVM, we should install the following extensions for VSCode:
Python Debugger: Search ms-python.debugpy in VSCode extension marketplace.
C/C++: Search ms-vscode.cpptools in VSCode extension marketplace.
Python C++ Debugger: Search benjamin-simmonds.pythoncpp-debug in VSCode extension marketplace.
After installing the extensions, we should copy the .vscode/launch.json file to the root directory of your own TVM project. And the next steps will explain some details that you should modify in the launch.json file.
2. Debugging Modes and Usage
The current configuration supports two debugging modes:
Hybrid Python Frontend + C++ Backend Debugging for TVM
Pure C++ Backend Debugging for TVM
As the fowllowing image shows, we can choose the debugging mode in graphical interface. Ther are four choices:
Full Auto Debug (Python+C++) is the entry for Hybrid Python Frontend + C++ Backend Debugging.
Python: TVM Frontend is responsible for the debugging of the Python Frontend.
C++: TVM Backend is responsible for the debugging of the C++ Backend.
Pure C++ Debug (C++) is the entry for Pure C++ Backend Debugging.
2.1 Hybrid Python + C++ Debugging for TVM
This is a hybrid debugging approach, and requires users to first launch the Python script, after which the C++ process will be automatically attached.
IMPORTANT
Customize the "program" entry in .vscode/launch.json to point to your Python virtual environment executable. Example path: