/* Print values for GDB, the GNU debugger.
- Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
- 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
+ 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "gdb_string.h"
#include "floatformat.h"
#include "doublest.h"
#include "exceptions.h"
+#include "dfp.h"
#include <errno.h>
}
\f
-/* Print data of type TYPE located at VALADDR (within GDB), which came from
- the inferior at address ADDRESS, onto stdio stream STREAM according to
- FORMAT (a letter, or 0 for natural format using TYPE).
+/* Print using the given LANGUAGE the data of type TYPE located at VALADDR
+ (within GDB), which came from the inferior at address ADDRESS, onto
+ stdio stream STREAM according to FORMAT (a letter, or 0 for natural
+ format using TYPE).
If DEREF_REF is nonzero, then dereference references, otherwise just print
them like pointers.
int
val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
CORE_ADDR address, struct ui_file *stream, int format,
- int deref_ref, int recurse, enum val_prettyprint pretty)
+ int deref_ref, int recurse, enum val_prettyprint pretty,
+ const struct language_defn *language)
{
volatile struct gdb_exception except;
+ volatile enum val_prettyprint real_pretty = pretty;
int ret = 0;
struct type *real_type = check_typedef (type);
if (pretty == Val_pretty_default)
- {
- pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint;
- }
+ real_pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint;
QUIT;
TRY_CATCH (except, RETURN_MASK_ERROR)
{
- ret = LA_VAL_PRINT (type, valaddr, embedded_offset, address,
- stream, format, deref_ref, recurse, pretty);
+ ret = language->la_val_print (type, valaddr, embedded_offset, address,
+ stream, format, deref_ref, recurse,
+ real_pretty);
}
if (except.reason < 0)
fprintf_filtered (stream, _("<error reading variable>"));
return 1;
}
-/* Print the value VAL onto stream STREAM according to FORMAT (a
- letter, or 0 for natural format using TYPE).
+/* Print using the given LANGUAGE the value VAL onto stream STREAM according
+ to FORMAT (a letter, or 0 for natural format using TYPE).
If DEREF_REF is nonzero, then dereference references, otherwise just print
them like pointers.
int
common_val_print (struct value *val, struct ui_file *stream, int format,
- int deref_ref, int recurse, enum val_prettyprint pretty)
+ int deref_ref, int recurse, enum val_prettyprint pretty,
+ const struct language_defn *language)
{
if (!value_check_printable (val, stream))
return 0;
return val_print (value_type (val), value_contents_all (val),
value_embedded_offset (val), VALUE_ADDRESS (val),
- stream, format, deref_ref, recurse, pretty);
+ stream, format, deref_ref, recurse, pretty,
+ language);
}
/* Print the value VAL in C-ish syntax on stream STREAM.
val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
struct ui_file *stream)
{
+ enum bfd_endian byte_order = gdbarch_byte_order (current_gdbarch);
+
if (TYPE_LENGTH (type) > sizeof (LONGEST))
{
LONGEST val;
complement (a reasonable assumption, I think) and do
better than this. */
print_hex_chars (stream, (unsigned char *) valaddr,
- TYPE_LENGTH (type));
+ TYPE_LENGTH (type), byte_order);
}
}
else
int inv;
const struct floatformat *fmt = NULL;
unsigned len = TYPE_LENGTH (type);
+ enum float_kind kind;
/* If it is a floating-point, check for obvious problems. */
if (TYPE_CODE (type) == TYPE_CODE_FLT)
fmt = floatformat_from_type (type);
- if (fmt != NULL && floatformat_is_nan (fmt, valaddr))
+ if (fmt != NULL)
{
- if (floatformat_is_negative (fmt, valaddr))
- fprintf_filtered (stream, "-");
- fprintf_filtered (stream, "nan(");
- fputs_filtered ("0x", stream);
- fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
- fprintf_filtered (stream, ")");
- return;
+ kind = floatformat_classify (fmt, valaddr);
+ if (kind == float_nan)
+ {
+ if (floatformat_is_negative (fmt, valaddr))
+ fprintf_filtered (stream, "-");
+ fprintf_filtered (stream, "nan(");
+ fputs_filtered ("0x", stream);
+ fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
+ fprintf_filtered (stream, ")");
+ return;
+ }
+ else if (kind == float_infinite)
+ {
+ if (floatformat_is_negative (fmt, valaddr))
+ fputs_filtered ("-", stream);
+ fputs_filtered ("inf", stream);
+ return;
+ }
}
/* NOTE: cagney/2002-01-15: The TYPE passed into print_floating()
#endif
}
+void
+print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+ struct ui_file *stream)
+{
+ char decstr[MAX_DECIMAL_STRING];
+ unsigned len = TYPE_LENGTH (type);
+
+ decimal_to_string (valaddr, len, decstr);
+ fputs_filtered (decstr, stream);
+ return;
+}
+
void
print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
- unsigned len)
+ unsigned len, enum bfd_endian byte_order)
{
#define BITS_IN_BYTES 8
/* FIXME: We should be not printing leading zeroes in most cases. */
- if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
+ if (byte_order == BFD_ENDIAN_BIG)
{
for (p = valaddr;
p < valaddr + len;
*/
void
print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
- unsigned len)
+ unsigned len, enum bfd_endian byte_order)
{
const gdb_byte *p;
unsigned char octa1, octa2, octa3, carry;
carry = 0;
fputs_filtered ("0", stream);
- if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
+ if (byte_order == BFD_ENDIAN_BIG)
{
for (p = valaddr;
p < valaddr + len;
*/
void
print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
- unsigned len)
+ unsigned len, enum bfd_endian byte_order)
{
#define TEN 10
-#define TWO_TO_FOURTH 16
#define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */
#define CARRY_LEFT( x ) ((x) % TEN)
#define SHIFT( x ) ((x) << 4)
-#define START_P \
- ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1)
-#define NOT_END_P \
- ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
-#define NEXT_P \
- ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? p++ : p-- )
#define LOW_NIBBLE( x ) ( (x) & 0x00F)
#define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
* LSD end.
*/
decimal_digits = 0; /* Number of decimal digits so far */
- p = START_P;
+ p = (byte_order == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1;
flip = 0;
- while (NOT_END_P)
+ while ((byte_order == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
{
/*
* Multiply current base-ten number by 16 in place.
/* Take low nibble and bump our pointer "p".
*/
digits[0] += LOW_NIBBLE (*p);
- NEXT_P;
+ if (byte_order == BFD_ENDIAN_BIG)
+ p++;
+ else
+ p--;
flip = 0;
}
void
print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
- unsigned len)
+ unsigned len, enum bfd_endian byte_order)
{
const gdb_byte *p;
/* FIXME: We should be not printing leading zeroes in most cases. */
fputs_filtered ("0x", stream);
- if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
+ if (byte_order == BFD_ENDIAN_BIG)
{
for (p = valaddr;
p < valaddr + len;
void
print_char_chars (struct ui_file *stream, const gdb_byte *valaddr,
- unsigned len)
+ unsigned len, enum bfd_endian byte_order)
{
const gdb_byte *p;
- if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
+ if (byte_order == BFD_ENDIAN_BIG)
{
p = valaddr;
while (p < valaddr + len - 1 && *p == 0)
return print_array_indexes;
}
-/* Assuming TYPE is a simple, non-empty array type, compute its lower bound.
- Save it into LOW_BOUND if not NULL.
+/* Assuming TYPE is a simple, non-empty array type, compute its upper
+ and lower bound. Save the low bound into LOW_BOUND if not NULL.
+ Save the high bound into HIGH_BOUND if not NULL.
Return 1 if the operation was successful. Return zero otherwise,
- in which case the value of LOW_BOUND is unmodified.
+ in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
- Computing the array lower bound is pretty easy, but this function
- does some additional verifications before returning the low bound.
+ Computing the array upper and lower bounds is pretty easy, but this
+ function does some additional verifications before returning them.
If something incorrect is detected, it is better to return a status
rather than throwing an error, making it easier for the caller to
implement an error-recovery plan. For instance, it may decide to
- warn the user that the bound was not found and then use a default
- value instead. */
+ warn the user that the bounds were not found and then use some
+ default values instead. */
int
-get_array_low_bound (struct type *type, long *low_bound)
+get_array_bounds (struct type *type, long *low_bound, long *high_bound)
{
struct type *index = TYPE_INDEX_TYPE (type);
long low = 0;
+ long high = 0;
if (index == NULL)
return 0;
- if (TYPE_CODE (index) != TYPE_CODE_RANGE
- && TYPE_CODE (index) != TYPE_CODE_ENUM)
+ if (TYPE_CODE (index) == TYPE_CODE_RANGE)
+ {
+ low = TYPE_LOW_BOUND (index);
+ high = TYPE_HIGH_BOUND (index);
+ }
+ else if (TYPE_CODE (index) == TYPE_CODE_ENUM)
+ {
+ const int n_enums = TYPE_NFIELDS (index);
+
+ low = TYPE_FIELD_BITPOS (index, 0);
+ high = TYPE_FIELD_BITPOS (index, n_enums - 1);
+ }
+ else
return 0;
- low = TYPE_LOW_BOUND (index);
- if (low > TYPE_HIGH_BOUND (index))
+ /* Abort if the lower bound is greater than the higher bound, except
+ when low = high + 1. This is a very common idiom used in Ada when
+ defining empty ranges (for instance "range 1 .. 0"). */
+ if (low > high + 1)
return 0;
if (low_bound)
*low_bound = low;
+ if (high_bound)
+ *high_bound = high;
+
return 1;
}
-
+
/* Print on STREAM using the given FORMAT the index for the element
at INDEX of an array whose index type is INDEX_TYPE. */
elttype = TYPE_TARGET_TYPE (type);
eltlen = TYPE_LENGTH (check_typedef (elttype));
- len = TYPE_LENGTH (type) / eltlen;
index_type = TYPE_INDEX_TYPE (type);
+ /* Compute the number of elements in the array. On most arrays,
+ the size of its elements is not zero, and so the number of elements
+ is simply the size of the array divided by the size of the elements.
+ But for arrays of elements whose size is zero, we need to look at
+ the bounds. */
+ if (eltlen != 0)
+ len = TYPE_LENGTH (type) / eltlen;
+ else
+ {
+ long low, hi;
+ if (get_array_bounds (type, &low, &hi))
+ len = hi - low + 1;
+ else
+ {
+ warning (_("unable to get bounds of array, assuming null array"));
+ len = 0;
+ }
+ }
+
/* Get the array low bound. This only makes sense if the array
has one or more element in it. */
- if (len > 0 && !get_array_low_bound (type, &low_bound_index))
+ if (len > 0 && !get_array_bounds (type, &low_bound_index, NULL))
{
- warning ("unable to get low bound of array, using zero as default");
+ warning (_("unable to get low bound of array, using zero as default"));
low_bound_index = 0;
}
if (reps > repeat_count_threshold)
{
val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format,
- deref_ref, recurse + 1, pretty);
+ deref_ref, recurse + 1, pretty, current_language);
annotate_elt_rep (reps);
fprintf_filtered (stream, " <repeats %u times>", reps);
annotate_elt_rep_end ();
else
{
val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format,
- deref_ref, recurse + 1, pretty);
+ deref_ref, recurse + 1, pretty, current_language);
annotate_elt ();
things_printed++;
}
if (errcode == EIO)
{
fprintf_filtered (stream, " <Address ");
- deprecated_print_address_numeric (addr, 1, stream);
+ fputs_filtered (paddress (addr), stream);
fprintf_filtered (stream, " out of bounds>");
}
else
{
fprintf_filtered (stream, " <Error reading address ");
- deprecated_print_address_numeric (addr, 1, stream);
+ fputs_filtered (paddress (addr), stream);
fprintf_filtered (stream, ": %s>", safe_strerror (errcode));
}
}