This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch 2/3] Keith's psymtabs fix [Re: [RFA] c++/11734 revisited]
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Keith Seitz <keiths at redhat dot com>
- Cc: Tom Tromey <tromey at redhat dot com>, gdb-patches at sourceware dot org
- Date: Sun, 6 Feb 2011 23:46:22 +0100
- Subject: [patch 2/3] Keith's psymtabs fix [Re: [RFA] c++/11734 revisited]
- References: <4D002672.5090504@redhat.com> <m3oc8u1uzs.fsf@fleche.redhat.com> <4D07CD68.5000700@redhat.com>
Hi Keith,
[patch 2/3] is application of the 11734 non-decode_compound part psymtabs fix.
this is a part of the patch of yours which should be applied in any case.
Jan
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -35,6 +35,7 @@
#include "exceptions.h"
#include "expression.h"
#include "value.h"
+#include "language.h"
#include "safe-ctype.h"
@@ -936,7 +937,8 @@ make_symbol_overload_list_qualified (const char *func_name)
ALL_OBJFILES (objfile)
{
if (objfile->sf)
- objfile->sf->qf->expand_symtabs_for_function (objfile, func_name);
+ objfile->sf->qf->expand_symtabs_for_function (objfile, func_name,
+ language_cplus);
}
/* Search upwards from currently selected frame (so that we can
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2362,7 +2362,8 @@ dw2_lookup_symtab (struct objfile *objfile, const char *name,
static struct symtab *
dw2_lookup_symbol (struct objfile *objfile, int block_index,
- const char *name, domain_enum domain)
+ const char *name, domain_enum domain,
+ enum language language)
{
/* We do all the work in the pre_expand_symtabs_matching hook
instead. */
@@ -2438,7 +2439,8 @@ dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
static void
dw2_expand_symtabs_for_function (struct objfile *objfile,
- const char *func_name)
+ const char *func_name,
+ enum language language)
{
dw2_do_expand_symtabs_matching (objfile, func_name);
}
@@ -2498,7 +2500,8 @@ dw2_expand_symtabs_with_filename (struct objfile *objfile,
}
static const char *
-dw2_find_symbol_file (struct objfile *objfile, const char *name)
+dw2_find_symbol_file (struct objfile *objfile, const char *name,
+ enum language language)
{
struct dwarf2_per_cu_data *per_cu;
offset_type *vec;
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -33,6 +33,8 @@
#include "readline/readline.h"
#include "gdb_regex.h"
#include "dictionary.h"
+#include "language.h"
+#include "cp-support.h"
#ifndef DEV_TTY
#define DEV_TTY "/dev/tty"
@@ -55,7 +57,8 @@ static struct partial_symbol *match_partial_symbol (struct partial_symtab *,
static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
const char *, int,
- domain_enum);
+ domain_enum,
+ enum language);
static char *psymtab_to_fullname (struct partial_symtab *ps);
@@ -418,15 +421,35 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
static struct symtab *
lookup_symbol_aux_psymtabs (struct objfile *objfile,
int block_index, const char *name,
- const domain_enum domain)
+ const domain_enum domain, enum language language)
{
struct partial_symtab *ps;
const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
ALL_OBJFILE_PSYMTABS (objfile, ps)
{
- if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
- return PSYMTAB_TO_SYMTAB (ps);
+ if (!ps->readin
+ && lookup_partial_symbol (ps, name, psymtab_index, domain, language))
+ {
+ struct symbol *sym;
+ struct symtab *stab = PSYMTAB_TO_SYMTAB (ps);
+ sym = NULL;
+
+ /* Some caution must be observed with overloaded functions
+ and methods, since the psymtab will not contain any overload
+ information (but NAME might contain it). */
+ if (stab->primary)
+ {
+ struct blockvector *bv = BLOCKVECTOR (stab);
+ struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
+ sym = lookup_block_symbol (block, name, domain);
+ }
+
+ if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
+ return stab;
+
+ /* Keep looking through other psymtabs. */
+ }
}
return NULL;
@@ -519,22 +542,58 @@ pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
/* Nothing. */
}
+/* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
+ not contain any method/function instance information (since this would
+ force reading type information while reading psymtabs). Therefore,
+ if NAME contains overload information, it must be stripped before searching
+ psymtabs.
+
+ The caller is responsible for freeing the return result. */
+
+static const char *
+psymtab_search_name (const char *name, enum language language)
+{
+ switch (language)
+ {
+ case language_cplus:
+ case language_java:
+ {
+ if (strchr (name, '('))
+ {
+ char *ret = cp_remove_params (name);
+ if (ret)
+ return ret;
+ }
+ }
+
+ default:
+ break;
+ }
+
+ return xstrdup (name);
+}
+
/* Look, in partial_symtab PST, for symbol whose natural name is NAME.
Check the global symbols if GLOBAL, the static symbols if not. */
static struct partial_symbol *
lookup_partial_symbol (struct partial_symtab *pst, const char *name,
- int global, domain_enum domain)
+ int global, domain_enum domain, enum language language)
{
struct partial_symbol **start, **psym;
struct partial_symbol **top, **real_top, **bottom, **center;
int length = (global ? pst->n_global_syms : pst->n_static_syms);
int do_linear_search = 1;
+ const char *search_name;
+ struct cleanup *cleanup;
if (length == 0)
{
return (NULL);
}
+
+ search_name = psymtab_search_name (name, language);
+ cleanup = make_cleanup (xfree, (void *) search_name);
start = (global ?
pst->objfile->global_psymbols.list + pst->globals_offset :
pst->objfile->static_psymbols.list + pst->statics_offset);
@@ -563,7 +622,8 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
{
do_linear_search = 1;
}
- if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center), name) >= 0)
+ if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
+ search_name) >= 0)
{
top = center;
}
@@ -577,11 +637,14 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
_("failed internal consistency check"));
while (top <= real_top
- && SYMBOL_MATCHES_SEARCH_NAME (*top, name))
+ && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
SYMBOL_DOMAIN (*top), domain))
- return (*top);
+ {
+ do_cleanups (cleanup);
+ return (*top);
+ }
top++;
}
}
@@ -596,10 +659,14 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
SYMBOL_DOMAIN (*psym), domain)
&& SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
- return (*psym);
+ {
+ do_cleanups (cleanup);
+ return (*psym);
+ }
}
}
+ do_cleanups (cleanup);
return (NULL);
}
@@ -911,7 +978,8 @@ dump_psymtabs_for_objfile (struct objfile *objfile)
by matching FUNC_NAME. Make sure we read that symbol table in. */
static void
-read_symtabs_for_function (struct objfile *objfile, const char *func_name)
+read_symtabs_for_function (struct objfile *objfile, const char *func_name,
+ enum language language)
{
struct partial_symtab *ps;
@@ -920,9 +988,9 @@ read_symtabs_for_function (struct objfile *objfile, const char *func_name)
if (ps->readin)
continue;
- if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
+ if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN, language)
!= NULL)
- || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
+ || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN, language)
!= NULL))
psymtab_to_symtab (ps);
}
@@ -1042,13 +1110,14 @@ psymtab_to_fullname (struct partial_symtab *ps)
}
static const char *
-find_symbol_file_from_partial (struct objfile *objfile, const char *name)
+find_symbol_file_from_partial (struct objfile *objfile, const char *name,
+ enum language language)
{
struct partial_symtab *pst;
ALL_OBJFILE_PSYMTABS (objfile, pst)
{
- if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
+ if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN, language))
return pst->filename;
}
return NULL;
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -167,14 +167,15 @@ struct quick_symbol_functions
/* Check to see if the symbol is defined in a "partial" symbol table
of OBJFILE. KIND should be either GLOBAL_BLOCK or STATIC_BLOCK,
depending on whether we want to search global symbols or static
- symbols. NAME is the name of the symbol to look for. DOMAIN
- indicates what sort of symbol to search for.
+ symbols. NAME (valid in LANGUAGE) is the name of the symbol to look for.
+ DOMAIN indicates what sort of symbol to search for.
Returns the newly-expanded symbol table in which the symbol is
defined, or NULL if no such symbol table exists. */
struct symtab *(*lookup_symbol) (struct objfile *objfile,
int kind, const char *name,
- domain_enum domain);
+ domain_enum domain,
+ enum language language);
/* This is called to expand symbol tables before looking up a
symbol. A backend can choose to implement this and then have its
@@ -200,10 +201,11 @@ struct quick_symbol_functions
struct section_offsets *new_offsets,
struct section_offsets *delta);
- /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
- the corresponding symbol tables are loaded. */
+ /* Find all the symbols in OBJFILE named FUNC_NAME (valid in LANGUAGE),
+ and ensure that the corresponding symbol tables are loaded. */
void (*expand_symtabs_for_function) (struct objfile *objfile,
- const char *func_name);
+ const char *func_name,
+ enum language language);
/* Read all symbol tables associated with OBJFILE. */
void (*expand_all_symtabs) (struct objfile *objfile);
@@ -217,8 +219,10 @@ struct quick_symbol_functions
const char *filename);
/* Return the file name of the file holding the symbol in OBJFILE
- named NAME. If no such symbol exists in OBJFILE, return NULL. */
- const char *(*find_symbol_file) (struct objfile *objfile, const char *name);
+ named NAME (valid in LANGUAGE). If no such symbol exists in OBJFILE,
+ return NULL. */
+ const char *(*find_symbol_file) (struct objfile *objfile, const char *name,
+ enum language language);
/* Find global or static symbols in all tables that are in NAMESPACE
and for which MATCH (symbol name, NAME) == 0, passing each to
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1380,7 +1380,8 @@ lookup_symbol_aux_quick (struct objfile *objfile, int kind,
if (!objfile->sf)
return NULL;
- symtab = objfile->sf->qf->lookup_symbol (objfile, kind, name, domain);
+ symtab = objfile->sf->qf->lookup_symbol (objfile, kind, name, domain,
+ current_language->la_language);
if (!symtab)
return NULL;
@@ -1554,7 +1555,8 @@ basic_lookup_transparent_type_quick (struct objfile *objfile, int kind,
if (!objfile->sf)
return NULL;
- symtab = objfile->sf->qf->lookup_symbol (objfile, kind, name, STRUCT_DOMAIN);
+ symtab = objfile->sf->qf->lookup_symbol (objfile, kind, name, STRUCT_DOMAIN,
+ current_language->la_language);
if (!symtab)
return NULL;
@@ -1686,7 +1688,8 @@ find_main_filename (void)
if (!objfile->sf)
continue;
- result = objfile->sf->qf->find_symbol_file (objfile, name);
+ result = objfile->sf->qf->find_symbol_file (objfile, name,
+ current_language->la_language);
if (result)
return result;
}