gpt4 book ai didi

python - 如何在 Visual Code 中设置 launch.json 来调试 C

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:41:44 28 4
gpt4 key购买 nike

我是视觉代码的新手。我想在 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).

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

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

最佳答案

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

您的 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
}
]
},

关于python - 如何在 Visual Code 中设置 launch.json 来调试 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48641739/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com