bashgdb

Problems adding a breakpoint with commands from command line with ex command


I try to start a program with gdb from commands line, then immediately add a breakpoint with commands, then run:

gdb -q -ex 'set pagination off' -ex 'break XOpenDisplay' \
-ex 'commands' -ex 'silent' -ex 'info locals' -ex 'bt full' \
-ex 'cont' -ex 'end'  -ex 'r' ./myprogram

The program gets stuck after the commands prompting me to enter commands via keyboard then enter end.

Did I forget something?

Regards

Update:

I added a .gdbinit with the following content:

define breakXOpenDisplayRun
set pagination off
break XOpenDisplay
commands
  silent
  info locals
  bt full
  cont
end
run
end
gdb -q -ex breakXOpenDisplayRun ./myapp

When the program encounters the breakpoint the first time it stops there prompting a user input which should not happen. After the first cont it works as expected.


Solution

  • Thanks to gdb mailing list Andrew Burgess. This is a bug that has been fixed in gdb 11. For versions before that, using a separate source worked for me:

    gdb -q -ex 'source breakXOpenDisplayRun.gdb' ./myapp