#include "defs.h"
#include "gdb_string.h"
#include "symtab.h"
#include "gdbtypes.h"
#include "value.h"
#include "gdbcore.h"
#include "gdbcmd.h"
#include "target.h"
#include "language.h"
#include "annotate.h"
#include "valprint.h"
#include "floatformat.h"
#include "doublest.h"
#include <errno.h>
#include <ctype.h>
static int partial_memory_read (CORE_ADDR memaddr, char *myaddr,
int len, int *errnoptr);
static void show_print (char *, int);
static void set_print (char *, int);
static void set_radix (char *, int);
static void show_radix (char *, int);
static void set_input_radix (char *, int, struct cmd_list_element *);
static void set_input_radix_1 (int, unsigned);
static void set_output_radix (char *, int, struct cmd_list_element *);
static void set_output_radix_1 (int, unsigned);
void _initialize_valprint (void);
unsigned int print_max;
#define PRINT_MAX_DEFAULT 200
static void
show_print_max (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("\
Limit on string chars or array elements to print is %s.\n"),
value);
}
unsigned input_radix = 10;
static void
show_input_radix (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("\
Default input radix for entering numbers is %s.\n"),
value);
}
unsigned output_radix = 10;
static void
show_output_radix (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("\
Default output radix for printing of values is %s.\n"),
value);
}
int output_format = 0;
unsigned int repeat_count_threshold = 10;
static void
show_repeat_count_threshold (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"),
value);
}
int stop_print_at_null;
static void
show_stop_print_at_null (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("\
Printing of char arrays to stop at first null char is %s.\n"),
value);
}
int prettyprint_structs;
static void
show_prettyprint_structs (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Prettyprinting of structures is %s.\n"), value);
}
int prettyprint_arrays;
static void
show_prettyprint_arrays (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Prettyprinting of arrays is %s.\n"), value);
}
int unionprint;
static void
show_unionprint (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("\
Printing of unions interior to structures is %s.\n"),
value);
}
int addressprint;
static void
show_addressprint (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Printing of addresses is %s.\n"), value);
}
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)
{
struct type *real_type = check_typedef (type);
if (pretty == Val_pretty_default)
{
pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint;
}
QUIT;
if (TYPE_STUB (real_type))
{
fprintf_filtered (stream, "<incomplete type>");
gdb_flush (stream);
return (0);
}
return (LA_VAL_PRINT (type, valaddr, embedded_offset, address,
stream, format, deref_ref, recurse, pretty));
}
static int
value_check_printable (struct value *val, struct ui_file *stream)
{
if (val == 0)
{
fprintf_filtered (stream, _("<address of value unknown>"));
return 0;
}
switch (value_optimized_out (val))
{
case opt_okay:
break;
case opt_away:
fprintf_filtered (stream, _("<variable optimized away by compiler>"));
return 0;
case opt_evicted:
case opt_other:
fprintf_filtered (stream,
_("<value temporarily unavailable, due to optimizations>"));
return 0;
default:
fprintf_filtered (stream, _("<variable not found>"));
return 0;
}
return 1;
}
int
common_val_print (struct value *val, struct ui_file *stream, int format,
int deref_ref, int recurse, enum val_prettyprint pretty)
{
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);
}
int
value_print (struct value *val, struct ui_file *stream, int format,
enum val_prettyprint pretty)
{
if (!value_check_printable (val, stream))
return 0;
return LA_VALUE_PRINT (val, stream, format, pretty);
}
void
val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
struct ui_file *stream)
{
if (TYPE_LENGTH (type) > sizeof (LONGEST))
{
LONGEST val;
if (TYPE_UNSIGNED (type)
&& extract_long_unsigned_integer_with_byte_order
(valaddr, TYPE_LENGTH (type), &val, TYPE_BYTE_ORDER (type)))
{
print_longest (stream, 'u', 0, val);
}
else
{
print_hex_chars_with_byte_order (stream, (const bfd_byte *) valaddr,
TYPE_LENGTH (type), TYPE_BYTE_ORDER (type));
}
}
else
{
print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0,
unpack_long (type, valaddr));
}
}
void
print_longest (struct ui_file *stream, int format, int use_c_format,
LONGEST val_long)
{
const char *val;
switch (format)
{
case 'd':
val = int_string (val_long, 10, 1, 0, 1); break;
case 'u':
val = int_string (val_long, 10, 0, 0, 1); break;
case 'x':
val = int_string (val_long, 16, 0, 0, use_c_format); break;
case 'b':
val = int_string (val_long, 16, 0, 2, 1); break;
case 'h':
val = int_string (val_long, 16, 0, 4, 1); break;
case 'w':
val = int_string (val_long, 16, 0, 8, 1); break;
case 'g':
val = int_string (val_long, 16, 0, 16, 1); break;
break;
case 'o':
val = int_string (val_long, 8, 0, 0, use_c_format); break;
default:
internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
}
fputs_filtered (val, stream);
}
int
longest_to_int (LONGEST arg)
{
int rtnval = (int) arg;
if (sizeof (LONGEST) > sizeof (int))
{
if (rtnval != arg)
{
error (_("Value out of range."));
}
}
return (rtnval);
}
void
print_floating (const gdb_byte *valaddr, struct type *type,
struct ui_file *stream)
{
DOUBLEST doub;
int inv;
const struct floatformat *fmt = NULL;
unsigned len = TYPE_LENGTH (type);
if (TYPE_CODE (type) == TYPE_CODE_FLT)
fmt = floatformat_from_type (type);
if (fmt != NULL && floatformat_is_nan (fmt, valaddr))
{
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;
}
doub = unpack_double (type, valaddr, &inv);
if (inv)
{
fprintf_filtered (stream, "<invalid float value>");
return;
}
if (len < sizeof (double))
fprintf_filtered (stream, "%.9g", (double) doub);
else if (len == sizeof (double))
fprintf_filtered (stream, "%.17g", (double) doub);
else
#ifdef PRINTF_HAS_LONG_DOUBLE
fprintf_filtered (stream, "%.35Lg", doub);
#else
fprintf_filtered (stream, "%.17g", (double) doub);
#endif
}
void
print_floating_in_hex (const gdb_byte *valaddr, struct type *type,
struct ui_file *stream)
{
DOUBLEST doub;
int inv;
const struct floatformat *fmt = NULL;
unsigned len = TYPE_LENGTH (type);
if (TYPE_CODE (type) == TYPE_CODE_FLT)
fmt = floatformat_from_type (type);
if (fmt != NULL && floatformat_is_nan (fmt, valaddr))
{
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;
}
doub = unpack_double (type, valaddr, &inv);
if (inv)
{
fprintf_filtered (stream, "<invalid float value>");
return;
}
if (len < sizeof (double))
fprintf_filtered (stream, "%.6a", (double) doub);
else if (len == sizeof (double))
fprintf_filtered (stream, "%.13a", (double) doub);
else
#ifdef PRINTF_HAS_LONG_DOUBLE
fprintf_filtered (stream, "%.35La", doub);
#else
fprintf_filtered (stream, "%.17a", (double) doub);
#endif
}
void
print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
unsigned len)
{
#define BITS_IN_BYTES 8
const gdb_byte *p;
unsigned int i;
int b;
const int mask = 0x080;
if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = valaddr;
p < valaddr + len;
p++)
{
for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
{
if (*p & (mask >> i))
b = 1;
else
b = 0;
fprintf_filtered (stream, "%1d", b);
}
}
}
else
{
for (p = valaddr + len - 1;
p >= valaddr;
p--)
{
for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
{
if (*p & (mask >> i))
b = 1;
else
b = 0;
fprintf_filtered (stream, "%1d", b);
}
}
}
}
void
print_ostype (struct ui_file *stream, struct type *type, unsigned char *valaddr)
{
unsigned int buf_extracted = unpack_long (type, valaddr);
int i;
for (i = 3; i >= 0; i--)
{
unsigned char c = (buf_extracted >> (i * 8)) & 0xff;
if (c == '\'')
fprintf_filtered (stream, "\\'");
else if (isprint (c))
fprintf_filtered (stream, "%c", c);
else
fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
}
}
void
print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
unsigned len)
{
const gdb_byte *p;
unsigned char octa1, octa2, octa3, carry;
int cycle;
#define BITS_IN_OCTAL 3
#define HIGH_ZERO 0340
#define LOW_ZERO 0016
#define CARRY_ZERO 0003
#define HIGH_ONE 0200
#define MID_ONE 0160
#define LOW_ONE 0016
#define CARRY_ONE 0001
#define HIGH_TWO 0300
#define MID_TWO 0070
#define LOW_TWO 0007
cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL;
carry = 0;
fputs_filtered ("0", stream);
if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
{
for (p = valaddr;
p < valaddr + len;
p++)
{
switch (cycle)
{
case 0:
octa1 = (HIGH_ZERO & *p) >> 5;
octa2 = (LOW_ZERO & *p) >> 2;
carry = (CARRY_ZERO & *p);
fprintf_filtered (stream, "%o", octa1);
fprintf_filtered (stream, "%o", octa2);
break;
case 1:
octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
octa2 = (MID_ONE & *p) >> 4;
octa3 = (LOW_ONE & *p) >> 1;
carry = (CARRY_ONE & *p);
fprintf_filtered (stream, "%o", octa1);
fprintf_filtered (stream, "%o", octa2);
fprintf_filtered (stream, "%o", octa3);
break;
case 2:
octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
octa2 = (MID_TWO & *p) >> 3;
octa3 = (LOW_TWO & *p);
carry = 0;
fprintf_filtered (stream, "%o", octa1);
fprintf_filtered (stream, "%o", octa2);
fprintf_filtered (stream, "%o", octa3);
break;
default:
error (_("Internal error in octal conversion;"));
}
cycle++;
cycle = cycle % BITS_IN_OCTAL;
}
}
else
{
for (p = valaddr + len - 1;
p >= valaddr;
p--)
{
switch (cycle)
{
case 0:
octa1 = (HIGH_ZERO & *p) >> 5;
octa2 = (LOW_ZERO & *p) >> 2;
carry = (CARRY_ZERO & *p);
fprintf_filtered (stream, "%o", octa1);
fprintf_filtered (stream, "%o", octa2);
break;
case 1:
octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
octa2 = (MID_ONE & *p) >> 4;
octa3 = (LOW_ONE & *p) >> 1;
carry = (CARRY_ONE & *p);
fprintf_filtered (stream, "%o", octa1);
fprintf_filtered (stream, "%o", octa2);
fprintf_filtered (stream, "%o", octa3);
break;
case 2:
octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
octa2 = (MID_TWO & *p) >> 3;
octa3 = (LOW_TWO & *p);
carry = 0;
fprintf_filtered (stream, "%o", octa1);
fprintf_filtered (stream, "%o", octa2);
fprintf_filtered (stream, "%o", octa3);
break;
default:
error (_("Internal error in octal conversion;"));
}
cycle++;
cycle = cycle % BITS_IN_OCTAL;
}
}
}
void
print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
unsigned len)
{
#define TEN 10
#define TWO_TO_FOURTH 16
#define CARRY_OUT( x ) ((x) / TEN)
#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)
const gdb_byte *p;
unsigned char *digits;
int carry;
int decimal_len;
int i, j, decimal_digits;
int dummy;
int flip;
decimal_len = len * 2 * 2;
digits = (unsigned char *) xmalloc (decimal_len);
for (i = 0; i < decimal_len; i++)
{
digits[i] = 0;
}
decimal_digits = 0;
p = START_P;
flip = 0;
while (NOT_END_P)
{
for (j = 0; j < decimal_digits; j++)
{
digits[j] = SHIFT (digits[j]);
}
if (flip == 0)
{
digits[0] += HIGH_NIBBLE (*p);
flip = 1;
}
else
{
digits[0] += LOW_NIBBLE (*p);
NEXT_P;
flip = 0;
}
carry = 0;
for (j = 0; j < decimal_len - 1; j++)
{
digits[j] += carry;
dummy = digits[j];
carry = CARRY_OUT (dummy);
digits[j] = CARRY_LEFT (dummy);
if (j >= decimal_digits && carry == 0)
{
decimal_digits = j + 1;
break;
}
}
}
for (i = decimal_digits - 1; i >= 0; i--)
{
fprintf_filtered (stream, "%1d", digits[i]);
}
xfree (digits);
}
void
print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
unsigned int len)
{
print_hex_chars_with_byte_order (stream, valaddr, len, BFD_ENDIAN_UNKNOWN);
}
void
print_hex_chars_with_byte_order (struct ui_file *stream, const bfd_byte *valaddr,
unsigned int len, int byte_order)
{
const gdb_byte *p;
fputs_filtered ("0x", stream);
if (byte_order == BFD_ENDIAN_UNKNOWN)
byte_order = TARGET_BYTE_ORDER;
if (byte_order == BFD_ENDIAN_BIG)
{
for (p = valaddr;
p < valaddr + len;
p++)
{
fprintf_filtered (stream, "%02x", *p);
}
}
else
{
for (p = valaddr + len - 1;
p >= valaddr;
p--)
{
fprintf_filtered (stream, "%02x", *p);
}
}
}
void
print_char_chars (struct ui_file *stream, const gdb_byte *valaddr,
unsigned int len)
{
print_char_chars_with_byte_order (stream, valaddr, len, BFD_ENDIAN_UNKNOWN);
}
void
print_char_chars_with_byte_order (struct ui_file *stream, const gdb_byte *valaddr,
unsigned int len, int byte_order)
{
const gdb_byte *p;
if (byte_order == BFD_ENDIAN_UNKNOWN)
byte_order = TARGET_BYTE_ORDER;
if (byte_order == BFD_ENDIAN_BIG)
{
p = valaddr;
while (p < valaddr + len - 1 && *p == 0)
++p;
while (p < valaddr + len)
{
LA_EMIT_CHAR (*p, stream, '\'');
++p;
}
}
else
{
p = valaddr + len - 1;
while (p > valaddr && *p == 0)
--p;
while (p >= valaddr)
{
LA_EMIT_CHAR (*p, stream, '\'');
--p;
}
}
}
static const gdb_byte *
val_elt_addr (struct type *type, const gdb_byte *valaddr,
unsigned int i)
{
struct type *elttype;
unsigned eltlen;
LONGEST lowerbound, upperbound, stride;
get_array_bounds (type, &lowerbound, &upperbound, &stride);
if (stride == 1)
;
else if (stride == -1)
i = (upperbound - i);
else
internal_error (__FILE__, __LINE__, _("unsupported stride %ld"), stride);
elttype = TYPE_TARGET_TYPE (type);
eltlen = TYPE_LENGTH (check_typedef (elttype));
return (valaddr + i * eltlen);
}
void
val_print_array_elements (struct type *type, const gdb_byte *valaddr,
CORE_ADDR address, struct ui_file *stream,
int format, int deref_ref,
int recurse, enum val_prettyprint pretty,
unsigned int i)
{
unsigned int things_printed = 0;
unsigned len;
struct type *elttype;
unsigned eltlen;
unsigned int rep1;
unsigned int reps;
elttype = TYPE_TARGET_TYPE (type);
eltlen = TYPE_LENGTH (check_typedef (elttype));
len = TYPE_LENGTH (type) / eltlen;
annotate_array_section_begin (i, elttype);
for (; i < len && things_printed < print_max; i++)
{
if (i != 0)
{
if (prettyprint_arrays)
{
fprintf_filtered (stream, ",\n");
print_spaces_filtered (2 + 2 * recurse, stream);
}
else
{
fprintf_filtered (stream, ", ");
}
}
wrap_here (n_spaces (2 + 2 * recurse));
rep1 = i + 1;
reps = 1;
while ((rep1 < len) &&
!memcmp (val_elt_addr (type, valaddr, i), val_elt_addr (type, valaddr, rep1), eltlen))
{
++reps;
++rep1;
}
if (reps > repeat_count_threshold)
{
val_print (elttype, val_elt_addr (type, valaddr, i), 0, 0, stream, format,
deref_ref, recurse + 1, pretty);
annotate_elt_rep (reps);
fprintf_filtered (stream, " <repeats %u times>", reps);
annotate_elt_rep_end ();
i = rep1 - 1;
things_printed += repeat_count_threshold;
}
else
{
val_print (elttype, val_elt_addr (type, valaddr, i), 0, 0, stream, format,
deref_ref, recurse + 1, pretty);
annotate_elt ();
things_printed++;
}
}
annotate_array_section_end ();
if (i < len)
{
fprintf_filtered (stream, "...");
}
}
static int
partial_memory_read (CORE_ADDR memaddr, char *myaddr, int len, int *errnoptr)
{
int nread;
int errcode;
errcode = target_read_memory (memaddr, myaddr, len);
if (errcode == 0)
{
nread = len;
}
else
{
for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
{
errcode = target_read_memory (memaddr++, myaddr++, 1);
}
if (errcode != 0)
{
nread--;
}
}
if (errnoptr != NULL)
{
*errnoptr = errcode;
}
return (nread);
}
int
val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream)
{
int force_ellipsis = 0;
int errcode;
unsigned int fetchlimit;
unsigned int nfetch;
unsigned int chunksize;
char *buffer = NULL;
char *bufptr;
char *limit;
struct cleanup *old_chain = NULL;
int found_nul;
fetchlimit = (len == -1 ? print_max : min (len, print_max));
chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit);
found_nul = 0;
old_chain = make_cleanup (null_cleanup, 0);
if (len > 0)
{
buffer = (char *) xmalloc (len * width);
bufptr = buffer;
old_chain = make_cleanup (xfree, buffer);
nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
/ width;
addr += nfetch * width;
bufptr += nfetch * width;
}
else if (len == -1)
{
unsigned long bufsize = 0;
do
{
QUIT;
nfetch = min (chunksize, fetchlimit - bufsize);
if (buffer == NULL)
buffer = (char *) xmalloc (nfetch * width);
else
{
discard_cleanups (old_chain);
buffer = (char *) xrealloc (buffer, (nfetch + bufsize) * width);
}
old_chain = make_cleanup (xfree, buffer);
bufptr = buffer + bufsize * width;
bufsize += nfetch;
nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode)
/ width;
limit = bufptr + nfetch * width;
while (bufptr < limit)
{
unsigned long c;
c = extract_unsigned_integer (bufptr, width);
addr += width;
bufptr += width;
if (c == 0)
{
errcode = 0;
found_nul = 1;
break;
}
}
}
while (errcode == 0
&& bufptr - buffer < fetchlimit * width
&& !found_nul);
}
else
{
buffer = bufptr = NULL;
errcode = 0;
}
if (len == -1 && !found_nul)
{
char *peekbuf;
peekbuf = (char *) alloca (width);
if (target_read_memory (addr, peekbuf, width) == 0
&& extract_unsigned_integer (peekbuf, width) != 0)
force_ellipsis = 1;
}
else if ((len >= 0 && errcode != 0) || (len > (bufptr - buffer) / width))
{
force_ellipsis = 1;
}
QUIT;
if (errcode == 0 || bufptr > buffer)
{
if (addressprint)
{
fputs_filtered (" ", stream);
}
LA_PRINT_STRING (stream, buffer, (bufptr - buffer) / width, width, force_ellipsis);
}
if (errcode != 0)
{
if (errcode == EIO)
{
fprintf_filtered (stream, " <Address ");
deprecated_print_address_numeric (addr, 1, stream);
fprintf_filtered (stream, " out of bounds>");
}
else
{
fprintf_filtered (stream, " <Error reading address ");
deprecated_print_address_numeric (addr, 1, stream);
fprintf_filtered (stream, ": %s>", safe_strerror (errcode));
}
}
gdb_flush (stream);
do_cleanups (old_chain);
return ((bufptr - buffer) / width);
}
static void
set_input_radix (char *args, int from_tty, struct cmd_list_element *c)
{
set_input_radix_1 (from_tty, input_radix);
}
static void
set_input_radix_1 (int from_tty, unsigned radix)
{
if (radix < 2)
{
error (_("Nonsense input radix ``decimal %u''; input radix unchanged."),
radix);
}
input_radix = radix;
set_internalvar (lookup_internalvar ("input_radix"),
value_from_longest (builtin_type_int, (LONGEST) radix));
if (from_tty)
{
printf_filtered (_("Input radix now set to decimal %u, hex %x, octal %o.\n"),
radix, radix, radix);
}
}
static void
set_output_radix (char *args, int from_tty, struct cmd_list_element *c)
{
set_output_radix_1 (from_tty, output_radix);
}
static void
set_output_radix_1 (int from_tty, unsigned radix)
{
switch (radix)
{
case 16:
output_format = 'x';
break;
case 10:
output_format = 0;
break;
case 8:
output_format = 'o';
break;
default:
error (_("Unsupported output radix ``decimal %u''; output radix unchanged."),
radix);
}
output_radix = radix;
set_internalvar (lookup_internalvar ("output_radix"),
value_from_longest (builtin_type_int, (LONGEST) radix));
if (from_tty)
{
printf_filtered (_("Output radix now set to decimal %u, hex %x, octal %o.\n"),
radix, radix, radix);
}
}
static void
set_radix (char *arg, int from_tty)
{
unsigned radix;
radix = (arg == NULL) ? 10 : parse_and_eval_long (arg);
set_output_radix_1 (0, radix);
set_input_radix_1 (0, radix);
if (from_tty)
{
printf_filtered (_("Input and output radices now set to decimal %u, hex %x, octal %o.\n"),
radix, radix, radix);
}
}
static void
show_radix (char *arg, int from_tty)
{
if (from_tty)
{
if (input_radix == output_radix)
{
printf_filtered (_("Input and output radices set to decimal %u, hex %x, octal %o.\n"),
input_radix, input_radix, input_radix);
}
else
{
printf_filtered (_("Input radix set to decimal %u, hex %x, octal %o.\n"),
input_radix, input_radix, input_radix);
printf_filtered (_("Output radix set to decimal %u, hex %x, octal %o.\n"),
output_radix, output_radix, output_radix);
}
}
}
static void
set_print (char *arg, int from_tty)
{
printf_unfiltered (
"\"set print\" must be followed by the name of a print subcommand.\n");
help_list (setprintlist, "set print ", -1, gdb_stdout);
}
static void
show_print (char *args, int from_tty)
{
cmd_show_list (showprintlist, from_tty, "");
}
void
_initialize_valprint (void)
{
add_prefix_cmd ("print", no_class, set_print,
_("Generic command for setting how things print."),
&setprintlist, "set print ", 0, &setlist);
add_alias_cmd ("p", "print", no_class, 1, &setlist);
add_alias_cmd ("pr", "print", no_class, 1, &setlist);
add_prefix_cmd ("print", no_class, show_print,
_("Generic command for showing print settings."),
&showprintlist, "show print ", 0, &showlist);
add_alias_cmd ("p", "print", no_class, 1, &showlist);
add_alias_cmd ("pr", "print", no_class, 1, &showlist);
add_setshow_uinteger_cmd ("elements", no_class, &print_max, _("\
Set limit on string chars or array elements to print."), _("\
Show limit on string chars or array elements to print."), _("\
\"set print elements 0\" causes there to be no limit."),
NULL,
show_print_max,
&setprintlist, &showprintlist);
add_setshow_boolean_cmd ("null-stop", no_class, &stop_print_at_null, _("\
Set printing of char arrays to stop at first null char."), _("\
Show printing of char arrays to stop at first null char."), NULL,
NULL,
show_stop_print_at_null,
&setprintlist, &showprintlist);
add_setshow_uinteger_cmd ("repeats", no_class,
&repeat_count_threshold, _("\
Set threshold for repeated print elements."), _("\
Show threshold for repeated print elements."), _("\
\"set print repeats 0\" causes all elements to be individually printed."),
NULL,
show_repeat_count_threshold,
&setprintlist, &showprintlist);
add_setshow_boolean_cmd ("pretty", class_support, &prettyprint_structs, _("\
Set prettyprinting of structures."), _("\
Show prettyprinting of structures."), NULL,
NULL,
show_prettyprint_structs,
&setprintlist, &showprintlist);
add_setshow_boolean_cmd ("union", class_support, &unionprint, _("\
Set printing of unions interior to structures."), _("\
Show printing of unions interior to structures."), NULL,
NULL,
show_unionprint,
&setprintlist, &showprintlist);
add_setshow_boolean_cmd ("array", class_support, &prettyprint_arrays, _("\
Set prettyprinting of arrays."), _("\
Show prettyprinting of arrays."), NULL,
NULL,
show_prettyprint_arrays,
&setprintlist, &showprintlist);
add_setshow_boolean_cmd ("address", class_support, &addressprint, _("\
Set printing of addresses."), _("\
Show printing of addresses."), NULL,
NULL,
show_addressprint,
&setprintlist, &showprintlist);
add_setshow_uinteger_cmd ("input-radix", class_support, &input_radix, _("\
Set default input radix for entering numbers."), _("\
Show default input radix for entering numbers."), NULL,
set_input_radix,
show_input_radix,
&setlist, &showlist);
add_setshow_uinteger_cmd ("output-radix", class_support, &output_radix, _("\
Set default output radix for printing of values."), _("\
Show default output radix for printing of values."), NULL,
set_output_radix,
show_output_radix,
&setlist, &showlist);
add_cmd ("radix", class_support, set_radix, _("\
Set default input and output number radices.\n\
Use 'set input-radix' or 'set output-radix' to independently set each.\n\
Without an argument, sets both radices back to the default value of 10."),
&setlist);
add_cmd ("radix", class_support, show_radix, _("\
Show the default input and output number radices.\n\
Use 'show input-radix' or 'show output-radix' to independently show each."),
&showlist);
prettyprint_structs = 1;
prettyprint_arrays = 0;
unionprint = 1;
addressprint = 1;
print_max = PRINT_MAX_DEFAULT;
}