* buildsym.c (add_symbol_to_list): Do not call

cp_scan_for_anonymous_namespaces here.
	(finish_block): Do not call cp_set_block_scope here.
	* cp-namespace.c (processing_has_namespace_info)
	(processing_current_prefix): Delete.
	(cp_initialize_namespace): Do not initialize
	processing_has_namespace_info.
	(cp_scan_for_anonymous_namespaces): Use SYMBOL_DEMANGLED_NAME.  Do
	not check processing_has_namespace_info.
	(cp_set_block_scope): Take prefix and namespace info flag as
	arguments.  Honor namespaces regardless of a demangled name.
	* cp-support.h (processing_has_namespace_info)
	(processing_current_prefix): Delete declarations.
	(cp_set_block_scope): Update prototype.
	* dwarf2read.c (processing_has_namespace_info)
	(processing_current_prefix): New static variables.
	(read_file_scope): Initialize processing_has_namespace_info.
	(read_func_scope): Call cp_set_block_scope for C++.
	(new_symbol): Call cp_scan_for_anonymous_namespaces for C++.
	* symtab.c (symbol_demangled_name): Accept a const argument.
	* symtab.h (symbol_demangled_name): Update prototype.
This commit is contained in:
Daniel Jacobowitz
2008-08-21 18:40:34 +00:00
parent 3567439cde
commit df8a16a1ee
9 changed files with 115 additions and 81 deletions

View File

@ -1,3 +1,27 @@
2008-08-21 Daniel Jacobowitz <dan@codesourcery.com>
* buildsym.c (add_symbol_to_list): Do not call
cp_scan_for_anonymous_namespaces here.
(finish_block): Do not call cp_set_block_scope here.
* cp-namespace.c (processing_has_namespace_info)
(processing_current_prefix): Delete.
(cp_initialize_namespace): Do not initialize
processing_has_namespace_info.
(cp_scan_for_anonymous_namespaces): Use SYMBOL_DEMANGLED_NAME. Do
not check processing_has_namespace_info.
(cp_set_block_scope): Take prefix and namespace info flag as
arguments. Honor namespaces regardless of a demangled name.
* cp-support.h (processing_has_namespace_info)
(processing_current_prefix): Delete declarations.
(cp_set_block_scope): Update prototype.
* dwarf2read.c (processing_has_namespace_info)
(processing_current_prefix): New static variables.
(read_file_scope): Initialize processing_has_namespace_info.
(read_func_scope): Call cp_set_block_scope for C++.
(new_symbol): Call cp_scan_for_anonymous_namespaces for C++.
* symtab.c (symbol_demangled_name): Accept a const argument.
* symtab.h (symbol_demangled_name): Update prototype.
2008-08-21 Daniel Jacobowitz <dan@codesourcery.com> 2008-08-21 Daniel Jacobowitz <dan@codesourcery.com>
* ax-gdb.c (gen_var_ref): Use SYMBOL_LINKAGE_NAME. * ax-gdb.c (gen_var_ref): Use SYMBOL_LINKAGE_NAME.

View File

@ -147,12 +147,6 @@ add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
} }
(*listhead)->symbol[(*listhead)->nsyms++] = symbol; (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
/* Check to see if we might need to look for a mention of anonymous
namespaces. */
if (SYMBOL_LANGUAGE (symbol) == language_cplus)
cp_scan_for_anonymous_namespaces (symbol);
} }
/* Find a symbol named NAME on a LIST. NAME need not be /* Find a symbol named NAME on a LIST. NAME need not be
@ -307,12 +301,6 @@ finish_block (struct symbol *symbol, struct pending **listhead,
} }
} }
} }
/* If we're in the C++ case, set the block's scope. */
if (SYMBOL_LANGUAGE (symbol) == language_cplus)
{
cp_set_block_scope (symbol, block, &objfile->objfile_obstack);
}
} }
else else
{ {

View File

@ -31,32 +31,6 @@
#include "command.h" #include "command.h"
#include "frame.h" #include "frame.h"
/* When set, the file that we're processing is known to have debugging
info for C++ namespaces. */
/* NOTE: carlton/2004-01-13: No currently released version of GCC (the
latest of which is 3.3.x at the time of this writing) produces this
debug info. GCC 3.4 should, however. */
unsigned char processing_has_namespace_info;
/* This contains our best guess as to the name of the current
enclosing namespace(s)/class(es), if any. For example, if we're
within the method foo() in the following code:
namespace N {
class C {
void foo () {
}
};
}
then processing_current_prefix should be set to "N::C". If
processing_has_namespace_info is false, then this variable might
not be reliable. */
const char *processing_current_prefix;
/* List of using directives that are active in the current file. */ /* List of using directives that are active in the current file. */
static struct using_direct *using_list; static struct using_direct *using_list;
@ -109,7 +83,6 @@ static void maintenance_cplus_namespace (char *args, int from_tty);
void cp_initialize_namespace () void cp_initialize_namespace ()
{ {
processing_has_namespace_info = 0;
using_list = NULL; using_list = NULL;
} }
@ -140,10 +113,9 @@ cp_finalize_namespace (struct block *static_block,
void void
cp_scan_for_anonymous_namespaces (const struct symbol *symbol) cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
{ {
if (!processing_has_namespace_info if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
&& SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL)
{ {
const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol); const char *name = SYMBOL_DEMANGLED_NAME (symbol);
unsigned int previous_component; unsigned int previous_component;
unsigned int next_component; unsigned int next_component;
const char *len; const char *len;
@ -217,38 +189,34 @@ cp_add_using_directive (const char *name, unsigned int outer_length,
void void
cp_set_block_scope (const struct symbol *symbol, cp_set_block_scope (const struct symbol *symbol,
struct block *block, struct block *block,
struct obstack *obstack) struct obstack *obstack,
const char *processing_current_prefix,
int processing_has_namespace_info)
{ {
/* Make sure that the name was originally mangled: if not, there if (processing_has_namespace_info)
certainly isn't any namespace information to worry about! */
if (SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL)
{ {
if (processing_has_namespace_info) block_set_scope
{ (block, obsavestring (processing_current_prefix,
block_set_scope strlen (processing_current_prefix),
(block, obsavestring (processing_current_prefix, obstack),
strlen (processing_current_prefix), obstack);
obstack), }
obstack); else if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
} {
else /* Try to figure out the appropriate namespace from the
{ demangled name. */
/* Try to figure out the appropriate namespace from the
demangled name. */
/* FIXME: carlton/2003-04-15: If the function in question is /* FIXME: carlton/2003-04-15: If the function in question is
a method of a class, the name will actually include the a method of a class, the name will actually include the
name of the class as well. This should be harmless, but name of the class as well. This should be harmless, but
is a little unfortunate. */ is a little unfortunate. */
const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol); const char *name = SYMBOL_DEMANGLED_NAME (symbol);
unsigned int prefix_len = cp_entire_prefix_len (name); unsigned int prefix_len = cp_entire_prefix_len (name);
block_set_scope (block, block_set_scope (block,
obsavestring (name, prefix_len, obstack), obsavestring (name, prefix_len, obstack),
obstack); obstack);
}
} }
} }

View File

@ -74,10 +74,6 @@ extern struct type *cp_lookup_rtti_type (const char *name,
/* Functions/variables from cp-namespace.c. */ /* Functions/variables from cp-namespace.c. */
extern unsigned char processing_has_namespace_info;
extern const char *processing_current_prefix;
extern int cp_is_anonymous (const char *namespace); extern int cp_is_anonymous (const char *namespace);
extern void cp_add_using_directive (const char *name, extern void cp_add_using_directive (const char *name,
@ -91,7 +87,9 @@ extern void cp_finalize_namespace (struct block *static_block,
extern void cp_set_block_scope (const struct symbol *symbol, extern void cp_set_block_scope (const struct symbol *symbol,
struct block *block, struct block *block,
struct obstack *obstack); struct obstack *obstack,
const char *processing_current_prefix,
int processing_has_namespace_info);
extern void cp_scan_for_anonymous_namespaces (const struct symbol *symbol); extern void cp_scan_for_anonymous_namespaces (const struct symbol *symbol);

View File

@ -54,6 +54,7 @@
#include "demangle.h" #include "demangle.h"
#include "complaints.h" #include "complaints.h"
#include "cp-abi.h" #include "cp-abi.h"
#include "cp-support.h"
#include "gdb_assert.h" #include "gdb_assert.h"
#include "gdb_string.h" #include "gdb_string.h"
@ -2738,6 +2739,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
{ {
/* This N_FUN marks the end of a function. This closes off /* This N_FUN marks the end of a function. This closes off
the current block. */ the current block. */
struct block *block;
if (context_stack_depth <= 0) if (context_stack_depth <= 0)
{ {
@ -2756,9 +2758,14 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
new = pop_context (); new = pop_context ();
/* Make a block for the local symbols within. */ /* Make a block for the local symbols within. */
finish_block (new->name, &local_symbols, new->old_blocks, block = finish_block (new->name, &local_symbols, new->old_blocks,
new->start_addr, new->start_addr + valu, new->start_addr, new->start_addr + valu,
objfile); objfile);
/* For C++, set the block's scope. */
if (SYMBOL_LANGUAGE (new->name) == language_cplus)
cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
"", 0);
/* May be switching to an assembler file which may not be using /* May be switching to an assembler file which may not be using
block relative stabs, so reset the offset. */ block relative stabs, so reset the offset. */
@ -3148,10 +3155,19 @@ no enclosing block"));
if (context_stack_depth > 0) if (context_stack_depth > 0)
{ {
struct block *block;
new = pop_context (); new = pop_context ();
/* Make a block for the local symbols within. */ /* Make a block for the local symbols within. */
finish_block (new->name, &local_symbols, new->old_blocks, block = finish_block (new->name, &local_symbols,
new->start_addr, valu, objfile); new->old_blocks, new->start_addr,
valu, objfile);
/* For C++, set the block's scope. */
if (SYMBOL_LANGUAGE (new->name) == language_cplus)
cp_set_block_scope (new->name, block,
&objfile->objfile_obstack,
"", 0);
} }
new = push_context (0, valu); new = push_context (0, valu);

View File

@ -141,6 +141,29 @@ typedef struct statement_prologue
} }
_STATEMENT_PROLOGUE; _STATEMENT_PROLOGUE;
/* When set, the file that we're processing is known to have debugging
info for C++ namespaces. GCC 3.3.x did not produce this information,
but later versions do. */
static int processing_has_namespace_info;
/* This contains our best guess as to the name of the current
enclosing namespace(s)/class(es), if any. For example, if we're
within the method foo() in the following code:
namespace N {
class C {
void foo () {
}
};
}
then processing_current_prefix should be set to "N::C". If
processing_has_namespace_info is false, then this variable might
not be reliable. */
static const char *processing_current_prefix;
static const struct objfile_data *dwarf2_objfile_data_key; static const struct objfile_data *dwarf2_objfile_data_key;
struct dwarf2_per_objfile struct dwarf2_per_objfile
@ -2850,6 +2873,8 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
/* We assume that we're processing GCC output. */ /* We assume that we're processing GCC output. */
processing_gcc_compilation = 2; processing_gcc_compilation = 2;
processing_has_namespace_info = 0;
start_symtab (name, comp_dir, lowpc); start_symtab (name, comp_dir, lowpc);
record_debugformat ("DWARF 2"); record_debugformat ("DWARF 2");
record_producer (cu->producer); record_producer (cu->producer);
@ -3020,6 +3045,12 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
block = finish_block (new->name, &local_symbols, new->old_blocks, block = finish_block (new->name, &local_symbols, new->old_blocks,
lowpc, highpc, objfile); lowpc, highpc, objfile);
/* For C++, set the block's scope. */
if (cu->language == language_cplus)
cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
processing_current_prefix,
processing_has_namespace_info);
/* If we have address ranges, record them. */ /* If we have address ranges, record them. */
dwarf2_record_block_ranges (die, block, baseaddr, cu); dwarf2_record_block_ranges (die, block, baseaddr, cu);
@ -7606,6 +7637,13 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
dwarf_tag_name (die->tag)); dwarf_tag_name (die->tag));
break; break;
} }
/* For the benefit of old versions of GCC, check for anonymous
namespaces based on the demangled name. */
if (!processing_has_namespace_info
&& cu->language == language_cplus
&& dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL)
cp_scan_for_anonymous_namespaces (sym);
} }
return (sym); return (sym);
} }

View File

@ -684,6 +684,8 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
normal: normal:
SYMBOL_LANGUAGE (sym) = current_subfile->language; SYMBOL_LANGUAGE (sym) = current_subfile->language;
SYMBOL_SET_NAMES (sym, string, p - string, objfile); SYMBOL_SET_NAMES (sym, string, p - string, objfile);
if (SYMBOL_LANGUAGE (sym) == language_cplus)
cp_scan_for_anonymous_namespaces (sym);
} }
p++; p++;

