This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 2/6] Change representation of psymbol to flush out accessors
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Thu, 3 May 2018 16:36:17 -0600
- Subject: [RFA 2/6] Change representation of psymbol to flush out accessors
- References: <20180503223621.22544-1-tom@tromey.com>
This is the psymbol analog to the patch to change the representation
of minimal symbols:
https://sourceware.org/ml/gdb-patches/2013-10/msg00524.html
It has the same rationale: namely, that we're going to change the code
to apply psymbol offsets at runtime. This will be done by adding an
argument to the SYMBOL_VALUE_ADDRESS macro -- but since we can't
convert all the symbol types at once, we need a new macro.
Also, as noted before, these macros implement a kind of "phony
polymorphism" that is not actually useful in practice; so introducing
a new macro that is specific to psymbols is probably a slight
improvement anyhow.
ChangeLog
2018-05-03 Tom Tromey <tom@tromey.com>
* dwarf-index-write.c (write_psymbols, debug_names::insert)
(debug_names::write_psymbols): Update.
* psympriv.h (struct partial_symbol) <pginfo>: Rename from
'ginfo'.
(PSYMBOL_VALUE, PSYMBOL_VALUE_ADDRESS, PSYMBOL_LANGUAGE)
(PSYMBOL_SECTION, PSYMBOL_OBJ_SECTION, PSYMBOL_SET_LANGUAGE)
(PSYMBOL_SET_NAMES, PSYMBOL_LINKAGE_NAME, PSYMBOL_DEMANGLED_NAME)
(PSYMBOL_SEARCH_NAME, PSYMBOL_MATCHES_SEARCH_NAME): New macros.
* psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab)
(find_pc_sect_psymbol, fixup_psymbol_section)
(match_partial_symbol, lookup_partial_symbol, relocate_psymtabs)
(print_partial_symbols, recursively_search_psymtabs)
(compare_psymbols, psymbol_hash, psymbol_compare)
(add_psymbol_to_bcache, maintenance_check_psymtabs)
(psymbol_name_matches, psym_fill_psymbol_map): Update.
---
gdb/ChangeLog | 18 ++++++++
gdb/dwarf-index-write.c | 8 ++--
gdb/psympriv.h | 25 +++++++++-
gdb/psymtab.c | 118 ++++++++++++++++++++++++------------------------
4 files changed, 106 insertions(+), 63 deletions(-)
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index a5e196db32..74080c48b8 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -546,7 +546,7 @@ write_psymbols (struct mapped_symtab *symtab,
{
struct partial_symbol *psym = *psymp;
- if (SYMBOL_LANGUAGE (psym) == language_ada)
+ if (PSYMBOL_LANGUAGE (psym) == language_ada)
error (_("Ada is not currently supported by the index"));
/* Only add a given psymbol once. */
@@ -554,7 +554,7 @@ write_psymbols (struct mapped_symtab *symtab,
{
gdb_index_symbol_kind kind = symbol_kind (psym);
- add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym),
+ add_index_entry (symtab, PSYMBOL_SEARCH_NAME (psym),
is_static, kind, cu_index);
}
}
@@ -688,7 +688,7 @@ public:
const int dwarf_tag = psymbol_tag (psym);
if (dwarf_tag == 0)
return;
- const char *const name = SYMBOL_SEARCH_NAME (psym);
+ const char *const name = PSYMBOL_SEARCH_NAME (psym);
const auto insertpair
= m_name_to_value_set.emplace (c_str_view (name),
std::set<symbol_value> ());
@@ -1184,7 +1184,7 @@ private:
{
struct partial_symbol *psym = *psymp;
- if (SYMBOL_LANGUAGE (psym) == language_ada)
+ if (PSYMBOL_LANGUAGE (psym) == language_ada)
error (_("Ada is not currently supported by the index"));
/* Only add a given psymbol once. */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 45746a26a7..31f2a2b3e9 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -37,7 +37,7 @@ struct partial_symbol
{
/* The general symbol info required for all types of symbols. */
- struct general_symbol_info ginfo;
+ struct general_symbol_info pginfo;
/* Name space code. */
@@ -50,9 +50,32 @@ struct partial_symbol
ENUM_BITFIELD(address_class) aclass : SYMBOL_ACLASS_BITS;
};
+#define PSYMBOL_VALUE(symbol) (symbol)->pginfo.value.ivalue
+#define PSYMBOL_VALUE_ADDRESS(symbol) (symbol)->pginfo.value.address
+#define PSYMBOL_LANGUAGE(symbol) (symbol)->pginfo.language
+#define PSYMBOL_SECTION(symbol) (symbol)->pginfo.section
+#define PSYMBOL_OBJ_SECTION(objfile, symbol) \
+ (((symbol)->pginfo.section >= 0) \
+ ? (&(((objfile)->sections)[(symbol)->pginfo.section])) \
+ : NULL)
+
+#define PSYMBOL_SET_LANGUAGE(symbol,language,obstack) \
+ (symbol_set_language (&(symbol)->pginfo, (language), (obstack)))
+#define PSYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
+ symbol_set_names (&(symbol)->pginfo, linkage_name, len, copy_name, objfile)
+
+#define PSYMBOL_LINKAGE_NAME(symbol) (symbol)->pginfo.name
+#define PSYMBOL_DEMANGLED_NAME(symbol) \
+ (symbol_demangled_name (&(symbol)->pginfo))
+#define PSYMBOL_SEARCH_NAME(symbol) \
+ (symbol_search_name (&(symbol)->pginfo))
+
#define PSYMBOL_DOMAIN(psymbol) (psymbol)->domain
#define PSYMBOL_CLASS(psymbol) (psymbol)->aclass
+#define PSYMBOL_MATCHES_SEARCH_NAME(symbol, name) \
+ symbol_matches_search_name (&(symbol)->pginfo, (name))
+
/* A convenience enum to give names to some constants used when
searching psymtabs. This is internal to psymtab and should not be
used elsewhere. */
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index ac0ee0a5a6..e9a6a23b9d 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -267,7 +267,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
object's symbol table. */
p = find_pc_sect_psymbol (objfile, tpst, pc, section);
if (p != NULL
- && (SYMBOL_VALUE_ADDRESS (p)
+ && (PSYMBOL_VALUE_ADDRESS (p)
== BMSYMBOL_VALUE_ADDRESS (msymbol)))
return tpst;
@@ -276,7 +276,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
symbol tables with line information but no debug
symbols (e.g. those produced by an assembler). */
if (p != NULL)
- this_addr = SYMBOL_VALUE_ADDRESS (p);
+ this_addr = PSYMBOL_VALUE_ADDRESS (p);
else
this_addr = tpst->textlow;
@@ -334,7 +334,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
object's symbol table. */
p = find_pc_sect_psymbol (objfile, pst, pc, section);
if (p == NULL
- || (SYMBOL_VALUE_ADDRESS (p)
+ || (PSYMBOL_VALUE_ADDRESS (p)
!= BMSYMBOL_VALUE_ADDRESS (msymbol)))
goto next;
}
@@ -427,19 +427,19 @@ find_pc_sect_psymbol (struct objfile *objfile,
if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
&& PSYMBOL_CLASS (p) == LOC_BLOCK
- && pc >= SYMBOL_VALUE_ADDRESS (p)
- && (SYMBOL_VALUE_ADDRESS (p) > best_pc
+ && pc >= PSYMBOL_VALUE_ADDRESS (p)
+ && (PSYMBOL_VALUE_ADDRESS (p) > best_pc
|| (psymtab->textlow == 0
- && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
+ && best_pc == 0 && PSYMBOL_VALUE_ADDRESS (p) == 0)))
{
if (section != NULL) /* Match on a specific section. */
{
fixup_psymbol_section (p, objfile);
- if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, p),
+ if (!matching_obj_sections (PSYMBOL_OBJ_SECTION (objfile, p),
section))
continue;
}
- best_pc = SYMBOL_VALUE_ADDRESS (p);
+ best_pc = PSYMBOL_VALUE_ADDRESS (p);
best = p;
}
}
@@ -450,19 +450,19 @@ find_pc_sect_psymbol (struct objfile *objfile,
if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
&& PSYMBOL_CLASS (p) == LOC_BLOCK
- && pc >= SYMBOL_VALUE_ADDRESS (p)
- && (SYMBOL_VALUE_ADDRESS (p) > best_pc
+ && pc >= PSYMBOL_VALUE_ADDRESS (p)
+ && (PSYMBOL_VALUE_ADDRESS (p) > best_pc
|| (psymtab->textlow == 0
- && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
+ && best_pc == 0 && PSYMBOL_VALUE_ADDRESS (p) == 0)))
{
if (section != NULL) /* Match on a specific section. */
{
fixup_psymbol_section (p, objfile);
- if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, p),
+ if (!matching_obj_sections (PSYMBOL_OBJ_SECTION (objfile, p),
section))
continue;
}
- best_pc = SYMBOL_VALUE_ADDRESS (p);
+ best_pc = PSYMBOL_VALUE_ADDRESS (p);
best = p;
}
}
@@ -478,7 +478,7 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
if (psym == NULL)
return;
- if (SYMBOL_SECTION (psym) >= 0)
+ if (PSYMBOL_SECTION (psym) >= 0)
return;
gdb_assert (objfile);
@@ -488,7 +488,7 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
case LOC_STATIC:
case LOC_LABEL:
case LOC_BLOCK:
- addr = SYMBOL_VALUE_ADDRESS (psym);
+ addr = PSYMBOL_VALUE_ADDRESS (psym);
break;
default:
/* Nothing else will be listed in the minsyms -- no use looking
@@ -496,7 +496,7 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
return;
}
- fixup_section (&psym->ginfo, addr, objfile);
+ fixup_section (&psym->pginfo, addr, objfile);
}
/* Psymtab version of lookup_symbol. See its definition in
@@ -554,10 +554,10 @@ static bool
psymbol_name_matches (partial_symbol *psym,
const lookup_name_info &lookup_name)
{
- const language_defn *lang = language_def (SYMBOL_LANGUAGE (psym));
+ const language_defn *lang = language_def (PSYMBOL_LANGUAGE (psym));
symbol_name_matcher_ftype *name_match
= get_symbol_name_matcher (lang, lookup_name);
- return name_match (SYMBOL_SEARCH_NAME (psym), lookup_name, NULL);
+ return name_match (PSYMBOL_SEARCH_NAME (psym), lookup_name, NULL);
}
/* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
@@ -607,11 +607,11 @@ match_partial_symbol (struct objfile *objfile,
center = bottom + (top - bottom) / 2;
gdb_assert (center < top);
- enum language lang = SYMBOL_LANGUAGE (*center);
+ enum language lang = PSYMBOL_LANGUAGE (*center);
const char *lang_ln
= lookup_name.language_lookup_name (lang).c_str ();
- if (ordered_compare (SYMBOL_SEARCH_NAME (*center), lang_ln) >= 0)
+ if (ordered_compare (PSYMBOL_SEARCH_NAME (*center), lang_ln) >= 0)
top = center;
else
bottom = center + 1;
@@ -621,8 +621,8 @@ match_partial_symbol (struct objfile *objfile,
while (top <= real_top
&& psymbol_name_matches (*top, lookup_name))
{
- if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
- SYMBOL_DOMAIN (*top), domain))
+ if (symbol_matches_domain (PSYMBOL_LANGUAGE (*top),
+ PSYMBOL_DOMAIN (*top), domain))
return *top;
top++;
}
@@ -635,7 +635,7 @@ match_partial_symbol (struct objfile *objfile,
{
for (psym = start; psym < start + length; psym++)
{
- if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
+ if (symbol_matches_domain (PSYMBOL_LANGUAGE (*psym),
SYMBOL_DOMAIN (*psym), domain)
&& psymbol_name_matches (*psym, lookup_name))
return *psym;
@@ -718,7 +718,7 @@ lookup_partial_symbol (struct objfile *objfile,
if (!(center < top))
internal_error (__FILE__, __LINE__,
_("failed internal consistency check"));
- if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
+ if (strcmp_iw_ordered (PSYMBOL_SEARCH_NAME (*center),
search_name.get ()) >= 0)
{
top = center;
@@ -734,15 +734,15 @@ lookup_partial_symbol (struct objfile *objfile,
/* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
- while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, lookup_name))
+ while (top >= start && PSYMBOL_MATCHES_SEARCH_NAME (*top, lookup_name))
top--;
/* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
top++;
- while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, lookup_name))
+ while (top <= real_top && PSYMBOL_MATCHES_SEARCH_NAME (*top, lookup_name))
{
- if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
+ if (symbol_matches_domain (PSYMBOL_LANGUAGE (*top),
SYMBOL_DOMAIN (*top), domain))
return *top;
top++;
@@ -756,9 +756,9 @@ lookup_partial_symbol (struct objfile *objfile,
{
for (psym = start; psym < start + length; psym++)
{
- if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
+ if (symbol_matches_domain (PSYMBOL_LANGUAGE (*psym),
SYMBOL_DOMAIN (*psym), domain)
- && SYMBOL_MATCHES_SEARCH_NAME (*psym, lookup_name))
+ && PSYMBOL_MATCHES_SEARCH_NAME (*psym, lookup_name))
return *psym;
}
}
@@ -814,14 +814,16 @@ psym_relocate (struct objfile *objfile,
for (partial_symbol *psym : objfile->global_psymbols)
{
fixup_psymbol_section (psym, objfile);
- if (SYMBOL_SECTION (psym) >= 0)
- SYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta, SYMBOL_SECTION (psym));
+ if (PSYMBOL_SECTION (psym) >= 0)
+ PSYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta,
+ PSYMBOL_SECTION (psym));
}
for (partial_symbol *psym : objfile->static_psymbols)
{
fixup_psymbol_section (psym, objfile);
- if (SYMBOL_SECTION (psym) >= 0)
- SYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta, SYMBOL_SECTION (psym));
+ if (PSYMBOL_SECTION (psym) >= 0)
+ PSYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta,
+ PSYMBOL_SECTION (psym));
}
objfile->psymbol_map.clear ();
@@ -893,10 +895,10 @@ print_partial_symbols (struct gdbarch *gdbarch,
while (count-- > 0)
{
QUIT;
- fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
- if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
+ fprintf_filtered (outfile, " `%s'", PSYMBOL_LINKAGE_NAME (*p));
+ if (PSYMBOL_DEMANGLED_NAME (*p) != NULL)
{
- fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
+ fprintf_filtered (outfile, " `%s'", PSYMBOL_DEMANGLED_NAME (*p));
}
fputs_filtered (", ", outfile);
switch (SYMBOL_DOMAIN (*p))
@@ -969,7 +971,7 @@ print_partial_symbols (struct gdbarch *gdbarch,
break;
}
fputs_filtered (", ", outfile);
- fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
+ fputs_filtered (paddress (gdbarch, PSYMBOL_VALUE_ADDRESS (*p)), outfile);
fprintf_filtered (outfile, "\n");
p++;
}
@@ -1371,7 +1373,7 @@ recursively_search_psymtabs
|| (domain == TYPES_DOMAIN
&& PSYMBOL_CLASS (*psym) == LOC_TYPEDEF))
&& psymbol_name_matches (*psym, lookup_name)
- && (sym_matcher == NULL || sym_matcher (SYMBOL_SEARCH_NAME (*psym))))
+ && (sym_matcher == NULL || sym_matcher (PSYMBOL_SEARCH_NAME (*psym))))
{
/* Found a match, so notify our caller. */
result = PST_SEARCHED_AND_FOUND;
@@ -1477,7 +1479,7 @@ psym_fill_psymbol_map (struct objfile *objfile,
if (PSYMBOL_CLASS (psym) == LOC_STATIC)
{
- CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (psym);
+ CORE_ADDR addr = PSYMBOL_VALUE_ADDRESS (psym);
if (seen_addrs->find (addr) == seen_addrs->end ())
{
seen_addrs->insert (addr);
@@ -1573,8 +1575,8 @@ sort_pst_symbols (struct objfile *objfile, struct partial_symtab *pst)
std::sort (begin, end, [] (partial_symbol *s1, partial_symbol *s2)
{
- return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (s1),
- SYMBOL_SEARCH_NAME (s2)) < 0;
+ return strcmp_iw_ordered (PSYMBOL_SEARCH_NAME (s1),
+ PSYMBOL_SEARCH_NAME (s2)) < 0;
});
}
@@ -1621,17 +1623,17 @@ psymbol_hash (const void *addr, int length)
{
unsigned long h = 0;
struct partial_symbol *psymbol = (struct partial_symbol *) addr;
- unsigned int lang = psymbol->ginfo.language;
+ unsigned int lang = PSYMBOL_LANGUAGE (psymbol);
unsigned int domain = PSYMBOL_DOMAIN (psymbol);
unsigned int theclass = PSYMBOL_CLASS (psymbol);
- h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
+ h = hash_continue (&psymbol->pginfo.value, sizeof (psymbol->pginfo.value), h);
h = hash_continue (&lang, sizeof (unsigned int), h);
h = hash_continue (&domain, sizeof (unsigned int), h);
h = hash_continue (&theclass, sizeof (unsigned int), h);
/* Note that psymbol names are interned via symbol_set_names, so
there's no need to hash the contents of the name here. */
- h = hash_continue (&psymbol->ginfo.name, sizeof (psymbol->ginfo.name), h);
+ h = hash_continue (&psymbol->pginfo.name, sizeof (psymbol->pginfo.name), h);
return h;
}
@@ -1646,15 +1648,15 @@ psymbol_compare (const void *addr1, const void *addr2, int length)
struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
- return (memcmp (&sym1->ginfo.value, &sym2->ginfo.value,
- sizeof (sym1->ginfo.value)) == 0
- && sym1->ginfo.language == sym2->ginfo.language
+ return (memcmp (&sym1->pginfo.value, &sym2->pginfo.value,
+ sizeof (sym1->pginfo.value)) == 0
+ && sym1->pginfo.language == sym2->pginfo.language
&& PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
&& PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
/* Note that psymbol names are interned via
symbol_set_names, so there's no need to compare the
contents of the name here. */
- && sym1->ginfo.name == sym2->ginfo.name);
+ && sym1->pginfo.name == sym2->pginfo.name);
}
/* Initialize a partial symbol bcache. */
@@ -1724,13 +1726,13 @@ add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
holes. */
memset (&psymbol, 0, sizeof (psymbol));
- SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
- SYMBOL_SECTION (&psymbol) = -1;
- SYMBOL_SET_LANGUAGE (&psymbol, language, &objfile->objfile_obstack);
+ PSYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
+ PSYMBOL_SECTION (&psymbol) = -1;
+ PSYMBOL_SET_LANGUAGE (&psymbol, language, &objfile->objfile_obstack);
PSYMBOL_DOMAIN (&psymbol) = domain;
PSYMBOL_CLASS (&psymbol) = theclass;
- SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
+ PSYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
/* Stash the partial symbol away in the cache. */
return psymbol_bcache_full (&psymbol, objfile->psymbol_cache, added);
@@ -2254,13 +2256,13 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
length = ps->n_static_syms;
while (length--)
{
- sym = block_lookup_symbol (b, SYMBOL_SEARCH_NAME (*psym),
+ sym = block_lookup_symbol (b, PSYMBOL_SEARCH_NAME (*psym),
symbol_name_match_type::SEARCH_NAME,
- SYMBOL_DOMAIN (*psym));
+ PSYMBOL_DOMAIN (*psym));
if (!sym)
{
printf_filtered ("Static symbol `");
- puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
+ puts_filtered (PSYMBOL_LINKAGE_NAME (*psym));
printf_filtered ("' only found in ");
puts_filtered (ps->filename);
printf_filtered (" psymtab\n");
@@ -2272,13 +2274,13 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
length = ps->n_global_syms;
while (length--)
{
- sym = block_lookup_symbol (b, SYMBOL_SEARCH_NAME (*psym),
+ sym = block_lookup_symbol (b, PSYMBOL_SEARCH_NAME (*psym),
symbol_name_match_type::SEARCH_NAME,
- SYMBOL_DOMAIN (*psym));
+ PSYMBOL_DOMAIN (*psym));
if (!sym)
{
printf_filtered ("Global symbol `");
- puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
+ puts_filtered (PSYMBOL_LINKAGE_NAME (*psym));
printf_filtered ("' only found in ");
puts_filtered (ps->filename);
printf_filtered (" psymtab\n");
--
2.13.6