vscode附着调试

我有一个程序,是别的程序调用启动的,所以需要等它的进程启动后,再附着上去调试。

编写Launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/cmakeBuild/build/bin/abc",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/cmakeBuild/build/bin",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "preLaunchTask": "",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "envFile": "${workspaceFolder}/.env"
        },
        {
            "name":"(gdb) Attach",
            "type": "cppdbg",
            "request": "attach"
            "processId":"${command:pickProcess}",
            "program": "${workspaceRoot}/cmakeBuild/build/bin/abc",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

调试时,选(gdb) Attach,等要调试的进程启动了,按F5,会跳出选择进程的窗口,选择要附加的进程, 附加后,就可以调试了,以前设置的断点,也会被捕捉中断。

有时候,我们要调试的是在进程启动时的代码,等我们附着上后,设置的断点已经运行过去了。这时候可以在进程启动的地方,加延时,方便附着。

int loop = 0;
while(loop <20)
{
    sleep(1);
    ++loop;
}

这个要加在初始化代码后面,不要影响初始化。会sleep 20秒,附着上后,暂停,修改loop大于20,就退出循环了,往后走了。vscode里,有时候loop会修改不了,就等它自己超过20退出吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值