Article directory
Reference: Wheat Academy - C language programming and quick start
Common C language development environment
1 Composition of the development environment
编辑
编译
调试
2 common development environment
Turbo C
VC6
VS系列
CODEBLOCKS
Installation and configuration of VScode-C compilation and debugging environment
1 VScode installation (win10 64-bit system as an example)
Download address: vscode
uses VSCODE as the development environment, download the installation file and install it directly.
Lightweight codeblocks can also be used, download address: codeblocks-20.03 .
2 vscode compiler configuration
Use vscode to open the directory where the C test project is located, and create a new input sample code program.
sample program code
#include <stdio.h>
int main()
{
char c='A';
printf("c(char)=%c,c(int)=%d,c_change(char)=%c,c_change(int)=%d,c_change(HEX)=%#x\n",c,c,c+32,c+32,c+0x20);
return 0;
}
Output result:
3 Configuration of debugging environment
Use vscode to open the .vscode folder in the C test project directory, and modify the configuration file:
If the configuration file has not been generated, you need to configure the default generation task:
"setupCommands" at the bottom of launch.json: Add a comma after the right square bracket [] ",", and add a line of code on the next line, such as:
"preLaunchTask": "C/C++: gcc.exe"
The name after the pre-execution task must be consistent with the value of "label" in tasks.json.
For the file in tasks.json, the command configuration specifies that the compiler is gcc (with a full path):
f:\dev\rtools40\mingw32\bin\gcc.exe
args is the compiler option, where -g means to compile with debugging information The executable file, " file" is the name of the file to be compiled, the − o parameter specifies the name of the generated executable file, such as: "{file}" is the name of the file to be compiled, and the -o parameter specifies the name of the generated executable file ,like: "f i l e " is the name of the file to be compiled,−The o parameter specifies the name of the generated executable file, such as: " {fileDirname}/${fileBasenameNoExtension}.exe"
Notice
To start gdb normally, you must ensure that the version of the .exe executable file generated by gcc is consistent with the version of the gdb debugger, otherwise there will be a debugging error: " File format not recognized ", such as:
if the gdb version used is 32-bit, the compiler A 32-bit version of gcc is also used.
The tasks.json and launch.json configuration files ( 32-bit ) are as follows:
tasks.json :
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "f:\\dev\\rtools40\\mingw32\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "f:\\dev\\rtools40\\mingw32\\bin\\"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: f:\\dev\\rtools40\\mingw32\\bin\\gcc.exe"
}
]
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true, //false单独打开console窗口用于程序执行
"MIMode": "gdb",
"miDebuggerPath": "F:\\dev\\rtools40\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe 生成活动文件"
},
{
"name": "(Windows) 启动",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal"
}
]
}
debug mode
After normal debugging, the program stops at the set breakpoint, and subsequent debugging operations can be performed.
The program execution result is displayed in the console window that pops up:
the debug console displays the gdb version and configuration information:
=thread-group-added,id="i1"
GNU gdb (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
You can see that the GNU gdb (GDB) version is 7.5, This GDB was configured as “i686-pc-mingw32”. 32-bit version.
At this point, the debugging of the routine is completed.