Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set breakpoints on future shared libraries with a command flag

Tags:

c++

c

linux

unix

gdb

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.

like image 733
Shlomi Fish Avatar asked Sep 19 '08 08:09

Shlomi Fish


People also ask

What allows to set breakpoints?

Set breakpoints in source code To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

How do I add a breakpoint in GDB?

Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.

What command would you use to display all defined breakpoints?

You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes.


2 Answers

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> 
like image 132
Shlomi Fish Avatar answered Sep 28 '22 01:09

Shlomi Fish


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 
like image 37
äxl Avatar answered Sep 28 '22 01:09

äxl