/* Support for printing Pascal values for GDB, the GNU debugger.
- Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009
+ Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of GDB.
struct ui_file *stream, int recurse,
const struct value_print_options *options)
{
+ struct gdbarch *gdbarch = get_type_arch (type);
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
unsigned int i = 0; /* Number of characters printed */
unsigned len;
struct type *elttype;
unsigned eltlen;
int length_pos, length_size, string_pos;
- int char_size;
+ struct type *char_type;
LONGEST val;
CORE_ADDR addr;
{
print_spaces_filtered (2 + 2 * recurse, stream);
}
- /* For an array of chars, print with string syntax. */
- if ((eltlen == 1 || eltlen == 2 || eltlen == 4)
- && ((TYPE_CODE (elttype) == TYPE_CODE_INT)
- || ((current_language->la_language == language_pascal)
- && (TYPE_CODE (elttype) == TYPE_CODE_CHAR)))
- && (options->format == 0 || options->format == 's'))
+ /* If 's' format is used, try to print out as string.
+ If no format is given, print as string if element type
+ is of TYPE_CODE_CHAR and element size is 1,2 or 4. */
+ if (options->format == 's'
+ || ((eltlen == 1 || eltlen == 2 || eltlen == 4)
+ && TYPE_CODE (elttype) == TYPE_CODE_CHAR
+ && options->format == 0))
{
/* If requested, look for the first null char and only print
elements up to it. */
/* Look for a NULL char. */
for (temp_len = 0;
extract_unsigned_integer (valaddr + embedded_offset +
- temp_len * eltlen, eltlen)
+ temp_len * eltlen, eltlen,
+ byte_order)
&& temp_len < len && temp_len < options->print_max;
temp_len++);
len = temp_len;
}
- LA_PRINT_STRING (stream, valaddr + embedded_offset, len,
- eltlen, 0, options);
+ LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
+ valaddr + embedded_offset, len, NULL, 0,
+ options);
i = len;
}
else
/* Print vtable entry - we only get here if we ARE using
-fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
/* Extract the address, assume that it is unsigned. */
- print_address_demangle (extract_unsigned_integer (valaddr + embedded_offset, TYPE_LENGTH (type)),
- stream, demangle);
+ addr = extract_unsigned_integer (valaddr + embedded_offset,
+ TYPE_LENGTH (type), byte_order);
+ print_address_demangle (gdbarch, addr, stream, demangle);
break;
}
elttype = check_typedef (TYPE_TARGET_TYPE (type));
+
+ addr = unpack_pointer (type, valaddr + embedded_offset);
+ print_unpacked_pointer:
+ elttype = check_typedef (TYPE_TARGET_TYPE (type));
+
+ if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
{
- addr = unpack_pointer (type, valaddr + embedded_offset);
- print_unpacked_pointer:
- elttype = check_typedef (TYPE_TARGET_TYPE (type));
+ /* Try to print what function it points to. */
+ print_address_demangle (gdbarch, addr, stream, demangle);
+ /* Return value is irrelevant except for string pointers. */
+ return (0);
+ }
- if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
- {
- /* Try to print what function it points to. */
- print_address_demangle (addr, stream, demangle);
- /* Return value is irrelevant except for string pointers. */
- return (0);
- }
+ if (options->addressprint && options->format != 's')
+ {
+ fputs_filtered (paddress (gdbarch, addr), stream);
+ }
- if (options->addressprint && options->format != 's')
- {
- fputs_filtered (paddress (addr), stream);
- }
+ /* For a pointer to char or unsigned char, also print the string
+ pointed to, unless pointer is null. */
+ if (((TYPE_LENGTH (elttype) == 1
+ && (TYPE_CODE (elttype) == TYPE_CODE_INT
+ || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
+ || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
+ && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
+ && (options->format == 0 || options->format == 's')
+ && addr != 0)
+ {
+ /* no wide string yet */
+ i = val_print_string (elttype, addr, -1, stream, options);
+ }
+ /* also for pointers to pascal strings */
+ /* Note: this is Free Pascal specific:
+ as GDB does not recognize stabs pascal strings
+ Pascal strings are mapped to records
+ with lowercase names PM */
+ if (is_pascal_string_type (elttype, &length_pos, &length_size,
+ &string_pos, &char_type, NULL)
+ && addr != 0)
+ {
+ ULONGEST string_length;
+ void *buffer;
+ buffer = xmalloc (length_size);
+ read_memory (addr + length_pos, buffer, length_size);
+ string_length = extract_unsigned_integer (buffer, length_size,
+ byte_order);
+ xfree (buffer);
+ i = val_print_string (char_type ,addr + string_pos, string_length, stream, options);
+ }
+ else if (pascal_object_is_vtbl_member (type))
+ {
+ /* print vtbl's nicely */
+ CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
- /* For a pointer to char or unsigned char, also print the string
- pointed to, unless pointer is null. */
- if (((TYPE_LENGTH (elttype) == 1
- && (TYPE_CODE (elttype) == TYPE_CODE_INT
- || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
- || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
- && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
- && (options->format == 0 || options->format == 's')
- && addr != 0)
- {
- /* no wide string yet */
- i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream,
- options);
- }
- /* also for pointers to pascal strings */
- /* Note: this is Free Pascal specific:
- as GDB does not recognize stabs pascal strings
- Pascal strings are mapped to records
- with lowercase names PM */
- if (is_pascal_string_type (elttype, &length_pos, &length_size,
- &string_pos, &char_size, NULL)
- && addr != 0)
+ struct minimal_symbol *msymbol =
+ lookup_minimal_symbol_by_pc (vt_address);
+ if ((msymbol != NULL)
+ && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
{
- ULONGEST string_length;
- void *buffer;
- buffer = xmalloc (length_size);
- read_memory (addr + length_pos, buffer, length_size);
- string_length = extract_unsigned_integer (buffer, length_size);
- xfree (buffer);
- i = val_print_string (addr + string_pos, string_length, char_size, stream, options);
+ fputs_filtered (" <", stream);
+ fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
+ fputs_filtered (">", stream);
}
- else if (pascal_object_is_vtbl_member (type))
+ if (vt_address && options->vtblprint)
{
- /* print vtbl's nicely */
- CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
+ struct value *vt_val;
+ struct symbol *wsym = (struct symbol *) NULL;
+ struct type *wtype;
+ struct block *block = (struct block *) NULL;
+ int is_this_fld;
- struct minimal_symbol *msymbol =
- lookup_minimal_symbol_by_pc (vt_address);
- if ((msymbol != NULL)
- && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
+ if (msymbol != NULL)
+ wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
+ VAR_DOMAIN, &is_this_fld);
+
+ if (wsym)
+ {
+ wtype = SYMBOL_TYPE (wsym);
+ }
+ else
{
- fputs_filtered (" <", stream);
- fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
- fputs_filtered (">", stream);
+ wtype = TYPE_TARGET_TYPE (type);
}
- if (vt_address && options->vtblprint)
+ vt_val = value_at (wtype, vt_address);
+ common_val_print (vt_val, stream, recurse + 1, options,
+ current_language);
+ if (options->pretty)
{
- struct value *vt_val;
- struct symbol *wsym = (struct symbol *) NULL;
- struct type *wtype;
- struct block *block = (struct block *) NULL;
- int is_this_fld;
-
- if (msymbol != NULL)
- wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
- VAR_DOMAIN, &is_this_fld);
-
- if (wsym)
- {
- wtype = SYMBOL_TYPE (wsym);
- }
- else
- {
- wtype = TYPE_TARGET_TYPE (type);
- }
- vt_val = value_at (wtype, vt_address);
- common_val_print (vt_val, stream, recurse + 1, options,
- current_language);
- if (options->pretty)
- {
- fprintf_filtered (stream, "\n");
- print_spaces_filtered (2 + 2 * recurse, stream);
- }
+ fprintf_filtered (stream, "\n");
+ print_spaces_filtered (2 + 2 * recurse, stream);
}
}
-
- /* Return number of characters printed, including the terminating
- '\0' if we reached the end. val_print_string takes care including
- the terminating '\0' if necessary. */
- return i;
}
+
+ /* Return number of characters printed, including the terminating
+ '\0' if we reached the end. val_print_string takes care including
+ the terminating '\0' if necessary. */
+ return i;
+
break;
case TYPE_CODE_REF:
elttype = check_typedef (TYPE_TARGET_TYPE (type));
if (options->addressprint)
{
+ CORE_ADDR addr
+ = extract_typed_address (valaddr + embedded_offset, type);
fprintf_filtered (stream, "@");
- /* Extract the address, assume that it is unsigned. */
- fputs_filtered (paddress (
- extract_unsigned_integer (valaddr + embedded_offset,
- gdbarch_ptr_bit (current_gdbarch) / HOST_CHAR_BIT)), stream);
+ fputs_filtered (paddress (gdbarch, addr), stream);
if (options->deref_ref)
fputs_filtered (": ", stream);
}
-fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
/* Extract the address, assume that it is unsigned. */
print_address_demangle
- (extract_unsigned_integer (valaddr + embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8,
- TYPE_LENGTH (TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET))),
+ (gdbarch,
+ extract_unsigned_integer (valaddr + embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8,
+ TYPE_LENGTH (TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET)), byte_order),
stream, demangle);
}
else
{
if (is_pascal_string_type (type, &length_pos, &length_size,
- &string_pos, &char_size, NULL))
+ &string_pos, &char_type, NULL))
{
- len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size);
- LA_PRINT_STRING (stream, valaddr + embedded_offset + string_pos, len, char_size, 0, options);
+ len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size, byte_order);
+ LA_PRINT_STRING (stream, char_type,
+ valaddr + embedded_offset + string_pos,
+ len, NULL, 0, options);
}
else
pascal_object_print_value_fields (type, valaddr + embedded_offset, address, stream,
type_print (type, "", stream, -1);
fprintf_filtered (stream, "} ");
/* Try to print what function it points to, and its address. */
- print_address_demangle (address, stream, demangle);
+ print_address_demangle (gdbarch, address, stream, demangle);
break;
case TYPE_CODE_BOOL:
else
fprintf_filtered (stream, "%d", (int) val);
fputs_filtered (" ", stream);
- LA_PRINT_CHAR ((unsigned char) val, stream);
+ LA_PRINT_CHAR ((unsigned char) val, type, stream);
}
break;
if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
{
- CORE_ADDR *first_dont_print;
+ CORE_ADDR *first_dont_print, addr;
int i;
first_dont_print
while (--i >= 0)
{
- if (VALUE_ADDRESS (val) == first_dont_print[i])
+ if (value_address (val) == first_dont_print[i])
{
fputs_filtered ("<same as static member of an already seen type>",
stream);
}
}
- obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val),
+ addr = value_address (val);
+ obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
sizeof (CORE_ADDR));
CHECK_TYPEDEF (type);
- pascal_object_print_value_fields (type, value_contents (val), VALUE_ADDRESS (val),
+ pascal_object_print_value_fields (type, value_contents (val), addr,
stream, recurse, options, NULL, 1);
return;
}