diff options
author | David Carlton <carlton@bactrian.org> | 2002-11-22 01:16:14 +0000 |
---|---|---|
committer | David Carlton <carlton@bactrian.org> | 2002-11-22 01:16:14 +0000 |
commit | 61f961891ae9ef26ea3a1d51ce64ebd28bd7bdfc (patch) | |
tree | a866bbbe3549fbd454e99e24fc3d044c7ee26255 | |
parent | b17e7772ce2570e9ff4eeedfd6c7595832992669 (diff) | |
download | gdb-61f961891ae9ef26ea3a1d51ce64ebd28bd7bdfc.zip gdb-61f961891ae9ef26ea3a1d51ce64ebd28bd7bdfc.tar.gz gdb-61f961891ae9ef26ea3a1d51ce64ebd28bd7bdfc.tar.bz2 |
2002-11-21 David Carlton <carlton@math.stanford.edu>
* cp-support.c (get_namespace_objfile): Set
namespace_objfile->name.
* dwarf2read.c (scan_partial_symbols): Allow empty pdi.name if
we're reading a namespace.
* Makefile.in (dwarf2read.o): Depend on cp_support_h.
* dwarf2read.c (scan_partial_symbols): Add 'namespace' arg.
(dwarf2_build_psymtabs_hard): Update call to
scan_partial_symbols.
(add_partial_namespace): New function.
(scan_partial_symbols): Call add_partial_namespace.
#include "cp-support.h"
* cp-support.c: Add me to contributors.
* cp-support.h: Ditto.
* buildsym.c (scan_for_anonymous_namespaces): Convert for loop
into a clearer while loop.
(finish_block): Ditto.
-rw-r--r-- | gdb/ChangeLog | 19 | ||||
-rw-r--r-- | gdb/Makefile.in | 2 | ||||
-rw-r--r-- | gdb/buildsym.c | 43 | ||||
-rw-r--r-- | gdb/cp-support.c | 4 | ||||
-rw-r--r-- | gdb/cp-support.h | 3 | ||||
-rw-r--r-- | gdb/dwarf2read.c | 79 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rwxr-xr-x | gdb/testsuite/carlton_runnamespace | 13 |
8 files changed, 133 insertions, 34 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8b3908f..1fd22cf 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,22 @@ +2002-11-21 David Carlton <carlton@math.stanford.edu> + + * cp-support.c (get_namespace_objfile): Set + namespace_objfile->name. + * dwarf2read.c (scan_partial_symbols): Allow empty pdi.name if + we're reading a namespace. + * Makefile.in (dwarf2read.o): Depend on cp_support_h. + * dwarf2read.c (scan_partial_symbols): Add 'namespace' arg. + (dwarf2_build_psymtabs_hard): Update call to + scan_partial_symbols. + (add_partial_namespace): New function. + (scan_partial_symbols): Call add_partial_namespace. + #include "cp-support.h" + * cp-support.c: Add me to contributors. + * cp-support.h: Ditto. + * buildsym.c (scan_for_anonymous_namespaces): Convert for loop + into a clearer while loop. + (finish_block): Ditto. + 2002-11-20 David Carlton <carlton@math.stanford.edu> * dwarf2read.c (scan_partial_symbols): Move lowpc, highpc initial diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 625fc1b..7d3f96c 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1657,7 +1657,7 @@ dwarf2read.o: dwarf2read.c $(defs_h) $(bfd_h) $(symtab_h) $(gdbtypes_h) \ $(symfile_h) $(objfiles_h) $(elf_dwarf2_h) $(buildsym_h) \ $(demangle_h) $(expression_h) $(filenames_h) $(macrotab_h) \ $(language_h) $(complaints_h) $(bcache_h) $(gdb_string_h) \ - $(gdb_assert_h) + $(gdb_assert_h) $(cp_support_h) dwarfread.o: dwarfread.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(symfile_h) \ $(objfiles_h) $(elf_dwarf_h) $(buildsym_h) $(demangle_h) \ $(expression_h) $(language_h) $(complaints_h) $(gdb_string_h) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 311bc96..7d5009b 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -179,23 +179,26 @@ static void scan_for_anonymous_namespaces (struct symbol *symbol) { const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol); - const char *beginning, *end; + const char *beginning = name; + const char *end = cp_find_first_component (beginning); - for (beginning = name, end = cp_find_first_component (name); - *end == ':'; - /* The "+ 2" is for the "::"-. */ - beginning = end + 2, end = cp_find_first_component (beginning)) + while (*end == ':') { if ((end - beginning) == ANONYMOUS_NAMESPACE_LEN && strncmp (beginning, "(anonymous namespace)", ANONYMOUS_NAMESPACE_LEN) == 0) - /* We've found a component of the name that's an anonymous - namespace. So add symbols in it to the namespace given by - the previous component if there is one, or to the global - namespace if there isn't. */ - add_using_directive (name, - beginning == name ? 0 : beginning - name - 2, - end - name); + { + /* We've found a component of the name that's an anonymous + namespace. So add symbols in it to the namespace given + by the previous component if there is one, or to the + global namespace if there isn't. */ + add_using_directive (name, + beginning == name ? 0 : beginning - name - 2, + end - name); + } + /* The "+ 2" is for the "::". */ + beginning = end + 2; + end = cp_find_first_component (beginning); } } @@ -458,13 +461,15 @@ finish_block (struct symbol *symbol, struct pending **listhead, /* FIXME: carlton/2002-11-14: For members of classes, with this include the class name as well? I don't think that's a problem yet, but it will be. */ - - for (current = name, next = cp_find_first_component (current); - *next == ':'; - /* The '+ 2' is to skip the '::'. */ - current = next, - next = cp_find_first_component (current + 2)) - ; + + current = name; + next = cp_find_first_component (current); + while (*next == ':') + { + current = next; + /* The '+ 2' is to skip the '::'. */ + next = cp_find_first_component (current + 2); + } if (current == name) block_set_scope (block, "", &objfile->symbol_obstack); else diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 0efb1d8..dc56d88 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1,7 +1,8 @@ /* Helper routines for C++ support in GDB. Copyright 2002 Free Software Foundation, Inc. - Contributed by MontaVista Software. + Contributed by MontaVista Software and by David Carlton, Stanford + University. This file is part of GDB. @@ -440,6 +441,7 @@ get_namespace_objfile (void) if (namespace_objfile == NULL) { namespace_objfile = allocate_objfile (NULL, 0); + namespace_objfile->name = "<C++-namespaces>"; } return namespace_objfile; diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 5d7b4af..3247287 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -1,7 +1,8 @@ /* Helper routines for C++ support in GDB. Copyright 2002 Free Software Foundation, Inc. - Contributed by MontaVista Software. + Contributed by MontaVista Software and by David Carlton, Stanford + University. This file is part of GDB. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 281e2e9..0737539 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -46,6 +46,7 @@ #include "gdb_string.h" #include "gdb_assert.h" #include <sys/types.h> +#include "cp-support.h" #ifndef DWARF2_REG_TO_REGNUM #define DWARF2_REG_TO_REGNUM(REG) (REG) @@ -706,11 +707,19 @@ static void dwarf2_build_psymtabs_hard (struct objfile *, int); static char *scan_partial_symbols (char *, struct objfile *, CORE_ADDR *, CORE_ADDR *, - const struct comp_unit_head *); + const struct comp_unit_head *, + const char *namespace); static void add_partial_symbol (struct partial_die_info *, struct objfile *, const struct comp_unit_head *); +static char *add_partial_namespace (struct partial_die_info *pdi, + char *info_ptr, + struct objfile *objfile, + CORE_ADDR *lowpc, CORE_ADDR *highpc, + const struct comp_unit_head *cu_header, + const char *namespace); + static void dwarf2_psymtab_to_symtab (struct partial_symtab *); static void psymtab_to_symtab_1 (struct partial_symtab *); @@ -1300,7 +1309,7 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) highpc = ((CORE_ADDR) 0); info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc, - &cu_header); + &cu_header, NULL); /* If we didn't find a lowpc, set it to highpc to avoid complaints from `maint check'. */ @@ -1336,12 +1345,17 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) } /* Read in all interesting dies to the end of the compilation unit or - to the end of the current namespace. */ + to the end of the current namespace. NAMESPACE is NULL if we + haven't yet encountered any DW_TAG_namespace entries; otherwise, + it's the name of the current namespace. (In particular, it's the + empty string if we're currently in the global namespace but have + previously encountered a DW_TAG_namespace.) */ static char * scan_partial_symbols (char *info_ptr, struct objfile *objfile, CORE_ADDR *lowpc, CORE_ADDR *highpc, - const struct comp_unit_head *cu_header) + const struct comp_unit_head *cu_header, + const char *namespace) { bfd *abfd = objfile->obfd; struct partial_die_info pdi; @@ -1358,7 +1372,9 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile, { info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu_header); - if (pdi.name) + /* Anonymous namespaces have no name but are interesting. */ + + if (pdi.name != NULL || pdi.tag == DW_TAG_namespace) { switch (pdi.tag) { @@ -1407,10 +1423,14 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile, add_partial_symbol (&pdi, objfile, cu_header); break; case DW_TAG_namespace: - if (pdi.has_children) - info_ptr = scan_partial_symbols (info_ptr, objfile, - lowpc, highpc, - cu_header); + /* We've hit a DW_TAG_namespace entry, so we know this + file has been compiled using a compiler that + generates them; update NAMESPACE to reflect that. */ + if (namespace == NULL) + namespace = ""; + info_ptr = add_partial_namespace (&pdi, info_ptr, objfile, + lowpc, highpc, cu_header, + namespace); default: break; } @@ -1418,7 +1438,7 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile, /* If the die has a sibling, skip to the sibling. Do not skip enumeration types, we want to record their enumerators. Do - not skip namespaces, the scan_partial_symbols call has + not skip namespaces, the add_partial_namespace call has already updated info_ptr for us. */ if (pdi.sibling && pdi.tag != DW_TAG_enumeration_type @@ -1426,7 +1446,7 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile, { info_ptr = pdi.sibling; } - else if (pdi.has_children) + else if (pdi.has_children && pdi.tag != DW_TAG_namespace) { /* Die has children, but either the optional DW_AT_sibling attribute is missing or we want to look at them. */ @@ -1548,6 +1568,43 @@ add_partial_symbol (struct partial_die_info *pdi, struct objfile *objfile, } } +/* Read a partial die corresponding to a namespace; also, add a symbol + corresponding to that namespace to the symbol table. NAMESPACE is + the name of the enclosing namespace. */ + +static char * +add_partial_namespace (struct partial_die_info *pdi, char *info_ptr, + struct objfile *objfile, + CORE_ADDR *lowpc, CORE_ADDR *highpc, + const struct comp_unit_head *cu_header, + const char *namespace) +{ + /* Calculate the full name of the namespace that we just entered. */ + + const char *new_name = pdi->name; + if (new_name == NULL) + new_name = "(anonymous namespace)"; + char *full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1); + strcpy (full_name, namespace); + if (*namespace != '\0') + strcat (full_name, "::"); + strcat (full_name, new_name); + + /* Make sure that there's a symbol associated to that namespace. */ + + cp_check_namespace_symbol (full_name, strlen (full_name)); + + /* Now scan partial symbols in that namespace. */ + + if (pdi->has_children) + info_ptr = scan_partial_symbols (info_ptr, objfile, + lowpc, highpc, + cu_header, full_name); + + return info_ptr; +} + + /* Expand this partial symbol table into a full symbol table. */ static void diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d6c1f82..bb061d2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-11-21 David Carlton <carlton@math.stanford.edu> + + * carlton_runnamespace: Run using multiple compilers. + 2002-11-19 David Carlton <carlton@math.stanford.edu> * gdb.c++/namespace.exp: Delete FIXME comment. diff --git a/gdb/testsuite/carlton_runnamespace b/gdb/testsuite/carlton_runnamespace index fb37149..37a8364 100755 --- a/gdb/testsuite/carlton_runnamespace +++ b/gdb/testsuite/carlton_runnamespace @@ -1,6 +1,17 @@ #!/bin/bash -# Just run the namespace test. +# Just run the namespace test. But run it using multiple compilers: +# the regular one, and one which generates more namespace debugging +# info. Maybe eventually I should run this on one which generates +# stabs info, too? +EXTRACOMPPATH=/usr/local/testbed/gcc3/bin + +echo "Running tests using regular compiler." runtest namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout diff -u {carlton_,/tmp/}namespaceout +echo "Running tests using compiler with extra debug info." +PATH=${EXTRACOMPPATH}:${PATH} runtest namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout +diff -u {carlton_,/tmp/}namespaceout + +echo "Done." |