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:
"program": "/home/user/miniconda3/envs/tvm-build-venv/bin/python3"
Commands that interact with the Debug Console should be preceded by
-exec
, example:
-exec p pc
or-exec call tvm::Dump(mod)
Example:
2.2 Pure C++ Debugging
This is a pure C++ debugging approach, where users can debug C++ components without Python scripts.
IMPORTANT
Customize the
"program"
entry in.vscode/launch.json
to your C++ executable path. Example path:
"program": "${workspaceFolder}/oot-tvm-example-project/build/oottvm_test"
Example:
You can also check .vscode/launch.json
for debugging mode details - we’ve added extensive comments there.
3. Maintenance
This configuration is maintained at: