[Linux]用VScode 调试Linux命令行带参数可执行程序

最近在研究大神给我的一个程序,挺长的,如果不是单步调试估计是看不懂了,其实编译运行都是没问题的,然后注意编译的时候要加一个"-g"选项,保留调试信息,最好不要优化,即"-O0",运行时的命令行参数是:

./mkimage_imx8mm -fit -loader u-boot-spl-ddr.bin 0x7E1000 -out flash.bin

然后需要在调试时弹出来的launch.json配置文件中设置,主要注意两个地方,
第一个是指定运行程序的位置:"program": "${workspaceFolder}/iMX8MM/mkimage_imx8mm",
另一个要注意的地方带的参数之间每个空格都要用引号分隔开:"args": ["-fit","-loader","u-boot-spl-ddr.bin","0x7E1000","-out","flash.bin"]
其他基本保持默认就可以了。
完整的launch.json文件如下所示:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/iMX8MM/mkimage_imx8mm",
            "args": ["-fit","-loader","u-boot-spl-ddr.bin","0x7E1000","-out","flash.bin"],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}/iMX8MM/",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

你可能感兴趣的:(Linux)