【问题标题】:VSCode Debug C++: Why does the flow not stop at breakpoint?VSCode 调试 C++:为什么流程不会在断点处停止?
【发布时间】:2016-11-19 21:55:36
【问题描述】:

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
        }
    ]
}

【问题讨论】:

  • 如果我的答案解决了您的问题,请随时将我的答案标记为解决方案;)

标签: c++ debugging visual-studio-code


【解决方案1】:

注意,如何编译代码:
为了能够调试,您需要编译例如带有g++ 带有标志-g

【讨论】:

    【解决方案2】:

    我遇到同样的问题已经有一段时间了,现在我可以编写一个适用于所有 C 和 CPP 程序的工作配置,并且您不需要在执行期间进行任何更改。

    • 安装 Code-Runner 扩展
    • 将下面给出的配置粘贴到您的 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)Launch )。它将从工作断点和其他东西开始调试。

    【讨论】:

    • 这让我意识到我在编译命令中遗漏了 -g 参数,以及如何在 gdb 中使用文件名。
    【解决方案3】:

    我很确定

    "cwd": "${workspaceRoot}/build"

    不正确,因为“cwd”应该包含源代码的路径。否则断点无法从源代码映射到您的程序。

    您是否尝试将其更改为

    "cwd": "${workspaceRoot}/InfiniTAM"

    ?

    目前我也遇到了 VSCode 和 C 的调试问题,这也可能与您的问题有关。因此,我可能会很快更新我的帖子,并附上我的问题的链接。

    【讨论】:

      猜你喜欢
      • 2021-07-21
      • 2020-02-08
      • 2021-04-16
      • 2014-04-12
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 2013-09-26
      • 2023-03-12
      相关资源
      最近更新 更多