[RFC] Proposed changes in symbol-handling for Ada

Paul Hilfinger
2004-01-20T10:16:17Z

David,

I'd appreciate your comments on the following approach to handling the
... um ... difference of opinion between the Ada world and everyone else
regarding symbols. We've briefly discussed it before; now I'd like to get
specific.

We decided years ago NOT to store demangled names, considering it an
unnecessary waste of space (some ACT customers have very large symbol tables)
and start-up time. Instead we MANGLE names that are searched for and then
look those up. In our own sources, we've added a level of indirection to
minimize the effect on the rest of GDB. It's worked out well, and we've
experienced very few maintenance problems with this approach (aside,
of course, from a SMALL amount of fuss to adapt your major re-organization
of the symbol stuff (:->)).

Basically, we found it sufficient to introduce some additional macros in
symtab.h:

+/* Macro that returns the name to be used when sorting and searching symbols.
+ In C++, Chill, and Java, we search for the demangled form of a name,
+ and so sort symbols accordingly. In Ada, however, we search by mangled
+ name. */
+#define SYMBOL_SEARCH_NAME(symbol) \
+ (SYMBOL_LANGUAGE (symbol) == language_ada \
+ ? SYMBOL_LINKAGE_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_LANGUAGE (symbol) == language_ada \
+ ? NULL \
+ : SYMBOL_DEMANGLED_NAME (symbol))
+

We then use these in place of SYMBOL_DEMANGLED_NAME, SYMBOL_NATURAL_NAME,
etc. in several places. More details are in the patch below

I'd appreciate your comments before attempting to fill this out into an
offical patch. Thanks.

Paul Hilfinger

Index: current-public.41/gdb/defs.h
--- current-public.41/gdb/defs.h Sun, 04 Jan 2004 17:51:24 -0800 hilfingr (GdbPub/h/12_defs.h 1.1.1.5.2.1.1.2.1.1.1.1.1.1.1.1.2.1 644)
+++ submit.29/gdb/defs.h Thu, 15 Jan 2004 03:02:36 -0800 hilfingr (GdbPub/h/12_defs.h 1.1.1.5.2.1.1.2.1.1.1.1.1.1.1.1.2.1.1.1 644)
@@ -223,6 +223,7 @@ enum language
language_asm, /* Assembly language */
language_scm, /* Scheme / Guile */
language_pascal, /* Pascal */
+ language_ada, /* Ada */
language_minimal /* All other languages, minimal support only */
};

Index: current-public.41/gdb/minsyms.c
--- current-public.41/gdb/minsyms.c Wed, 19 Nov 2003 00:01:38 -0800 hilfingr (GdbPub/j/4_minsyms.c 1.1.1.3.1.1.1.1.1.1.1.1.1.1 644)
+++ submit.29/gdb/minsyms.c Tue, 20 Jan 2004 00:56:34 -0800 hilfingr (GdbPub/j/4_minsyms.c 1.1.1.3.1.1.1.1.1.1.1.1.1.1.2.1 644)
@@ -785,7 +785,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.41/gdb/symfile.c
--- current-public.41/gdb/symfile.c Sat, 13 Dec 2003 03:27:23 -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 644)
+++ submit.29/gdb/symfile.c Tue, 20 Jan 2004 00:56:34 -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.2.1 644)
@@ -210,7 +211,7 @@ compare_symbols (const void *s1p, const

s1 = (struct symbol **) s1p;
s2 = (struct symbol **) s2p;
- return (strcmp (SYMBOL_NATURAL_NAME (*s1), SYMBOL_NATURAL_NAME (*s2)));
+ return (strcmp (SYMBOL_SEARCH_NAME (*s1), SYMBOL_SEARCH_NAME (*s2)));
}

/* This compares two partial symbols by names, using strcmp_iw_ordered
@@ -222,8 +223,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.41/gdb/symtab.c
--- current-public.41/gdb/symtab.c Sun, 04 Jan 2004 17:51:24 -0800 hilfingr (GdbPub/k/50_symtab.c 1.1.1.4.1.1.1.1.1.1.1.1.1.1.2.1 644)
+++ submit.29/gdb/symtab.c Thu, 15 Jan 2004 03:02:36 -0800 hilfingr (GdbPub/k/50_symtab.c 1.1.1.4.1.1.1.1.1.1.1.1.1.1.2.1.1.1 644)
@@ -54,6 +54,7 @@
#include "gdb_stat.h"
#include <ctype.h>
#include "cp-abi.h"
+#include "ada-lang.h"

/* Prototypes for local functions */

@@ -639,6 +640,10 @@ symbol_natural_name (const struct genera
{
return gsymbol->language_specific.cplus_specific.demangled_name;
}
+ else if (gsymbol->language == language_ada)
+ {
+ return ada_demangle (gsymbol->name);
+ }
else
{
return gsymbol->name;
@@ -654,7 +659,10 @@ symbol_demangled_name (struct general_sy
|| gsymbol->language == language_java
|| gsymbol->language == language_objc)
return gsymbol->language_specific.cplus_specific.demangled_name;
-
+ else if (gsymbol->language == language_ada)
+ {
+ return ada_demangle (gsymbol->name);
+ }
else
return NULL;
}
@@ -1432,7 +1462,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;
}
@@ -1447,7 +1477,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)
{
@@ -1468,7 +1498,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.41/gdb/symtab.h
--- current-public.41/gdb/symtab.h Wed, 19 Nov 2003 00:01:38 -0800 hilfingr (GdbPub/l/2_symtab.h 1.1.1.5.1.1.1.1.1.1.1.1.1.1 644)
+++ submit.29/gdb/symtab.h Thu, 15 Jan 2004 03:02:36 -0800 hilfingr (GdbPub/l/2_symtab.h 1.1.1.5.1.1.1.1.1.1.1.1.1.1.2.1 644)
@@ -258,6 +260,27 @@ 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 C++, Chill, and Java, we search for the demangled form of a name,
+ and so sort symbols accordingly. In Ada, however, we search by mangled
+ name. */
+#define SYMBOL_SEARCH_NAME(symbol) \
+ (SYMBOL_LANGUAGE (symbol) == language_ada \
+ ? SYMBOL_LINKAGE_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_LANGUAGE (symbol) == language_ada \
+ ? NULL \
+ : 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
classification it simply selects mst_unknown. It may also have to
Index: current-public.41/gdb/dictionary.c
--- current-public.41/gdb/dictionary.c Tue, 17 Jun 2003 02:41:56 -0700 hilfingr (GdbPub/L/b/35_dictionary 1.1 644)
+++ submit.29/gdb/dictionary.c Tue, 20 Jan 2004 00:56:34 -0800 hilfingr (GdbPub/L/b/35_dictionary 1.1.3.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;