View File

@ -651,7 +651,7 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
/* Return the demangled name for a symbol based on the language for /* Return the demangled name for a symbol based on the language for
that symbol. If no demangled name exists, return NULL. */ that symbol. If no demangled name exists, return NULL. */
char * char *
symbol_demangled_name (struct general_symbol_info *gsymbol) symbol_demangled_name (const struct general_symbol_info *gsymbol)
{ {
switch (gsymbol->language) switch (gsymbol->language)
{ {

View File

@ -224,7 +224,7 @@ extern char *symbol_natural_name (const struct general_symbol_info *symbol);
that symbol. If no demangled name exists, return NULL. */ that symbol. If no demangled name exists, return NULL. */
#define SYMBOL_DEMANGLED_NAME(symbol) \ #define SYMBOL_DEMANGLED_NAME(symbol) \
(symbol_demangled_name (&(symbol)->ginfo)) (symbol_demangled_name (&(symbol)->ginfo))
extern char *symbol_demangled_name (struct general_symbol_info *symbol); extern char *symbol_demangled_name (const struct general_symbol_info *symbol);
/* Macro that returns a version of the name of a symbol that is /* Macro that returns a version of the name of a symbol that is
suitable for output. In C++ this is the "demangled" form of the suitable for output. In C++ this is the "demangled" form of the