This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[dictionary] fix bug in decode_compound


This fixes a bug in decode_compound on the branch, where

  break C::D::x

didn't work if C was a class.  (It worked if C was a namesepace.)

It also adds a new test for this, in files
gdb.c++/breakpoint.{cc,exp}; I'll probably move that over to mainline
soon, because this test works fine on mainline.  And there's an
unrelated test fix in gdb.c++/namespace.exp.

David Carlton
carlton@bactrian.org

2003-05-09  David Carlton  <carlton@bactrian.org>

	* linespec.c (examine_compound_token): Handled classes nested
	within classes, not just classes nested within namespaces.

2003-05-09  David Carlton  <carlton@bactrian.org>

	* gdb.c++/breakpoint.cc: New.
	* gdb.c++/breakpoint.exp: New.
	* gdb.c++/namespace.exp: Update "print C::D::cd" for current
	output.

Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.22.2.18
diff -u -p -r1.22.2.18 linespec.c
--- linespec.c	2 May 2003 20:36:08 -0000	1.22.2.18
+++ linespec.c	9 May 2003 18:22:41 -0000
@@ -801,6 +801,7 @@ examine_compound_token (char **argptr, i
 			char *saved_arg, char *current_component,
 			struct symtabs_and_lines *values)
 {
+  /* The namespace or class that we're nested within.  */
   const char *namespace = "";
 
   while (1)
@@ -817,57 +818,56 @@ examine_compound_token (char **argptr, i
 
       if (class_sym == NULL)
 	return 0;
-
       t = check_typedef (SYMBOL_TYPE (class_sym));
 
-      switch (TYPE_CODE (t))
+      current_component = find_next_token (argptr);
+      if (*current_component == ':')
+	{
+	  /* We're still in the process of reading types: we haven't
+	     found the method at the bottom yet.  */
+	  namespace = TYPE_TAG_NAME (t);
+	}
+      else
 	{
-	case TYPE_CODE_STRUCT:
-	case TYPE_CODE_UNION:
-	  /* Find the next token (everything up to end or next blank).  */
-
-	  current_component = find_next_token (argptr);
-	  copy = alloca (current_component - *argptr + 1);
-	  memcpy (copy, *argptr, current_component - *argptr);
-	  copy[current_component - *argptr] = '\0';
-	  if (current_component != *argptr
-	      && copy[current_component - *argptr - 1]
-	      && (strchr (get_gdb_completer_quote_characters (),
-			  copy[current_component - *argptr - 1])
-		  != NULL))
-	    copy[current_component - *argptr - 1] = '\0';
+	  switch (TYPE_CODE (t))
+	    {
+	    case TYPE_CODE_STRUCT:
+	    case TYPE_CODE_UNION:
+	      /* Find the next token (everything up to end or next blank).  */
+
+	      copy = alloca (current_component - *argptr + 1);
+	      memcpy (copy, *argptr, current_component - *argptr);
+	      copy[current_component - *argptr] = '\0';
+	      if (current_component != *argptr
+		  && copy[current_component - *argptr - 1]
+		  && (strchr (get_gdb_completer_quote_characters (),
+			      copy[current_component - *argptr - 1])
+		      != NULL))
+		copy[current_component - *argptr - 1] = '\0';
 	      
-	  while (*current_component == ' ' || *current_component == '\t')
-	    current_component++;
-	  *argptr = current_component;
+	      while (*current_component == ' ' || *current_component == '\t')
+		current_component++;
+	      *argptr = current_component;
 
-	  *values = find_method (funfirstline, canonical, saved_arg, copy,
-				 t, class_sym);
+	      *values = find_method (funfirstline, canonical, saved_arg, copy,
+				     t, class_sym);
       
-	  return 1;
-	case TYPE_CODE_NAMESPACE:
-	  {
-	    char *next_component = find_next_token (argptr);
-	    namespace = TYPE_TAG_NAME (t);
-	    if (*next_component == ':')
-	      {
-		current_component = next_component;
-		break;
-	      }
-	    else
+	      return 1;
+	    case TYPE_CODE_NAMESPACE:
 	      {
 		return decode_namespace (argptr, funfirstline,
 					 canonical,
-					 next_component, namespace,
+					 current_component,
+					 TYPE_TAG_NAME (t),
 					 values);
 	      }
-	  }
-	default:
-	  /* FIXME: carlton/2002-11-19: Once this all settles down, this
-	     case should be an error rather than a return 0; that will
-	     allow us to make VALUES the return value rather than an
-	     argument.  */
-	  return 0;
+	    default:
+	      /* FIXME: carlton/2002-11-19: Once this all settles
+		 down, this case should be an error rather than a
+		 return 0; that will allow us to make VALUES the
+		 return value rather than an argument.  */
+	      return 0;
+	    }
 	}
     }
 }
