From: Sami Wagiaalla <swagiaal@redhat.com>
To: Sami Wagiaalla <swagiaal@redhat.com>,
GDB Patches <gdb-patches@sourceware.org>
Subject: [patch 2/2] Perform a namespace lookup at every block level
Date: Tue, 18 Aug 2009 20:46:00 -0000 [thread overview]
Message-ID: <4A8B0FD9.7010603@redhat.com> (raw)
In-Reply-To: <4A68B91D.2080206@redhat.com>
In cases like this
namespace A{
int ax;
}
namespace B{
using namespace A;
}
namespace C{
using namespace B;
}
using namespace A
void foo(){
C::ax;
}
And this:
namespace{
namespace{
in xx;
}
}
void foo(){
xx;
}
A recursive search must be performed. This patch provides that functionality:
2009-08-14 Sami Wagiaalla <swagiaal@redhat.com>
* cp-support.h: Add 'searched' feild to using_direct struct.
* cp-namespace.c (cp_lookup_symbol_imports): Perform recursive search.
(cp_add_using): Initialize 'searched' feild.
(cp_copy_usings): Copy searched feild.
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index a0ccd7f..909ec2c 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -229,6 +229,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;
}
@@ -255,6 +256,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);
@@ -408,7 +411,7 @@ cp_lookup_symbol_imports (const char *scope,
const struct block *block,
const domain_enum domain)
{
- const struct using_direct *current;
+ struct using_direct *current;
struct symbol *sym;
/* First, try to find the symbol in the given namespace. */
@@ -428,13 +431,20 @@ cp_lookup_symbol_imports (const char *scope,
/* If the import destination is the current scope or one of its ancestors then
it is applicable. */
- if (strncmp (scope, current->import_dest, strlen(current->import_dest)) == 0)
+ if (strncmp (scope, current->import_dest,
+ strlen(current->import_dest)) == 0 &&
+ !current->searched )
{
- sym = cp_lookup_symbol_in_namespace (current->import_src,
+ /* Mark this import as searched so that the recursive call does not
+ search it again. */
+ current->searched = 1;
+ sym = cp_lookup_symbol_namespace (current->import_src,
name,
linkage_name,
block,
domain);
+
+ current->searched = 0;
if (sym != NULL)
return sym;
}
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index b5a5c5f..c9d53e5 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 temporarly mark this node as searced. */
+ int searched;
};
diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.cc b/gdb/testsuite/gdb.cp/namespace-recursive.cc
new file mode 100644
index 0000000..9368ad8
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/namespace-recursive.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;
+}
\ No newline at end of file
diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.exp b/gdb/testsuite/gdb.cp/namespace-recursive.exp
new file mode 100644
index 0000000..ebc898f
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/namespace-recursive.exp
@@ -0,0 +1,66 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile namespace-recursive
+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"
+
next prev parent reply other threads:[~2009-08-18 20:34 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-10 15:10 [patch] " Sami Wagiaalla
2009-07-10 20:16 ` Daniel Jacobowitz
2009-07-13 17:55 ` Sami Wagiaalla
2009-07-23 19:46 ` Sami Wagiaalla
2009-07-23 22:19 ` Sami Wagiaalla
2009-07-29 22:12 ` Tom Tromey
2009-08-18 20:34 ` [patch 1/2] " Sami Wagiaalla
2009-10-13 19:47 ` Tom Tromey
2009-10-20 20:50 ` Sami Wagiaalla
2009-11-10 22:23 ` Tom Tromey
2009-11-10 22:26 ` Tom Tromey
2009-11-16 15:32 ` Sami Wagiaalla
2009-11-16 19:16 ` Sami Wagiaalla
2009-11-24 19:06 ` Sami Wagiaalla
2009-12-21 21:44 ` Tom Tromey
2009-08-18 20:46 ` Sami Wagiaalla [this message]
2009-09-04 16:57 ` [patch 2/2] " Sami Wagiaalla
2009-10-13 20:22 ` Tom Tromey
2009-10-22 17:47 ` Sami Wagiaalla
2009-11-10 22:52 ` Tom Tromey
2009-11-16 17:55 ` Sami Wagiaalla
2009-11-24 19:12 ` Sami Wagiaalla
2009-12-21 21:55 ` Tom Tromey
2010-01-11 21:24 ` Sami Wagiaalla
2010-01-12 17:43 ` Tom Tromey
2010-01-14 16:47 ` Sami Wagiaalla
2010-01-14 20:18 ` Sami Wagiaalla
2010-01-15 18:06 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A8B0FD9.7010603@redhat.com \
--to=swagiaal@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox