Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Paul Hilfinger <hilfingr@CS.Berkeley.EDU>
To: David Carlton <carlton@math.stanford.edu>
Cc: Elena Zannoni <ezannoni@redhat.com>, Adam Fedor <fedor@doc.com>,
	GDB Patches <gdb@sources.redhat.com>,
	Daniel Jacobowitz <drow@mvista.com>
Subject: Re: Demangling and searches
Date: Thu, 09 Jan 2003 02:38:00 -0000	[thread overview]
Message-ID: <200301090237.SAA22983@tully.CS.Berkeley.EDU> (raw)
In-Reply-To: Message from David Carlton <carlton@math.stanford.edu>  of "Tue, 07 Jan 2003 16:13:38 PST." <ro1n0mcebwt.fsf@jackfruit.Stanford.EDU>


 > I'm curious: in Ada, what does the mangling do?  In particular, how
 > much type info does it contain?  In C++, the mangled name contains
 > type info for the arguments for functions; I don't see how, using
 > GDB's current data structures, to allow us to allow users to, say,
 > break on a function without requiring them to specify the types of the
 > arguments, if we took your approach.  (Though it might be possible to
 > modify GDB's data structures to allow that.)

In Ada, the mangled name does not contain type information, but we
actually solve an even harder problem.  The mangled name contains
certain information that the user doesn't necessarily know, so that the system
CANNOT reconstruct the full mangled name from the user's input a
priori.  Yet nevertheless, we look up quite successfully, thank you
very much.  The technique is simple: the mangled names have the form

     <NAME><OTHER INFO>

where the syntax of <OTHER INFO> is such that we can find its
beginning.  In Ada mode, GDB has to use a special lookup function
that ignores <OTHER INFO>, but otherwise the algorithm is the same as
for C or C++, etc.

Let's look at this a bit abstractly.  We're given a key K to
search for, among a set of symbols, S.  There is some predicate, P,
that defines success: you want s in S such that P(K, s).   The current
scheme achieves speed with two complementary strategies:

       1. Use K to find a subset, S', of S, limiting the number of 
          comparisons.
       2. Speed up P with preprocessing: P has (roughly) the form
                 K equals SYMBOL_SOURCE_NAME (s)
	  where SYMBOL_SOURCE_NAME (s) = f (SYMBOL_NAME (s), SYMBOL_LANGUAGE(s)),

I am asking why we can't change P to 

       K equals f (SYMBOL_NAME (s), SYMBOL_LANGUAGE (s)),

or, more abstractly, to something like

       compare_demangled (K, SYMBOL_NAME (s), SYMBOL_LANGUAGE (s)) == 0

saving considerable space in the process.  (Daniel Berlin points out
that ABI also figures into these, but here I'll just go by the
parameterization in symtab.h).  The answer is "because f is costly
when applied to lots of symbols."  But this answer really makes sense
only if strategy 1 above is ineffective.

If your symbol-search structure is a hash table, then all you have to
do is use SYMBOL_SOURCE_NAME (s) as the hash key; it is irrelevant
whether you actually store the SYMBOL_SOURCE_NAME in s.  Hash tables
have precisely the effect of drastically decreasing the size of S'.  
If you are relying on binary search, admittedly, things are not so
simple, since the sort itself requires several evaluations of
SYMBOL_SOURCE_NAME for each symbol (but then, I've always preferred
hash tables (:->)).


Paul Hilfinger


  parent reply	other threads:[~2003-01-09  2:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-07 23:56 Paul Hilfinger
2003-01-08  0:13 ` David Carlton
2003-01-08  0:38   ` Daniel Berlin
2003-01-09  2:38   ` Paul Hilfinger [this message]
2003-01-09 21:51     ` David Carlton
2003-01-08  1:04 ` Daniel Jacobowitz
2003-01-08  1:39 ` Elena Zannoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200301090237.SAA22983@tully.CS.Berkeley.EDU \
    --to=hilfingr@cs.berkeley.edu \
    --cc=carlton@math.stanford.edu \
    --cc=drow@mvista.com \
    --cc=ezannoni@redhat.com \
    --cc=fedor@doc.com \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox