This is the mail archive of the
archer-commits@sourceware.org
mailing list for the Archer project.
[SCM] archer-swagiaal-upstream: Patch2.
- From: swagiaal at sourceware dot org
- To: archer-commits at sourceware dot org
- Date: 16 Nov 2009 16:24:14 -0000
- Subject: [SCM] archer-swagiaal-upstream: Patch2.
The branch, archer-swagiaal-upstream has been updated
via 5a485fd089a02958bb00e967fb8b6479c256b612 (commit)
from 38ad178f0572d16ad6c19a759e14ab013a3032c8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 5a485fd089a02958bb00e967fb8b6479c256b612
Author: Sami Wagiaalla <swagiaal@redhat.com>
Date: Mon Nov 16 11:20:52 2009 -0500
Patch2.
-----------------------------------------------------------------------
Summary of changes:
gdb/cp-namespace.c | 72 ++++++++++++++++++++++----
gdb/cp-support.h | 6 ++-
gdb/testsuite/gdb.cp/namespace-recursive.cc | 30 +++++++++++
gdb/testsuite/gdb.cp/namespace-recursive.exp | 65 +++++++++++++++++++++++
gdb/testsuite/gdb.cp/namespace-stress.cc | 60 +++++++++++++++++++++
gdb/testsuite/gdb.cp/namespace-stress.exp | 50 ++++++++++++++++++
gdb/valops.c | 2 +-
7 files changed, 272 insertions(+), 13 deletions(-)
create mode 100644 gdb/testsuite/gdb.cp/namespace-recursive.cc
create mode 100644 gdb/testsuite/gdb.cp/namespace-recursive.exp
create mode 100644 gdb/testsuite/gdb.cp/namespace-stress.cc
create mode 100644 gdb/testsuite/gdb.cp/namespace-stress.exp
First 500 lines of diff:
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 1980681..4ea09c4 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,
@@ -331,14 +362,32 @@ cp_lookup_symbol_imports (const char *scope,
current = current->next)
{
+ directive_match = (search_parents
+ ? (strncmp (scope, current->import_dest,
+ strlen (current->import_dest)) == 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
- && (scope[len] == ':' || scope[len] == '\0'))
+ if (directive_match && !current->searched)
{
- sym = cp_lookup_symbol_in_namespace (current->import_src, name,
- linkage_name, block, domain);
+ /* 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;
}
@@ -347,7 +396,6 @@ cp_lookup_symbol_imports (const char *scope,
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/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..7fa6bd1
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/namespace-recursive.exp
@@ -0,0 +1,65 @@
+# 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"
diff --git a/gdb/testsuite/gdb.cp/namespace-stress.cc b/gdb/testsuite/gdb.cp/namespace-stress.cc
new file mode 100644
index 0000000..f34083e
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/namespace-stress.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;
+}
\ No newline at end of file
diff --git a/gdb/testsuite/gdb.cp/namespace-stress.exp b/gdb/testsuite/gdb.cp/namespace-stress.exp
new file mode 100644
index 0000000..64da6df
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/namespace-stress.exp
@@ -0,0 +1,50 @@
+# 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-stress
+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;
hooks/post-receive
--
Repository for Project Archer.