前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >vscode gcc debug dbg gdb c cpp c++ cuckoo monitor

vscode gcc debug dbg gdb c cpp c++ cuckoo monitor

作者头像
战神伽罗
发布2019-07-24 14:24:33
6860
发布2019-07-24 14:24:33
举报
文章被收录于专栏:Eureka的技术时光轴

装cygwin 或者mingGW,装gcc工具链,并将cygwin的bin目录加入环境变量PATH中。

ctrl+shift+b

代码语言:javascript
复制
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "gcc",
            "command": "g++",
            "args": [
                "-g ${file}",   //指定编译源代码文件                    
                "-o ${fileDirname}/${fileBasenameNoExtension}.exe", // 指定输出文件名,不加该参数则默认输出a.exe
                "-ggdb3",   // 生成和调试有关的信息
                "-Wall",    // 开启额外警告
                "-static-libgcc",   // 静态链接
                "-std=c++17",       // 使用最新的c++17标准
                "-Wno-format",
                "-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8
                "-fexec-charset=GBK"//编译器输出文本编码 自行选择
            ],

            "type": "shell",

            "group": {
                "kind": "build",
                "isDefault": true
            },

            "presentation": {
                "echo": true,
                "reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never
                 "focus": false,
                 "panel": "shared" // 不同的文件的编译信息共享一个终端面板
            },

            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative", "\\"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

launch.json

代码语言:javascript
复制
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            //"program": "${file}.exe",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            //"cwd": "${workspaceFolder}",
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb.exe",
            "preLaunchTask": "gcc",
            "windows": {
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
        }
    ]
}

cuckoo的配置如下,其中参数是从makefile里面提取出来的。

代码语言:javascript
复制
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "i686-w64-mingw32-gcc",
            "args": [
                "-m32 -Wall -Wextra -std=c99 -static -Wno-missing-field-initializers -I inc/ -I objects/code/ -I src/bson/ -I src/sha1/", //-mwindows
                //最后一个参数 -mwindows加上后输出只能出现在cygwin环境,而不会出现在dos环境
                "-g",
                "${file}",
                "-o",
                "${workspaceRoot}/test.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

完整版配置环境:

task.json

代码语言:javascript
复制
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "mingw32",
            "command": "i686-w64-mingw32-gcc",
            "args": [
                "-m32 -Wall -Wextra -std=c99 -static -Wno-missing-field-initializers -I inc/ -I objects/code/ -I src/bson/ -I src/sha1/",
                "-g ${file}",   //指定编译源代码文件                    
                "-o ${fileDirname}/${fileBasenameNoExtension}.exe", // 指定输出文件名,不加该参数则默认输出a.exe
                "-ggdb3",   // 生成和调试有关的信息
                "-Wall",    // 开启额外警告
                "-static-libgcc",   // 静态链接
               // "-std=c++17",       // 使用最新的c++17标准
                "-Wno-format",
                "-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8
                "-fexec-charset=GBK"//编译器输出文本编码 自行选择
            ],

            "type": "shell",

            "group": {
                "kind": "build",
                "isDefault": true
            },

            "presentation": {
                "echo": true,
                "reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never
                 "focus": false,
                 "panel": "shared" // 不同的文件的编译信息共享一个终端面板
            },

            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative", "\\"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        },
        {
            "label": "gcc",
            "command": "g++",
            "args": [
                "-g ${file}",   //指定编译源代码文件                    
                "-o ${fileDirname}/${fileBasenameNoExtension}.exe", // 指定输出文件名,不加该参数则默认输出a.exe
                "-ggdb3",   // 生成和调试有关的信息
                "-Wall",    // 开启额外警告
                "-static-libgcc",   // 静态链接
                "-std=c++17",       // 使用最新的c++17标准
                "-Wno-format",
                "-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8
                "-fexec-charset=GBK"//编译器输出文本编码 自行选择
            ],

            "type": "shell",

            "group": {
                "kind": "build",
                "isDefault": true
            },

            "presentation": {
                "echo": true,
                "reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never
                 "focus": false,
                 "panel": "shared" // 不同的文件的编译信息共享一个终端面板
            },

            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative", "\\"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

launch.json

代码语言:javascript
复制
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "mingw32",
            "type": "cppdbg",
            "request": "launch",
            //"program": "${file}.exe",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            //"cwd": "${workspaceFolder}",
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb.exe",
            "preLaunchTask": "mingw32",
            "windows": {
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            //"program": "${file}.exe",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            //"cwd": "${workspaceFolder}",
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb.exe",
            "preLaunchTask": "gcc",
            "windows": {
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
        }
    ]
}

参考:

VSCode下C++环境的配置

http://blog.csdn.net/feynman1999/article/details/79437524

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • VSCode下C++环境的配置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档