Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* How to load only selected libraries?
@ 2008-01-20 22:37 Srinath Avadhanula
  2008-01-21  3:16 ` Daniel Jacobowitz
  0 siblings, 1 reply; 5+ messages in thread
From: Srinath Avadhanula @ 2008-01-20 22:37 UTC (permalink / raw)
  To: gdb

Hi,

Is it possible to have GDB only load selected libraries? I know about doing

set auto-solib-add off

and then following it up with

sha foolib

However, what I would really like is something like

set auto-solib-regexp <regexp>

And then have GDB only (automatically) load libraries which match the
<regexp>. The problem with 'sha <regexp>' of course is that its not
automatic. I have to interrupt the program after ensuring that the
library is loaded.

I am using gdb-6.9-40-debian. Is such a feature available in a newer version?

Thanks,
Srinath


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to load only selected libraries?
  2008-01-20 22:37 How to load only selected libraries? Srinath Avadhanula
@ 2008-01-21  3:16 ` Daniel Jacobowitz
  2008-01-21 18:56   ` Jim Ingham
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2008-01-21  3:16 UTC (permalink / raw)
  To: Srinath Avadhanula; +Cc: gdb

On Sun, Jan 20, 2008 at 05:37:32PM -0500, Srinath Avadhanula wrote:
> I am using gdb-6.9-40-debian. Is such a feature available in a newer version?

No, but I've wanted this too.


-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to load only selected libraries?
  2008-01-21  3:16 ` Daniel Jacobowitz
@ 2008-01-21 18:56   ` Jim Ingham
  2008-01-26 14:53     ` Srinath Avadhanula
  0 siblings, 1 reply; 5+ messages in thread
From: Jim Ingham @ 2008-01-21 18:56 UTC (permalink / raw)
  To: gdb

We did this at Apple a while back.  We have a command "set  
sharedlibrary load-rules" that works like:

(gdb) help set sharedlibrary load-rules
Set the rules governing the level of symbol loading for shared  
libraries.
  * Each load rule is a triple.
  * The command takes a flattened list of triples.
  * The first two elements of the triple specify the library, by giving
       - "who loaded it" (i.e. dyld, cfm or all) in the first element,
       - and a regexp to match the library name in the second.
  * The last element specifies the level of loading for that library
       - The options are:  all, extern, container or none.

Example: To load only external symbols from all dyld-based system  
libraries, use:
     set sharedlibrary load-rules dyld ^/System/Library.* extern


The "who loaded it" is an Apple specific bit and I don't know if that  
would be relevant for any other system. Originally there were two  
loaders on Mac OS X - the CFM loader which handled modules built with  
the older classic Mac OS object file format, and dyld which handles  
the "native" mac os object file format.  We had to support CFM for a  
while because some of the larger software vendors who had Mac OS code  
bases didn't want to have to switch object file formats and OS'es at  
the same time...

The load levels have the meaning:

none - only note the FACT that the library has loaded, nothing else
container - make the section table for the library, but don't read any  
symbols
extern - roughly read the minysms for the exported functions in the  
library.  This is a little more tricky for ObjC, since there are very  
few exported symbols, all the methods are stored in ObjC runtime data  
structures, but we consider them "extern" since that's what they are  
functionally.
all - obvious

The load rules work from left to right, and the first match sets the  
state.  So you can do:

set sharedlibrary load-rules dyld ^/usr/lib/myLibrary.dylib all dyld ^/ 
usr/lib/.* extern

to load all the symbols from your library, but not for other libraries  
on the same path...

Then there's a command:

(gdb) help sharedlibrary set-load-state
Set the load level of a library (given by the index from "info  
sharedlibrary").

Whereby you modify the state.

Manually monkeying around with these states was not a very good user  
experience.  Furthermore, to get things to work right, you sometimes  
have to automatically load in symbols.  For instance, a lot of times,  
backtraces don't work very well if you don't have symbols for the  
functions in the backtrace, so if we see a shared library in a  
backtrace we auto-raise the load levels.

We found that when you have an IDE that knows the relationship between  
source files & built products, you can usually get away with setting  
all the load levels to Extern, then letting the automatic raising  
bring in symbols as you encounter them.  The one missing bit is how to  
set file & line breakpoints.  For that we added:

(gdb) break -shlib <Foo.dylib> bar.c:12

which has the dual function of restricting the breakpoint to Foo.dylib  
& also instructing gdb to load the symbols for Foo.dylib before  
setting the breakpoint.

I tried for a while to get lowering the symbol level of a library to  
work, but there are too many places in gdb - particularly if you use  
variable objects much - where objfile data is referenced.  In the end  
it didn't seem a useful enough feature to be worth the bother.

The changes are kind of all over, I don't know how useful it would be  
to look at them. But this basic model seems to have worked pretty  
well.  It certainly has made a big difference in debugging on a system  
like Mac OS X, where you generally pull in lots & lots of shlibs, many  
of which you don't at all care about...

Jim



On Jan 20, 2008, at 7:16 PM, Daniel Jacobowitz wrote:

> On Sun, Jan 20, 2008 at 05:37:32PM -0500, Srinath Avadhanula wrote:
>> I am using gdb-6.9-40-debian. Is such a feature available in a  
>> newer version?
>
> No, but I've wanted this too.
>
>
> -- 
> Daniel Jacobowitz
> CodeSourcery


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to load only selected libraries?
  2008-01-21 18:56   ` Jim Ingham
@ 2008-01-26 14:53     ` Srinath Avadhanula
  2008-01-26 23:52       ` Jim Ingham
  0 siblings, 1 reply; 5+ messages in thread
From: Srinath Avadhanula @ 2008-01-26 14:53 UTC (permalink / raw)
  To: Jim Ingham; +Cc: gdb

Hi Jim,

On Jan 21, 2008 1:55 PM, Jim Ingham <jingham@apple.com> wrote:
> We did this at Apple a while back.  We have a command "set
> sharedlibrary load-rules" that works like:
>
[snip interesting explanation of this feature]

This sounds incredibly useful. Any idea if this will be incorporated
back into gdb itself?

Thanks,
Srinath


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to load only selected libraries?
  2008-01-26 14:53     ` Srinath Avadhanula
@ 2008-01-26 23:52       ` Jim Ingham
  0 siblings, 0 replies; 5+ messages in thread
From: Jim Ingham @ 2008-01-26 23:52 UTC (permalink / raw)
  To: Srinath Avadhanula; +Cc: gdb

For historical reasons the Apple shared library handling code doesn't  
share the mechanisms that Linux/etc. use.  So the majority of the code  
would have to be ported over from the macosx/*dyld* code, where it  
lives in our gdb, to the solib code in FSF gdb.  I don't have any  
experience with the Linux solib code in gdb, so I'm not likely to  
tackle this.

I was offering this more as an interesting design point.

Jim


On Jan 26, 2008, at 6:52 AM, Srinath Avadhanula wrote:

> Hi Jim,
>
> On Jan 21, 2008 1:55 PM, Jim Ingham <jingham@apple.com> wrote:
>> We did this at Apple a while back.  We have a command "set
>> sharedlibrary load-rules" that works like:
>>
> [snip interesting explanation of this feature]
>
> This sounds incredibly useful. Any idea if this will be incorporated
> back into gdb itself?
>
> Thanks,
> Srinath


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-01-26 23:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-20 22:37 How to load only selected libraries? Srinath Avadhanula
2008-01-21  3:16 ` Daniel Jacobowitz
2008-01-21 18:56   ` Jim Ingham
2008-01-26 14:53     ` Srinath Avadhanula
2008-01-26 23:52       ` Jim Ingham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox