使用书籍与相关笔记
[书籍]《软件调试的艺术》(《 The Art of Debugging with GDB, DDD, and Eclipse》)
https://www.jianshu.com/p/0805ba683126
什么是断点、监视点与捕获点?
断点、监视点与捕获点A breakpoint tells GDB to pause execution at a particular location within the program.
A watchpoint tells GDB to pause execution when a particular memory location (or an expression involving one or more locations) changes value.
A catchpoint tells GDB to pause execution when a particular event occurs.
设置断点
-
截图取自 2.4.1 在GDB中设置断点的方法
GDB中设置断点的方法.PNG
查看断点
(gdb) info breakpoints
一个可以照着做的简短例子: 2.5 展开GDB示例
1、源码文件
main.c
#include <stdio.h>
void swap(int *a, int *b);
int main( void )
{
int i = 3;
int j = 5;
printf("i: %d, j: %d\n", i, j);
swap(&i, &j);
printf("i: %d, j: %d\n", i, j);
return 0;
}
swapper.c
void swap(int *a, int *b)
{
int c = *a;
*a = *b;
*b = c;
}
Makefile
TARGET = swap
CFLAGS = -g3 -Wall -Wextra
all: $(TARGET)
$(TARGET): main.o swapper.o
$(CC) -o $@ $^
.PHONY:
clean:
$(RM) $(TARGET) a.out core *.o
2、实例操作过程
1.png$ gcc -g3 -Wall -Wextra -c main.c swapper.c
$ gcc -o swap main.o swapper.o
$ gdb swap
2.PNG
3.PNG
4.PNG
网友评论