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