diff options
author | David Carlton <carlton@bactrian.org> | 2002-11-15 01:10:43 +0000 |
---|---|---|
committer | David Carlton <carlton@bactrian.org> | 2002-11-15 01:10:43 +0000 |
commit | 5ed92c4602037e0f39a6a089e3842319a48b7af0 (patch) | |
tree | ee1470d2e31e057f59acd8cc30129571722f2a56 | |
parent | 248e20ab489d52d38f34f2014b6ee6fecc1b726c (diff) | |
download | gdb-5ed92c4602037e0f39a6a089e3842319a48b7af0.zip gdb-5ed92c4602037e0f39a6a089e3842319a48b7af0.tar.gz gdb-5ed92c4602037e0f39a6a089e3842319a48b7af0.tar.bz2 |
2002-11-14 David Carlton <carlton@math.stanford.edu>
* Makefile.in (symtab.o): Depend on gdb_assert_h.
* symtab.c: #include "gdb_assert.h"
* Makefile.in (namespace): Add 'namespace' target.
* buildsym.c (finish_block): Comment out the using declarations
generation.
* block.h: Make argument to block_scope const.
* block.c (block_scope): Make argument const.
* symtab.c (lookup_symbol_aux_using): Gather usings via
block_all_usings.
(lookup_symbol_namespace): Rename from
lookup_symbol_aux_using_loop.
(lookup_symbol_aux_using_loop): New function.
* block.h: Declare block_all_usings.
* block.c (block_all_usings): New function.
* symtab.c (lookup_symbol_aux_nonlocal): Delete FIXME comment.
* buildsym.c (finish_block): Add FIXME comment.
2002-11-14 David Carlton <carlton@math.stanford.edu>
* carlton_runnamespace: New file.
-rw-r--r-- | gdb/ChangeLog | 19 | ||||
-rw-r--r-- | gdb/Makefile.in | 5 | ||||
-rw-r--r-- | gdb/block.c | 21 | ||||
-rw-r--r-- | gdb/block.h | 4 | ||||
-rw-r--r-- | gdb/buildsym.c | 16 | ||||
-rw-r--r-- | gdb/symtab.c | 108 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rwxr-xr-x | gdb/testsuite/carlton_runnamespace | 6 |
8 files changed, 142 insertions, 41 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 82304c2..2b1233c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,22 @@ +2002-11-14 David Carlton <carlton@math.stanford.edu> + + * Makefile.in (symtab.o): Depend on gdb_assert_h. + * symtab.c: #include "gdb_assert.h" + * Makefile.in (namespace): Add 'namespace' target. + * buildsym.c (finish_block): Comment out the using declarations + generation. + * block.h: Make argument to block_scope const. + * block.c (block_scope): Make argument const. + * symtab.c (lookup_symbol_aux_using): Gather usings via + block_all_usings. + (lookup_symbol_namespace): Rename from + lookup_symbol_aux_using_loop. + (lookup_symbol_aux_using_loop): New function. + * block.h: Declare block_all_usings. + * block.c (block_all_usings): New function. + * symtab.c (lookup_symbol_aux_nonlocal): Delete FIXME comment. + * buildsym.c (finish_block): Add FIXME comment. + 2002-11-13 David Carlton <carlton@math.stanford.edu> * buildsym.c (finish_block): Initialize block_scope (block) in diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 266dd97..91316a9 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2222,7 +2222,7 @@ symtab.o: symtab.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \ $(language_h) $(demangle_h) $(inferior_h) $(linespec_h) \ $(filenames_h) $(dictionary_h) $(gdb_obstack_h) \ $(gdb_string_h) $(gdb_stat_h) $(cp_abi_h) $(source_h) $(cp_support_h) \ - $(block_h) + $(block_h) $(gdb_assert_h) target.o: target.c $(defs_h) $(gdb_string_h) $(target_h) $(gdbcmd_h) \ $(symtab_h) $(inferior_h) $(bfd_h) $(symfile_h) $(objfiles_h) \ $(gdb_wait_h) $(dcache_h) $(regcache_h) @@ -2659,4 +2659,7 @@ xdr_rdb.o: vx-share/xdr_rdb.c $(defs_h) vx-share/vxTypes.h \ carlton: all cd testsuite; ./carlton_runtest +namespace: all + cd testsuite; ./carlton_runnamespace + ### end of the gdb Makefile.in. diff --git a/gdb/block.c b/gdb/block.c index f7161ae..7becf2e 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -66,6 +66,25 @@ block_using (const struct block *block) return BLOCK_NAMESPACE (block)->using; } +/* This returns the using directives associated to BLOCK and its + parents, if any. The resulting structure must be freed by calling + cp_free_usings on it. */ + +struct using_direct_node * +block_all_usings (const struct block *block) +{ + struct using_direct_node *using = NULL; + + while (block != NULL) + { + using = cp_copy_usings (block_using (block), using); + block = BLOCK_SUPERBLOCK (block); + } + + return using; +} + + /* Set block_using (BLOCK) to USING; if needed, allocate memory via OBSTACK. */ @@ -83,7 +102,7 @@ block_set_using (struct block *block, struct using_direct_node *using, superblocks looking for a scope, if necessary. */ const char * -block_scope (struct block *block) +block_scope (const struct block *block) { for (; block != NULL; block = BLOCK_SUPERBLOCK (block)) { diff --git a/gdb/block.h b/gdb/block.h index 9ad53af..d0700c1 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -139,11 +139,13 @@ extern int contained_in (struct block *, struct block *); extern struct using_direct_node *block_using (const struct block *); +extern struct using_direct_node *block_all_usings (const struct block *block); + extern void block_set_using (struct block *block, struct using_direct_node *using, struct obstack *obstack); -extern const char *block_scope (struct block *block); +extern const char *block_scope (const struct block *block); extern void block_set_scope (struct block *block, const char *scope, struct obstack *obstack); diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 6a0433f..b786536 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -454,6 +454,10 @@ finish_block (struct symbol *symbol, struct pending **listhead, else { const char *current, *next; + + /* 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 == ':'; @@ -468,8 +472,14 @@ finish_block (struct symbol *symbol, struct pending **listhead, obsavestring (name, current - name, &objfile->symbol_obstack), &objfile->symbol_obstack); + + /* FIXME: carlton/2002-10-09: Until I understand the + possible pitfalls of demangled names a lot better, I + want to make sure I'm not running into surprises. */ + gdb_assert (*next == '\0'); } +#if 0 for (next = cp_find_first_component (name); *next == ':'; /* The '+ 2' is to skip the '::'. */ @@ -481,11 +491,7 @@ finish_block (struct symbol *symbol, struct pending **listhead, &objfile->symbol_obstack), &objfile->symbol_obstack); } - - /* FIXME: carlton/2002-10-09: Until I understand the - possible pitfalls of demangled names a lot better, I want - to make sure I'm not running into surprises. */ - gdb_assert (*next == '\0'); +#endif } } else diff --git a/gdb/symtab.c b/gdb/symtab.c index 73c3b21..3f2c1ff 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -52,6 +52,7 @@ #include <ctype.h> #include "cp-abi.h" #include "cp-support.h" +#include "gdb_assert.h" /* Prototypes for local functions */ @@ -130,13 +131,21 @@ struct symbol *lookup_symbol_aux_using (const char *name, struct symtab **symtab); static -struct symbol *lookup_symbol_aux_using_loop (const char *prefix, - int prefix_len, - const char *rest, - struct using_direct_node *using, +struct symbol *lookup_symbol_aux_using_loop (const char *name, const char *mangled_name, namespace_enum namespace, - struct symtab **symtab); + struct symtab **symtab, + const char *scope, + int scope_len, + struct using_direct_node *using); +static +struct symbol *lookup_symbol_namespace (const char *prefix, + int prefix_len, + const char *rest, + struct using_direct_node *using, + const char *mangled_name, + namespace_enum namespace, + struct symtab **symtab); static struct symbol *lookup_symbol_aux_minsyms (int block_index, @@ -997,9 +1006,6 @@ lookup_symbol_aux_block (const char *name, const char *mangled_name, STATIC_BLOCK, depending on whether or not we want to search global symbols or static symbols. */ -/* FIXME: carlton/2002-10-11: Should this also do some minsym - lookup? */ - static struct symbol * lookup_symbol_aux_nonlocal (int block_index, const char *name, @@ -1169,32 +1175,69 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name, /* This function gathers using directives from BLOCK and its superblocks, and then searches for symbols in the global namespace by trying to apply those various using directives. */ + static struct symbol *lookup_symbol_aux_using (const char *name, const char *mangled_name, const struct block *block, const namespace_enum namespace, struct symtab **symtab) { - struct using_direct_node *using = NULL; + struct using_direct_node *using; + const char *scope; struct symbol *sym; - while (block != NULL) - { - using = cp_copy_usings (block_using (block), using); - block = BLOCK_SUPERBLOCK (block); - } - - sym = lookup_symbol_aux_using_loop ("", 0, name, using, mangled_name, - namespace, symtab); + using = block_all_usings (block); + scope = block_scope (block); + + sym = lookup_symbol_aux_using_loop (name, mangled_name, namespace, symtab, + scope, 0, using); cp_free_usings (using); return sym; } +/* Look up NAME in the namespaces given by SCOPE and its initial + prefixes, applying using directives given by USING; only consider + prefixes that are at least as long as SCOPE_LEN, however. Look up + longest prefixes first. */ + +static struct +symbol *lookup_symbol_aux_using_loop (const char *name, + const char *mangled_name, + namespace_enum namespace, + struct symtab **symtab, + const char *scope, + int scope_len, + struct using_direct_node *using) +{ + if (scope[scope_len] != '\0') + { + struct symbol *sym; + int next_component; + int new_scope_len = scope_len; + + /* If the current scope is followed by "::", skip past that. */ + if (new_scope_len != 0) + { + gdb_assert (scope[new_scope_len] == ':'); + new_scope_len += 2; + } + next_component = cp_find_first_component (scope + new_scope_len) - scope; + sym = lookup_symbol_aux_using_loop (name, mangled_name, namespace, + symtab, scope, next_component, + using); + if (sym != NULL) + return sym; + } + + return lookup_symbol_namespace (scope, scope_len, name, using, + mangled_name, namespace, symtab); +} + /* This tries to look up REST in the namespace given by the initial substring of PREFIX of length PREFIX_LEN. - Basically, assume that we have using directives adding A to the + For example, assume that we have using directives adding A to the global namespace, adding A::inner to namespace A, and adding B to the global namespace. Then, when looking up a symbol "foo", we want to recurse by looking up stuff in A::foo and seeing which @@ -1216,13 +1259,13 @@ static struct symbol *lookup_symbol_aux_using (const char *name, for other reasons, but it will take a little while.) */ static struct symbol * -lookup_symbol_aux_using_loop (const char *prefix, - int prefix_len, - const char *rest, - struct using_direct_node *using, - const char *mangled_name, - namespace_enum namespace, - struct symtab **symtab) +lookup_symbol_namespace (const char *prefix, + int prefix_len, + const char *rest, + struct using_direct_node *using, + const char *mangled_name, + namespace_enum namespace, + struct symtab **symtab) { struct using_direct_node *current; struct symbol *sym; @@ -1256,14 +1299,13 @@ lookup_symbol_aux_using_loop (const char *prefix, if (*new_rest == ':') new_rest += 2; - sym = lookup_symbol_aux_using_loop - (current->current->name, - current->current->inner_length, - new_rest, - using, - mangled_name, - namespace, - symtab); + sym = lookup_symbol_namespace (current->current->name, + current->current->inner_length, + new_rest, + using, + mangled_name, + namespace, + symtab); if (sym != NULL) return sym; } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index fe23998..a54cbdd 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-11-14 David Carlton <carlton@math.stanford.edu> + + * carlton_runnamespace: New file. + 2002-10-22 Daniel Jacobowitz <drow@mvista.com> * gdb.threads/schedlock.c (args): Make unsigned. diff --git a/gdb/testsuite/carlton_runnamespace b/gdb/testsuite/carlton_runnamespace new file mode 100755 index 0000000..fb37149 --- /dev/null +++ b/gdb/testsuite/carlton_runnamespace @@ -0,0 +1,6 @@ +#!/bin/bash + +# Just run the namespace test. + +runtest namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout +diff -u {carlton_,/tmp/}namespaceout |