美文网首页
[GDB]断点(breakpoint )设置:break

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

作者: AkuRinbu | 来源:发表于2018-08-30 22:59 被阅读27次

    使用书籍与相关笔记

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

    相关文章

      网友评论

          本文标题:[GDB]断点(breakpoint )设置:break

          本文链接:https://www.haomeiwen.com/subject/qfljwftx.html