Modified Files:
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
index d4627e0f5a87625a28b48d16c37b4eed3bc84f09..b370db9f67b04e677963a5e326c66065d32c01b1 100644 (file)
@@ -32,15 +32,18 @@ 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 int
-cp_is_vtbl_ptr_type PARAMS ((struct type *));
+extern void
+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
+cp_is_vtbl_ptr_type PARAMS ((struct type *));
+
 extern int
 cp_is_vtbl_member PARAMS ((struct type *));
 
@@ -50,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 */
 
 
@@ -80,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))
     {
@@ -105,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))
@@ -127,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')
@@ -142,78 +147,7 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
        }
       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
        {
-         struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
-         struct fn_field *f;
-         int j, len2;
-         char *kind = "";
-         CORE_ADDR addr;
-
-         addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
-                               valaddr);
-         if (METHOD_PTR_IS_VIRTUAL(addr))
-           {
-             int offset = METHOD_PTR_TO_VOFFSET(addr);
-             len = TYPE_NFN_FIELDS (domain);
-             for (i = 0; i < len; i++)
-               {
-                 f = TYPE_FN_FIELDLIST1 (domain, i);
-                 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
-
-                 for (j = 0; j < len2; j++)
-                   {
-                     QUIT;
-                     if (TYPE_FN_FIELD_VOFFSET (f, j) == offset)
-                       {
-                         kind = "virtual ";
-                         goto common;
-                       }
-                   }
-               }
-           }
-         else
-           {
-             struct symbol *sym = find_pc_function (addr);
-             if (sym == 0)
-               {
-                 error ("invalid pointer to member function");
-               }
-             len = TYPE_NFN_FIELDS (domain);
-             for (i = 0; i < len; i++)
-               {
-                 f = TYPE_FN_FIELDLIST1 (domain, i);
-                 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
-
-                 for (j = 0; j < len2; j++)
-                   {
-                     QUIT;
-                     if (STREQ (SYMBOL_NAME (sym),
-                                 TYPE_FN_FIELD_PHYSNAME (f, j)))
-                       {
-                         goto common;
-                       }
-                   }
-               }
-           }
-       common:
-         if (i < len)
-           {
-             fprintf_filtered (stream, "&");
-             c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
-             fprintf (stream, kind);
-             if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
-                 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
-               cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
-                                          TYPE_FN_FIELDLIST_NAME (domain, i),
-                                          0, stream);
-             else
-               cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j), "",
-                                          TYPE_FN_FIELDLIST_NAME (domain, i),
-                                          0, stream);
-             break;
-           }
-         fprintf_filtered (stream, "(");
-         type_print (type, "", stream, -1);
-         fprintf_filtered (stream, ") %d", (int) addr >> 3);
+         cp_print_class_method (valaddr, type, stream);
        }
       else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
        {
@@ -223,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)
@@ -236,95 +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)
            {
-             int first_addr_err = 0;
-             int errcode = 0;
-             
-             /* Get first character.  */
-             errcode = target_read_memory (addr, (char *)&c, 1);
-             if (errcode != 0)
-               {
-                 /* First address out of bounds.  */
-                 first_addr_err = 1;
-               }
-             else
-               {
-                 /* A real string.  */
-                 char *string = (char *) alloca (print_max);
-
-                 /* If the loop ends by us hitting print_max characters,
-                    we need to have elipses at the end.  */
-                 int force_ellipses = 1;
-
-                 /* This loop always fetches print_max characters, even
-                    though LA_PRINT_STRING might want to print more or fewer
-                    (with repeated characters).  This is so that
-                    we don't spend forever fetching if we print
-                    a long string consisting of the same character
-                    repeated.  Also so we can do it all in one memory
-                    operation, which is faster.  However, this will be
-                    slower if print_max is set high, e.g. if you set
-                    print_max to 1000, not only will it take a long
-                    time to fetch short strings, but if you are near
-                    the end of the address space, it might not work. */
-                 QUIT;
-                 errcode = target_read_memory (addr, string, print_max);
-                 if (errcode != 0)
-                   {
-                     /* Try reading just one character.  If that succeeds,
-                        assume we hit the end of the address space, but
-                        the initial part of the string is probably safe. */
-                     char x[1];
-                     errcode = target_read_memory (addr, x, 1);
-                   }
-                 if (errcode != 0)
-                     force_ellipses = 0;
-                 else 
-                   for (i = 0; i < print_max; i++)
-                     if (string[i] == '\0')
-                       {
-                         force_ellipses = 0;
-                         break;
-                       }
-                 QUIT;
-
-                 if (addressprint)
-                   {
-                     fputs_filtered (" ", stream);
-                   }
-                 LA_PRINT_STRING (stream, string, i, force_ellipses);
-               }
-
-             if (errcode != 0)
-               {
-                 if (errcode == EIO)
-                   {
-                     fprintf_filtered (stream,
-                                       (" <Address 0x%x out of bounds>" +
-                                        first_addr_err),
-                                       addr + i);
-                   }
-                 else
-                   {
-                     error ("Error reading memory address 0x%x: %s.",
-                            addr + i, safe_strerror (errcode));
-                   }
-               }
-
-             fflush (stream);
+             i = val_print_string (addr, 0, stream);
            }
          else if (cp_is_vtbl_member(type))
            {
@@ -340,11 +197,28 @@ c_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
                  fputs_filtered (SYMBOL_SOURCE_NAME (msymbol), stream);
                  fputs_filtered (">", stream);
                }
-             if (vtblprint)
+             if (vt_address && vtblprint)
                {
                  value vt_val;
-
-                 vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address);
+                 struct symbol *wsym = (struct symbol *)NULL;
+                 struct type *wtype;
+                 struct symtab *s;
+                 struct block *block = (struct block *)NULL;
+                 int is_this_fld;
+
+                 if (msymbol != NULL)
+                   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);
@@ -428,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;
@@ -443,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;
 
@@ -466,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)
@@ -537,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.034721 seconds and 4 git commands to generate.