106

I'm trying to automate a gdb session using the --command flag. I'm trying to set a breakpoint on a function in a shared library (the Unix equivalent of a DLL) . My cmds.gdb looks like this:

set args /home/shlomi/conf/bugs/kde/font-break.txt
b IA__FcFontMatch
r

However, I'm getting the following:

shlomi:~/progs/bugs-external/kde/font-breaking$ gdb --command=cmds.gdb...
GNU gdb 6.8-2mdv2009.0 (Mandriva Linux release 2009.0)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
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 "i586-mandriva-linux-gnu"...
(no debugging symbols found)
Function "IA__FcFontMatch" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]

So it doesn't set the breakpoint after all. How can I make it default to answer "y" to set breakpoints on pending future shared library load?

I recall that I was able to do something, but cannot recall what.

jww
  • 97,681
  • 90
  • 411
  • 885
Shlomi Fish
  • 4,380
  • 3
  • 23
  • 27
  • related: [Can gdb's “input not from terminal” messages be suppressed?](http://stackoverflow.com/questions/23005668/can-gdbs-input-not-from-terminal-messages-be-suppressed) – TooTone Jul 16 '15 at 11:08

3 Answers3

176

Replying to myself, I'd like to give the answer that someone gave me on IRC:

(gdb) apropos pending
actions -- Specify the actions to be taken at a tracepoint
set breakpoint -- Breakpoint specific settings
set breakpoint pending -- Set debugger's behavior regarding pending breakpoints
show breakpoint -- Breakpoint specific settings
show breakpoint pending -- Show debugger's behavior regarding pending breakpoints

And so set breakpoint pending on does the trick; it is used in cmds.gdb like e.g.

set breakpoint pending on
break <source file name>:<line number>
ssc
  • 9,528
  • 10
  • 64
  • 94
Shlomi Fish
  • 4,380
  • 3
  • 23
  • 27
  • 2
    that has saved my bacon trying to debug under Windows 7 using MinGW, the default setting was different than on Linux - many thanks – bph May 16 '12 at 09:22
  • For some reason, I get this error `Program received signal SIGILL, Illegal instruction`. I am sourcing breakpoints from a file and I have `set breakpoint pending on` since some of my breakpoints are in a library that the program loads. If I add breakpoints manually, then there is no error. Anyone else facing similar problem? – brokenfoot Oct 05 '16 at 17:59
  • @brokenfoot : I think you should ask your question in a new top-level question instead of in a comment to an answer here. That way more people will notice it. Moreover, you should provide more info about your system. – Shlomi Fish Oct 07 '16 at 07:13
14

OT: In terminal it would look like this to debug Caja in one line:

gdb -ex "set breakpoint pending on" -ex "break gdk_x_error" -ex run --args caja --sync
Botz3000
  • 39,020
  • 8
  • 103
  • 127
äxl
  • 141
  • 1
  • 2
  • 3
    Where did you find the 'ex' switch?, I cannot find any reference to this parameter in the documentation (but it works :) ) – Gearoid Murphy Oct 17 '12 at 16:46
  • `-ex` didn't work for me. I had to put the commands in a tmp file and call with: `gdb -x /tmp/gdb.commands myexecutible` – Jason Moore Apr 16 '13 at 08:56
5

With no symbols.

objdump -t /lib/libacl.so
SYMBOL TABLE:
no symbols
objdump -T /lib/libacl.so
...
00002bd0 g    DF .text  000000d0  ACL_1.0     acl_delete_entry
...


(gdb) break 0x0002bd0 

(gdb) x/20i acl_delete_entry
0x2bd0 <acl_delete_entry>:      stwu    r1,-32(r1)
0x2bd4 <acl_delete_entry+4>:    mflr    r0
0x2bd8 <acl_delete_entry+8>:    stw     r29,20(r1)
0x2bdc <acl_delete_entry+12>:   stw     r30,24(r1)
0x2be0 <acl_delete_entry+16>:   mr      r29,r4
0x2be4 <acl_delete_entry+20>:   li      r4,28972
RandomNickName42
  • 5,923
  • 1
  • 36
  • 35