需要在服务器上用vscode调试cpp程序,写此记录launch.json配置和相关步骤错误导致的问题
 1.在需要运行程序的服务器上安装C/C++ Extension Pack(之前只在本地装了),可以支持调试C/C++应用程序(设置断点,单步执行,查看变量和调用栈等)

 
 安装成功后,会显示安装在了哪里
2.配置launch.json
{
    "version": "0.2.0",
    //调试器一
    "configurations": [
        {
            "name": "(gdb) HDR",				
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/Cmodel/run/xk_isp.o"
            "args": ["-if", "../../Image/input/picture1.f",
                     "-mf", "../../Image/input/picture2.f",
                     "-lf", "../../Image/input/picture3.f",
                     "-o", "../../Image/output/",
                     "-p", "./config/config.txt",
                     "-f", "raw",
                     "-s", "true"],       
            "stopAtEntry": false, 
            
            "cwd": "${workspaceFolder}/Cmodel/run",             
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                },
            ],
            "miDebuggerPath": "/usr/bin/gdb", 
        },
       	//调试器二
        {
            "name": "(gdb) noHDR",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/Cmodel/run/xk_isp.o",
            "args": ["-i", "../../Image/input/rgbb_12bpp_1920x1080_hdr.raw",
                     "-o", "../../Image/output/",
                     "-p", "./config/config_basepipe.txt",
                     "-f", "rgb",
                     "-s", "false"],                       
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/Cmodel/run",             
            "environment": [],
            "externalConsole": false, 
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                },
            ],
            "miDebuggerPath": "/usr/bin/gdb", 
        }
    ]
}
- “name”: “(gdb) HDR”,配置调试器名称。
 因为支持同时设置多个调试器,可以用不同名字区分,我设置了两个,这样就可以根据调试器名称任意选择对应调试器的配置,而不用手动去改args的配参
  
- “type”: “cppdbg”,配置调试器类型为C++调试器
 launch.json支持多种类型的调试器,比如js,python,c++等,此处是用C++,所以设置为cppdbg。调试器类型选对了,可以避免很多不必要的问题
- “request”: “launch”,配置调试器请求类型为launch(启动)
 另外一种是attach(附加),没详细了解其中的区别,用的默认值
- “program”: “${workspaceFolder}/Cmodel/run/xk_isp.o”,//配置可执行程序路径
 ${workspaceFolder} 为vsCode打开你工程文件夹的绝对路径,
 ${workspaceFolder}/Cmodel/run/xk_isp.o 即工程编译链接完成后生成的可执行文件路径
- “args”: [“-if”, “…/…/Image/input/picture1.f”,
 “-mf”, “…/…/Image/input/picture2.f”,
 “-lf”, “…/…/Image/input/picture3.f”,
 “-o”, “…/…/Image/output/”,
 “-p”, “./config/config.txt”,
 “-f”, “raw”,
 “-s”, “true”],配置main(int argc,char* argv[])传参
 等效于argc = 15,
 argv[0] = ${workspaceFolder}/Cmodel/run/xk_isp.o 执行文件的绝对路径
 argv[1] = “-if”
 argv[2] = “…/…/Image/input/picture1.f”
 argv[3] = “-mf”
 …
- “stopAtEntry”: false, 设置启动调试后,不停止在第一行程序,直接运行直到碰到第一个断点
- “cwd”: “${workspaceFolder}/Cmodel/run”, 配置可执行文件所在目录。
对于main函数带传参且参数包含相对路径的,这个配置会比较重要。最开始用的${workspaceFolder},调试运行报错“找不到…/…/Image/input/picture1.f文件”
 因为不用调试模式直接运行时,工程是通过执行bash脚本来编译链接并运行可执行程序,比如最后一行执行语句中传参的相对路径是相对本bash脚本路径,也就是${workspaceFolder}/Cmodel/run, 脚本参数中的…/…/Image/input/picture1.f 即${workspaceFolder}/Image/input/picture1.f,也就是文本实际所在位置。但是填了${workspaceFolder}之后,launch.json中args的参数…/…/Image/input/picture1.f已经不在工程目录内了
#脚本部分贴图
cd ../build/		#makefile脚本在该目录下
	make clean
	make gdb -j16 ***#需要开启调试功能,需要在原脚本文件中添加gdb编译选项,或直接-g***     
	
	echo "==============  C Linking" 
	cd ../run/
	./xk_isp.o -if ../../Image/input/picture1.f -mf ../../Image/input/picture2.f -lf ../../Image/input/picture3.f -o 	../../Image/output/ -p ./config/config.txt -f raw -s true
	
工程目录:
 
 这里有两个bash脚本,只有运行命令的带参不同,所以我配置了两个调试器分别对应HDR和noHdr
- “externalConsole”: false, //设为false,在IDE中直接显示,true是通过外部中断,比如用命令行调试
 这时候如果设为ture,能打断点,但是在断点处停不了
- “miDebuggerPath”: “/usr/bin/gdb”, //设置调试器路径
 这里用了linux自带的gdb调试工具,可以通过which gdb查询路径;也可以设置为自己安装的调试器路径
- setupCommands不影响启动,没看具体用途



















![[Linux]多线程(在Linux中的轻量级进程(LWP),怎么使用线程(接口))](https://img-blog.csdnimg.cn/direct/e20da0d5ac5c414d924eaae445536b79.png)