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 @   夜行过客  阅读(2187)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
历史上的今天:
2019-10-28 蓝牙BLE: 蓝牙4.0 BLE广播数据解析(转)
2016-10-28 新浪微博客户端(16)-获得并显示用户昵称
点击右上角即可分享
微信分享提示