VScode编译调试环境配置

VScode MySnippets.code-snippets

VScode用户Snippet设置

{
	// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"new file header description":
	{
		"prefix": "newfile",
		"body": [
			"/**",
			"******************************************************************************",
			"* @file           : $1",
			"* @brief          : $2",
			"******************************************************************************",
			"* @attention",
			"*",
			"* Copyright (c) 202$3 WLJ.",
			"* All rights reserved.",
			"*",
			"* More brief       :$4",
			"*",
			"******************************************************************************",
			"*/"
		],
		"description": "description for new file"


	},
	"new function header description":
	{
		"prefix": "newfunction",
		"body": [
			"/******************************************************************************",
			"* @brief          : $1",
			"* @param          : $2",
			"* @return         : $3",
			"******************************************************************************",
			"*",
			"* Copyright (c) 202$4.",
			"* All rights reserved.",
			"* Function Details: $1",
			"* Example         : $5",
			"******************************************************************************/"
		],
		"description": "description for new function"


	}
}

c/c++编译调试

参考网址:VS Code 配置C/C++多文件编译和调试(初学一劳永逸版)_哔哩哔哩_bilibili

编译器配置

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "E:\\Program Files\\mingw32\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-x64"
        },
        {
            "name": "c++",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "E:/Program Files/mingw32/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

编译项配置

tasks.json

{
    "version": "2.0.0",
    "command": "gc",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileBasenameNoExtension}.exe"
    ],
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "${workspaceFolder}"
        ],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    },
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 生成活动文件",
            "command": "E:\\Program Files\\mingw32\\bin\\gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}\\*.c",
                "-o",
                "${workspaceFolder}\\${workspaceRootFolderName}.exe",
                "-fexec-charset=GBK" //解决弹出cmd窗口的中文乱码问题
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "编译器: E:\\Program Files\\mingw32\\bin\\gcc.exe"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "E:\\Program Files\\mingw32\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}\\*.cpp",
                "-o",
                "${workspaceFolder}\\${workspaceRootFolderName}.exe",
                "-fexec-charset=GBK" //解决弹出cmd窗口的中文乱码问题
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "编译器: E:\\Program Files\\mingw32\\bin\\g++.exe"
        }
    ]
}

调试配置项

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\${workspaceRootFolderName}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            //"console":"externalTerminal",    //弹出cmd窗口
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\Program Files\\mingw32\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

调试十六、八进制显示变量

参考:vscode调试时以16进制查看变量_vscode 16进制-CSDN博客

调试时vscode变量值默认以10进制显示,如下图:

 我们将变量vec添加到监视,并编辑在vec后添加h,即可查看vec的16进制数据,如下图:

 同样的,添加x可以16进制显示,o以8进制显示。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值