From: David Carlton Date: Tue, 15 Oct 2002 23:59:24 +0000 (+0000) Subject: 2002-10-15 David Carlton X-Git-Tag: newlib-1_11_0~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a5203383dfcd685b461718ba6c072e4c750cfa6;p=thirdparty%2Fbinutils-gdb.git 2002-10-15 David Carlton * symtab.c (lookup_symbol_aux_using_loop): prefix_len should be <= outer_length. (lookup_symbol_aux_using_loop): Don't skip colons in rest_of_outer if we've used all of outer. * cp-support.h: Rename declaration of cp_add_using to cp_add_using_obstack. * cp-support.c (cp_add_using_obstack): Rename from cp_add_using. * buildsym.h: Rename arguments in declaration of add_using_directive. * buildsym.c (add_using_directive): Finish definition, rename arguments. * cp-support.h: Add declaration for cp_add_using_xmalloc. * cp-support.c (cp_add_using_xmalloc): New function. * buildsym.c (copy_usings_to_obstack): New function. (end_symtab): Set STATIC_BLOCK's BLOCK_USING using copy_usings_to_obstack. 2002-10-15 David Carlton * gdb.c++/namespace.exp: Add anonymous namespace tests. * gdb.c++/namespace.cc: Add anonymous namespaces. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c6ddf0a1bf2..505e69d1b5f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,21 +1,34 @@ +2002-10-15 David Carlton + + * symtab.c (lookup_symbol_aux_using_loop): prefix_len should be <= + outer_length. + (lookup_symbol_aux_using_loop): Don't skip colons in rest_of_outer + if we've used all of outer. + * cp-support.h: Rename declaration of cp_add_using to + cp_add_using_obstack. + * cp-support.c (cp_add_using_obstack): Rename from cp_add_using. + * buildsym.h: Rename arguments in declaration of + add_using_directive. + * buildsym.c (add_using_directive): Finish definition, rename + arguments. + * cp-support.h: Add declaration for cp_add_using_xmalloc. + * cp-support.c (cp_add_using_xmalloc): New function. + * buildsym.c (copy_usings_to_obstack): New function. + (end_symtab): Set STATIC_BLOCK's BLOCK_USING using + copy_usings_to_obstack. + 2002-10-14 David Carlton * buildsym.c (add_using_directive): Rewrite to match new version of struct using_direct. (finish_block): Ditto. - * symtab.c (lookup_symbol_aux_using_loop): Add 'prefix_len' argument; rewrite to match new version of struct using_direct. - * cp-support.h: Update declaration for cp_add_using. - * cp-support.c (cp_add_using): Rewrite to match new version of struct using_direct. - * cp-support.h (struct using_direct): Rewrite struct. - * buildsym.h: Declaration for add_using_directive. - * buildsym.c: New variable 'using_list'. (start_symtab): Initialize using_list. (end_symtab): Initialize BLOCK_USING of STATIC_BLOCK. diff --git a/gdb/buildsym.c b/gdb/buildsym.c index a2322e24eeb..bca5332171d 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -72,6 +72,12 @@ static struct using_direct_node *using_list; static int compare_line_numbers (const void *ln1p, const void *ln2p); static void scan_for_anonymous_namespaces (struct symbol *symbol); + +static struct using_direct_node *copy_usings_to_obstack (struct + using_direct_node + *usings, + struct obstack + *obstack); /* Initial sizes of data structures. These are realloc'd larger if @@ -115,9 +121,9 @@ add_free_pendings (struct pending *list) } } -/* Add a symbol to one of the lists of symbols. While we're at it, - check to see if it references an anonymous namespace; if so, add an - appropriate using directive. */ +/* Add a symbol to one of the lists of symbols. While we're at it, if + we're in the C++ case, check to see if it references an anonymous + namespace; if so, add an appropriate using directive. */ void add_symbol_to_list (struct symbol *symbol, struct pending **listhead) @@ -151,10 +157,10 @@ add_symbol_to_list (struct symbol *symbol, struct pending **listhead) /* Check to see if we might need to look for a mention of anonymous namespaces. */ - /* TODOTODO */ -/* if (SYMBOL_LANGUAGE (symbol) == language_cplus */ -/* && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL) */ -/* scan_for_anonymous_namespaces (symbol) */ + + if (SYMBOL_LANGUAGE (symbol) == language_cplus + && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL) + scan_for_anonymous_namespaces (symbol); } /* Check to see if a symbol is contained within an anonymous @@ -176,7 +182,7 @@ scan_for_anonymous_namespaces (struct symbol *symbol) for (beginning = name, end = cp_find_first_component (name); *end == ':'; - /* The "+ 2" is for ':'. */ + /* The "+ 2" is for the "::"-. */ beginning = end + 2, end = cp_find_first_component (beginning)) { if ((end - beginning) == ANONYMOUS_NAMESPACE_LEN @@ -219,27 +225,31 @@ find_symbol_in_list (struct pending *list, char *name, int length) /* This adds a using directive to using_list. NAME is the start of a string that should contain the namespaces we want to add as initial - substrings, OUTER_INDEX is the end of the outer namespace, and - INNER_INDEX is the end of the inner namespace. If the using + substrings, OUTER_LENGTH is the end of the outer namespace, and + INNER_LENGTH is the end of the inner namespace. If the using directive in question has already been added, don't add it twice. */ void -add_using_directive (const char *name, unsigned int outer_index, - unsigned int inner_index) +add_using_directive (const char *name, unsigned int outer_length, + unsigned int inner_length) { struct using_direct_node *current; + struct using_direct_node *new_node; + struct using_direct *new; - gdb_assert (outer_index < inner_index); + gdb_assert (outer_length < inner_length); /* Has it already been added? */ for (current = using_list; current; current = current->next) - if (strncmp (current->current->name, name, outer_index) == 0 - && strncmp (current->current->name, name, inner_index) == 0) + if (current->current->outer_length == outer_length + && current->current->inner_length == inner_length + && (strncmp (current->current->name, name, inner_length) == 0)) return; - /* TODOTODO */ + using_list = cp_add_using_xmalloc (name, outer_length, inner_length, + using_list); } @@ -444,8 +454,9 @@ finish_block (struct symbol *symbol, struct pending **listhead, next = cp_find_first_component (next + 2)) { BLOCK_USING (block) - = cp_add_using (name, 0, next - name, BLOCK_USING (block), - &objfile->symbol_obstack); + = cp_add_using_obstack (name, 0, next - name, + BLOCK_USING (block), + &objfile->symbol_obstack); } /* FIMXE: carlton/2002-10-09: Until I understand the @@ -1011,10 +1022,13 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section) finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr, objfile); blockvector = make_blockvector (objfile); - /* TODOTODO */ -/* BLOCK_USING (BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK)) */ -/* = cp_copy_usings_obstack (using_list, &objfile->symbol_obstack); */ -/* cp_deep_free_usings (using_list); */ + if (using_list != NULL) + { + BLOCK_USING (BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK)) + = copy_usings_to_obstack (using_list, + &objfile->symbol_obstack); + using_list = NULL; + } } #ifndef PROCESS_LINENUMBER_HOOK @@ -1145,6 +1159,32 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section) return symtab; } +/* This reallocates USINGS using OBSTACK and xfree's USINGS. It + returns the reallocated version of USINGS. */ + +static struct using_direct_node * +copy_usings_to_obstack (struct using_direct_node *usings, + struct obstack *obstack) +{ + if (usings == NULL) + return NULL; + else + { + struct using_direct_node *new_node + = cp_add_using_obstack (usings->current->name, + usings->current->outer_length, + usings->current->inner_length, + copy_usings_to_obstack (usings->next, + obstack), + obstack); + + xfree (usings->current); + xfree (usings); + + return new_node; + } +} + /* Search the block for global symbols indicating the presence of anonymous namespaces; add using declarations for them, if found. */ diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 1e678d01016..28442a7f28f 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -240,8 +240,8 @@ extern void add_symbol_to_list (struct symbol *symbol, extern struct symbol *find_symbol_in_list (struct pending *list, char *name, int length); -extern void add_using_directive (const char *name, unsigned int outer_index, - unsigned int inner_index); +extern void add_using_directive (const char *name, unsigned int outer_length, + unsigned int inner_length); extern void finish_block (struct symbol *symbol, struct pending **listhead, diff --git a/gdb/cp-support.c b/gdb/cp-support.c index d5ca1a1364c..a13967f9f82 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -176,11 +176,11 @@ method_name_from_physname (const char *physname) using_direct_node. All memory is allocated using OBSTACK. */ struct using_direct_node * -cp_add_using (const char *name, - unsigned short outer_length, - unsigned short inner_length, - struct using_direct_node *next, - struct obstack *obstack) +cp_add_using_obstack (const char *name, + unsigned short outer_length, + unsigned short inner_length, + struct using_direct_node *next, + struct obstack *obstack) { struct using_direct *current = obstack_alloc (obstack, sizeof (struct using_direct)); @@ -198,8 +198,33 @@ cp_add_using (const char *name, return retval; } +/* Same as cp_add_using, except that it uses xmalloc instead of + obstacks. */ + +struct using_direct_node * +cp_add_using_xmalloc (const char *name, + unsigned short outer_length, + unsigned short inner_length, + struct using_direct_node *next) +{ + struct using_direct *current = xmalloc (sizeof (struct using_direct)); + struct using_direct_node *retval + = xmalloc (sizeof (struct using_direct_node)); + + gdb_assert (outer_length < inner_length); + + current->name = name; + current->outer_length = outer_length; + current->inner_length = inner_length; + retval->current = current; + retval->next = next; + + return retval; +} + /* This copies the using_direct_nodes in TOCOPY, using xmalloc, and - sticks them onto a list ending in TAIL. */ + sticks them onto a list ending in TAIL. (It doesn't copy the + using_directs, just the using_direct_nodes.) */ struct using_direct_node * cp_copy_usings (struct using_direct_node *tocopy, diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 31eab6e3ba6..bb89c6fe26f 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -67,11 +67,19 @@ struct using_direct_node struct using_direct_node *next; }; -extern struct using_direct_node *cp_add_using (const char *name, - unsigned short outer_length, - unsigned short inner_length, - struct using_direct_node *next, - struct obstack *obstack); +extern struct +using_direct_node *cp_add_using_obstack (const char *name, + unsigned short outer_length, + unsigned short inner_length, + struct using_direct_node *next, + struct obstack *obstack); + +extern +struct using_direct_node *cp_add_using_xmalloc (const char *name, + unsigned short outer_length, + unsigned short inner_length, + struct using_direct_node + *next); extern struct using_direct_node *cp_copy_usings (struct using_direct_node *tocopy, diff --git a/gdb/symtab.c b/gdb/symtab.c index 5db5b6a559b..390c7643c47 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1114,7 +1114,7 @@ lookup_symbol_aux_using_loop (const char *prefix, { /* First, see if the prefix matches the start of this using directive. */ - if (prefix_len >= current->current->outer_length + if (prefix_len <= current->current->outer_length && strncmp (prefix, current->current->name, prefix_len) == 0) { /* Great, it matches: now does the rest of the using @@ -1123,10 +1123,10 @@ lookup_symbol_aux_using_loop (const char *prefix, const char *rest_of_outer = current->current->name + prefix_len; int rest_of_outer_len = current->current->outer_length - prefix_len; - /* Should we skip some colons? (Should always be true - unless PREFIX_LEN is zero (and hence we're in the global - namespace.) */ - if (*rest_of_outer == ':') + /* Should we skip some colons? Should be true unless + PREFIX_LEN is zero (and hence we're in the global + namespace) or we've finished all of outer. */ + if (rest_of_outer_len != 0 && *rest_of_outer == ':') { rest_of_outer += 2; rest_of_outer_len -= 2; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 43a345550fe..5ca6345e15f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-10-15 David Carlton + + * gdb.c++/namespace.exp: Add anonymous namespace tests. + * gdb.c++/namespace.cc: Add anonymous namespaces. + 2002-10-11 David Carlton * gdb.c++/namespace.exp: Add tests from within C::D::marker2. diff --git a/gdb/testsuite/gdb.c++/namespace.cc b/gdb/testsuite/gdb.c++/namespace.cc index 76b8a36b12b..c5ec895f5ef 100644 --- a/gdb/testsuite/gdb.c++/namespace.cc +++ b/gdb/testsuite/gdb.c++/namespace.cc @@ -68,10 +68,40 @@ void marker1(void) return; } +namespace +{ + int X = 9; + + namespace G + { + int Xg = 10; + + namespace + { + int XgX = 11; + } + } +} + namespace C { int c = 1; + namespace + { + int cX = 6; + + namespace F + { + int cXf = 7; + + namespace + { + int cXfX = 8; + } + } + } + namespace C { int cc = 2; @@ -103,13 +133,18 @@ namespace C cd; E::cde; //E::ce; + cX; + F::cXf; + F::cXfX; + X; + G::Xg; + G::XgX; return; } } } - int main () { using AAA::inA; diff --git a/gdb/testsuite/gdb.c++/namespace.exp b/gdb/testsuite/gdb.c++/namespace.exp index e87425b26d1..30a68fe2adf 100644 --- a/gdb/testsuite/gdb.c++/namespace.exp +++ b/gdb/testsuite/gdb.c++/namespace.exp @@ -205,3 +205,10 @@ gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5" "print E::cde" # FIXME: carlton/2002-10-11: It would be nice to test printing # "E::ce", but unfortunately GDB will print it out even though it # shouldn't. Oops. + +gdb_test "print cX" "\\$\[0-9\].* = 6" "print cX" +gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7" "print F::cXf" +gdb_test "print 'F::cXfX'" "\\$\[0-9\].* = 8" "print F::cXfX" +gdb_test "print X" "\\$\[0-9\].* = 9" "print X" +gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" "print G::Xg" +gdb_test "print 'G::XgX'" "\\$\[0-9\].* = 11" "print G::XgX"