This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc] lookups with natural/linkage names


Right now, both lookup_symbol and lookup_minimal_symbol accept either
a linkage name or a natural name as an argument.  This seems to me to
not be very desirable: having spent a lot of time cleaning up the
internals of lookup_symbol (and lookup_partial_symbol, and other
functions) to get rid of bugs related to this confusion, I'd rather
have it as clear as possible within GDB's code when one is expected
and when the other is expected, and have as few functions as possible
that accept both.

My basic attitude is that symbols should normally be accessed via
natural names and minimal symbols should normally be accessed via
linkage names.  (There are exceptions, of course: if you want to find
the symbol associated to a minsym, for example, you'll probably be
doing a symbol search via a linkage name.)  Furthermore, for names
that are generated internally to GDB, we should always know whether
the name is a natural name or a linkage name, so it's safe to use a
lookup function that only accepts one sort of name or the other.

But sometimes we have to deal with user-provided names, which are
usually natural names but might occasionally be linkage names.
Exactly what we should do with those is open to question (which is why
this is an RFC!).  In all situations (I _think_; certainly most of
them) where we look up something from a user-provided name, GDB first
tries to look up a symbol and then, if that fails, tries to look up a
minsym.  So it seems to me that it's a reasonable choice to, when
looking up a symbol from a user-provided name, always assume that it's
a natural name, but when looking up a minsym, to accept either a
natural name or a linkage name.

That leads to the following recommendations:

* Add a function

    struct symbol *lookup_symbol_linkage (const char *name);

  that looks up the symbol whose linkage name is NAME.  It only looks
  up global or static symbols (with preference to the former), and
  only looks up symbols in VAR_DOMAIN; it doesn't apply any
  language-specific rules.  This will, for example, give us a reliable
  way to find the symbol associated to a minsym, no matter how
  complicated C++ lookup rules make things.

* Eventually, once lookup_symbol_linkage is being used wherever it's
  appropriate, have lookup_symbol stop accepting linkage names: only
  allow natural names.

* Provide a function

    struct minimal_symbol *
    lookup_minimal_symbol_linkage_or_natural (const char *name);

  that looks up a minsym via either a natural name or a linkage name.
  (Yes, the name is ugly; on the other hand, we should never blithely
  use this function, so an ungainly but descriptive name isn't such a
  bad idea.)

* Eventually, once lookup_minimal_symbol_linkage_or_natural is being
  used wherever is appropriate, have lookup_minimal_symbol only accept
  linkage names.

I don't believe that there's a need for a version of
lookup_minimal_symbol that only accepts natural names: it is my belief
that the only calls to lookup_minimal_symbol that might want to accept
a natural name are those using user-provide names, where
lookup_minimal_symbol_linkage_or_natural is appropriate.

I've had these implemented on my branch for a few months, and they
seem to work fine.

David Carlton
carlton@bactrian.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]