VSCode-Add_Configuration后launch.json为空的解决办法

VSCode - Add Configuration后launch.json为空的解决办法

今天需要使用VSCode debug一个程序,点击菜单栏的“Run”-"Add Configuration" 选项,准备生成一个默认的launch.json文件,结果出来的json文件是这个样子的:

image-20221028175403019

以前不是可以自动生成 launch.json 的么?

没办法,只能手动点击上图的“Add Configuratioin”按钮,手动添加json文件:

image-20221028175544913

结果生成的文件如下:

{
    // 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": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "输入程序名称,例如 ${workspaceFolder}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/path/to/gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }


    ]
}

有几个地方需要手动修改下:

  • program: 就是要运行的程序名字,打开 tasks.json, 复制生成的程序名字即可:

    image-20221028175907812

  • miDebuggerPath: 就是gdb调试器的路径,这里修改成:E:\\msys64\\mingw64\\bin\\gdb.exe就是gdb调试器所在的路径;

  • 添加一个preLaunchTask项,拷贝tasks.json中的label项:

    image-20221028180226471
    复制到 launch.jsonpreLaunchTask 项中:

    image-20221028180836120

最终修改后的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": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "preLaunchTask": "C/C++: g++.exe 生成活动文件",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\msys64\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }


    ]
}

不明白为什么要把这个功能改成现在这样。。。

posted @ 2022-10-28 18:05  夜行过客  阅读(2043)  评论(0编辑  收藏  举报