From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1585 invoked by alias); 14 Jan 2010 20:18:00 -0000 Received: (qmail 1565 invoked by uid 22791); 14 Jan 2010 20:17:55 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Jan 2010 20:17:46 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0EKHjwu019323 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Jan 2010 15:17:45 -0500 Received: from toner.yyz.redhat.com (toner.yyz.redhat.com [10.15.16.55]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0EKHiWB028939 for ; Thu, 14 Jan 2010 15:17:44 -0500 Message-ID: <4B4F7CEC.4060704@redhat.com> Date: Thu, 14 Jan 2010 20:18:00 -0000 From: Sami Wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090922 Fedora/3.0-3.9.b4.fc12 Thunderbird/3.0b4 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: [patch 2/2] Perform a namespace lookup at every block level References: <4A57512A.7090208@redhat.com> <20090710194949.GA2064@caradoc.them.org> <4A5B68A4.30006@redhat.com> <4A68B91D.2080206@redhat.com> <4A8B0FD9.7010603@redhat.com> <4AA14648.7090600@redhat.com> <4AE09A10.9040703@redhat.com> <4B019120.7090504@redhat.com> <4B0C3011.4080000@redhat.com> <4B4B9820.1060609@redhat.com> <4B4F4B90.30502@redhat.com> In-Reply-To: <4B4F4B90.30502@redhat.com> Content-Type: multipart/mixed; boundary="------------090403000105060309050201" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-01/txt/msg00382.txt.bz2 This is a multi-part message in MIME format. --------------090403000105060309050201 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 16717 On 01/14/2010 11:51 AM, Sami Wagiaalla wrote: > On 01/12/2010 12:43 PM, Tom Tromey wrote: >>>>>>> "Sami" == Sami Wagiaalla writes: >> >> Tom> We're mostly following 8.3 rules, so I would suggest renaming >> these to >> Tom> "ns-*". >> >> Sami> Can I do this in a separate patch ? There are more files to rename, >> Sami> so I would like to do the renaming in one patch >> >> No, it is really preferable to do this from the first checkin to CVS. >> >> Sami> \ No newline at end of file >> >> A few of the new files are missing newlines at the end. >> >> Tom > > Renamed test files to fit 8.3, and added comments in the beginning of > the files to compensate for the loss of readability. > > Corrected Changelog 2010-01-14 Sami Wagiaalla * cp-namespace.c (cp_lookup_symbol_namespace): Added search_parent argument. (cp_add_using): Initialize 'searched' field. (cp_copy_usings): Copy searched field. (reset_directive_searched): New function. * cp-support.h: Add 'searched' field to using_direct struct. (cp_lookup_symbol_imports): Ditto. * cp-namespace.c (cp_lookup_symbol_imports): Ditto. Perform recursive search. Implement non parent search. * valops.c (value_maybe_namespace_elt): Updated. 2010-01-14 Sami Wagiaalla * gdb.cp/namespace-stress.exp: New test. * gdb.cp/namespace-stress.cc: New test program. * gdb.cp/nsrecurs.exp: New test. * gdb.cp/nsrecurs.cc: New test program. * gdb.cp/nsstress.exp: New test. * gdb.cp/nsstress.cc: New test program. * gdb.cp/nsdecl.exp: New test. * gdb.cp/nsdecl.cc: New test program. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index f63cf8a..5790ebf 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -217,6 +217,7 @@ cp_add_using (const char *dest, retval->import_src = savestring (src, strlen(src)); retval->import_dest = savestring (dest, strlen(dest)); retval->next = next; + retval->searched = 0; return retval; } @@ -243,6 +244,8 @@ cp_copy_usings (struct using_direct *using, obstack); retval->next = cp_copy_usings (using->next, obstack); + retval->searched = using->searched; + xfree (using->import_src); xfree (using->import_dest); xfree (using); @@ -272,7 +275,8 @@ cp_lookup_symbol_nonlocal (const char *name, if (sym != NULL) return sym; - return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain); + return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain, + 1); } /* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in @@ -302,19 +306,46 @@ cp_lookup_symbol_in_namespace (const char *namespace, } } +/* Used for cleanups to reset the "searched" flag incase + of an error. */ + +static void +reset_directive_searched (void *data) +{ + struct using_direct *direct = data; + direct->searched = 0; +} + /* Search for NAME by applying all import statements belonging - to BLOCK which are applicable in SCOPE. */ + to BLOCK which are applicable in SCOPE. + If SEARCH_PARENTS the search will include imports which are applicable in + parents of SCOPE. + Example: + + namespace A{ + using namespace X; + namespace B{ + using namespace Y; + } + } + + If SCOPE is "A::B" and SEARCH_PARENTS is true the imports of namespaces X + and Y will be considered. If SEARCH_PARENTS is false only the import of Y + is considered. */ static struct symbol * cp_lookup_symbol_imports (const char *scope, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain) + const domain_enum domain, + const int search_parents) { - const struct using_direct *current; + struct using_direct *current; struct symbol *sym; int len; + int directive_match; + struct cleanup *searched_cleanup; /* First, try to find the symbol in the given namespace. */ sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block, @@ -330,24 +361,41 @@ cp_lookup_symbol_imports (const char *scope, current != NULL; current = current->next) { + len = strlen (current->import_dest); + directive_match = (search_parents + ? (strncmp (scope, current->import_dest, + strlen (current->import_dest)) == 0 + && (len == 0 + || scope[len] == ':' || scope[len] == '\0')) + : strcmp (scope, current->import_dest) == 0); /* If the import destination is the current scope or one of its ancestors then it is applicable. */ - len = strlen (current->import_dest); - if (strncmp (scope, current->import_dest, len) == 0 - && (len == 0 || scope[len] == ':' || scope[len] == '\0')) + if (directive_match && !current->searched) { - sym = cp_lookup_symbol_in_namespace (current->import_src, name, - linkage_name, block, domain); - if (sym != NULL) - return sym; + /* Mark this import as searched so that the recursive call does not + search it again. */ + current->searched = 1; + searched_cleanup = make_cleanup (reset_directive_searched, current); + + sym = cp_lookup_symbol_namespace (current->import_src, + name, + linkage_name, + block, + domain, + 0); + + current->searched = 0; + discard_cleanups (searched_cleanup); + + if (sym != NULL) + return sym; } } return NULL; } - /* Searches for NAME in the current namespace, and by applying relevant import statements belonging to BLOCK and its parents. SCOPE is the namespace scope of the context in which the search is being evaluated. */ @@ -357,14 +405,16 @@ cp_lookup_symbol_namespace (const char *scope, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain) + const domain_enum domain, + const int search_parents) { struct symbol *sym; /* Search for name in namespaces imported to this and parent blocks. */ while (block != NULL) { - sym = cp_lookup_symbol_imports (scope,name, linkage_name, block, domain); + sym = cp_lookup_symbol_imports (scope, name, linkage_name, block, domain, + search_parents); if (sym) return sym; diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 7ecd201..9400469 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -47,6 +47,9 @@ struct using_direct char *import_src; char *import_dest; struct using_direct *next; + + /* Used during import search to temporarily mark this node as searched. */ + int searched; }; @@ -107,7 +110,8 @@ extern struct symbol *cp_lookup_symbol_namespace (const char *namespace, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain); + const domain_enum domain, + const int search_parents); extern struct type *cp_lookup_nested_type (struct type *parent_type, const char *nested_name, diff --git a/gdb/testsuite/gdb.cp/nsdecl.cc b/gdb/testsuite/gdb.cp/nsdecl.cc new file mode 100644 index 0000000..01a9c75 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsdecl.cc @@ -0,0 +1,93 @@ +int a; +int b; +int c; +int d; +int e; +int f; +int g; +int h; +int i; +int j; +int k; +int l; +int m; +int n; +int o; +int p; +int q; +int r; +int s; +int t; +int u; +int v; +int w; +int x; +int y; +int z; + +namespace A +{ + int xyz; + + using ::a; + using ::b; + using ::c; + using ::d; + using ::e; + using ::f; + using ::g; + using ::h; + using ::i; + using ::j; + using ::k; + using ::l; + using ::m; + using ::n; + using ::o; + using ::p; + using ::q; + using ::r; + using ::s; + using ::t; + using ::u; + using ::v; + using ::w; + using ::x; + using ::y; + using ::z; + +} + +using A::a; +using A::b; +using A::c; +using A::d; +using A::e; +using A::f; +using A::g; +using A::h; +using A::i; +using A::j; +using A::k; +using A::l; +using A::m; +using A::n; +using A::o; +using A::p; +using A::q; +using A::r; +using A::s; +using A::t; +using A::u; +using A::v; +using A::w; +using A::x; +using A::y; +using A::z; + +using namespace A; + +int main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.cp/nsdecl.exp b/gdb/testsuite/gdb.cp/nsdecl.exp new file mode 100644 index 0000000..6e0d875 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsdecl.exp @@ -0,0 +1,52 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Stress test the lookup of declarations + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile nsdecl +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +if [get_compiler_info ${binfile}] { + return -1; +} + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +############################################ +# Test that the search can fail efficiently + +gdb_test "print fakex" "No symbol \"fakex\" in current context." diff --git a/gdb/testsuite/gdb.cp/nsrecurs.cc b/gdb/testsuite/gdb.cp/nsrecurs.cc new file mode 100644 index 0000000..84605a6 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsrecurs.cc @@ -0,0 +1,30 @@ +namespace A{ + int ax = 9; +} + +namespace B{ + using namespace A; +} + +namespace C{ + using namespace B; +} + +//--------------- +namespace D{ + using namespace D; + int dx = 99; +} +using namespace C; + +//--------------- +namespace{ + namespace{ + int xx = 999; + } +} + +int main(){ + using namespace D; + return ax + dx + xx; +} diff --git a/gdb/testsuite/gdb.cp/nsrecurs.exp b/gdb/testsuite/gdb.cp/nsrecurs.exp new file mode 100644 index 0000000..9939a9f --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsrecurs.exp @@ -0,0 +1,67 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test recursive namespace lookup + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile nsrecurs +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +if [get_compiler_info ${binfile}] { + return -1 +} + + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +############################################ +# test printing from namespace imported into +# imported namespace + +gdb_test "print ax" "= 9" + +############################################ +# test that gdb can print without falling +# into search loop + +gdb_test "print dx" "= 99" + +############################################ +# test printing from namespace imported into +# imported namespace where imports are implicit +# anonymous namespace imports. + +gdb_test "print xx" "= 999" diff --git a/gdb/testsuite/gdb.cp/nsstress.cc b/gdb/testsuite/gdb.cp/nsstress.cc new file mode 100644 index 0000000..de84ab1 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsstress.cc @@ -0,0 +1,60 @@ + +namespace A{ int x; } +namespace B{ int x; } +namespace C{ int x; } +namespace D{ int x; } +namespace E{ int x; } +namespace F{ int x; } +namespace G{ int x; } +namespace H{ int x; } +namespace I{ int x; } +namespace J{ int x; } +namespace K{ int x; } +namespace L{ int x; } +namespace M{ int x; } +namespace N{ int x; } +namespace O{ int x; } +namespace P{ int x; } +namespace Q{ int x; } +namespace R{ int x; } +namespace S{ int x; } +namespace T{ int x; } +namespace U{ int x; } +namespace V{ int x; } +namespace W{ int x; } +namespace X{ int x; } +namespace Y{ int x; } +namespace Z{ int x; } + + +int main(){ + + using namespace A; + using namespace B; + using namespace C; + using namespace D; + using namespace E; + using namespace F; + using namespace G; + using namespace H; + using namespace I; + using namespace J; + using namespace K; + using namespace L; + using namespace M; + using namespace N; + using namespace O; + using namespace P; + using namespace Q; + using namespace R; + using namespace S; + using namespace T; + using namespace U; + using namespace V; + using namespace W; + using namespace X; + using namespace Y; + using namespace Z; + + return 0; +} diff --git a/gdb/testsuite/gdb.cp/nsstress.exp b/gdb/testsuite/gdb.cp/nsstress.exp new file mode 100644 index 0000000..afe1bb0 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsstress.exp @@ -0,0 +1,52 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Stress test namespace lookup + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile nsstress +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +if [get_compiler_info ${binfile}] { + return -1 +} + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +############################################ +# Test that the search can fail efficiently + +gdb_test "print y" "No symbol \"y\" in current context." diff --git a/gdb/valops.c b/gdb/valops.c index 012ea6a..6fdea95 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -2765,7 +2765,7 @@ value_maybe_namespace_elt (const struct type *curtype, sym = cp_lookup_symbol_namespace (namespace_name, name, NULL, get_selected_block (0), - VAR_DOMAIN); + VAR_DOMAIN, 1); if (sym == NULL) return NULL; --------------090403000105060309050201 Content-Type: text/plain; name="sami2-recursive-search.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sami2-recursive-search.patch" Content-length: 14910 diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index f63cf8a..5790ebf 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -217,6 +217,7 @@ cp_add_using (const char *dest, retval->import_src = savestring (src, strlen(src)); retval->import_dest = savestring (dest, strlen(dest)); retval->next = next; + retval->searched = 0; return retval; } @@ -243,6 +244,8 @@ cp_copy_usings (struct using_direct *using, obstack); retval->next = cp_copy_usings (using->next, obstack); + retval->searched = using->searched; + xfree (using->import_src); xfree (using->import_dest); xfree (using); @@ -272,7 +275,8 @@ cp_lookup_symbol_nonlocal (const char *name, if (sym != NULL) return sym; - return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain); + return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain, + 1); } /* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in @@ -302,19 +306,46 @@ cp_lookup_symbol_in_namespace (const char *namespace, } } +/* Used for cleanups to reset the "searched" flag incase + of an error. */ + +static void +reset_directive_searched (void *data) +{ + struct using_direct *direct = data; + direct->searched = 0; +} + /* Search for NAME by applying all import statements belonging - to BLOCK which are applicable in SCOPE. */ + to BLOCK which are applicable in SCOPE. + If SEARCH_PARENTS the search will include imports which are applicable in + parents of SCOPE. + Example: + + namespace A{ + using namespace X; + namespace B{ + using namespace Y; + } + } + + If SCOPE is "A::B" and SEARCH_PARENTS is true the imports of namespaces X + and Y will be considered. If SEARCH_PARENTS is false only the import of Y + is considered. */ static struct symbol * cp_lookup_symbol_imports (const char *scope, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain) + const domain_enum domain, + const int search_parents) { - const struct using_direct *current; + struct using_direct *current; struct symbol *sym; int len; + int directive_match; + struct cleanup *searched_cleanup; /* First, try to find the symbol in the given namespace. */ sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block, @@ -330,24 +361,41 @@ cp_lookup_symbol_imports (const char *scope, current != NULL; current = current->next) { + len = strlen (current->import_dest); + directive_match = (search_parents + ? (strncmp (scope, current->import_dest, + strlen (current->import_dest)) == 0 + && (len == 0 + || scope[len] == ':' || scope[len] == '\0')) + : strcmp (scope, current->import_dest) == 0); /* If the import destination is the current scope or one of its ancestors then it is applicable. */ - len = strlen (current->import_dest); - if (strncmp (scope, current->import_dest, len) == 0 - && (len == 0 || scope[len] == ':' || scope[len] == '\0')) + if (directive_match && !current->searched) { - sym = cp_lookup_symbol_in_namespace (current->import_src, name, - linkage_name, block, domain); - if (sym != NULL) - return sym; + /* Mark this import as searched so that the recursive call does not + search it again. */ + current->searched = 1; + searched_cleanup = make_cleanup (reset_directive_searched, current); + + sym = cp_lookup_symbol_namespace (current->import_src, + name, + linkage_name, + block, + domain, + 0); + + current->searched = 0; + discard_cleanups (searched_cleanup); + + if (sym != NULL) + return sym; } } return NULL; } - /* Searches for NAME in the current namespace, and by applying relevant import statements belonging to BLOCK and its parents. SCOPE is the namespace scope of the context in which the search is being evaluated. */ @@ -357,14 +405,16 @@ cp_lookup_symbol_namespace (const char *scope, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain) + const domain_enum domain, + const int search_parents) { struct symbol *sym; /* Search for name in namespaces imported to this and parent blocks. */ while (block != NULL) { - sym = cp_lookup_symbol_imports (scope,name, linkage_name, block, domain); + sym = cp_lookup_symbol_imports (scope, name, linkage_name, block, domain, + search_parents); if (sym) return sym; diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 7ecd201..9400469 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -47,6 +47,9 @@ struct using_direct char *import_src; char *import_dest; struct using_direct *next; + + /* Used during import search to temporarily mark this node as searched. */ + int searched; }; @@ -107,7 +110,8 @@ extern struct symbol *cp_lookup_symbol_namespace (const char *namespace, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain); + const domain_enum domain, + const int search_parents); extern struct type *cp_lookup_nested_type (struct type *parent_type, const char *nested_name, diff --git a/gdb/testsuite/gdb.cp/nsdecl.cc b/gdb/testsuite/gdb.cp/nsdecl.cc new file mode 100644 index 0000000..01a9c75 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsdecl.cc @@ -0,0 +1,93 @@ +int a; +int b; +int c; +int d; +int e; +int f; +int g; +int h; +int i; +int j; +int k; +int l; +int m; +int n; +int o; +int p; +int q; +int r; +int s; +int t; +int u; +int v; +int w; +int x; +int y; +int z; + +namespace A +{ + int xyz; + + using ::a; + using ::b; + using ::c; + using ::d; + using ::e; + using ::f; + using ::g; + using ::h; + using ::i; + using ::j; + using ::k; + using ::l; + using ::m; + using ::n; + using ::o; + using ::p; + using ::q; + using ::r; + using ::s; + using ::t; + using ::u; + using ::v; + using ::w; + using ::x; + using ::y; + using ::z; + +} + +using A::a; +using A::b; +using A::c; +using A::d; +using A::e; +using A::f; +using A::g; +using A::h; +using A::i; +using A::j; +using A::k; +using A::l; +using A::m; +using A::n; +using A::o; +using A::p; +using A::q; +using A::r; +using A::s; +using A::t; +using A::u; +using A::v; +using A::w; +using A::x; +using A::y; +using A::z; + +using namespace A; + +int main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.cp/nsdecl.exp b/gdb/testsuite/gdb.cp/nsdecl.exp new file mode 100644 index 0000000..6e0d875 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsdecl.exp @@ -0,0 +1,52 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Stress test the lookup of declarations + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile nsdecl +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +if [get_compiler_info ${binfile}] { + return -1; +} + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +############################################ +# Test that the search can fail efficiently + +gdb_test "print fakex" "No symbol \"fakex\" in current context." diff --git a/gdb/testsuite/gdb.cp/nsrecurs.cc b/gdb/testsuite/gdb.cp/nsrecurs.cc new file mode 100644 index 0000000..84605a6 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsrecurs.cc @@ -0,0 +1,30 @@ +namespace A{ + int ax = 9; +} + +namespace B{ + using namespace A; +} + +namespace C{ + using namespace B; +} + +//--------------- +namespace D{ + using namespace D; + int dx = 99; +} +using namespace C; + +//--------------- +namespace{ + namespace{ + int xx = 999; + } +} + +int main(){ + using namespace D; + return ax + dx + xx; +} diff --git a/gdb/testsuite/gdb.cp/nsrecurs.exp b/gdb/testsuite/gdb.cp/nsrecurs.exp new file mode 100644 index 0000000..9939a9f --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsrecurs.exp @@ -0,0 +1,67 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test recursive namespace lookup + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile nsrecurs +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +if [get_compiler_info ${binfile}] { + return -1 +} + + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +############################################ +# test printing from namespace imported into +# imported namespace + +gdb_test "print ax" "= 9" + +############################################ +# test that gdb can print without falling +# into search loop + +gdb_test "print dx" "= 99" + +############################################ +# test printing from namespace imported into +# imported namespace where imports are implicit +# anonymous namespace imports. + +gdb_test "print xx" "= 999" diff --git a/gdb/testsuite/gdb.cp/nsstress.cc b/gdb/testsuite/gdb.cp/nsstress.cc new file mode 100644 index 0000000..de84ab1 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsstress.cc @@ -0,0 +1,60 @@ + +namespace A{ int x; } +namespace B{ int x; } +namespace C{ int x; } +namespace D{ int x; } +namespace E{ int x; } +namespace F{ int x; } +namespace G{ int x; } +namespace H{ int x; } +namespace I{ int x; } +namespace J{ int x; } +namespace K{ int x; } +namespace L{ int x; } +namespace M{ int x; } +namespace N{ int x; } +namespace O{ int x; } +namespace P{ int x; } +namespace Q{ int x; } +namespace R{ int x; } +namespace S{ int x; } +namespace T{ int x; } +namespace U{ int x; } +namespace V{ int x; } +namespace W{ int x; } +namespace X{ int x; } +namespace Y{ int x; } +namespace Z{ int x; } + + +int main(){ + + using namespace A; + using namespace B; + using namespace C; + using namespace D; + using namespace E; + using namespace F; + using namespace G; + using namespace H; + using namespace I; + using namespace J; + using namespace K; + using namespace L; + using namespace M; + using namespace N; + using namespace O; + using namespace P; + using namespace Q; + using namespace R; + using namespace S; + using namespace T; + using namespace U; + using namespace V; + using namespace W; + using namespace X; + using namespace Y; + using namespace Z; + + return 0; +} diff --git a/gdb/testsuite/gdb.cp/nsstress.exp b/gdb/testsuite/gdb.cp/nsstress.exp new file mode 100644 index 0000000..afe1bb0 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsstress.exp @@ -0,0 +1,52 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Stress test namespace lookup + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile nsstress +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +if [get_compiler_info ${binfile}] { + return -1 +} + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +############################################ +# Test that the search can fail efficiently + +gdb_test "print y" "No symbol \"y\" in current context." diff --git a/gdb/valops.c b/gdb/valops.c index 012ea6a..6fdea95 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -2765,7 +2765,7 @@ value_maybe_namespace_elt (const struct type *curtype, sym = cp_lookup_symbol_namespace (namespace_name, name, NULL, get_selected_block (0), - VAR_DOMAIN); + VAR_DOMAIN, 1); if (sym == NULL) return NULL; --------------090403000105060309050201--