Index: testsuite/gdb.c++/namespace.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.c++/namespace.exp,v
retrieving revision 1.12.16.13
diff -u -p -r1.12.16.13 namespace.exp
--- testsuite/gdb.c++/namespace.exp	8 May 2003 01:10:52 -0000	1.12.16.13
+++ testsuite/gdb.c++/namespace.exp	9 May 2003 18:22:55 -0000
@@ -240,7 +240,7 @@ gdb_test "print cc" "No symbol \"cc\" in
 gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
 gdb_test "print C::cc" "\\$\[0-9\].* = 2"
 gdb_test "print cd" "\\$\[0-9\].* = 3"
-gdb_test "print C::D::cd" "No type \"D\" within context \"C::C\"."
+gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"."
 gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
 gdb_test "print E::cde" "\\$\[0-9\].* = 5"
 gdb_test "print shadow" "\\$\[0-9\].* = 13"
--- /dev/null	2002-08-30 16:31:37.000000000 -0700
+++ testsuite/gdb.c++/breakpoint.cc	2003-05-09 11:13:39.000000000 -0700
@@ -0,0 +1,44 @@
+/* Code to go along with tests in breakpoint.exp.
+   
+   Copyright 2003 Free Software Foundation, Inc.
+
+   Contributed by David Carlton <carlton@bactrian.org> and by Kealia,
+   Inc.
+
+   This file is part of GDB.
+
+   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 2 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, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+class C1 {
+public:
+  class Nested {
+  public:
+    int
+    foo ()
+    {
+      return 1;
+    }
+  };
+};
+
+int main ()
+{
+  C1::Nested c1;
+
+  c1.foo();
+
+  return 0;
+}
--- /dev/null	2002-08-30 16:31:37.000000000 -0700
+++ testsuite/gdb.c++/breakpoint.exp	2003-05-09 11:20:39.000000000 -0700
@@ -0,0 +1,68 @@
+# Copyright 2003 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# This file is part of the gdb testsuite.
+
+# This contains tests for breakpoints in C++.
+
+# NOTE: carlton/2003-05-09: It's not at all comprehensive right now,
+# and lots of the other files test breakpoints as well.  But I wanted
+# to add a test covering a bug I found in linespec.c:decode_compound,
+# and putting it in a separate file seemed natural.
+
+if $tracelevel then {
+        strace $tracelevel
+        }
+
+if { [skip_cplus_tests] } { continue }
+
+#
+# test running programs
+#
+set prms_id 0
+set bug_id 0
+
+set testfile "breakpoint"
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${testfile}
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+if [get_compiler_info ${binfile} "c++"] {
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+proc test_breakpoint {name} {
+    gdb_breakpoint "${name}"
+    gdb_test "continue" "Continuing.\r\n\r\nBreakpoint \[0-9\]*, ${name}.*" "continue to ${name}"
+}
+
+if ![runto_main] then {
+    perror "couldn't run to breakpoint"
+    continue
+}
+
+test_breakpoint "C1::Nested::foo"
+
+gdb_exit
+return 0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]