在vscode中,启动调试依赖于launch.json。
该文件位于工程目录下的.vscode文件夹中。如果不存在可以自己创建。
以gdb启动程序
{ "version": "0.2.0", "configurations": [ { "name": "Debug Program", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/your_exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
|
通过附加方式调试程序
{ "version": "0.2.0", "configurations": [ { "name": "Attach", "type": "cppdbg", "request": "attach", "processId": "${command:pickProcess}", "program": "${workspaceFolder}/your_exe", "MIMode": "gdb", "setupCommands": [ { "description": "启用pretty-print", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "symbolLoadInfo": { "loadAll": true } }, ] }
|
Python调用C++库的联合调试
这里推荐安装vscode插件Python C++ Debugger。
安装完成后,在launch.json中设置
{ "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", "processId": "", }, { "name": "Python: Current File", "type": "debugpy", "request": "launch", "program": "${file}", "console": "integratedTerminal" } ] }
|
打开python脚本,然后在左侧的调试项中选择Python C++ Debug启动调试,即可同时应用C++和Python的断点。