2012-12-11 Pedro Alves <pedro@codesourcery.com>
[binutils-gdb.git] / gdb / p-valprint.c
index d6373aedd4e52437a70ec3150858163b1099e506..b2287f2177d1a767f183304d61ccc4c39ed597b4 100644 (file)
@@ -72,8 +72,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
   unsigned eltlen;
   int length_pos, length_size, string_pos;
   struct type *char_type;
-  LONGEST val;
   CORE_ADDR addr;
+  int want_space = 0;
 
   CHECK_TYPEDEF (type);
   switch (TYPE_CODE (type))
@@ -157,7 +157,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
          /* Extract the address, assume that it is unsigned.  */
          addr = extract_unsigned_integer (valaddr + embedded_offset,
                                           TYPE_LENGTH (type), byte_order);
-         print_address_demangle (gdbarch, addr, stream, demangle);
+         print_address_demangle (options, gdbarch, addr, stream, demangle);
          break;
        }
       check_typedef (TYPE_TARGET_TYPE (type));
@@ -169,13 +169,14 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
       if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
        {
          /* Try to print what function it points to.  */
-         print_address_demangle (gdbarch, addr, stream, demangle);
+         print_address_demangle (options, gdbarch, addr, stream, demangle);
          return;
        }
 
       if (options->addressprint && options->format != 's')
        {
          fputs_filtered (paddress (gdbarch, addr), stream);
+         want_space = 1;
        }
 
       /* For a pointer to char or unsigned char, also print the string
@@ -188,6 +189,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
          && (options->format == 0 || options->format == 's')
          && addr != 0)
        {
+         if (want_space)
+           fputs_filtered (" ", stream);
          /* No wide string yet.  */
          i = val_print_string (elttype, NULL, addr, -1, stream, options);
        }
@@ -203,6 +206,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
          ULONGEST string_length;
          void *buffer;
 
+         if (want_space)
+           fputs_filtered (" ", stream);
          buffer = xmalloc (length_size);
          read_memory (addr + length_pos, buffer, length_size);
          string_length = extract_unsigned_integer (buffer, length_size,
@@ -220,12 +225,17 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
          struct minimal_symbol *msymbol =
            lookup_minimal_symbol_by_pc (vt_address);
 
-         if ((msymbol != NULL)
+         /* If 'symbol_print' is set, we did the work above.  */
+         if (!options->symbol_print
+             && (msymbol != NULL)
              && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
            {
-             fputs_filtered (" <", stream);
+             if (want_space)
+               fputs_filtered (" ", stream);
+             fputs_filtered ("<", stream);
              fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
              fputs_filtered (">", stream);
+             want_space = 1;
            }
          if (vt_address && options->vtblprint)
            {
@@ -235,6 +245,9 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
              struct block *block = (struct block *) NULL;
              int is_this_fld;
 
+             if (want_space)
+               fputs_filtered (" ", stream);
+
              if (msymbol != NULL)
                wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
                                      VAR_DOMAIN, &is_this_fld);
@@ -292,7 +305,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
             -fvtable_thunks.  (Otherwise, look under TYPE_CODE_PTR.)  */
          /* Extract the address, assume that it is unsigned.  */
          print_address_demangle
-           (gdbarch,
+           (options, gdbarch,
             extract_unsigned_integer (valaddr + embedded_offset
                                       + TYPE_FIELD_BITPOS (type,
                                                            VTBL_FNADDR_OFFSET) / 8,
@@ -321,7 +334,6 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
        }
       break;
 
-    case TYPE_CODE_BITSTRING:
     case TYPE_CODE_SET:
       elttype = TYPE_INDEX_TYPE (type);
       CHECK_TYPEDEF (elttype);
@@ -336,13 +348,9 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
          struct type *range = elttype;
          LONGEST low_bound, high_bound;
          int i;
-         int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
          int need_comma = 0;
 
-         if (is_bitstring)
-           fputs_filtered ("B'", stream);
-         else
-           fputs_filtered ("[", stream);
+         fputs_filtered ("[", stream);
 
          i = get_discrete_bounds (range, &low_bound, &high_bound);
          if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
@@ -370,9 +378,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
                  i = element;
                  goto maybe_bad_bstring;
                }
-             if (is_bitstring)
-               fprintf_filtered (stream, "%d", element);
-             else if (element)
+             if (element)
                {
                  if (need_comma)
                    fputs_filtered (", ", stream);
@@ -396,10 +402,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
                }
            }
        done:
-         if (is_bitstring)
-           fputs_filtered ("'", stream);
-         else
-           fputs_filtered ("]", stream);
+         fputs_filtered ("]", stream);
        }
       break;
 
@@ -784,8 +787,11 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 
          if (boffset < 0 || boffset >= TYPE_LENGTH (type))
            {
-             /* FIXME (alloc): not safe is baseclass is really really big. */
-             gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
+             gdb_byte *buf;
+             struct cleanup *back_to;
+
+             buf = xmalloc (TYPE_LENGTH (baseclass));
+             back_to = make_cleanup (xfree, buf);
 
              base_valaddr = buf;
              if (target_read_memory (address + boffset, buf,
@@ -794,6 +800,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
              address = address + boffset;
              thisoffset = 0;
              boffset = 0;
+             do_cleanups (back_to);
            }
          else
            base_valaddr = valaddr;