如何在添加文件的情况下在VSCode中调试C++程序
How to debug C++ program in VSCode with file added
我可以在不添加文件的情况下进行调试,但是,我不知道如何处理添加的文件。
命令如下:
g++ -g --std=c++11 lab1.cpp -o lab1
./lab1 ./tests/extracredit-test-0.txt
以下是我的task.json
和launch.json
.我想知道如何修改它以支持添加文件的调试。
启动.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"preLaunchTask": "build active file",
"name": "CodeLLDB",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
},
{
"preLaunchTask": "build active file",
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
},
{
"name": "GDB",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"cwd": "${workspaceFolder}",
"MIMode": "gdb"
}
]
}
任务.json
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
"version": "2.0.0",
"tasks": [
{
"label": "build active file",
"type": "shell",
"command": "g++ --std=c++11 ${file} -g -o ${fileDirname}/${fileBasenameNoExtension}",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"osx": {
"command": "g++ --std=c++11 ${file} -g -o ${fileDirname}/${fileBasenameNoExtension}",
},
"windows": {
"command": "g++",
"args": [
"-ggdb",
""${file}"",
"--std=c++11",
"-o",
""${fileDirname}\${fileBasenameNoExtension}""
]
}
}
]
}
如何在添加文件的情况下在VSCode中调试C++程序
您正在使用 GCC。考虑升级到 GCC 10。然后使用g++ -Wall -Wextra -g
(所有警告和 DWARF 调试信息(进行编译并使用 GDB 调试器。您可能会对GCC 10中引入的静态分析工具和/或Frama-C或Clang Static Analyzer等工具感兴趣。
阅读 GCC、VSCode 和您最喜欢的调试器的文档。
另见本报告草稿。
如果你编译了一个大软件(例如一百万行C++(,你可能也会对通过构建自动化工具(如ninja或GNU make(将GCC与ccache或冰淇淋或GCC预编译头文件相结合感兴趣。在某些情况下,您可能会对某些C++代码生成器(如SWIG或ANTLR(感兴趣。在某些项目中,您将编写自己的C++代码生成器(例如使用Guile,GPP,GNU gawk,Python或m4(。请注意,GCC 在内部使用多个C++代码生成器,并接受插件。
在几个开源项目的源代码中寻找灵感,如Qt,Wt,Clang,libbacktrace或FLTK。你也可以对LinuxFromScratch感兴趣。
这很简单,在这个代码片段中
"configurations": [
{
"preLaunchTask": "build active file",
"name": "CodeLLDB",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
},
只需添加像网络这样的文件.txt在 args 中,在这种情况下,就像
"args": ["network.txt"]
这就完成了!
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 在linux上调试巨大的C++项目
- 为什么使用__LINE_的代码在发布模式下在MSVC下编译,而不是在调试模式下
- 如何针对特定情况调试和修复此双自由内存损坏问题
- 正在VS调试器中监视映射条目
- 使用调试/崩溃报告将应用程序部署到客户端
- VC++本机单元测试,找不到调试符号
- 如何在C++生成器中禁用"使用调试.dcus"
- 使用vscode调试时,GDB意外退出
- 即使使用调试编译标志,表达式也是"optimized out"
- 调试 CUDA MMU 故障
- 小字符串优化(调试与发布模式)
- 调试和自由执行中的信号处理
- 调试编译的服务器在数据库打开时崩溃
- Visual Studio 调试优化如何工作?
- 如何配置Visual Studio Code以使用cygwin,cmake和gcc进行调试
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 如何在大型c++项目的可视化代码中设置调试
- Qt 调试显示行号
- 如何将可变参数模板转换为多个单个模板?(C++竞争编程调试模板)