This is the mail archive of the gdb-patches@sourceware.org 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]

[commit] Fix a C++ segfault


Something Michael Chastain pointed out to me a long time ago.
This prevents GDB from crashing, in the fairly obvious way.
It still doesn't pass the test:

+# TODO: GDB doesn't know to convert the string to a const char *, and
+# instead tries to use the string as a structure initializer.

But this is well into the range of where you need a real C++ compiler wired
up.  In Ottawa I talked to Mark Mitchell about the general problem; he said
that something like 20,000 lines of g++ is devoted to selecting the correct
conversions and overloaded functions.  I have absolutely zero interest, full
stop, in duplicating that code.  I don't intend any major improvements in
this area, unless someone is motivated enough to let us share the code for
it with g++.

Checked in.

-- 
Daniel Jacobowitz
CodeSourcery

2006-07-20  Daniel Jacobowitz  <dan@codesourcery.com>

	* eval.c (evaluate_struct_tuple): Skip static fields.

2006-07-20  Daniel Jacobowitz  <dan@codesourcery.com>

	* gdb.cp/bs15503.exp: Update comment for no longer crashing
	test.

Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.61
diff -u -p -r1.61 eval.c
--- eval.c	18 Feb 2006 20:47:54 -0000	1.61
+++ eval.c	20 Jul 2006 22:36:01 -0000
@@ -283,6 +283,10 @@ evaluate_struct_tuple (struct value *str
 	      if (variantno < 0)
 		{
 		  fieldno++;
+		  /* Skip static fields.  */
+		  while (fieldno < TYPE_NFIELDS (struct_type)
+			 && TYPE_FIELD_STATIC_KIND (struct_type, fieldno))
+		    fieldno++;
 		  subfieldno = fieldno;
 		  if (fieldno >= TYPE_NFIELDS (struct_type))
 		    error (_("too many initializers"));
Index: testsuite/gdb.cp/bs15503.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/bs15503.exp,v
retrieving revision 1.5
diff -u -p -r1.5 bs15503.exp
--- testsuite/gdb.cp/bs15503.exp	27 Apr 2005 16:35:15 -0000	1.5
+++ testsuite/gdb.cp/bs15503.exp	20 Jul 2006 22:36:02 -0000
@@ -83,11 +83,11 @@ gdb_test "print (const char *) s" \
 # gdb_test "print s > "AAA"			"\\$\[0-9\]+ = true"
 # gdb_test "print s < "ZZZ"			"\\$\[0-9\]+ = true"
 
-# TODO crash gdb!  This is going to be a great test!
-# -- chastain 2004-01-07
+# TODO: GDB doesn't know to convert the string to a const char *, and
+# instead tries to use the string as a structure initializer.
 # 
 # gdb_test "print s == \"I am a short stringand now a longer string\"" \
-#     "\\$\[0-9\]+ = "true"
+#     "\\$\[0-9\]+ = true"
 
 gdb_test "print (const char *) s.substr(0,4)"	"\\$\[0-9\]+ = $hex \"I am\""
 gdb_test "print (const char *) (s=s.substr(0,4))" \


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