From df8a16a1ee1a3d464ecffd6ad66a1d2e09d47838 Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Thu, 21 Aug 2008 18:40:34 +0000 Subject: [PATCH] * 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. --- gdb/ChangeLog | 24 ++++++++++++++ gdb/buildsym.c | 12 ------- gdb/cp-namespace.c | 82 ++++++++++++++-------------------------------- gdb/cp-support.h | 8 ++--- gdb/dbxread.c | 26 ++++++++++++--- gdb/dwarf2read.c | 38 +++++++++++++++++++++ gdb/stabsread.c | 2 ++ gdb/symtab.c | 2 +- gdb/symtab.h | 2 +- 9 files changed, 115 insertions(+), 81 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fcd482bdfc1..3d928689f3e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,27 @@ +2008-08-21 Daniel Jacobowitz + + * 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 * ax-gdb.c (gen_var_ref): Use SYMBOL_LINKAGE_NAME. diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 686e600c7c7..1945c224037 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -147,12 +147,6 @@ add_symbol_to_list (struct symbol *symbol, struct pending **listhead) } (*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 @@ -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 { diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 9c7ea599a96..4b45f6c8975 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -31,32 +31,6 @@ #include "command.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. */ static struct using_direct *using_list; @@ -109,7 +83,6 @@ static void maintenance_cplus_namespace (char *args, int from_tty); void cp_initialize_namespace () { - processing_has_namespace_info = 0; using_list = NULL; } @@ -140,10 +113,9 @@ cp_finalize_namespace (struct block *static_block, void cp_scan_for_anonymous_namespaces (const struct symbol *symbol) { - if (!processing_has_namespace_info - && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL) + if (SYMBOL_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 next_component; const char *len; @@ -217,38 +189,34 @@ cp_add_using_directive (const char *name, unsigned int outer_length, void cp_set_block_scope (const struct symbol *symbol, 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 - certainly isn't any namespace information to worry about! */ - - if (SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL) + if (processing_has_namespace_info) { - if (processing_has_namespace_info) - { - block_set_scope - (block, obsavestring (processing_current_prefix, - strlen (processing_current_prefix), - obstack), - obstack); - } - else - { - /* Try to figure out the appropriate namespace from the - demangled name. */ + block_set_scope + (block, obsavestring (processing_current_prefix, + strlen (processing_current_prefix), + obstack), + obstack); + } + else if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) + { + /* Try to figure out the appropriate namespace from the + demangled name. */ - /* FIXME: carlton/2003-04-15: If the function in question is - a method of a class, the name will actually include the - name of the class as well. This should be harmless, but - is a little unfortunate. */ + /* FIXME: carlton/2003-04-15: If the function in question is + a method of a class, the name will actually include the + name of the class as well. This should be harmless, but + is a little unfortunate. */ - const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol); - unsigned int prefix_len = cp_entire_prefix_len (name); + const char *name = SYMBOL_DEMANGLED_NAME (symbol); + unsigned int prefix_len = cp_entire_prefix_len (name); - block_set_scope (block, - obsavestring (name, prefix_len, obstack), - obstack); - } + block_set_scope (block, + obsavestring (name, prefix_len, obstack), + obstack); } } diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 8e55733fe08..a004783b992 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -74,10 +74,6 @@ extern struct type *cp_lookup_rtti_type (const char *name, /* 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 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, 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); diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 42c9f4bec72..25ec3130660 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -54,6 +54,7 @@ #include "demangle.h" #include "complaints.h" #include "cp-abi.h" +#include "cp-support.h" #include "gdb_assert.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 the current block. */ + struct block *block; if (context_stack_depth <= 0) { @@ -2756,9 +2758,14 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name, new = pop_context (); /* Make a block for the local symbols within. */ - finish_block (new->name, &local_symbols, new->old_blocks, - new->start_addr, new->start_addr + valu, - objfile); + block = finish_block (new->name, &local_symbols, new->old_blocks, + new->start_addr, 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); /* May be switching to an assembler file which may not be using block relative stabs, so reset the offset. */ @@ -3148,10 +3155,19 @@ no enclosing block")); if (context_stack_depth > 0) { + struct block *block; + new = pop_context (); /* Make a block for the local symbols within. */ - finish_block (new->name, &local_symbols, new->old_blocks, - new->start_addr, valu, objfile); + block = finish_block (new->name, &local_symbols, + 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); diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index d0676ed3d5b..1721ee1a748 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -141,6 +141,29 @@ typedef struct 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; 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. */ processing_gcc_compilation = 2; + processing_has_namespace_info = 0; + start_symtab (name, comp_dir, lowpc); record_debugformat ("DWARF 2"); 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, 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. */ 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)); 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); } diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 110f9373b34..248f061b615 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -684,6 +684,8 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type, normal: SYMBOL_LANGUAGE (sym) = current_subfile->language; SYMBOL_SET_NAMES (sym, string, p - string, objfile); + if (SYMBOL_LANGUAGE (sym) == language_cplus) + cp_scan_for_anonymous_namespaces (sym); } p++; diff --git a/gdb/symtab.c b/gdb/symtab.c index f1573190dc8..db84f4fc719 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -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 that symbol. If no demangled name exists, return NULL. */ char * -symbol_demangled_name (struct general_symbol_info *gsymbol) +symbol_demangled_name (const struct general_symbol_info *gsymbol) { switch (gsymbol->language) { diff --git a/gdb/symtab.h b/gdb/symtab.h index 43c4e812b90..31aed86536c 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -224,7 +224,7 @@ extern char *symbol_natural_name (const struct general_symbol_info *symbol); that symbol. If no demangled name exists, return NULL. */ #define SYMBOL_DEMANGLED_NAME(symbol) \ (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 suitable for output. In C++ this is the "demangled" form of the -- 2.30.2