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