revert 1.9. Not approved.
[deliverable/binutils-gdb.git] / gdb / typeprint.c
index e892e5e6da2cb81f412e4d82a3d9594828bfd7af..9050e82afcf805f5d02ab53bfea702db17ab29d6 100644 (file)
@@ -1,5 +1,5 @@
 /* Language independent support for printing types for GDB, the GNU debugger.
-   Copyright 1986, 88, 89, 91, 92, 93, 1998 Free Software Foundation, Inc.
+   Copyright 1986, 1988, 1989, 1991-1993, 1998, 2000 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -64,7 +64,7 @@ void
 type_print (type, varstring, stream, show)
      struct type *type;
      char *varstring;
-     GDB_FILE *stream;
+     struct ui_file *stream;
      int show;
 {
   LA_PRINT_TYPE (type, varstring, stream, show, 0);
@@ -82,6 +82,7 @@ whatis_exp (exp, show)
   register value_ptr val;
   register struct cleanup *old_chain = NULL;
   struct type *real_type = NULL;
+  struct type *type;
   int full = 0;
   int top = -1;
   int using_enc = 0;
@@ -89,24 +90,46 @@ whatis_exp (exp, show)
   if (exp)
     {
       expr = parse_expression (exp);
-      old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
-                               &expr);
+      old_chain = make_cleanup (free_current_contents, &expr);
       val = evaluate_type (expr);
     }
   else
     val = access_value_history (0);
 
+  type = VALUE_TYPE (val);
+
+  if (objectprint)
+    {
+      if (((TYPE_CODE (type) == TYPE_CODE_PTR) ||
+           (TYPE_CODE (type) == TYPE_CODE_REF))
+          &&
+          (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
+        {
+          real_type = value_rtti_target_type (val, &full, &top, &using_enc);
+          if (real_type)
+            {
+              if (TYPE_CODE (type) == TYPE_CODE_PTR)
+                real_type = lookup_pointer_type (real_type);
+              else
+                real_type = lookup_reference_type (real_type);
+            }
+        }
+      else if (TYPE_CODE (type) == TYPE_CODE_CLASS)
   real_type = value_rtti_type (val, &full, &top, &using_enc);
+    }
 
   printf_filtered ("type = ");
 
-  if (real_type && objectprint)
-    printf_filtered ("/* real type = %s%s */\n",
-                    TYPE_NAME (real_type),
-                    full ? "" : " (incomplete object)");
-  /* FIXME: maybe better to use type_print (real_type, "", gdb_stdout, -1); */
+  if (real_type)
+    {
+      printf_filtered ("/* real type = ");
+      type_print (real_type, "", gdb_stdout, -1);
+      if (! full)
+        printf_filtered (" (incomplete object)");
+      printf_filtered (" */\n");    
+    }
 
-  type_print (VALUE_TYPE (val), "", gdb_stdout, show);
+  type_print (type, "", gdb_stdout, show);
   printf_filtered ("\n");
 
   if (exp)
@@ -161,8 +184,7 @@ ptype_command (typename, from_tty)
   else
     {
       expr = parse_expression (typename);
-      old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
-                               &expr);
+      old_chain = make_cleanup (free_current_contents, &expr);
       type = ptype_eval (expr);
       if (type != NULL)
        {
@@ -197,7 +219,7 @@ void
 print_type_scalar (type, val, stream)
      struct type *type;
      LONGEST val;
-     GDB_FILE *stream;
+     struct ui_file *stream;
 {
   unsigned int i;
   unsigned len;
@@ -282,7 +304,7 @@ maintenance_print_type (typename, from_tty)
   if (typename != NULL)
     {
       expr = parse_expression (typename);
-      old_chain = make_cleanup ((make_cleanup_func) free_current_contents, &expr);
+      old_chain = make_cleanup (free_current_contents, &expr);
       if (expr->elts[0].opcode == OP_TYPE)
        {
          /* The user expression names a type directly, just use that type. */
This page took 0.024685 seconds and 4 git commands to generate.