Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Introduce notion of "search name"
@ 2004-03-03 19:15 Paul Hilfinger
  2004-03-19  0:09 ` Paul Hilfinger
                   ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: Paul Hilfinger @ 2004-03-03 19:15 UTC (permalink / raw)
  To: gdb-patches


The following patch does nothing except to prepare the way for some later
Ada modifications by providing a few "hooks". I've discussed this 
modification earlier on this newsgroup.  At the moment, I've given
the definitions placeholder definitions that simply result in the
current semantics.  I propose to change them when Ada support is turned on.

The idea is to define "search name" as "the name that a language
module uses when searching for this symbol".  As discussed earlier,
the search name would be normally be the natural name, but in the case
of Ada, would just be the linkage name.

The modification to the signature of symbol_natural_name is to allow the
option of delayed (lazy) evaluation of the demangled name, which is
actually the point of introducing search names.

Paul Hilfinger

2004-03-03  Paul N. Hilfinger  <hilfinger@gnat.com>

	* symtab.h (symbol_natural_name): Remove const qualification 
	from argument.
	(SYMBOL_SEARCH_NAME): New definition.
	(SYMBOL_MATCHES_SEARCH_NAME): New definition.
	(SYMBOL_DEMANGLED_SEARCH_NAME): New definition.	

	* dictionary.c (iter_name_first_hashed): Match on SYMBOL_SEARCH_NAME.
	(iter_name_next_hashed): Ditto.
	(iter_name_next_linear): Ditto.
	(insert_symbol_hashed): Hash on SYMBOL_SEARCH_NAME.

	* symtab.c (symbol_natural_name): Remove const qualification from
	argument to allow lazy evaluation of demangled name.
	(lookup_partial_symbol): Assume symbols ordered by search name, using
	SYMBOL_SEARCH_NAME and SYMBOL_MATCHES_SEARCH_NAME.
	
	* symfile.c (compare_psymbols): Order by SYMBOL_SEARCH_NAME.
	
	* minsyms.c (build_minimal_symbol_hash_tables): Use 
	SYMBOL_DEMANGLED_SEARCH_NAME to test for adding to demangled
	hash table.
	

Index: current-public.49/gdb/minsyms.c
--- current-public.49/gdb/minsyms.c Mon, 09 Feb 2004 23:40:20 -0800 hilfingr (GdbPub/j/4_minsyms.c 1.1.1.3.1.1.1.1.1.1.1.1.1.1.3.2 644)
+++ submit.31(w)/gdb/minsyms.c Wed, 03 Mar 2004 00:34:32 -0800 hilfingr (GdbPub/j/4_minsyms.c 1.1.1.3.1.1.1.1.1.1.1.1.1.1.3.2.1.1 644)
@@ -794,7 +794,7 @@ build_minimal_symbol_hash_tables (struct
       add_minsym_to_hash_table (msym, objfile->msymbol_hash);
 
       msym->demangled_hash_next = 0;
-      if (SYMBOL_DEMANGLED_NAME (msym) != NULL)
+      if (SYMBOL_DEMANGLED_SEARCH_NAME (msym) != NULL)
 	add_minsym_to_demangled_hash_table (msym,
                                             objfile->msymbol_demangled_hash);
     }
Index: current-public.49/gdb/symfile.c
--- current-public.49/gdb/symfile.c Tue, 02 Mar 2004 23:57:04 -0800 hilfingr (GdbPub/k/48_symfile.c 1.1.1.7.1.1.1.2.1.1.1.1.1.1.1.1.1.1.3.1.1.2.1.1.1.1 644)
+++ submit.31(w)/gdb/symfile.c Wed, 03 Mar 2004 00:34:32 -0800 hilfingr (GdbPub/k/48_symfile.c 1.1.1.7.1.1.1.2.1.1.1.1.1.1.1.1.1.1.3.1.1.2.1.1.1.1.1.1 644)
@@ -208,8 +208,8 @@ compare_psymbols (const void *s1p, const
   struct partial_symbol *const *s1 = s1p;
   struct partial_symbol *const *s2 = s2p;
 
-  return strcmp_iw_ordered (SYMBOL_NATURAL_NAME (*s1),
-			    SYMBOL_NATURAL_NAME (*s2));
+  return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
+			    SYMBOL_SEARCH_NAME (*s2));
 }
 
 void
Index: current-public.49/gdb/symtab.c
--- current-public.49/gdb/symtab.c Mon, 23 Feb 2004 00:44:25 -0800 hilfingr (GdbPub/k/50_symtab.c 1.1.1.4.1.1.1.1.1.1.1.1.1.1.2.1.2.1.1.1.1.1.1.1 644)
+++ submit.31(w)/gdb/symtab.c Wed, 03 Mar 2004 01:55:44 -0800 hilfingr (GdbPub/k/50_symtab.c 1.1.1.4.1.1.1.1.1.1.1.1.1.1.2.1.2.1.1.1.1.1.1.1.1.1 644)
@@ -630,7 +630,7 @@ symbol_init_demangled_name (struct gener
    demangling is necessary, this is the demangled name.  */
 
 char *
-symbol_natural_name (const struct general_symbol_info *gsymbol)
+symbol_natural_name (struct general_symbol_info *gsymbol)
 {
   if ((gsymbol->language == language_cplus
        || gsymbol->language == language_java
@@ -1467,7 +1467,7 @@ lookup_partial_symbol (struct partial_sy
 	    {
 	      do_linear_search = 1;
 	    }
-	  if (strcmp_iw_ordered (SYMBOL_NATURAL_NAME (*center), name) >= 0)
+	  if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center), name) >= 0)
 	    {
 	      top = center;
 	    }
@@ -1482,7 +1482,7 @@ lookup_partial_symbol (struct partial_sy
       while (top <= real_top
 	     && (linkage_name != NULL
 		 ? strcmp (SYMBOL_LINKAGE_NAME (*top), linkage_name) == 0
-		 : SYMBOL_MATCHES_NATURAL_NAME (*top,name)))
+		 : SYMBOL_MATCHES_SEARCH_NAME (*top,name)))
 	{
 	  if (SYMBOL_DOMAIN (*top) == domain)
 	    {
@@ -1503,7 +1503,7 @@ lookup_partial_symbol (struct partial_sy
 	    {
 	      if (linkage_name != NULL
 		  ? strcmp (SYMBOL_LINKAGE_NAME (*psym), linkage_name) == 0
-		  : SYMBOL_MATCHES_NATURAL_NAME (*psym, name))
+		  : SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
 		{
 		  return (*psym);
 		}
Index: current-public.49/gdb/symtab.h
--- current-public.49/gdb/symtab.h Wed, 18 Feb 2004 01:34:45 -0800 hilfingr (GdbPub/l/2_symtab.h 1.1.1.5.1.1.1.1.1.1.1.1.1.1.3.1.1.1.1.1.1.1 644)
+++ submit.31(w)/gdb/symtab.h Wed, 03 Mar 2004 01:55:59 -0800 hilfingr (GdbPub/l/2_symtab.h 1.1.1.5.1.1.1.1.1.1.1.1.1.1.3.1.1.1.1.1.1.1.1.1 644)
@@ -213,7 +213,7 @@ extern void symbol_set_names (struct gen
 
 #define SYMBOL_NATURAL_NAME(symbol) \
   (symbol_natural_name (&(symbol)->ginfo))
-extern char *symbol_natural_name (const struct general_symbol_info *symbol);
+extern char *symbol_natural_name (struct general_symbol_info *symbol);
 
 /* Return SYMBOL's name from the point of view of the linker.  In
    languages like C++ where symbols may be mangled for ease of
@@ -257,6 +257,22 @@ extern char *symbol_demangled_name (stru
 
 #define SYMBOL_MATCHES_NATURAL_NAME(symbol, name)			\
   (strcmp_iw (SYMBOL_NATURAL_NAME (symbol), (name)) == 0)
+
+/* Macro that returns the name to be used when sorting and searching symbols. 
+   In most languages, we search for the demangled form of a name,
+   and so sort symbols accordingly. */
+#define SYMBOL_SEARCH_NAME(symbol)					 \
+  SYMBOL_NATURAL_NAME (symbol)
+
+/* Analogous to SYMBOL_MATCHES_NATURAL_NAME, but uses the search
+   name. */
+#define SYMBOL_MATCHES_SEARCH_NAME(symbol, name)			\
+  (strcmp_iw (SYMBOL_SEARCH_NAME (symbol), (name)) == 0)
+
+/* For languages that do not demangle or that do not do searches by 
+   demangled name, NULL.  Otherwise, the demangled name. */
+#define SYMBOL_DEMANGLED_SEARCH_NAME(symbol)				 \
+  SYMBOL_DEMANGLED_NAME (symbol)
 
 /* Classification types for a minimal symbol.  These should be taken as
    "advisory only", since if gdb can't easily figure out a
Index: current-public.49/gdb/dictionary.c
--- current-public.49/gdb/dictionary.c Tue, 17 Jun 2003 02:41:56 -0700 hilfingr (GdbPub/L/b/35_dictionary 1.1 644)
+++ submit.31(w)/gdb/dictionary.c Wed, 03 Mar 2004 00:34:33 -0800 hilfingr (GdbPub/L/b/35_dictionary 1.1.4.1 644)
@@ -636,7 +636,7 @@ iter_name_first_hashed (const struct dic
        sym = sym->hash_next)
     {
       /* Warning: the order of arguments to strcmp_iw matters!  */
-      if (strcmp_iw (SYMBOL_NATURAL_NAME (sym), name) == 0)
+      if (strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
 	{
 	  break;
 	}
@@ -656,7 +656,7 @@ iter_name_next_hashed (const char *name,
        next != NULL;
        next = next->hash_next)
     {
-      if (strcmp_iw (SYMBOL_NATURAL_NAME (next), name) == 0)
+      if (strcmp_iw (SYMBOL_SEARCH_NAME (next), name) == 0)
 	break;
     }
 
@@ -674,7 +674,7 @@ insert_symbol_hashed (struct dictionary 
   unsigned int hash_index;
   struct symbol **buckets = DICT_HASHED_BUCKETS (dict);
 
-  hash_index = (msymbol_hash_iw (SYMBOL_NATURAL_NAME (sym))
+  hash_index = (msymbol_hash_iw (SYMBOL_SEARCH_NAME (sym))
 		% DICT_HASHED_NBUCKETS (dict));
   sym->hash_next = buckets[hash_index];
   buckets[hash_index] = sym;
@@ -789,7 +789,7 @@ iter_name_next_linear (const char *name,
   for (i = DICT_ITERATOR_INDEX (iterator) + 1; i < nsyms; ++i)
     {
       sym = DICT_LINEAR_SYM (dict, i);
-      if (strcmp_iw (SYMBOL_NATURAL_NAME (sym), name) == 0)
+      if (strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
 	{
 	  retval = sym;
 	  break;


^ permalink raw reply	[flat|nested] 43+ messages in thread
* Re: [RFA] Introduce notion of "search name"
@ 2004-03-30  9:37 Paul Hilfinger
  0 siblings, 0 replies; 43+ messages in thread
From: Paul Hilfinger @ 2004-03-30  9:37 UTC (permalink / raw)
  To: gdb-patches


Ping.  I have not yet received a reply after my last message on this
patch, posted Wed, 3 Mar 2004 14:15:50 -0500 (EST).  For reference, I
have appended the initial discussion (minus patch), plus my responses
to David Carlton and Daniel Jacobwitz.  David and Daniel suggested
some minor changes, which you may consider made, but I haven't received 
any definitive word.

Paul Hilfinger

------------------------------------------------------------

Original discussion of 3 March.




The following patch does nothing except to prepare the way for some later
Ada modifications by providing a few "hooks". I've discussed this 
modification earlier on this newsgroup.  At the moment, I've given
the definitions placeholder definitions that simply result in the
current semantics.  I propose to change them when Ada support is turned on.

The idea is to define "search name" as "the name that a language
module uses when searching for this symbol".  As discussed earlier,
the search name would be normally be the natural name, but in the case
of Ada, would just be the linkage name.

The modification to the signature of symbol_natural_name is to allow the
option of delayed (lazy) evaluation of the demangled name, which is
actually the point of introducing search names.

Paul Hilfinger

2004-03-03  Paul N. Hilfinger  <hilfinger@gnat.com>

        * symtab.h (symbol_natural_name): Remove const qualification 
        from argument.
        (SYMBOL_SEARCH_NAME): New definition.
        (SYMBOL_MATCHES_SEARCH_NAME): New definition.
        (SYMBOL_DEMANGLED_SEARCH_NAME): New definition. 

        * dictionary.c (iter_name_first_hashed): Match on SYMBOL_SEARCH_NAME.
        (iter_name_next_hashed): Ditto.
        (iter_name_next_linear): Ditto.
        (insert_symbol_hashed): Hash on SYMBOL_SEARCH_NAME.

        * symtab.c (symbol_natural_name): Remove const qualification from
        argument to allow lazy evaluation of demangled name.
        (lookup_partial_symbol): Assume symbols ordered by search name, using
        SYMBOL_SEARCH_NAME and SYMBOL_MATCHES_SEARCH_NAME.
        
        * symfile.c (compare_psymbols): Order by SYMBOL_SEARCH_NAME.
        
        * minsyms.c (build_minimal_symbol_hash_tables): Use 
        SYMBOL_DEMANGLED_SEARCH_NAME to test for adding to demangled
        hash table.
        
------------------------------------------------------------

Reply to David Carlton of Thu, 4 Mar 2004 03:45:22 -0500 (EST) 


> Personally, I would leave the signature as is and cast away the
> constness when you eventually add this lazy demangling.  My
> justification is that the operation is logically a const operation;
> you're planning to generate some information on the fly, but it
> wouldn't actually change the state of the object.

Sounds fine to me.  I suppose that would be as close to the "mutable" idiom
as one can come in C.

Paul Hilfinger
Hilfinger@gnat.com

------------------------------------------------------------

Reply to Daniel Jacobowitz of Fri, 5 Mar 2004 05:39:25 -0500 (EST)  

Daniel,

> It doesn't address on of the thornier problems I hit when doing the
> same thing, namely that of allocation.  OK, someone uses
> SYMBOL_DEMANGLED_NAME, we lazily allocate a demangled name - where? The
> objfile is not available.  I think there may be no option but to
> pass the objfile to SYMBOL_DEMANGLED_NAME.  What did you do for Ada?

You're right, I did not address this in the patch proper.  I had
prepared a patch in which I used that extra byte in struct symtab to
tag the union and allow an objfile member.  However, I was aware from
correspondence with you that you were working in this area, and that
some of what you proposed to do might eventually allow us to re-do Ada
symbol lookup.  So I decided not to modify the symtab struct for the
moment, and instead submit a patch that would change as little as
possible.  I figured it would be better not to do anything just now
that might interfere with on-going work on the symbol table.

So as an interim measure, I use your suggestion of 21 Jan and first
try to find an objfile via the BFD section.  When that doesn't work, I
simply use a global hashtable to hold the demangled strings.  Yes,
that is a memory leak, but on consideration, I realized that it's only
REALLY a memory leak if (a) I routinely change the entire set of
demangled names numerous times during a single GDB session, or (b)
demangle entirely different, large sets of names each time I reload
the symbol tables.  Yeah, I know, it's not pretty, but again I am hoping
it will ensure that demangled names behave until the next interation of
symtab modifications allow an entirely different strategy.

> You define SYMBOL_DEMANGLED_SEARCH_NAME.  What's it really good for,
> and how does it do any good?  You only use it for the minimal symbol
> hash tables; the fundamental problem with minimal symbols is that we
> don't know their language, so I don't know how you can reliably make a
> language-specific decision like this one.

The relevant code now reads

      if (SYMBOL_DEMANGLED_NAME (msym) != NULL)
        add_minsym_to_demangled_hash_table (msym,
                                            objfile->msymbol_demangled_hash);

Ada does demangle; SYMBOL_DEMANGLED_NAME does have to return a
demangled name, if there is one.  Therefore the test here will
precipitate computing and caching the demangled name prematurely (once
symbol_demangled_name is extended to include the Ada case).  This code
also adds the demangled name to the hash table.  But we never look for
demangled names, so that is a waste.

As to your question about how this can work: Ada doesn't really change
your question.  I could just as well ask "How can
SYMBOL_DEMANGLED_NAME work on minimal symbols, given that it doesn't
know what language to use for demangling?" The answer is that if it
quacks like a duck ... excuse me, I mean if ObjC demangling works,
assume you have an ObjC symbol, if C++ demangling works, then assume
it is a C++ symbol, etc., and hope that the demangling schemes don't
collide.  That's what the code says now.  You'll have to argue the 
sensibility of this strategy with others.

> SYMBOL_DEMANGLED_SEARCH_NAME also codifies more than necessary of the
> difference between the other SYMBOL_*_NAME macros and
> SYMBOL_SEARCH_NAME.  Something that I think may be useful is to use
> just the basename for the search name and then have language-specific
> code to cherry-pick the resulting matches afterwards; one big advantage
> of this is that it lets me sidestep the Java vs. C++ demangling issues.
> I suspect it is possible (for all supported languages) to unambiguously
> and efficiently identify the basename. I need to look at some of the
> other in-use manglings to follow up on that idea though, particularly
> g++ v2 and ObjC.

Yes, I know: you discussed that before and I eagerly await these changes.
For the nonce, I still think I've found a reasonably small hook that 
accomplishes our purposes.

> Oh, and two spaces after a full stop in comments.

Oh, woe: of all your comments, this will be the most difficult to
accommodate.  You see, ACT is full of these confounded Europeans who
insist on single spaces after periods and yell whenever I do things
properly instead.  No doubt they will relent when they hear how this
practice will slow up these patches.  :->).

Paul Hilfinger
Ada Core Technologies, Inc.


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

end of thread, other threads:[~2004-05-21 20:01 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-03 19:15 [RFA] Introduce notion of "search name" Paul Hilfinger
2004-03-19  0:09 ` Paul Hilfinger
2004-03-19  0:09 ` David Carlton
2004-03-03 19:26   ` David Carlton
2004-03-19  0:09   ` Paul Hilfinger
2004-03-04  8:45     ` Paul Hilfinger
2004-03-19  0:09 ` Daniel Jacobowitz
2004-03-05  3:59   ` Daniel Jacobowitz
2004-03-05 10:39   ` Paul Hilfinger
2004-03-19  0:09     ` Paul Hilfinger
2004-03-31 22:12     ` Daniel Jacobowitz
2004-04-01 14:53       ` Jim Blandy
2004-04-01 15:00         ` Daniel Jacobowitz
2004-04-01 15:21           ` Jim Blandy
2004-04-02  9:30             ` Paul Hilfinger
2004-04-02 22:27               ` Jim Blandy
2004-04-03 12:04                 ` Paul Hilfinger
2004-04-06 14:37                   ` Jim Blandy
2004-04-02  9:33         ` Paul Hilfinger
2004-04-02  8:29       ` Paul Hilfinger
2004-04-09 22:40         ` Daniel Jacobowitz
2004-04-12  8:22           ` Paul Hilfinger
2004-04-16  4:11             ` Jim Blandy
2004-04-29 10:37               ` Paul Hilfinger
     [not found]                 ` <20040429211458.GB27523@nevyn.them.org>
     [not found]                   ` <vt2n04umj8b.fsf@zenia.home>
     [not found]                     ` <20040430084538.ECDE1F2E1C@nile.gnat.com>
     [not found]                       ` <20040430134955.GA15786@nevyn.them.org>
2004-05-03  8:49                         ` Paul Hilfinger
2004-05-11 19:48                           ` Daniel Jacobowitz
2004-05-12 11:00                             ` Paul Hilfinger
2004-05-12 13:27                               ` Daniel Jacobowitz
2004-05-12 14:14                                 ` Andrew Cagney
2004-05-12 14:23                                   ` Daniel Jacobowitz
2004-05-12 15:11                                     ` Andrew Cagney
2004-05-12 16:59                                       ` Joel Brobecker
2004-05-13 14:29                                         ` Andrew Cagney
2004-05-13  9:30                                   ` Paul Hilfinger
2004-05-13 13:49                                     ` Daniel Jacobowitz
2004-05-18 21:59                                     ` Jim Blandy
2004-05-19  9:55                                       ` Paul Hilfinger
2004-05-19 13:00                                         ` Daniel Jacobowitz
2004-05-19 15:21                                       ` Andrew Cagney
2004-05-20 10:18                                         ` Abstracting "name" Paul Hilfinger
2004-05-21 19:10                                           ` Andrew Cagney
2004-05-21 20:01                                             ` Jim Blandy
2004-03-30  9:37 [RFA] Introduce notion of "search name" Paul Hilfinger

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