main.c
#include <stdio.h>
typedef struct
{
int iW;
int iH;
int iX;
int iY;
}BOX_ST;
int sum(const int a, const int b)
{
int c = a + b;
return c;
}
int main()
{
BOX_ST stBox;
for (int i = 0; i < 10000; ++i)
{
stBox.iW = i;
stBox.iH = i;
stBox.iX = i;
stBox.iY = i;
sum(i, i + 1);
}
return 0;
}
gdb自动化脚本
当函数sum的入参a的值为77时在函数sum处打断点
tom@ubuntu:~/dvp$ cat -n gdbcmd_breakif.txt
1 b sum if a == 77
tom@ubuntu:~/dvp$
gdb自动化脚本的使用
tom@ubuntu:~/dvp$ gdb ./a.out -x ./gdbcmd_breakif.txt
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
Breakpoint 1 at 0x4004e0: file main.c, line 13.
(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x00000000004004e0 in sum at main.c:13
stop only if a == 77
(gdb) run
Starting program: /home/tom/dvp/a.out
Breakpoint 1, sum (a=77, b=78) at main.c:13
13 int c = a + b;
(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x00000000004004e0 in sum at main.c:13
stop only if a == 77
breakpoint already hit 1 time
(gdb) bt
#0 sum (a=77, b=78) at main.c:13
#1 0x000000000040052b in main () at main.c:29
(gdb)
《完》