1 //Test.cpp2#include <stdio.h>3 intG_var =0;4 voidPrint_line (Char*str)5 {6 if(str! =NULL)7printf"%s\r\n", str);8 Else9printf"NULL string\r\n");Ten } One intMain (intargcChar**argv) A { - intL_var =1; -Print_line ("Hello world!"); theprintf"G_var =%d, L_var =%d.\r\n", G_var, L_var); - return 0; -}
View Code
Launch.json
1 {2 "version":"0.2.0",3 "configurations": [4 {5 "name":"(GDB) Launch",6 "type":"cppdbg",7 "Request":"Launch",8 " Program":"${workspaceroot}/test.exe",9 "args": [],Ten "Stopatentry":false, One "CWD":"${workspaceroot}", A "Environment": [], - "Externalconsole":true, - "Mimode":"gdb", the "Midebuggerpath":"C:\\mingw\\bin\\gdb.exe", - "Setupcommands": [ - { - "Description":"Enable pretty-printing for GDB", + "text":"-enable-pretty-printing", - "Ignorefailures":true + } A ] at } - ] -}
View Code
Tasks.json
1 {2 // Seehttps://go.microsoft.com/fwlink/?LinkId=7335583 //For the documentation about the Tasks.json format4 "version":"2.0.0",5 "Tasks": [6 {7 "TaskName":"Test",8 "type":"Shell",9 "Command":"g++",Ten "args": ["- G","${file}","- o","${workspaceroot}/test.exe"] One } A ] -}
View Code
After the compilation succeeds, the breakpoint is set in the source code, but it cannot be killed.
Later review the official C + + compiled debug documentation and try, in the Launch.json file
"Setupcommands": [
{
"description": "Enable pretty-printing for GdB",
"Text": "-enable-pretty-printing",
"Ignorefailures": True
}
]
After adding
"Prelaunchtask": "Test" configuration, debugging can be normal to stop the breakpoint. Note: Don't forget to add a comma after the "setupcommands" with the brackets '] '.
Vscode A breakpoint is not hit when debugging after a C + + compilation Build