当前位置:网站首页>C language: 12. GDB tool debugging C program
C language: 12. GDB tool debugging C program
2022-07-27 19:33:00 【Brother rabbit head】
c Language :12、gdb Tool debugging c Program
- 1、 brief introduction
- 2、gdb Debugging example
- 1、 establish /main.c
- 2、 compile /main.c
- 3、 establish main2.c
- 4、 compile main2.c
- 5、 Start debugging
- 6、 List the source code of the current software project
- 7、 Carry on
- 8、 Start debugging
- 9、 Print variables
- 10、 Debug the next line
- 11、 Enter the function and execute
- 12、 Look at the function stack
- 13、 Switch stack
- 14、 Exit debugging
- 3、GDB Debug pointer
1、 brief introduction
GDB The tool is in linux A debugging tool used when programming in the environment , Powerful , Easy to use , It is a sharp tool for program debugging .
DB Commissioning conditions :
about GDB Program files for debugging , You need to add -g Options , Only the generated executable can be used GDB Conduct source level debugging . among -g Option is to add source code information to the executable , At the same time, it must be ensured that GDB Can find the source code file . Therefore, the source code file cannot be deleted
2、gdb Debugging example
1、 establish /main.c
#include <stdio.h>
void change(int *a, int *b)
{
int tmp = *a;
*a=*b;
*b=tmp;
}
int main()
{
int a=5;
int b=3;
change(&a, &b);
printf("num a=%d\nnum b=%d\n", a, b);
return 0;
}
2、 compile /main.c
gcc -g main.c -o main.out
3、 establish main2.c
#include <stdio.h>
void change(int a, int b)
{
int tmp = a;
a=b;
b=tmp;
}
int main()
{
int a=5;
int b=3;
change(a, b);
printf("num a=%d\nnum b=%d\n", a, b);
return 0;
}
4、 compile main2.c
gcc -g main2.c -o main2.out
5、 Start debugging
gdb main2.out
6、 List the source code of the current software project
Use l Command to view the source code ;l The order is list An abbreviation for a command , Therefore use l Command effect and list Orders are equal to ;
7、 Carry on
Press enter , It means to continue to execute the command of the previous step 
8、 Start debugging
Use command start Start debugging ,start The command says : Start debugging , Stop at the first line of code 
9、 Print variables
Use command p Print variables ;p The order is print An abbreviation for a command ;
10、 Debug the next line
Use command n Execute the next line of code ;n The order is next An abbreviation for a command ;
11、 Enter the function and execute
perform s command ;
s:step Execute a line of source code , If there is a function call in this line of code , Enter the function ;
12、 Look at the function stack
Carry out orders bt
13、 Switch stack
Carry out orders f 1

14、 Exit debugging
Use command q
3、GDB Debug pointer
Prove that memory is continuous
1、 establish /main.c
#include <stdio.h>
void change(int *a, int *b)
{
int tmp = *a;
*a=*b;
*b=tmp;
}
int main()
{
int a=5;
int b=3;
change(&a, &b);
printf("num a=%d\nnum b=%d\n", a, b);
return 0;
}
2、 compile /main.c
gcc -g main.c -o main.out
3、 debugging main.out
gdb main.out
边栏推荐
猜你喜欢
随机推荐
请问创建MySQL数据源资源组必须要选择新建独享数据集成资源组才可用?还是使用公共资源组就可以?谢谢
Nacos基本概念和单机部署
c语言:11、管道
What if idea successfully connects to the database without displaying the table
WSN journal indexed by SCI
Time complexity and space complexity
Some advice for NS2 beginner.
The first entry-level operation of kettle (reading excel, outputting Excel)
大佬们,ORACLE CDC,本地运行,老是遇到这个An exception occurred in
2022 Ningde Vocational College Teachers' practical teaching ability improvement training - network construction and management
带来高价值用户体验的低代码开发平台
Basic use of Nacos (1) - getting started
golang设置国内镜像,vscode配置golang开发环境,vscode调试golang代码
零知识证明的硬件加速
FZU1669 Right-angled Triangle【毕达哥拉斯三元组】
Cumulative output data of kettle Excel
c语言:12、gdb工具调试c程序
C language preprocessing instruction
Definition of graph traversal and depth first search and breadth first search (2)
Hardware acceleration of zero knowledge proof









