栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

ubuntu下vscode进行debug的配置(C/C++程序)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ubuntu下vscode进行debug的配置(C/C++程序)

利用vscode对C/C++代码进行debug,需要对以下文件进行配置。
参考:ubuntu20.04 vscode调试C++,CMake

launch.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": [
        {
            "name": "g++ - Build and debug active file", // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg",  // 配置类型,这里只能为cppdbg
            "request": "launch",  // 请求配置类型,可以为launch(启动)或attach(附加)
            "program": "${workspaceFolder}/build/ndt_trans", // 将要进行调试的程序的路径
            "args": ["4" ,"0.005"], // 程序调试时传递给程序的命令行参数
            "stopAtEntry": false,  // 设为true时程序将暂停在程序入口处               
            "cwd": "${workspaceFolder}",  // 调试程序时的工作目录
            "environment": [], // (环境变量)
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
            "MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build", // 调试会话开始前执行的任务,一般为编译程序。与tasks.json的label相对应
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

调试时如果要加入(多个)参数,在"args"里面添加,多个参数用“,”隔开。

task.json
{
    "tasks": [
        {
            "type": "shell",  // 可以为shell或process,前者相当于先打开shell再输入命令,后者是直接运行命令
            "label": "build", // 任务名称,与launch.json的preLaunchTask相对应
            "command": "cd ${workspaceFolder}/build;cmake ..;make", // 要使用的编译器
            "args": [
                
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
CMakeLists

如果使用cmake进行编译,需要对CMakeLists文件进行修改,只需添加以下语句。

set(CMAKE_BUILD_TYPE "Debug")

完成以上配置后,按F5进行调试即可。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/303371.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号