Personal blog Link: Ubuntu16.04 in vscode How to debug C language program breakpoints
Problem: Environment is Ubuntu16.04, how to use Vscode breakpoint to debug C language program.
Write code without debugging environment is unbearable, so toss a bit, finally succeeded. The process of tossing is this:
1, first install C + + extension, direct search the first is, or click this link to view its Help document for installation.
2, then open the current project directory, the left point debugging options, click Add Configuration, generated a Launch.json file, the contents are as follows:
{ // 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}/LearnC/bin/a.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }]}
All content is the default generated configuration, I just modified the "program" line, specified as the compiled executable file. This will debug this file by default when debugging.
Related actions:
Select Add Configuration
Select C + + (GDB/LLDB)
3, edit the code, after completion, the first to compile, the command is as follows:
$ gcc -g -o /path/LearnC/bin/a.out [[SOURCE_FILE]]
The first path specifies the generated file, and Source_file indicates the path of the C language file if the file path specified by the program parameter is the previous one.
4, then open debugging, my shortcut is F5, opened, you can directly run to the breakpoint, the effect is as follows:
Ubuntu16.04 Vscode How to debug a C language program in a breakpoint