From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16178 invoked by alias); 25 Jun 2010 15:46:19 -0000 Received: (qmail 16155 invoked by uid 22791); 25 Jun 2010 15:46:17 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_CX,T_RP_MATCHES_RCVD 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; Fri, 25 Jun 2010 15:46:09 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5PFk7GH014437 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 25 Jun 2010 11:46:07 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5PFk7Pc021911 for ; Fri, 25 Jun 2010 11:46:07 -0400 Received: from [10.15.16.55] (toner.yyz.redhat.com [10.15.16.55]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o5PFk6F2001199 for ; Fri, 25 Jun 2010 11:46:06 -0400 Message-ID: <4C24CBC3.4080905@redhat.com> Date: Fri, 25 Jun 2010 15:46:00 -0000 From: sami wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: Re: GDB crash due to endless recursion in namespace lookup References: <201006241809.o5OI9rPx014499@d12av02.megacenter.de.ibm.com> In-Reply-To: <201006241809.o5OI9rPx014499@d12av02.megacenter.de.ibm.com> Content-Type: multipart/mixed; boundary="------------050006020505090502050609" 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-06/txt/msg00579.txt.bz2 This is a multi-part message in MIME format. --------------050006020505090502050609 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1771 Hi Ulrich, Thanks for reporting things and the test case. I have attached a fix and added your test case to the test suite. Thoughts ? Sami On 06/24/2010 02:09 PM, Ulrich Weigand wrote: > Hello, > > since one of this year's C++ namespace search related changes, > GDB will go into an endless recursion and crash due to stack > overflow when looking up symbols in the presence of a cycle > in the "using" directive graph. > > For example, with the following test: > > namespace A > { > namespace B > { > using namespace ::A; > } > using namespace B; > } > > using namespace A; > > class test { }; > test x; > > int main() { } > > I'm seeing: > > (gdb) start > Temporary breakpoint 1 at 0x80000626: file xxx.cc, line 16. > Starting program: /home7/uweigand/fsf/gdb-head-build/gdb/a.out > > Temporary breakpoint 1, main () at xxx.cc:16 > 16 int main() { } > (gdb) print x[0] > Segmentation fault (core dumped) > > (The lookup that happens here is for operator[] -- which doesn't > exist, but in trying to find it we run into the endless loop.) > > This is particularly annyoing as the SLES10 system library on > s390 and ppc contains exactly this construct in the header > /usr/include/c++/4.1.2/bits/localefwd.h: > > namespace std > { > namespace __gnu_cxx_ldbl128 > { > using namespace ::std; > } > using namespace __gnu_cxx_ldbl128 __attribute__((__strong__)); > > which means it is present in just about every C++ executable. > > (This seems specific to the SLES backport of the long-double > compatibility support. The upstream implementation does not > have this cycle ... But still, the general construct looks > to be valid C++ as far as I can tell.) > > Any thoughts how to fix this? > > Bye, > Ulrich > --------------050006020505090502050609 Content-Type: text/plain; name="namespace-loop.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="namespace-loop.patch" Content-length: 4490 2010-06-24 Sami Wagiaalla * cp-namespace.c (reset_directive_searched): moved from here... * cp-support.c (reset_directive_searched): ... to here. (make_symbol_overload_list_using): Added check for search flag. 2010-06-24 Sami Wagiaalla * gdb.cp/operator.cc: Created an import loop. * gdb.cp/operator.exp: Added testcase for import loop. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 0daf732..525a90d 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -273,16 +273,6 @@ 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. If DECLARATION_ONLY the search is restricted to using declarations. diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 41af7ae..6e403ed 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -838,6 +838,16 @@ make_symbol_overload_list_adl (struct type **arg_types, int nargs, return sym_return_val; } +/* Used for cleanups to reset the "searched" flag incase + of an error. */ + +void +reset_directive_searched (void *data) +{ + struct using_direct *direct = data; + direct->searched = 0; +} + /* This applies the using directives to add namespaces to search in, and then searches for overloads in all of those namespaces. It adds the symbols found to sym_return_val. Arguments are as in @@ -847,8 +857,9 @@ static void make_symbol_overload_list_using (const char *func_name, const char *namespace) { - const struct using_direct *current; + struct using_direct *current; const struct block *block; + struct cleanup *searched_cleanup; /* First, go through the using directives. If any of them apply, look in the appropriate namespaces for new functions to match @@ -861,12 +872,23 @@ make_symbol_overload_list_using (const char *func_name, current != NULL; current = current->next) { - /* If this is a namespace alias or imported declaration ignore it. */ - if (current->alias != NULL || current->declaration != NULL) + /* If this import statement has been explored before, or if this is a + namespace alias or imported declaration ignore it. */ + if (current->searched + || current->alias != NULL + || current->declaration != NULL) continue; if (strcmp (namespace, current->import_dest) == 0) - make_symbol_overload_list_using (func_name, current->import_src); + { + current->searched = 1; + searched_cleanup = make_cleanup (reset_directive_searched, current); + + make_symbol_overload_list_using (func_name, current->import_src); + + discard_cleanups (searched_cleanup); + current->searched = 0; + } } /* Now, add names for this namespace. */ diff --git a/gdb/cp-support.h b/gdb/cp-support.h index ddc4c93..5e4e1e9 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -179,4 +179,9 @@ extern char *cp_comp_to_string (struct demangle_component *result, extern struct cmd_list_element *maint_cplus_cmd_list; +/* Used for cleanups to reset the "searched" flag incase + of an error. */ + +extern void reset_directive_searched (void *data); + #endif /* CP_SUPPORT_H */ diff --git a/gdb/testsuite/gdb.cp/operator.cc b/gdb/testsuite/gdb.cp/operator.cc index cc925a0..8431376 100644 --- a/gdb/testsuite/gdb.cp/operator.cc +++ b/gdb/testsuite/gdb.cp/operator.cc @@ -157,6 +157,22 @@ using namespace N; //------------------ +namespace O +{ + namespace P + { + using namespace ::O; + } + using namespace P; +} + +using namespace O; + +class test { }; +test x; + +//------------------ + int main () { A a; diff --git a/gdb/testsuite/gdb.cp/operator.exp b/gdb/testsuite/gdb.cp/operator.exp index ac89d2b..0e36e4c 100644 --- a/gdb/testsuite/gdb.cp/operator.exp +++ b/gdb/testsuite/gdb.cp/operator.exp @@ -56,3 +56,6 @@ gdb_test "p j == 1" "Cannot resolve function operator== to any overloaded instan # Test that indirectly imported operators work gdb_test "p l == 1" "= 88" + +# Test that we don't fall into an import loop +gdb_test {p x[0]} {No symbol "operator\[\]" in current context.} --------------050006020505090502050609--