(pe_ILF_build_a_bfd): Do not assume that an @ will be present when
[deliverable/binutils-gdb.git] / gdb / valprint.c
CommitLineData
c906108c 1/* Print values for GDB, the GNU debugger.
5c1c87f0
AC
2
3 Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
acf0f27f
AC
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2005 Free Software
5 Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
c906108c
SS
23
24#include "defs.h"
25#include "gdb_string.h"
26#include "symtab.h"
27#include "gdbtypes.h"
28#include "value.h"
29#include "gdbcore.h"
30#include "gdbcmd.h"
31#include "target.h"
c906108c 32#include "language.h"
c906108c
SS
33#include "annotate.h"
34#include "valprint.h"
39424bef 35#include "floatformat.h"
d16aafd8 36#include "doublest.h"
c906108c
SS
37
38#include <errno.h>
39
40/* Prototypes for local functions */
41
917317f4
JM
42static int partial_memory_read (CORE_ADDR memaddr, char *myaddr,
43 int len, int *errnoptr);
44
a14ed312 45static void show_print (char *, int);
c906108c 46
a14ed312 47static void set_print (char *, int);
c906108c 48
a14ed312 49static void set_radix (char *, int);
c906108c 50
a14ed312 51static void show_radix (char *, int);
c906108c 52
a14ed312 53static void set_input_radix (char *, int, struct cmd_list_element *);
c906108c 54
a14ed312 55static void set_input_radix_1 (int, unsigned);
c906108c 56
a14ed312 57static void set_output_radix (char *, int, struct cmd_list_element *);
c906108c 58
a14ed312 59static void set_output_radix_1 (int, unsigned);
c906108c 60
a14ed312 61void _initialize_valprint (void);
c906108c
SS
62
63/* Maximum number of chars to print for a string pointer value or vector
64 contents, or UINT_MAX for no limit. Note that "set print elements 0"
65 stores UINT_MAX in print_max, which displays in a show command as
66 "unlimited". */
67
68unsigned int print_max;
69#define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */
920d2a44
AC
70static void
71show_print_max (struct ui_file *file, int from_tty,
72 struct cmd_list_element *c, const char *value)
73{
74 fprintf_filtered (file, _("\
75Limit on string chars or array elements to print is %s.\n"),
76 value);
77}
78
c906108c
SS
79
80/* Default input and output radixes, and output format letter. */
81
82unsigned input_radix = 10;
920d2a44
AC
83static void
84show_input_radix (struct ui_file *file, int from_tty,
85 struct cmd_list_element *c, const char *value)
86{
87 fprintf_filtered (file, _("\
88Default input radix for entering numbers is %s.\n"),
89 value);
90}
91
c906108c 92unsigned output_radix = 10;
920d2a44
AC
93static void
94show_output_radix (struct ui_file *file, int from_tty,
95 struct cmd_list_element *c, const char *value)
96{
97 fprintf_filtered (file, _("\
98Default output radix for printing of values is %s.\n"),
99 value);
100}
c906108c
SS
101int output_format = 0;
102
103/* Print repeat counts if there are more than this many repetitions of an
104 element in an array. Referenced by the low level language dependent
105 print routines. */
106
107unsigned int repeat_count_threshold = 10;
920d2a44
AC
108static void
109show_repeat_count_threshold (struct ui_file *file, int from_tty,
110 struct cmd_list_element *c, const char *value)
111{
112 fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"),
113 value);
114}
c906108c
SS
115
116/* If nonzero, stops printing of char arrays at first null. */
117
118int stop_print_at_null;
920d2a44
AC
119static void
120show_stop_print_at_null (struct ui_file *file, int from_tty,
121 struct cmd_list_element *c, const char *value)
122{
123 fprintf_filtered (file, _("\
124Printing of char arrays to stop at first null char is %s.\n"),
125 value);
126}
c906108c
SS
127
128/* Controls pretty printing of structures. */
129
130int prettyprint_structs;
920d2a44
AC
131static void
132show_prettyprint_structs (struct ui_file *file, int from_tty,
133 struct cmd_list_element *c, const char *value)
134{
135 fprintf_filtered (file, _("Prettyprinting of structures is %s.\n"), value);
136}
c906108c
SS
137
138/* Controls pretty printing of arrays. */
139
140int prettyprint_arrays;
920d2a44
AC
141static void
142show_prettyprint_arrays (struct ui_file *file, int from_tty,
143 struct cmd_list_element *c, const char *value)
144{
145 fprintf_filtered (file, _("Prettyprinting of arrays is %s.\n"), value);
146}
c906108c
SS
147
148/* If nonzero, causes unions inside structures or other unions to be
149 printed. */
150
151int unionprint; /* Controls printing of nested unions. */
920d2a44
AC
152static void
153show_unionprint (struct ui_file *file, int from_tty,
154 struct cmd_list_element *c, const char *value)
155{
156 fprintf_filtered (file, _("\
157Printing of unions interior to structures is %s.\n"),
158 value);
159}
c906108c
SS
160
161/* If nonzero, causes machine addresses to be printed in certain contexts. */
162
163int addressprint; /* Controls printing of machine addresses */
920d2a44
AC
164static void
165show_addressprint (struct ui_file *file, int from_tty,
166 struct cmd_list_element *c, const char *value)
167{
168 fprintf_filtered (file, _("Printing of addresses is %s.\n"), value);
169}
c906108c 170\f
c5aa993b 171
c906108c
SS
172/* Print data of type TYPE located at VALADDR (within GDB), which came from
173 the inferior at address ADDRESS, onto stdio stream STREAM according to
174 FORMAT (a letter, or 0 for natural format using TYPE).
175
176 If DEREF_REF is nonzero, then dereference references, otherwise just print
177 them like pointers.
178
179 The PRETTY parameter controls prettyprinting.
180
181 If the data are a string pointer, returns the number of string characters
182 printed.
183
184 FIXME: The data at VALADDR is in target byte order. If gdb is ever
185 enhanced to be able to debug more than the single target it was compiled
186 for (specific CPU type and thus specific target byte ordering), then
187 either the print routines are going to have to take this into account,
188 or the data is going to have to be passed into here already converted
189 to the host byte ordering, whichever is more convenient. */
190
191
192int
a2bd3dcd
AC
193val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
194 CORE_ADDR address, struct ui_file *stream, int format,
195 int deref_ref, int recurse, enum val_prettyprint pretty)
c906108c
SS
196{
197 struct type *real_type = check_typedef (type);
198 if (pretty == Val_pretty_default)
199 {
200 pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint;
201 }
c5aa993b 202
c906108c
SS
203 QUIT;
204
205 /* Ensure that the type is complete and not just a stub. If the type is
206 only a stub and we can't find and substitute its complete type, then
207 print appropriate string and return. */
208
74a9bb82 209 if (TYPE_STUB (real_type))
c906108c
SS
210 {
211 fprintf_filtered (stream, "<incomplete type>");
212 gdb_flush (stream);
213 return (0);
214 }
c5aa993b 215
c906108c 216 return (LA_VAL_PRINT (type, valaddr, embedded_offset, address,
c5aa993b 217 stream, format, deref_ref, recurse, pretty));
c906108c
SS
218}
219
220/* Print the value VAL in C-ish syntax on stream STREAM.
221 FORMAT is a format-letter, or 0 for print in natural format of data type.
222 If the object printed is a string pointer, returns
223 the number of string bytes printed. */
224
225int
3d6d86c6 226value_print (struct value *val, struct ui_file *stream, int format,
fba45db2 227 enum val_prettyprint pretty)
c906108c
SS
228{
229 if (val == 0)
230 {
a3f17187 231 printf_filtered (_("<address of value unknown>"));
c906108c
SS
232 return 0;
233 }
feb13ab0 234 if (value_optimized_out (val))
c906108c 235 {
a3f17187 236 printf_filtered (_("<value optimized out>"));
c906108c
SS
237 return 0;
238 }
239 return LA_VALUE_PRINT (val, stream, format, pretty);
240}
241
242/* Called by various <lang>_val_print routines to print
243 TYPE_CODE_INT's. TYPE is the type. VALADDR is the address of the
244 value. STREAM is where to print the value. */
245
246void
5f547748 247val_print_type_code_int (struct type *type, const bfd_byte *valaddr,
fba45db2 248 struct ui_file *stream)
c906108c
SS
249{
250 if (TYPE_LENGTH (type) > sizeof (LONGEST))
251 {
252 LONGEST val;
253
254 if (TYPE_UNSIGNED (type)
255 && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type),
256 &val))
257 {
258 print_longest (stream, 'u', 0, val);
259 }
260 else
261 {
262 /* Signed, or we couldn't turn an unsigned value into a
263 LONGEST. For signed values, one could assume two's
264 complement (a reasonable assumption, I think) and do
265 better than this. */
266 print_hex_chars (stream, (unsigned char *) valaddr,
267 TYPE_LENGTH (type));
268 }
269 }
270 else
271 {
c906108c
SS
272 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0,
273 unpack_long (type, valaddr));
c906108c
SS
274 }
275}
276
277/* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
278 The raison d'etre of this function is to consolidate printing of
bb599908
PH
279 LONG_LONG's into this one function. The format chars b,h,w,g are
280 from print_scalar_formatted(). Numbers are printed using C
281 format.
282
283 USE_C_FORMAT means to use C format in all cases. Without it,
284 'o' and 'x' format do not include the standard C radix prefix
285 (leading 0 or 0x).
286
287 Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL
288 and was intended to request formating according to the current
289 language and would be used for most integers that GDB prints. The
290 exceptional cases were things like protocols where the format of
291 the integer is a protocol thing, not a user-visible thing). The
292 parameter remains to preserve the information of what things might
293 be printed with language-specific format, should we ever resurrect
294 that capability. */
c906108c
SS
295
296void
bb599908 297print_longest (struct ui_file *stream, int format, int use_c_format,
fba45db2 298 LONGEST val_long)
c906108c 299{
2bfb72ee
AC
300 const char *val;
301
c906108c
SS
302 switch (format)
303 {
304 case 'd':
bb599908 305 val = int_string (val_long, 10, 1, 0, 1); break;
c906108c 306 case 'u':
bb599908 307 val = int_string (val_long, 10, 0, 0, 1); break;
c906108c 308 case 'x':
bb599908 309 val = int_string (val_long, 16, 0, 0, use_c_format); break;
c906108c 310 case 'b':
bb599908 311 val = int_string (val_long, 16, 0, 2, 1); break;
c906108c 312 case 'h':
bb599908 313 val = int_string (val_long, 16, 0, 4, 1); break;
c906108c 314 case 'w':
bb599908 315 val = int_string (val_long, 16, 0, 8, 1); break;
c906108c 316 case 'g':
bb599908 317 val = int_string (val_long, 16, 0, 16, 1); break;
c906108c
SS
318 break;
319 case 'o':
bb599908 320 val = int_string (val_long, 8, 0, 0, use_c_format); break;
c906108c 321 default:
e2e0b3e5 322 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
bb599908 323 }
2bfb72ee 324 fputs_filtered (val, stream);
c906108c
SS
325}
326
c906108c
SS
327/* This used to be a macro, but I don't think it is called often enough
328 to merit such treatment. */
329/* Convert a LONGEST to an int. This is used in contexts (e.g. number of
330 arguments to a function, number in a value history, register number, etc.)
331 where the value must not be larger than can fit in an int. */
332
333int
fba45db2 334longest_to_int (LONGEST arg)
c906108c
SS
335{
336 /* Let the compiler do the work */
337 int rtnval = (int) arg;
338
339 /* Check for overflows or underflows */
340 if (sizeof (LONGEST) > sizeof (int))
341 {
342 if (rtnval != arg)
343 {
8a3fe4f8 344 error (_("Value out of range."));
c906108c
SS
345 }
346 }
347 return (rtnval);
348}
349
a73c86fb
AC
350/* Print a floating point value of type TYPE (not always a
351 TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM. */
c906108c
SS
352
353void
c84141d6
AC
354print_floating (const bfd_byte *valaddr, struct type *type,
355 struct ui_file *stream)
c906108c
SS
356{
357 DOUBLEST doub;
358 int inv;
a73c86fb 359 const struct floatformat *fmt = NULL;
c906108c 360 unsigned len = TYPE_LENGTH (type);
c5aa993b 361
a73c86fb
AC
362 /* If it is a floating-point, check for obvious problems. */
363 if (TYPE_CODE (type) == TYPE_CODE_FLT)
364 fmt = floatformat_from_type (type);
365 if (fmt != NULL && floatformat_is_nan (fmt, valaddr))
39424bef
MK
366 {
367 if (floatformat_is_negative (fmt, valaddr))
368 fprintf_filtered (stream, "-");
369 fprintf_filtered (stream, "nan(");
bb599908 370 fputs_filtered ("0x", stream);
306d9ac5 371 fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
39424bef
MK
372 fprintf_filtered (stream, ")");
373 return;
7355ddba 374 }
c906108c 375
a73c86fb
AC
376 /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating()
377 isn't necessarily a TYPE_CODE_FLT. Consequently, unpack_double
378 needs to be used as that takes care of any necessary type
379 conversions. Such conversions are of course direct to DOUBLEST
380 and disregard any possible target floating point limitations.
381 For instance, a u64 would be converted and displayed exactly on a
382 host with 80 bit DOUBLEST but with loss of information on a host
383 with 64 bit DOUBLEST. */
c2f05ac9 384
c906108c
SS
385 doub = unpack_double (type, valaddr, &inv);
386 if (inv)
387 {
388 fprintf_filtered (stream, "<invalid float value>");
389 return;
390 }
391
39424bef
MK
392 /* FIXME: kettenis/2001-01-20: The following code makes too much
393 assumptions about the host and target floating point format. */
394
a73c86fb
AC
395 /* NOTE: cagney/2002-02-03: Since the TYPE of what was passed in may
396 not necessarially be a TYPE_CODE_FLT, the below ignores that and
397 instead uses the type's length to determine the precision of the
398 floating-point value being printed. */
c2f05ac9 399
c906108c 400 if (len < sizeof (double))
c5aa993b 401 fprintf_filtered (stream, "%.9g", (double) doub);
c906108c 402 else if (len == sizeof (double))
c5aa993b 403 fprintf_filtered (stream, "%.17g", (double) doub);
c906108c
SS
404 else
405#ifdef PRINTF_HAS_LONG_DOUBLE
406 fprintf_filtered (stream, "%.35Lg", doub);
407#else
39424bef
MK
408 /* This at least wins with values that are representable as
409 doubles. */
c906108c
SS
410 fprintf_filtered (stream, "%.17g", (double) doub);
411#endif
412}
413
c5aa993b 414void
6c403953 415print_binary_chars (struct ui_file *stream, const bfd_byte *valaddr,
fba45db2 416 unsigned len)
c906108c
SS
417{
418
419#define BITS_IN_BYTES 8
420
6c403953 421 const bfd_byte *p;
745b8ca0 422 unsigned int i;
c5aa993b 423 int b;
c906108c
SS
424
425 /* Declared "int" so it will be signed.
426 * This ensures that right shift will shift in zeros.
427 */
c5aa993b 428 const int mask = 0x080;
c906108c
SS
429
430 /* FIXME: We should be not printing leading zeroes in most cases. */
431
d7449b42 432 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c906108c
SS
433 {
434 for (p = valaddr;
435 p < valaddr + len;
436 p++)
437 {
c5aa993b
JM
438 /* Every byte has 8 binary characters; peel off
439 * and print from the MSB end.
440 */
441 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
442 {
443 if (*p & (mask >> i))
444 b = 1;
445 else
446 b = 0;
447
448 fprintf_filtered (stream, "%1d", b);
449 }
c906108c
SS
450 }
451 }
452 else
453 {
454 for (p = valaddr + len - 1;
455 p >= valaddr;
456 p--)
457 {
c5aa993b
JM
458 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
459 {
460 if (*p & (mask >> i))
461 b = 1;
462 else
463 b = 0;
464
465 fprintf_filtered (stream, "%1d", b);
466 }
c906108c
SS
467 }
468 }
c906108c
SS
469}
470
471/* VALADDR points to an integer of LEN bytes.
472 * Print it in octal on stream or format it in buf.
473 */
474void
6c403953
AC
475print_octal_chars (struct ui_file *stream, const bfd_byte *valaddr,
476 unsigned len)
c906108c 477{
6c403953 478 const bfd_byte *p;
c906108c 479 unsigned char octa1, octa2, octa3, carry;
c5aa993b
JM
480 int cycle;
481
c906108c
SS
482 /* FIXME: We should be not printing leading zeroes in most cases. */
483
484
485 /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track
486 * the extra bits, which cycle every three bytes:
487 *
488 * Byte side: 0 1 2 3
489 * | | | |
490 * bit number 123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 |
491 *
492 * Octal side: 0 1 carry 3 4 carry ...
493 *
494 * Cycle number: 0 1 2
495 *
496 * But of course we are printing from the high side, so we have to
497 * figure out where in the cycle we are so that we end up with no
498 * left over bits at the end.
499 */
500#define BITS_IN_OCTAL 3
501#define HIGH_ZERO 0340
502#define LOW_ZERO 0016
503#define CARRY_ZERO 0003
504#define HIGH_ONE 0200
505#define MID_ONE 0160
506#define LOW_ONE 0016
507#define CARRY_ONE 0001
508#define HIGH_TWO 0300
509#define MID_TWO 0070
510#define LOW_TWO 0007
511
512 /* For 32 we start in cycle 2, with two bits and one bit carry;
513 * for 64 in cycle in cycle 1, with one bit and a two bit carry.
514 */
515 cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL;
516 carry = 0;
c5aa993b 517
bb599908 518 fputs_filtered ("0", stream);
d7449b42 519 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c906108c
SS
520 {
521 for (p = valaddr;
522 p < valaddr + len;
523 p++)
524 {
c5aa993b
JM
525 switch (cycle)
526 {
527 case 0:
528 /* No carry in, carry out two bits.
529 */
530 octa1 = (HIGH_ZERO & *p) >> 5;
531 octa2 = (LOW_ZERO & *p) >> 2;
532 carry = (CARRY_ZERO & *p);
533 fprintf_filtered (stream, "%o", octa1);
534 fprintf_filtered (stream, "%o", octa2);
535 break;
536
537 case 1:
538 /* Carry in two bits, carry out one bit.
539 */
540 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
541 octa2 = (MID_ONE & *p) >> 4;
542 octa3 = (LOW_ONE & *p) >> 1;
543 carry = (CARRY_ONE & *p);
544 fprintf_filtered (stream, "%o", octa1);
545 fprintf_filtered (stream, "%o", octa2);
546 fprintf_filtered (stream, "%o", octa3);
547 break;
548
549 case 2:
550 /* Carry in one bit, no carry out.
551 */
552 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
553 octa2 = (MID_TWO & *p) >> 3;
554 octa3 = (LOW_TWO & *p);
555 carry = 0;
556 fprintf_filtered (stream, "%o", octa1);
557 fprintf_filtered (stream, "%o", octa2);
558 fprintf_filtered (stream, "%o", octa3);
559 break;
560
561 default:
8a3fe4f8 562 error (_("Internal error in octal conversion;"));
c5aa993b
JM
563 }
564
565 cycle++;
566 cycle = cycle % BITS_IN_OCTAL;
c906108c
SS
567 }
568 }
569 else
570 {
571 for (p = valaddr + len - 1;
572 p >= valaddr;
573 p--)
574 {
c5aa993b
JM
575 switch (cycle)
576 {
577 case 0:
578 /* Carry out, no carry in */
579 octa1 = (HIGH_ZERO & *p) >> 5;
580 octa2 = (LOW_ZERO & *p) >> 2;
581 carry = (CARRY_ZERO & *p);
582 fprintf_filtered (stream, "%o", octa1);
583 fprintf_filtered (stream, "%o", octa2);
584 break;
585
586 case 1:
587 /* Carry in, carry out */
588 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
589 octa2 = (MID_ONE & *p) >> 4;
590 octa3 = (LOW_ONE & *p) >> 1;
591 carry = (CARRY_ONE & *p);
592 fprintf_filtered (stream, "%o", octa1);
593 fprintf_filtered (stream, "%o", octa2);
594 fprintf_filtered (stream, "%o", octa3);
595 break;
596
597 case 2:
598 /* Carry in, no carry out */
599 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
600 octa2 = (MID_TWO & *p) >> 3;
601 octa3 = (LOW_TWO & *p);
602 carry = 0;
603 fprintf_filtered (stream, "%o", octa1);
604 fprintf_filtered (stream, "%o", octa2);
605 fprintf_filtered (stream, "%o", octa3);
606 break;
607
608 default:
8a3fe4f8 609 error (_("Internal error in octal conversion;"));
c5aa993b
JM
610 }
611
612 cycle++;
613 cycle = cycle % BITS_IN_OCTAL;
c906108c
SS
614 }
615 }
616
c906108c
SS
617}
618
619/* VALADDR points to an integer of LEN bytes.
620 * Print it in decimal on stream or format it in buf.
621 */
622void
6c403953 623print_decimal_chars (struct ui_file *stream, const bfd_byte *valaddr,
fba45db2 624 unsigned len)
c906108c
SS
625{
626#define TEN 10
627#define TWO_TO_FOURTH 16
c5aa993b 628#define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */
c906108c
SS
629#define CARRY_LEFT( x ) ((x) % TEN)
630#define SHIFT( x ) ((x) << 4)
631#define START_P \
d7449b42 632 ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1)
c906108c 633#define NOT_END_P \
d7449b42 634 ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
c906108c 635#define NEXT_P \
d7449b42 636 ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? p++ : p-- )
c906108c
SS
637#define LOW_NIBBLE( x ) ( (x) & 0x00F)
638#define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
639
6c403953 640 const bfd_byte *p;
c906108c 641 unsigned char *digits;
c5aa993b
JM
642 int carry;
643 int decimal_len;
644 int i, j, decimal_digits;
645 int dummy;
646 int flip;
647
c906108c
SS
648 /* Base-ten number is less than twice as many digits
649 * as the base 16 number, which is 2 digits per byte.
650 */
651 decimal_len = len * 2 * 2;
3c37485b 652 digits = xmalloc (decimal_len);
c906108c 653
c5aa993b
JM
654 for (i = 0; i < decimal_len; i++)
655 {
c906108c 656 digits[i] = 0;
c5aa993b 657 }
c906108c 658
c906108c
SS
659 /* Ok, we have an unknown number of bytes of data to be printed in
660 * decimal.
661 *
662 * Given a hex number (in nibbles) as XYZ, we start by taking X and
663 * decemalizing it as "x1 x2" in two decimal nibbles. Then we multiply
664 * the nibbles by 16, add Y and re-decimalize. Repeat with Z.
665 *
666 * The trick is that "digits" holds a base-10 number, but sometimes
667 * the individual digits are > 10.
668 *
669 * Outer loop is per nibble (hex digit) of input, from MSD end to
670 * LSD end.
671 */
c5aa993b 672 decimal_digits = 0; /* Number of decimal digits so far */
c906108c
SS
673 p = START_P;
674 flip = 0;
c5aa993b
JM
675 while (NOT_END_P)
676 {
c906108c
SS
677 /*
678 * Multiply current base-ten number by 16 in place.
679 * Each digit was between 0 and 9, now is between
680 * 0 and 144.
681 */
c5aa993b
JM
682 for (j = 0; j < decimal_digits; j++)
683 {
684 digits[j] = SHIFT (digits[j]);
685 }
686
c906108c
SS
687 /* Take the next nibble off the input and add it to what
688 * we've got in the LSB position. Bottom 'digit' is now
689 * between 0 and 159.
690 *
691 * "flip" is used to run this loop twice for each byte.
692 */
c5aa993b
JM
693 if (flip == 0)
694 {
695 /* Take top nibble.
696 */
697 digits[0] += HIGH_NIBBLE (*p);
698 flip = 1;
699 }
700 else
701 {
702 /* Take low nibble and bump our pointer "p".
703 */
704 digits[0] += LOW_NIBBLE (*p);
705 NEXT_P;
706 flip = 0;
707 }
c906108c
SS
708
709 /* Re-decimalize. We have to do this often enough
710 * that we don't overflow, but once per nibble is
711 * overkill. Easier this way, though. Note that the
712 * carry is often larger than 10 (e.g. max initial
713 * carry out of lowest nibble is 15, could bubble all
714 * the way up greater than 10). So we have to do
715 * the carrying beyond the last current digit.
716 */
717 carry = 0;
c5aa993b
JM
718 for (j = 0; j < decimal_len - 1; j++)
719 {
720 digits[j] += carry;
721
722 /* "/" won't handle an unsigned char with
723 * a value that if signed would be negative.
724 * So extend to longword int via "dummy".
725 */
726 dummy = digits[j];
727 carry = CARRY_OUT (dummy);
728 digits[j] = CARRY_LEFT (dummy);
729
730 if (j >= decimal_digits && carry == 0)
731 {
732 /*
733 * All higher digits are 0 and we
734 * no longer have a carry.
735 *
736 * Note: "j" is 0-based, "decimal_digits" is
737 * 1-based.
738 */
739 decimal_digits = j + 1;
740 break;
741 }
742 }
743 }
c906108c
SS
744
745 /* Ok, now "digits" is the decimal representation, with
746 * the "decimal_digits" actual digits. Print!
747 */
c5aa993b
JM
748 for (i = decimal_digits - 1; i >= 0; i--)
749 {
750 fprintf_filtered (stream, "%1d", digits[i]);
751 }
b8c9b27d 752 xfree (digits);
c906108c
SS
753}
754
755/* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
756
6b9acc27 757void
6c403953
AC
758print_hex_chars (struct ui_file *stream, const bfd_byte *valaddr,
759 unsigned len)
c906108c 760{
6c403953 761 const bfd_byte *p;
c906108c
SS
762
763 /* FIXME: We should be not printing leading zeroes in most cases. */
764
bb599908 765 fputs_filtered ("0x", stream);
d7449b42 766 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c906108c
SS
767 {
768 for (p = valaddr;
769 p < valaddr + len;
770 p++)
771 {
772 fprintf_filtered (stream, "%02x", *p);
773 }
774 }
775 else
776 {
777 for (p = valaddr + len - 1;
778 p >= valaddr;
779 p--)
780 {
781 fprintf_filtered (stream, "%02x", *p);
782 }
783 }
c906108c
SS
784}
785
6b9acc27
JJ
786/* VALADDR points to a char integer of LEN bytes. Print it out in appropriate language form on stream.
787 Omit any leading zero chars. */
788
789void
6c403953
AC
790print_char_chars (struct ui_file *stream, const bfd_byte *valaddr,
791 unsigned len)
6b9acc27 792{
6c403953 793 const bfd_byte *p;
6b9acc27
JJ
794
795 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
796 {
797 p = valaddr;
798 while (p < valaddr + len - 1 && *p == 0)
799 ++p;
800
801 while (p < valaddr + len)
802 {
803 LA_EMIT_CHAR (*p, stream, '\'');
804 ++p;
805 }
806 }
807 else
808 {
809 p = valaddr + len - 1;
810 while (p > valaddr && *p == 0)
811 --p;
812
813 while (p >= valaddr)
814 {
815 LA_EMIT_CHAR (*p, stream, '\'');
816 --p;
817 }
818 }
819}
820
c906108c 821/* Called by various <lang>_val_print routines to print elements of an
c5aa993b 822 array in the form "<elem1>, <elem2>, <elem3>, ...".
c906108c 823
c5aa993b
JM
824 (FIXME?) Assumes array element separator is a comma, which is correct
825 for all languages currently handled.
826 (FIXME?) Some languages have a notation for repeated array elements,
827 perhaps we should try to use that notation when appropriate.
828 */
c906108c
SS
829
830void
a2bd3dcd
AC
831val_print_array_elements (struct type *type, const bfd_byte *valaddr,
832 CORE_ADDR address, struct ui_file *stream,
833 int format, int deref_ref,
fba45db2
KB
834 int recurse, enum val_prettyprint pretty,
835 unsigned int i)
c906108c
SS
836{
837 unsigned int things_printed = 0;
838 unsigned len;
839 struct type *elttype;
840 unsigned eltlen;
841 /* Position of the array element we are examining to see
842 whether it is repeated. */
843 unsigned int rep1;
844 /* Number of repetitions we have detected so far. */
845 unsigned int reps;
c5aa993b 846
c906108c
SS
847 elttype = TYPE_TARGET_TYPE (type);
848 eltlen = TYPE_LENGTH (check_typedef (elttype));
849 len = TYPE_LENGTH (type) / eltlen;
850
851 annotate_array_section_begin (i, elttype);
852
853 for (; i < len && things_printed < print_max; i++)
854 {
855 if (i != 0)
856 {
857 if (prettyprint_arrays)
858 {
859 fprintf_filtered (stream, ",\n");
860 print_spaces_filtered (2 + 2 * recurse, stream);
861 }
862 else
863 {
864 fprintf_filtered (stream, ", ");
865 }
866 }
867 wrap_here (n_spaces (2 + 2 * recurse));
868
869 rep1 = i + 1;
870 reps = 1;
c5aa993b 871 while ((rep1 < len) &&
c906108c
SS
872 !memcmp (valaddr + i * eltlen, valaddr + rep1 * eltlen, eltlen))
873 {
874 ++reps;
875 ++rep1;
876 }
877
878 if (reps > repeat_count_threshold)
879 {
880 val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format,
881 deref_ref, recurse + 1, pretty);
882 annotate_elt_rep (reps);
883 fprintf_filtered (stream, " <repeats %u times>", reps);
884 annotate_elt_rep_end ();
885
886 i = rep1 - 1;
887 things_printed += repeat_count_threshold;
888 }
889 else
890 {
891 val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format,
892 deref_ref, recurse + 1, pretty);
893 annotate_elt ();
894 things_printed++;
895 }
896 }
897 annotate_array_section_end ();
898 if (i < len)
899 {
900 fprintf_filtered (stream, "...");
901 }
902}
903
917317f4
JM
904/* Read LEN bytes of target memory at address MEMADDR, placing the
905 results in GDB's memory at MYADDR. Returns a count of the bytes
906 actually read, and optionally an errno value in the location
907 pointed to by ERRNOPTR if ERRNOPTR is non-null. */
908
909/* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this
910 function be eliminated. */
911
912static int
913partial_memory_read (CORE_ADDR memaddr, char *myaddr, int len, int *errnoptr)
914{
915 int nread; /* Number of bytes actually read. */
916 int errcode; /* Error from last read. */
917
918 /* First try a complete read. */
919 errcode = target_read_memory (memaddr, myaddr, len);
920 if (errcode == 0)
921 {
922 /* Got it all. */
923 nread = len;
924 }
925 else
926 {
927 /* Loop, reading one byte at a time until we get as much as we can. */
928 for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
929 {
930 errcode = target_read_memory (memaddr++, myaddr++, 1);
931 }
932 /* If an error, the last read was unsuccessful, so adjust count. */
933 if (errcode != 0)
934 {
935 nread--;
936 }
937 }
938 if (errnoptr != NULL)
939 {
940 *errnoptr = errcode;
941 }
942 return (nread);
943}
944
c906108c 945/* Print a string from the inferior, starting at ADDR and printing up to LEN
c5aa993b
JM
946 characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing
947 stops at the first null byte, otherwise printing proceeds (including null
948 bytes) until either print_max or LEN characters have been printed,
949 whichever is smaller. */
c906108c
SS
950
951/* FIXME: Use target_read_string. */
952
953int
fba45db2 954val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream)
c906108c
SS
955{
956 int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */
957 int errcode; /* Errno returned from bad reads. */
958 unsigned int fetchlimit; /* Maximum number of chars to print. */
959 unsigned int nfetch; /* Chars to fetch / chars fetched. */
960 unsigned int chunksize; /* Size of each fetch, in chars. */
961 char *buffer = NULL; /* Dynamically growable fetch buffer. */
962 char *bufptr; /* Pointer to next available byte in buffer. */
963 char *limit; /* First location past end of fetch buffer. */
c5aa993b 964 struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
c906108c
SS
965 int found_nul; /* Non-zero if we found the nul char */
966
967 /* First we need to figure out the limit on the number of characters we are
968 going to attempt to fetch and print. This is actually pretty simple. If
969 LEN >= zero, then the limit is the minimum of LEN and print_max. If
970 LEN is -1, then the limit is print_max. This is true regardless of
971 whether print_max is zero, UINT_MAX (unlimited), or something in between,
972 because finding the null byte (or available memory) is what actually
973 limits the fetch. */
974
975 fetchlimit = (len == -1 ? print_max : min (len, print_max));
976
977 /* Now decide how large of chunks to try to read in one operation. This
978 is also pretty simple. If LEN >= zero, then we want fetchlimit chars,
979 so we might as well read them all in one operation. If LEN is -1, we
980 are looking for a null terminator to end the fetching, so we might as
981 well read in blocks that are large enough to be efficient, but not so
982 large as to be slow if fetchlimit happens to be large. So we choose the
983 minimum of 8 and fetchlimit. We used to use 200 instead of 8 but
984 200 is way too big for remote debugging over a serial line. */
985
986 chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit);
987
988 /* Loop until we either have all the characters to print, or we encounter
989 some error, such as bumping into the end of the address space. */
990
991 found_nul = 0;
992 old_chain = make_cleanup (null_cleanup, 0);
993
994 if (len > 0)
995 {
996 buffer = (char *) xmalloc (len * width);
997 bufptr = buffer;
b8c9b27d 998 old_chain = make_cleanup (xfree, buffer);
c906108c 999
917317f4 1000 nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
c906108c
SS
1001 / width;
1002 addr += nfetch * width;
1003 bufptr += nfetch * width;
1004 }
1005 else if (len == -1)
1006 {
1007 unsigned long bufsize = 0;
1008 do
1009 {
1010 QUIT;
1011 nfetch = min (chunksize, fetchlimit - bufsize);
1012
1013 if (buffer == NULL)
1014 buffer = (char *) xmalloc (nfetch * width);
1015 else
1016 {
1017 discard_cleanups (old_chain);
1018 buffer = (char *) xrealloc (buffer, (nfetch + bufsize) * width);
1019 }
1020
b8c9b27d 1021 old_chain = make_cleanup (xfree, buffer);
c906108c
SS
1022 bufptr = buffer + bufsize * width;
1023 bufsize += nfetch;
1024
1025 /* Read as much as we can. */
917317f4 1026 nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode)
c5aa993b 1027 / width;
c906108c
SS
1028
1029 /* Scan this chunk for the null byte that terminates the string
1030 to print. If found, we don't need to fetch any more. Note
1031 that bufptr is explicitly left pointing at the next character
1032 after the null byte, or at the next character after the end of
1033 the buffer. */
1034
1035 limit = bufptr + nfetch * width;
1036 while (bufptr < limit)
1037 {
1038 unsigned long c;
1039
1040 c = extract_unsigned_integer (bufptr, width);
1041 addr += width;
1042 bufptr += width;
1043 if (c == 0)
1044 {
1045 /* We don't care about any error which happened after
1046 the NULL terminator. */
1047 errcode = 0;
1048 found_nul = 1;
1049 break;
1050 }
1051 }
1052 }
c5aa993b
JM
1053 while (errcode == 0 /* no error */
1054 && bufptr - buffer < fetchlimit * width /* no overrun */
1055 && !found_nul); /* haven't found nul yet */
c906108c
SS
1056 }
1057 else
1058 { /* length of string is really 0! */
1059 buffer = bufptr = NULL;
1060 errcode = 0;
1061 }
1062
1063 /* bufptr and addr now point immediately beyond the last byte which we
1064 consider part of the string (including a '\0' which ends the string). */
1065
1066 /* We now have either successfully filled the buffer to fetchlimit, or
1067 terminated early due to an error or finding a null char when LEN is -1. */
1068
1069 if (len == -1 && !found_nul)
1070 {
1071 char *peekbuf;
1072
1073 /* We didn't find a null terminator we were looking for. Attempt
c5aa993b
JM
1074 to peek at the next character. If not successful, or it is not
1075 a null byte, then force ellipsis to be printed. */
c906108c
SS
1076
1077 peekbuf = (char *) alloca (width);
1078
1079 if (target_read_memory (addr, peekbuf, width) == 0
1080 && extract_unsigned_integer (peekbuf, width) != 0)
1081 force_ellipsis = 1;
1082 }
c5aa993b 1083 else if ((len >= 0 && errcode != 0) || (len > (bufptr - buffer) / width))
c906108c
SS
1084 {
1085 /* Getting an error when we have a requested length, or fetching less
c5aa993b
JM
1086 than the number of characters actually requested, always make us
1087 print ellipsis. */
c906108c
SS
1088 force_ellipsis = 1;
1089 }
1090
1091 QUIT;
1092
1093 /* If we get an error before fetching anything, don't print a string.
1094 But if we fetch something and then get an error, print the string
1095 and then the error message. */
1096 if (errcode == 0 || bufptr > buffer)
1097 {
1098 if (addressprint)
1099 {
1100 fputs_filtered (" ", stream);
1101 }
c5aa993b 1102 LA_PRINT_STRING (stream, buffer, (bufptr - buffer) / width, width, force_ellipsis);
c906108c
SS
1103 }
1104
1105 if (errcode != 0)
1106 {
1107 if (errcode == EIO)
1108 {
1109 fprintf_filtered (stream, " <Address ");
66bf4b3a 1110 deprecated_print_address_numeric (addr, 1, stream);
c906108c
SS
1111 fprintf_filtered (stream, " out of bounds>");
1112 }
1113 else
1114 {
1115 fprintf_filtered (stream, " <Error reading address ");
66bf4b3a 1116 deprecated_print_address_numeric (addr, 1, stream);
c906108c
SS
1117 fprintf_filtered (stream, ": %s>", safe_strerror (errcode));
1118 }
1119 }
1120 gdb_flush (stream);
1121 do_cleanups (old_chain);
c5aa993b 1122 return ((bufptr - buffer) / width);
c906108c 1123}
c906108c 1124\f
c5aa993b 1125
c906108c
SS
1126/* Validate an input or output radix setting, and make sure the user
1127 knows what they really did here. Radix setting is confusing, e.g.
1128 setting the input radix to "10" never changes it! */
1129
c906108c 1130static void
fba45db2 1131set_input_radix (char *args, int from_tty, struct cmd_list_element *c)
c906108c 1132{
f66c9f11 1133 set_input_radix_1 (from_tty, input_radix);
c906108c
SS
1134}
1135
c906108c 1136static void
fba45db2 1137set_input_radix_1 (int from_tty, unsigned radix)
c906108c
SS
1138{
1139 /* We don't currently disallow any input radix except 0 or 1, which don't
1140 make any mathematical sense. In theory, we can deal with any input
1141 radix greater than 1, even if we don't have unique digits for every
1142 value from 0 to radix-1, but in practice we lose on large radix values.
1143 We should either fix the lossage or restrict the radix range more.
1144 (FIXME). */
1145
1146 if (radix < 2)
1147 {
f66c9f11
AC
1148 /* FIXME: cagney/2002-03-17: This needs to revert the bad radix
1149 value. */
8a3fe4f8 1150 error (_("Nonsense input radix ``decimal %u''; input radix unchanged."),
c906108c
SS
1151 radix);
1152 }
1153 input_radix = radix;
1154 if (from_tty)
1155 {
a3f17187 1156 printf_filtered (_("Input radix now set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1157 radix, radix, radix);
1158 }
1159}
1160
c906108c 1161static void
fba45db2 1162set_output_radix (char *args, int from_tty, struct cmd_list_element *c)
c906108c 1163{
f66c9f11 1164 set_output_radix_1 (from_tty, output_radix);
c906108c
SS
1165}
1166
1167static void
fba45db2 1168set_output_radix_1 (int from_tty, unsigned radix)
c906108c
SS
1169{
1170 /* Validate the radix and disallow ones that we aren't prepared to
1171 handle correctly, leaving the radix unchanged. */
1172 switch (radix)
1173 {
1174 case 16:
c5aa993b 1175 output_format = 'x'; /* hex */
c906108c
SS
1176 break;
1177 case 10:
c5aa993b 1178 output_format = 0; /* decimal */
c906108c
SS
1179 break;
1180 case 8:
c5aa993b 1181 output_format = 'o'; /* octal */
c906108c
SS
1182 break;
1183 default:
f66c9f11
AC
1184 /* FIXME: cagney/2002-03-17: This needs to revert the bad radix
1185 value. */
8a3fe4f8 1186 error (_("Unsupported output radix ``decimal %u''; output radix unchanged."),
c906108c
SS
1187 radix);
1188 }
1189 output_radix = radix;
1190 if (from_tty)
1191 {
a3f17187 1192 printf_filtered (_("Output radix now set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1193 radix, radix, radix);
1194 }
1195}
1196
1197/* Set both the input and output radix at once. Try to set the output radix
1198 first, since it has the most restrictive range. An radix that is valid as
1199 an output radix is also valid as an input radix.
1200
1201 It may be useful to have an unusual input radix. If the user wishes to
1202 set an input radix that is not valid as an output radix, he needs to use
1203 the 'set input-radix' command. */
1204
1205static void
fba45db2 1206set_radix (char *arg, int from_tty)
c906108c
SS
1207{
1208 unsigned radix;
1209
bb518678 1210 radix = (arg == NULL) ? 10 : parse_and_eval_long (arg);
c906108c
SS
1211 set_output_radix_1 (0, radix);
1212 set_input_radix_1 (0, radix);
1213 if (from_tty)
1214 {
a3f17187 1215 printf_filtered (_("Input and output radices now set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1216 radix, radix, radix);
1217 }
1218}
1219
1220/* Show both the input and output radices. */
1221
c906108c 1222static void
fba45db2 1223show_radix (char *arg, int from_tty)
c906108c
SS
1224{
1225 if (from_tty)
1226 {
1227 if (input_radix == output_radix)
1228 {
a3f17187 1229 printf_filtered (_("Input and output radices set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1230 input_radix, input_radix, input_radix);
1231 }
1232 else
1233 {
a3f17187 1234 printf_filtered (_("Input radix set to decimal %u, hex %x, octal %o.\n"),
c906108c 1235 input_radix, input_radix, input_radix);
a3f17187 1236 printf_filtered (_("Output radix set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1237 output_radix, output_radix, output_radix);
1238 }
1239 }
1240}
c906108c 1241\f
c5aa993b 1242
c906108c 1243static void
fba45db2 1244set_print (char *arg, int from_tty)
c906108c
SS
1245{
1246 printf_unfiltered (
c5aa993b 1247 "\"set print\" must be followed by the name of a print subcommand.\n");
c906108c
SS
1248 help_list (setprintlist, "set print ", -1, gdb_stdout);
1249}
1250
c906108c 1251static void
fba45db2 1252show_print (char *args, int from_tty)
c906108c
SS
1253{
1254 cmd_show_list (showprintlist, from_tty, "");
1255}
1256\f
1257void
fba45db2 1258_initialize_valprint (void)
c906108c
SS
1259{
1260 struct cmd_list_element *c;
1261
1262 add_prefix_cmd ("print", no_class, set_print,
1bedd215 1263 _("Generic command for setting how things print."),
c906108c 1264 &setprintlist, "set print ", 0, &setlist);
c5aa993b
JM
1265 add_alias_cmd ("p", "print", no_class, 1, &setlist);
1266 /* prefer set print to set prompt */
c906108c
SS
1267 add_alias_cmd ("pr", "print", no_class, 1, &setlist);
1268
1269 add_prefix_cmd ("print", no_class, show_print,
1bedd215 1270 _("Generic command for showing print settings."),
c906108c 1271 &showprintlist, "show print ", 0, &showlist);
c5aa993b
JM
1272 add_alias_cmd ("p", "print", no_class, 1, &showlist);
1273 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
c906108c 1274
35096d9d
AC
1275 add_setshow_uinteger_cmd ("elements", no_class, &print_max, _("\
1276Set limit on string chars or array elements to print."), _("\
1277Show limit on string chars or array elements to print."), _("\
1278\"set print elements 0\" causes there to be no limit."),
1279 NULL,
920d2a44 1280 show_print_max,
35096d9d 1281 &setprintlist, &showprintlist);
c906108c 1282
5bf193a2
AC
1283 add_setshow_boolean_cmd ("null-stop", no_class, &stop_print_at_null, _("\
1284Set printing of char arrays to stop at first null char."), _("\
1285Show printing of char arrays to stop at first null char."), NULL,
1286 NULL,
920d2a44 1287 show_stop_print_at_null,
5bf193a2 1288 &setprintlist, &showprintlist);
c906108c 1289
35096d9d
AC
1290 add_setshow_uinteger_cmd ("repeats", no_class,
1291 &repeat_count_threshold, _("\
1292Set threshold for repeated print elements."), _("\
1293Show threshold for repeated print elements."), _("\
1294\"set print repeats 0\" causes all elements to be individually printed."),
1295 NULL,
920d2a44 1296 show_repeat_count_threshold,
35096d9d 1297 &setprintlist, &showprintlist);
c906108c 1298
5bf193a2
AC
1299 add_setshow_boolean_cmd ("pretty", class_support, &prettyprint_structs, _("\
1300Set prettyprinting of structures."), _("\
1301Show prettyprinting of structures."), NULL,
1302 NULL,
920d2a44 1303 show_prettyprint_structs,
5bf193a2
AC
1304 &setprintlist, &showprintlist);
1305
1306 add_setshow_boolean_cmd ("union", class_support, &unionprint, _("\
1307Set printing of unions interior to structures."), _("\
1308Show printing of unions interior to structures."), NULL,
1309 NULL,
920d2a44 1310 show_unionprint,
5bf193a2
AC
1311 &setprintlist, &showprintlist);
1312
1313 add_setshow_boolean_cmd ("array", class_support, &prettyprint_arrays, _("\
1314Set prettyprinting of arrays."), _("\
1315Show prettyprinting of arrays."), NULL,
1316 NULL,
920d2a44 1317 show_prettyprint_arrays,
5bf193a2
AC
1318 &setprintlist, &showprintlist);
1319
1320 add_setshow_boolean_cmd ("address", class_support, &addressprint, _("\
1321Set printing of addresses."), _("\
1322Show printing of addresses."), NULL,
1323 NULL,
920d2a44 1324 show_addressprint,
5bf193a2 1325 &setprintlist, &showprintlist);
c906108c 1326
35096d9d
AC
1327 add_setshow_uinteger_cmd ("input-radix", class_support, &input_radix, _("\
1328Set default input radix for entering numbers."), _("\
1329Show default input radix for entering numbers."), NULL,
1330 set_input_radix,
920d2a44 1331 show_input_radix,
35096d9d
AC
1332 &setlist, &showlist);
1333
1334 add_setshow_uinteger_cmd ("output-radix", class_support, &output_radix, _("\
1335Set default output radix for printing of values."), _("\
1336Show default output radix for printing of values."), NULL,
1337 set_output_radix,
920d2a44 1338 show_output_radix,
35096d9d 1339 &setlist, &showlist);
c906108c 1340
cb1a6d5f
AC
1341 /* The "set radix" and "show radix" commands are special in that
1342 they are like normal set and show commands but allow two normally
1343 independent variables to be either set or shown with a single
b66df561 1344 command. So the usual deprecated_add_set_cmd() and [deleted]
cb1a6d5f 1345 add_show_from_set() commands aren't really appropriate. */
b66df561
AC
1346 /* FIXME: i18n: With the new add_setshow_integer command, that is no
1347 longer true - show can display anything. */
1a966eab
AC
1348 add_cmd ("radix", class_support, set_radix, _("\
1349Set default input and output number radices.\n\
c906108c 1350Use 'set input-radix' or 'set output-radix' to independently set each.\n\
1a966eab 1351Without an argument, sets both radices back to the default value of 10."),
c906108c 1352 &setlist);
1a966eab
AC
1353 add_cmd ("radix", class_support, show_radix, _("\
1354Show the default input and output number radices.\n\
1355Use 'show input-radix' or 'show output-radix' to independently show each."),
c906108c
SS
1356 &showlist);
1357
1358 /* Give people the defaults which they are used to. */
1359 prettyprint_structs = 0;
1360 prettyprint_arrays = 0;
1361 unionprint = 1;
1362 addressprint = 1;
1363 print_max = PRINT_MAX_DEFAULT;
1364}
This page took 0.644572 seconds and 4 git commands to generate.