This debugger starts a Python debugger and attaches a C++ debugger to it for debugging Python code that calls functions from shared object files (.so/.dll).
To use this debug extension you must have the following extensions installed:
- Python by Microsoft (
ms-python.python) - C/C++ by Microsoft (
ms-vscode.cpptools) - CodeLLDB by Vadim Chugunov (
vadimcn.vscode-lldb) - Optional, for LLDB debugging
If you plan to use the default configuration of the Python and/or C++ debugger, you don't need to define them manually.
-
Python:
pythonConfig: defaultwill start the Python debugger with the default configuration (Python: Current File) -
C++:
cppConfig: default (win) Attach- Windows debugger (cppvsdbg)cppConfig: default (gdb) Attach- GDB debugger (Linux recommended)cppConfig: default (codelldb) Attach- CodeLLDB debugger (macOS recommended, also works on Linux)
{
"version": "0.2.0",
"configurations": [
{
"name": "Python C++ Debug",
"type": "pythoncpp",
"request": "launch",
"pythonConfig": "default",
"cppConfig": "default (gdb) Attach"
}
]
}To manually define the configurations, set pythonLaunchName & cppAttachName to the name of the configuration you wish to use from your launch.json file.
{
"version": "0.2.0",
"configurations": [
{
"name": "Python C++ Debug",
"type": "pythoncpp",
"request": "launch",
"pythonLaunchName": "Python: Current File",
"cppAttachName": "(Windows) Attach"
},
{
"name": "(Windows) Attach",
"type": "cppvsdbg",
"request": "attach",
"processId": ""
},
{
"name": "Python: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}{
"version": "0.2.0",
"configurations": [
{
"name": "Python C++ Debug",
"type": "pythoncpp",
"request": "launch",
"pythonLaunchName": "Python: Current File",
"cppAttachName": "(gdb) Attach"
},
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/usr/bin/python3",
"processId": "",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Python: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}Note: Requires the CodeLLDB extension.
{
"version": "0.2.0",
"configurations": [
{
"name": "Python C++ Debug",
"type": "pythoncpp",
"request": "launch",
"pythonLaunchName": "Python: Current File",
"cppAttachName": "(codelldb) Attach"
},
{
"name": "(codelldb) Attach",
"type": "lldb",
"request": "attach",
"pid": ""
},
{
"name": "Python: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}When you start Python C++ Debug, it:
- Launches a Python debugger with
stopOnEntryenabled - Gets the Python process ID
- Attaches the C++ debugger to that process
- Continues Python execution (if
stopOnEntrywasn't originally set)
- Make sure the shared object files (.so/.dll) you are loading have been compiled with debug info (
-gflag). - Between consecutive breakpoints where one is in Python and the other in C++ code, only the Continue button will work correctly.
- The Restart button isn't supported due to the Python debugger changing its processId after a restart.
# Install dependencies
yarn install
# Compile TypeScript
yarn run compile
# Package extension
NODE_OPTIONS=--openssl-legacy-provider vsce package