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