What if vscode fails to debug c program
Editor to share with you what to do if vscode debug c program fails. I hope you will get something after reading this article. Let's discuss it together.
Question:
There was a problem while performing debugging:
Cannot create a "launch.json" file within the ".vscode" folder (Cannot read property 'name' of undefined)
Solution:
Create a folder
Click on the red box in the following figure to create a folder named ".vscode"
Second, create a launch.json
In the .vscode folder, create the launch.json file and copy the following code into it, where the path after miDubuggerPath is the installation path of the C++ editor
{"version": "0.2.0", "configurations": [{"name": "(gdb) Launch", / / configuration name, "type": "cppdbg", / / configuration type will be displayed in the drop-down menu of the startup configuration. Cppdbg corresponds to the debugging function provided by cpptools. It can only be cppdbg "request": "launch", / / request configuration type, and can be launch (startup) or attach (additional) "program": "${fileDirname} / ${fileBasenameNoExtension} .exe", / / the path of the program to be debugged "args": [], / / the command line parameters passed to the program during debugging Generally set to empty "stopAtEntry": false, / / when set to true, the program will be paused at the entrance of the program, which is equivalent to the working directory of "cwd": "${workspaceFolder}", / / when the program is debugged on main. This is the workspace folder. Change ${fileDirname} to the directory "environment": [], / / the environment variable "externalConsole": false, / / use a separate cmd window when it is true, which is the same as other IDE. After October 18, it was set to false to call VSC built-in terminal "internalConsoleOptions": "neverOpen", / / if it is not set to neverOpen, it will jump to the "debugging console" tab when debugging. You should not need to enter commands to gdb manually, do you? "MIMode": "gdb", / / specifies the debugger for the connection, which can be gdb or lldb. But I haven't tried lldb "miDebuggerPath": "D:\\ mingw64\\ bin\\ gdb.exe", / / debugger path. The suffix cannot be omitted under Windows, but not "setupCommands" under Linux: [{/ / template comes with it, which seems to better display the contents of the STL container. Google "description": "Enable pretty-printing for gdb", "text": "- enable-pretty-printing", "ignoreFailures": false}], "preLaunchTask": "Compile" / / tasks executed before the start of the debugging session, usually compilers. Corresponds to the label of tasks.json}]}
Third, create a tasks.json
In the .vscode file, create a new tasks.json file and edit the code
{"version": "2.0.0", "tasks": [{"label": "Compile", / / task name, corresponding to launch.json 's preLaunchTask "command": "Gmail +", / / the compiler to be used, C++ uses clang++ If the compilation fails, try gcc or Gmail +. Another problem is that there is an error in your own code: "args": ["${file}", "- o", / / specify the output file name. If this parameter is not added, a.exe will be output by default. Under Linux, the default a.out "${fileDirname} / ${fileBasenameNoExtension} .exe", "- g", / generate and debug related information "- Wall", / / enable additional warning "- static-libgcc", / / static link libgcc It is usually added with "- std=c++11", / / the latest standard of C++ is cached 17, or modify it according to your own needs], / / compile command parameter "type": "process", / / process is the vsc that parses the predefined variables and escapes and passes them directly to command. Shell is equivalent to opening shell first and then entering a command So args will parse again through shell "group": {"kind": "build", "isDefault": true / / if it is not true, ctrl shift B will manually select}, "presentation": {"echo": true, "reveal": "always" / / whether to jump to the terminal panel when performing a task Can be always,silent,never. For more information, see the VSC document "focus": false, / / set to true to focus on the terminal when executing task, but for compiling task Set to true meaningless "panel": "shared" / / compilation information of different files share a terminal panel}, / / "problemMatcher": "$gcc" / / this option captures the error message in the terminal at compile time Clang is used in this article, and double error messages may appear when turned on; only cpptools can be considered to enable}]}.
4. click the debug button at this time, and you can see the options that can be debugged.
After reading this article, I believe you have a certain understanding of "vscode debugging c program failure". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for your reading!