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

2018-08-30  本文已影响27人  AkuRinbu

使用书籍与相关笔记

[书籍]《软件调试的艺术》(《 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.5 展开GDB示例

1、源码文件

#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;
}

void swap(int *a, int *b)
{
    int c = *a;
    *a = *b;
    *b = c;
}

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
上一篇 下一篇

猜你喜欢

热点阅读