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