[GDB]断点(breakpoint )设置:break

使用书籍与相关笔记

[书籍]《软件调试的艺术》(《 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.

[GDB]断点(breakpoint )设置:break_第1张图片
断点、监视点与捕获点

设置断点

  • 截图取自 2.4.1 在GDB中设置断点的方法


    [GDB]断点(breakpoint )设置:break_第2张图片
    GDB中设置断点的方法.PNG

查看断点

  • (gdb) info breakpoints

一个可以照着做的简短例子: 2.5 展开GDB示例

1、源码文件

  • main.c
#include 
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、实例操作过程

[GDB]断点(breakpoint )设置:break_第3张图片
1.png
$ gcc -g3 -Wall -Wextra -c main.c swapper.c
$ gcc -o swap main.o swapper.o
$ gdb swap
[GDB]断点(breakpoint )设置:break_第4张图片
2.PNG
[GDB]断点(breakpoint )设置:break_第5张图片
3.PNG
[GDB]断点(breakpoint )设置:break_第6张图片
4.PNG

你可能感兴趣的:([GDB]断点(breakpoint )设置:break)