VSCode版本:1.3.1
操作系统版本:Ubuntu 14.04
我在Ubuntu 14.04上调试了一个C ++项目。我运行cmake来生成可执行文件并设置VSCode配置文件。当我按F5进行调试时,程序运行良好,但它不会在断点处停止!
我的源代码位于${workspaceRoot}/InfiniTAM
可执行文件位于${workspaceRoot}/build
我的配置文件:
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
}
]
}
答案 0 :(得分:7)
当心,如何编译代码:
为了能够进行调试,您需要编译例如g++
和标志-g
。
答案 1 :(得分:1)
我有一段时间遇到同样的问题,我现在能够编写一个适用于所有C和CPP程序的工作配置,并且您不需要在执行期间更改任何内容。
将下面给出的配置粘贴到 settings.json
文件中。
{
"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"
}
}
点击调试面板中的设置符号(位于左上角),将以下代码粘贴到 launch.json
中。
{
"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
}
]
}
]
}
此后当您按ctrl + Alt + N时,它会编译并执行,您可以在输出面板中看到输出。
选择正确的任务后按F5(选择(gdb)启动)。它将使用工作断点和内容开始调试。
答案 2 :(得分:0)
我很确定
" cwd":" $ {workspaceRoot} / build"
是不对的,因为" cwd"应该包含源代码的路径。否则,无法将断点从源代码映射到您的程序。
您是否尝试将其更改为
" cwd":" $ {workspaceRoot} / InfiniTAM"
目前我也遇到了VSCode和C的调试问题,这也与您的问题有关。因此,我可以通过指向我的问题的链接尽快更新我的帖子。