When I run a program with gdb and have a commands list, the commands aren't invoked the first time the breakpoint is hit. I setup a little test program to demonstrate.
test.c:
#include <stdio.h>
void incrementI(){
static int i = 0;
i++;
printf("i: %d\n", i);
sleep(10);
}
int main() {
int i = 0;
while(1){
incrementI();
}
return 0;
}
commands list: testgdbBreakpoint
set breakpoint pending on
b incrementI
commands
backtrace
continue
end
shell script which runs gdb: testgdbinvoke.sh
#!/bin/sh
gdb -x testGDBBreakpoint -ex=r --args testGDB
The output I see when running testgdbinvoke.sh is:
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 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.
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 testGDB...done.
Breakpoint 1 at 0x10478
Starting program: /data/config/testGDB
Breakpoint 1, 0x00010478 in incrementI ()
(gdb) c
Continuing.
i: 1
Breakpoint 1, 0x00010478 in incrementI ()
#0 0x00010478 in incrementI ()
#1 0x000104d8 in main ()
i: 2
Breakpoint 1, 0x00010478 in incrementI ()
#0 0x00010478 in incrementI ()
#1 0x000104d8 in main ()
i: 3
The first time the break point is hit, I don't see a backtrace, instead I have to manually continue. Are there specific options I have to set in the commands list in order to have them run everytime the breakpoint is hit?