• GDB设置step-mode

    创建三个文件:test.c、add.c、add.h。对比step-mode 模式的差别。

    test.c文件代码展示如下:

    #include <stdio.h>
    #include "add.h"
    int main(void)
    {
         int a = 10;
         int b = 20;
         int c = add(20,10);
         printf("%d\n",c);
         return 0;
    }

    add.c文件代码展示如下:

    #include <stdio.h>
    #include "add.h"
    int add(int a,int b)
    {
     return a + b;
    }

    add.h文件代码展示如下:

    #ifndef ADD_H__
    #define ADD_H__

    int add(int a, int b);

    #endif

    编译文件:

    gcc -c -g test.c
    gcc -c add.c
    gcc test.o add.o -o test

    进入调试文件:

    gdb test

    使用step-mode调试程序

    (gdb) show step-mode
    Mode of the step operation is off.

    (gdb) run
    Starting program: /home/wjc/test2/test
    Breakpoint 1, main () at test.c:9

    (gdb) s
    9  int c = add(20,10);

    (gdb) s
    10  printf("%d\n",c);

    (gdb) c
    Continuing.
    30
    [Inferior 1 (process 3423) exited normally] (gdb) set step-mode on

    (gdb) run
    Starting program: /home/wjc/test2/test
    Breakpoint 1, main () at test.c:9

    (gdb) s
    9  int c = add(20,10);

    (gdb) s
    0x000055555555468f in add ()

    (gdb) c
    Continuing.
    30
    [Inferior 1 (process 3424) exited normally]

     

更多...

加载中...