* config/m68k/nm-hp300bsd.h: Correctly identify 4.3BSD vs 4.4BSD.
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
index 4b7da623ac2ef6251465c1ac3e2541f913a9ad9b..be498dfff8aa0dc7d863ee1dc7c7c6717a1959ae 100644 (file)
@@ -32,13 +32,13 @@ extern int vtblprint;               /* Controls printing of vtbl's */
 extern int demangle;           /* whether to print C++ syms raw or src-form */
 
 extern void
-cp_print_class_member PARAMS ((char *, struct type *, FILE *, char *));
+cp_print_class_member PARAMS ((char *, struct type *, GDB_FILE *, char *));
 
 extern void
-cp_print_class_method PARAMS ((char *, struct type *, FILE *));
+cp_print_class_method PARAMS ((char *, struct type *, GDB_FILE *));
 
 extern void
-cp_print_value_fields PARAMS ((struct type *, char *, FILE *, int, int,
+cp_print_value_fields PARAMS ((struct type *, char *, GDB_FILE *, int, int,
                               enum val_prettyprint, struct type **));
 
 extern int
@@ -53,11 +53,11 @@ cp_is_vtbl_member PARAMS ((struct type *));
 /* BEGIN-FIXME:  Hooks into c-typeprint.c */
 
 extern void
-c_type_print_varspec_prefix PARAMS ((struct type *, FILE *, int, int));
+c_type_print_varspec_prefix PARAMS ((struct type *, GDB_FILE *, int, int));
 
 extern void
 cp_type_print_method_args PARAMS ((struct type **, char *, char *, int,
-                                  FILE *));
+                                  GDB_FILE *));
 /* END-FIXME */
 
 
@@ -83,18 +83,18 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
      struct type *type;
      char *valaddr;
      CORE_ADDR address;
-     FILE *stream;
+     GDB_FILE *stream;
      int format;
      int deref_ref;
      int recurse;
      enum val_prettyprint pretty;
 {
-  register unsigned int i;
+  register unsigned int i = 0;         /* Number of characters printed */
   unsigned len;
   struct type *elttype;
   unsigned eltlen;
   LONGEST val;
-  unsigned char c;
+  CORE_ADDR addr;
 
   switch (TYPE_CODE (type))
     {
@@ -108,15 +108,16 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
            {
              print_spaces_filtered (2 + 2 * recurse, stream);
            }
-         fprintf_filtered (stream, "{");
          /* For an array of chars, print with string syntax.  */
          if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
-             && (format == 0 || format == 's') )
+             && (format == 0 || format == 's'))
            {
              LA_PRINT_STRING (stream, valaddr, len, 0);
+             i = len;
            }
          else
            {
+             fprintf_filtered (stream, "{");
              /* If this is a virtual function table, print the 0th
                 entry specially, and the rest of the members normally.  */
              if (cp_is_vtbl_ptr_type (elttype))
@@ -130,12 +131,13 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
                }
              val_print_array_elements (type, valaddr, address, stream,
                                        format, deref_ref, recurse, pretty, i);
+             fprintf_filtered (stream, "}");
            }
-         fprintf_filtered (stream, "}");
          break;
        }
       /* Array of unspecified length: treat like pointer to first elt.  */
-      valaddr = (char *) &address;
+      addr = address;
+      goto print_unpacked_pointer;
 
     case TYPE_CODE_PTR:
       if (format && format != 's')
@@ -155,7 +157,8 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
        }
       else
        {
-         CORE_ADDR addr = unpack_pointer (type, valaddr);
+         addr = unpack_pointer (type, valaddr);
+       print_unpacked_pointer:
          elttype = TYPE_TARGET_TYPE (type);
 
          if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
@@ -168,21 +171,17 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
 
          if (addressprint && format != 's')
            {
-             fprintf_filtered (stream, "0x%x", addr);
+             fprintf_filtered (stream, "0x%lx", (unsigned long)addr);
            }
 
          /* For a pointer to char or unsigned char, also print the string
             pointed to, unless pointer is null.  */
-         i = 0;                /* Number of characters printed.  */
-         if (TYPE_LENGTH (elttype) == 1 &&
-             TYPE_CODE (elttype) == TYPE_CODE_INT &&
-             (format == 0 || format == 's') &&
-             addr != 0 &&
-             /* If print_max is UINT_MAX, the alloca below will fail.
-                In that case don't try to print the string.  */
-             print_max < UINT_MAX)
+         if (TYPE_LENGTH (elttype) == 1
+             && TYPE_CODE (elttype) == TYPE_CODE_INT
+             && (format == 0 || format == 's')
+             && addr != 0)
            {
-             i = val_print_string (addr, stream);
+             i = val_print_string (addr, 0, stream);
            }
          else if (cp_is_vtbl_member(type))
            {
@@ -201,8 +200,25 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
              if (vtblprint)
                {
                  value vt_val;
+                 struct symbol *wsym = (struct symbol *)NULL;
+                 struct type *wtype;
+                 struct symtab *s;
+                 struct block *block = (struct block *)NULL;
+                 int is_this_fld;
 
-                 vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address);
+
+                 wsym = lookup_symbol (SYMBOL_NAME(msymbol), block, 
+                               VAR_NAMESPACE, &is_this_fld, &s);
+                 if (wsym)
+                   {
+                     wtype = SYMBOL_TYPE(wsym);
+                   }
+                 else
+                   {
+                     wtype = TYPE_TARGET_TYPE(type);
+                   }
+                 vt_val = value_at (wtype, vt_address);
                  val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val),
                             VALUE_ADDRESS (vt_val), stream, format,
                             deref_ref, recurse + 1, pretty);
@@ -286,7 +302,7 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
          break;
        }
       len = TYPE_NFIELDS (type);
-      val = unpack_long (builtin_type_int, valaddr);
+      val = unpack_long (type, valaddr);
       for (i = 0; i < len; i++)
        {
          QUIT;
@@ -301,11 +317,7 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
        }
       else
        {
-#ifdef LONG_LONG
-         fprintf_filtered (stream, "%lld", val);
-#else
-         fprintf_filtered (stream, "%ld", val);
-#endif
+         print_longest (stream, 'd', 0, val);
        }
       break;
 
@@ -324,6 +336,10 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
       print_address_demangle (address, stream, demangle);
       break;
 
+    case TYPE_CODE_BOOL:
+      /* Do something at least vaguely reasonable, for example if the
+        language is set wrong.  */
+
     case TYPE_CODE_INT:
       format = format ? format : output_format;
       if (format)
@@ -395,6 +411,6 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
     default:
       error ("Invalid C/C++ type code %d in symbol table.", TYPE_CODE (type));
     }
-  fflush (stream);
+  gdb_flush (stream);
   return (0);
 }
This page took 0.028042 seconds and 4 git commands to generate.