Skip to content

vscode调试环境 #10

@lfeng14

Description

@lfeng14

注意事项:vscode需要先编译,然后debug

环境配置

  • 安装gcc g++ gdb
    • 界面安装MSYS2
    • 安装gcc g++ gdb
    pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
    
  • 安装vscode,以及安装插件
    Image
  • 配置工程
task.json
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "hi.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
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": "C/C++ Runner: Debug Session",
            "type": "cppdbg",
            "request": "launch",   # 注意需要launch而不是attatch
            "cwd": "${workspaceFolder}",//运行目录
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "MIMode": "gdb",
            "miDebuggerPath": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }

    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions