VS code debug c代码 配置
1.配置c_cpp_properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "E:\\MINGW\\bin\\gcc.exe", "cStandard": "c11", "cppStandard": "gnu++14", "intelliSenseMode": "windows-gcc-x86" } ], "version": 4 }
2.配置launch.json
/* launch.json */ { "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", //${fileDirname}为文件所在目录 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", //调试程序时的工作目录,可改成${fileDirname} "environment": [], "externalConsole": true, // 为true时使用系统的控制台窗口 "internalConsoleOptions": "neverOpen", "MIMode": "gdb", "miDebuggerPath": "E:\\MinGW\\bin\\gdb.exe", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "将反汇编风格设置为 Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ], "preLaunchTask": "gcc" }, ] }
3.配置tasks.json
/* tasks.json */ { "tasks": [ { "type": "shell", "label": "gcc", //一定要和launch.json的preLaunchTask名字一致 "command": "E:\\MinGW\\bin\\gcc.exe", "args": [ "-fdiagnostics-color=always", "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe", "-fexec-charset=GBK", //GBK编码,用于解决Winows中文乱码 ], "options": { "cwd": "E:\\MinGW\\bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "调试器生成的任务。" } ], "version": "2.0.0" }
4.加断点
5.debug