Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode Debug C++: Why does the flow not stop at breakpoint?

VSCode Version:1.3.1

OS Version:Ubuntu 14.04

I debug a C++ project on Ubuntu 14.04. I run cmake to produce an executable file and setting VSCode config file. When I press F5 to debug, the program runs well, but it doesn't stop at breakpoint!

my source code is in ${workspaceRoot}/InfiniTAM

executable file is in ${workspaceRoot}/build

My config file:

tasjs.json

    {
"version": "0.1.0",    
"command": "echo",    
"isShellCommand": true,    
"args": ["InfiniTAM!"],    
"showOutput": "always"    
}

launch.json    
{
    "version": "0.2.0",    
    "configurations": [    
        {    
            "name": "C++ Launch (GDB)",    
            "type": "cppdbg",    
            "request": "launch",
            "launchOptionType": "Local",    
            "targetArchitecture": "x64",    
            "program": "${workspaceRoot}/build/InfiniTAM",    
            "args": ["Teddy/calib.txt", "Teddy/Frames/%04i.ppm","Teddy/Frames/%04i.pgm"],    
            "stopAtEntry": false,    
            "cwd": "${workspaceRoot}/build",    
            "environment": [],    
            "externalConsole": true
        }
    ]
}
like image 817
李仕杰 Avatar asked Jul 17 '16 02:07

李仕杰


2 Answers

Watch out, how you compile your code:
In order to be able to debug you need to compile e.g. with g++ with the flag -g.

like image 196
Benjamin Zach Avatar answered Oct 16 '22 15:10

Benjamin Zach


I have had this same problem for a while and am now able to write a working configuration which works universally for all C and CPP programs and you don't need to change anything during execution.

  • Install Code-Runner Extention.
  • Paste the configuration given below into your settings.json file.

     {
       "code-runner.executorMap": {
    
        "javascript": "nodejs",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc -g \"$fileName\" -o \"$fileNameWithoutExt\" && $dir\"$fileNameWithoutExt\"",
        "cpp": "cd $dir && g++ -g \"$fileName\" -o \"$fileNameWithoutExt\" && $dir\"$fileNameWithoutExt\"",
        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "python3",
        "perl": "perl",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
        "groovy": "groovy",
        "powershell": "powershell -ExecutionPolicy ByPass -File",
        "bat": "cmd /c",
        "shellscript": "bash",
        "fsharp": "fsi",
        "csharp": "scriptcs",
        "vbscript": "cscript //Nologo",
        "typescript": "ts-node",
        "coffeescript": "coffee",
        "scala": "scala",
        "swift": "swift",
        "julia": "julia",
        "crystal": "crystal",
        "ocaml": "ocaml",
        "r": "Rscript",
        "applescript": "osascript",
        "clojure": "lein exec",
        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
        "racket": "racket",
        "ahk": "autohotkey",
        "autoit": "autoit3",
        "kotlin": "cd $dir && kotlinc $fileName -include-runtime -d $fileNameWithoutExt.jar && java -jar $fileNameWithoutExt.jar",
        "dart": "dart",
        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        "haskell": "runhaskell",
        "nim": "nim compile --verbosity:0 --hints:off --run"
    }
    }
    
  • Paste the below code in launch.json by clicking the settings symbol in the debugging panel (present at top left).

    {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
      ]
    }
    
  • After this When ever you press ctrl+Alt+N it compiles and executes and you can see the output in the output panel.

  • When You Press F5 after selecting the right Task ( choose (gdb)Launch ). It will start the debugging with working break points and stuff.

like image 43
Natesh bhat Avatar answered Oct 16 '22 16:10

Natesh bhat