2000-03-28 J.T. Conklin <jtc@redback.com>
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
index f791e4c20deb2f8f20aa93980433da5ac96f3d53..07289de0a9c108348f5a3a2c1e82147c02bacc72 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for printing C values for GDB, the GNU debugger.
-   Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997
+   Copyright 1986, 1988, 1989, 1991-1997, 2000
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -50,7 +50,7 @@ c_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref,
      char *valaddr;
      int embedded_offset;
      CORE_ADDR address;
-     GDB_FILE *stream;
+     struct ui_file *stream;
      int format;
      int deref_ref;
      int recurse;
@@ -87,7 +87,7 @@ c_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref,
                 elements up to it.  */
              if (stop_print_at_null)
                {
-                 int temp_len;
+                 unsigned int temp_len;
 
                  /* Look for a NULL char. */
                  for (temp_len = 0;
@@ -403,10 +403,13 @@ c_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref,
        }
       else
        {
-         fprintf_filtered (stream, TYPE_UNSIGNED (type) ? "%u" : "%d",
-                           unpack_long (type, valaddr + embedded_offset));
+         val = unpack_long (type, valaddr + embedded_offset);
+         if (TYPE_UNSIGNED (type))
+           fprintf_filtered (stream, "%u", (unsigned int) val);
+         else
+           fprintf_filtered (stream, "%d", (int) val);
          fputs_filtered (" ", stream);
-         LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset), stream);
+         LA_PRINT_CHAR ((unsigned char) val, stream);
        }
       break;
 
@@ -450,7 +453,7 @@ c_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref,
 int
 c_value_print (val, stream, format, pretty)
      value_ptr val;
-     GDB_FILE *stream;
+     struct ui_file *stream;
      int format;
      enum val_prettyprint pretty;
 {
@@ -480,20 +483,24 @@ c_value_print (val, stream, format, pretty)
        {
          /* Pointer to class, check real type of object */
          fprintf_filtered (stream, "(");
-         type = value_rtti_target_type (val, &full, &top, &using_enc);
-         if (type)
+          real_type = value_rtti_target_type (val, &full, &top, &using_enc);
+          if (real_type)
            {
              /* RTTI entry found */
-             type = lookup_pointer_type (type);
-             type_print (type, "", stream, -1);
-           }
-         else
-           {
-             /* No RTTI fields, do whatever we can */
-             type = VALUE_ENCLOSING_TYPE (val);
-             type_print (type, "", stream, -1);
-             fprintf_filtered (stream, " ?");
-           }
+              if (TYPE_CODE (type) == TYPE_CODE_PTR)
+                {
+                  /* create a pointer type pointing to the real type */
+                  type = lookup_pointer_type (real_type);
+                }
+              else
+                {
+                  /* create a reference type referencing the real type */
+                  type = lookup_reference_type (real_type);
+                }
+              /* Note: When we look up RTTI entries, we don't get any 
+                 information on const or volatile attributes */
+            }
+          type_print (type, "", stream, -1);
          fprintf_filtered (stream, ") ");
        }
       else
@@ -518,6 +525,8 @@ c_value_print (val, stream, format, pretty)
          /* Print out object: enclosing type is same as real_type if full */
          return val_print (VALUE_ENCLOSING_TYPE (val), VALUE_CONTENTS_ALL (val), 0,
                         VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
+          /* Note: When we look up RTTI entries, we don't get any information on
+             const or volatile attributes */
        }
       else if (type != VALUE_ENCLOSING_TYPE (val))
        {
This page took 0.024556 seconds and 4 git commands to generate.