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]

PATCH/c++: Print member functions successfully


This corrects two errors thrown while trying to print a variable of type
TYPE_CODE_METHOD:
  - The first argument to cp_print_class_method is currently supposed to
  be a pointer to the address of the member, in target byte order.  This
  is somewhat pointless but I'll address it separately, (much) later.

  - search_struct_method was not finding the method in this case.

Now, things like:

class Foo { int Bar(); };
Foo baz;

(gdb) print baz.Bar

will work.  The result is:
(gdb) p baz.Bar
$1 = &Foo::Bar(void)

Again, not the most useful result, but I'll address that later too :)

Committed.


-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer

2002-02-03  Daniel Jacobowitz  <drow@mvista.com>

	* c-valprint.c (c_val_print): Pass a proper valaddr to
	cp_print_class_method.
	* valops.c (search_struct_method): If there is only one method
	and args is NULL, return that method.

Index: c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.11
diff -u -p -r1.11 c-valprint.c
--- c-valprint.c	2001/11/10 20:44:37	1.11
+++ c-valprint.c	2002/02/04 02:11:39
@@ -441,8 +441,12 @@ c_val_print (struct type *type, char *va
       break;
 
     case TYPE_CODE_METHOD:
-      cp_print_class_method (valaddr + embedded_offset, lookup_pointer_type (type), stream);
-      break;
+      {
+	struct value *v = value_at (type, address, NULL);
+	cp_print_class_method (VALUE_CONTENTS (value_addr (v)),
+			       lookup_pointer_type (type), stream);
+	break;
+      }
 
     case TYPE_CODE_VOID:
       fprintf_filtered (stream, "void");
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.49
diff -u -p -r1.49 valops.c
--- valops.c	2002/01/08 02:09:31	1.49
+++ valops.c	2002/02/04 02:11:40
@@ -2274,23 +2274,32 @@ search_struct_method (char *name, struct
 
 	  if (j > 0 && args == 0)
 	    error ("cannot resolve overloaded method `%s': no arguments supplied", name);
-	  while (j >= 0)
+	  else if (j == 0 && args == 0)
 	    {
 	      if (TYPE_FN_FIELD_STUB (f, j))
 		check_stub_method (type, i, j);
-	      if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
-			    TYPE_FN_FIELD_ARGS (f, j), args))
-		{
-		  if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
-		    return value_virtual_fn_field (arg1p, f, j, type, offset);
-		  if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
-		    *static_memfuncp = 1;
-		  v = value_fn_field (arg1p, f, j, type, offset);
-		  if (v != NULL)
-		    return v;       
-		}
-	      j--;
+	      v = value_fn_field (arg1p, f, j, type, offset);
+	      if (v != NULL)
+		return v;
 	    }
+	  else
+	    while (j >= 0)
+	      {
+		if (TYPE_FN_FIELD_STUB (f, j))
+		  check_stub_method (type, i, j);
+		if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
+			      TYPE_FN_FIELD_ARGS (f, j), args))
+		  {
+		    if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
+		      return value_virtual_fn_field (arg1p, f, j, type, offset);
+		    if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
+		      *static_memfuncp = 1;
+		    v = value_fn_field (arg1p, f, j, type, offset);
+		    if (v != NULL)
+		      return v;       
+		  }
+		j--;
+	      }
 	}
     }
 


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