Linux c 开发-6 使用WSL_Ubuntu远程调试Linux程序

vscode除了使用ssh方式连接调试外,还有一种使用wsl_remote方式调试,这种方式和ssh界面什么的都一样,但是多了一个打开目录功能。

文件上点右键可以直接通过Explore进入代码文件所在目录

但区别在左下角有WSL:XXX的字样,这种方式无法直接启动调试(后来发现是因为本地bin下的gdb,gdbserver被替换成了arm版本),需要使用gdbserver方式,在服务端

使用-g 参数生成带调试信息的文件,然后使用gdbserver 127.0.0.1:1234 a.out启动监听,vscode中配置如下

{
    "configurations": [
    {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/a.out",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerServerAddress": "127.0.0.1:1234",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    }
    ]
}

然后就可以启动单步调试了。  

1、建了一个小群:616945527(软件), 欢迎大家加入,加群口令abc123,硬件嵌入式开发者推荐75764412(单片机)。
闲置域名www.nsxz.com出售(等宽等高字符四字域名,可组合多种有意义词语)。
原文地址:https://www.cnblogs.com/zhaogaojian/p/14579968.html