Symbol tables for separately linked pieces

Paul Koning
2008-07-10T14:27:45Z

I have an application that consists of two parts, a main program which
is one ELF image and a subsystem which is separately linked as an ELF
image of its own. The latter is loade into a portion of the address
space of the former at startup. The symbol table of the subsystem
image reflects its final load address.

The question is how to handle this with GDB. I've used the
add-symbol-file command, and that works up to a point.

The difficulty lies in the reason why the subsystem is separately
linked int he first place -- it has name conflicts with symbols in the
main program.

What I need to be able to do is this:

1. When debugging in the subsystem, have its symbol table loaded "on
top" -- so any name lookups are resolved first from that symbol
table and only after that from the other (main program) table.

2. When I switch to debugging in the main program, I want to be able
to tell GDB to deactivate the subsystem symbol table temporarily
(or perhaps better yet, keep it around "on the bottom") so a
name that exists in both is now resolved from the main program.

I've hacked up something like this by "context switching" the
object_files and symfile_objfile variables, but that seems to be a bit
fragile. I sometimes run into GDB internal errors with this approach.

So the questions are:

1. Does GDB have a way to do this?
2. If not, any hints about a clean way to add this?
3. If I were to add this, would it be of general interest (i.e.,
something I should submit)?

Thanks,
paul