【问题标题】:How can I set up launch.json in Visual Code to debbug C如何在 Visual Code 中设置 launch.json 来调试 C
【发布时间】:2018-02-06 11:16:12
【问题描述】:

我是 Visual Code 的新手。我想将调试功能与可视代码一起使用。 但是有一个问题可以做到。错误的launch.json设置可能会发生(在我的选择中)

我正在使用 ma​​c os 最新版本。

我自己参考了一些页面。

https://code.visualstudio.com/docs/languages/cpp

https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md

https://code.visualstudio.com/docs/python/debugging

但是我看到了同样的错误。它说“启动:程序 '${/Users/bpk/Documents/Study/C/Study}/study' 不存在”

这是我下面的 launch.json 文件

    {
    "version": "0.2.0",
    "configurations": [

{
    "name": "Python3",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${config:python.pythonPath}",
    "program": "${/Users/bpk/Documents/Study/Python3/study.py}",
    "cwd": "${/Users/bpk/Documents/Study/Python3}",
    "env": {},
    "envFile": "${/Users/bpk/Documents/Study/Python3}/.env",
    "debugOptions": [
        "RedirectOutput"
    ]
},
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${/Users/bpk/Documents/Study/C/Study}/study",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${/Users/bpk/Documents/Study/C/Study}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        { 
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${/Users/bpk/Documents/Study/C/Study}/study",
            "processId": "${command:pickProcess}",
            "MIMode": "gdb"
        }
    ],
    "compounds": []
}

=cmd-param-changed,param="pagination",value="off"
[New Thread 0x1803 of process 16326]
[New Thread 0x1a03 of process 16326]
[New Thread 0x2703 of process 16326]
ERROR: Unable to start debugging. Unexpected GDB output from command        "-exec-run". Warning:
Cannot insert breakpoint -1.
Cannot access memory at address 0xf782
The program '/Users/jaekwangkim/Documents/Workspace/Project/C/PE_File_Assembler/a.out' has exited with code 42 (0x0000002a).

上面的消息是来自可视代码的调试控制台日志

感谢阅读我的第一个问题!

【问题讨论】:

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


    【解决方案1】:

    我认为您混淆了变量和字符串 ${...} 表示在可视代码中使用的变量。目录路径不需要包含 ${}

    您的 Python3 配置应如下所示:

    {
        "name": "Python3",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config:python.pythonPath}",
        "program": "/Users/bpk/Documents/Study/Python3/study.py",
        "cwd": "/Users/bpk/Documents/Study/Python3",
        "env": {},
        "envFile": "/Users/bpk/Documents/Study/Python3/.env",
        "debugOptions": [
            "RedirectOutput"
        ]
    },
    

    对 C 调试配置的更改与 Python 大致相同,应如下所示:

     {
         "name": "(gdb) Launch",
         "type": "cppdbg",
         "request": "launch",
         "program": "/Users/bpk/Documents/Study/C/Study/study",
         "args": [],
         "stopAtEntry": false,
         "cwd": "/Users/bpk/Documents/Study/C/Study",
         "environment": [],
         "externalConsole": false,
         "MIMode": "gdb",
         "setupCommands": [
             {
                 "description": "Enable pretty-printing for gdb",
                 "text": "-enable-pretty-printing",
                 "ignoreFailures": true
             }
         ]
     },
    

    【讨论】:

      猜你喜欢
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-09
      • 2016-04-16
      • 2017-05-10
      • 2016-09-04
      • 2019-07-20
      相关资源
      最近更新 更多