Note: This is a community-maintained fork of the original Python C++ Debugger extension by Benjamin Simmonds.
This fork is not officially maintained by the original author. The code is largely unchanged from the original, but with an added default configuration to support debugging out of the box on macOS. The extension is also made available on the Open VSX Registry.
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)
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: defaultwill automatically choose the appropriate debugger based on your platform (LLDB for macOS, GDB for Linux, MS debugger for Windows)cppConfig: default (win) Attachwill attach the C++ debugger with the(Windows) Attachconfig.cppConfig: default (gdb) Attachwill attach the C++ debugger with the(gdb) Attachconfig. This will also set the program path automatically to the path of the current python interpreter and lookup the gdb path.cppConfig: default (lldb) Attachwill attach the C++ debugger with the(lldb) Attachconfig for macOS users.
{
"version": "0.3.0",
"configurations": [
{
"name": "Python C++ Debug",
"type": "pythoncpp",
"request": "launch",
"pythonConfig": "default",
"cppConfig": "default"
}
]
}To manually define the configurations you can set the attributes pythonLaunchName & cppAttachName to the name of the configuration you wish to use from your launch.json file.
The following is an example launch.json file for windows users. If your working on Linux make sure to have a (gdb) Attach configuration instead of (Windows) Attach.
{
"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": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}When you start Python C++ Debug it launches a Python debugger and attaches a C++ debugger to it by using the processId of the python debugger. As soon as both debuggers are attached the Python C++ debugger terminates.
This extension is available on the Open VSX Registry.
The original extension is still available on the VS Code Marketplace. On MacOs, this requires a manual configuration for LLDB.
You can also install this extension manually by downloading the .vsix file from the Open VSX Registry.
- Make sure the shared object files (.so/.dll) you are loading your functions from have been compiled with
debug info. - Between consecutive
breakpointswhere one is located in python and the other in the C++ code, only the 'continue' button will work correctly. - Additionally, the
restart buttonisn't supported due to the Python debugger changing its processId after a restart.
This is a community-maintained fork. Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Run
yarn lintandyarn formatto ensure code quality - Submit a pull request
This project is licensed under the MIT License.
