a negative signed value (e.g. "print/u (short)-1" should print 65535
(if shorts are 16 bits) instead of 4294967295). */
if (options->format != 'c'
- && (options->format != 'd' || TYPE_UNSIGNED (type)))
+ && (options->format != 'd' || type->is_unsigned ()))
{
if (len < TYPE_LENGTH (type) && byte_order == BFD_ENDIAN_BIG)
valaddr += TYPE_LENGTH (type) - len;
}
+ /* Allow LEN == 0, and in this case, don't assume that VALADDR is
+ valid. */
+ const gdb_byte zero = 0;
+ if (len == 0)
+ {
+ len = 1;
+ valaddr = &zero;
+ }
+
if (size != 0 && (options->format == 'x' || options->format == 't'))
{
/* Truncate to fit. */
long, and then printing the long. PR cli/16242 suggests changing
this to using C-style hex float format.
- Biased range types must also be unbiased here; the unbiasing is
- done by unpack_long. */
+ Biased range types and sub-word scalar types must also be handled
+ here; the value is correctly computed by unpack_long. */
gdb::byte_vector converted_bytes;
/* Some cases below will unpack the value again. In the biased
range case, we want to avoid this, so we store the unpacked value
|| options->format == 'z'
|| options->format == 'd'
|| options->format == 'u'))
- || (type->code () == TYPE_CODE_RANGE
- && TYPE_RANGE_DATA (type)->bias != 0))
+ || (type->code () == TYPE_CODE_RANGE && type->bounds ()->bias != 0)
+ || type->bit_size_differs_p ())
{
val_long.emplace (unpack_long (type, valaddr));
converted_bytes.resize (TYPE_LENGTH (type));
case 0:
if (type->code () != TYPE_CODE_FLT)
{
- print_decimal_chars (stream, valaddr, len, !TYPE_UNSIGNED (type),
+ print_decimal_chars (stream, valaddr, len, !type->is_unsigned (),
byte_order);
break;
}
val_long.emplace (unpack_long (type, valaddr));
opts.format = 0;
- if (TYPE_UNSIGNED (type))
+ if (type->is_unsigned ())
type = builtin_type (gdbarch)->builtin_true_unsigned_char;
else
type = builtin_type (gdbarch)->builtin_true_char;