1 /* Print values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
34 /* Prototypes for local functions */
37 print_hex_chars
PARAMS ((GDB_FILE
*, unsigned char *, unsigned int));
40 show_print
PARAMS ((char *, int));
43 set_print
PARAMS ((char *, int));
46 set_radix
PARAMS ((char *, int));
49 show_radix
PARAMS ((char *, int));
52 set_input_radix
PARAMS ((char *, int, struct cmd_list_element
*));
55 set_input_radix_1
PARAMS ((int, unsigned));
58 set_output_radix
PARAMS ((char *, int, struct cmd_list_element
*));
61 set_output_radix_1
PARAMS ((int, unsigned));
64 value_print_array_elements
PARAMS ((value
, GDB_FILE
*, int, enum val_prettyprint
));
66 /* Maximum number of chars to print for a string pointer value or vector
67 contents, or UINT_MAX for no limit. Note that "set print elements 0"
68 stores UINT_MAX in print_max, which displays in a show command as
71 unsigned int print_max
;
72 #define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */
74 /* Default input and output radixes, and output format letter. */
76 unsigned input_radix
= 10;
77 unsigned output_radix
= 10;
78 int output_format
= 0;
80 /* Print repeat counts if there are more than this many repetitions of an
81 element in an array. Referenced by the low level language dependent
84 unsigned int repeat_count_threshold
= 10;
86 int prettyprint_structs
; /* Controls pretty printing of structures */
87 int prettyprint_arrays
; /* Controls pretty printing of arrays. */
89 /* If nonzero, causes unions inside structures or other unions to be
92 int unionprint
; /* Controls printing of nested unions. */
94 /* If nonzero, causes machine addresses to be printed in certain contexts. */
96 int addressprint
; /* Controls printing of machine addresses */
99 /* Print data of type TYPE located at VALADDR (within GDB), which came from
100 the inferior at address ADDRESS, onto stdio stream STREAM according to
101 FORMAT (a letter, or 0 for natural format using TYPE).
103 If DEREF_REF is nonzero, then dereference references, otherwise just print
106 The PRETTY parameter controls prettyprinting.
108 If the data are a string pointer, returns the number of string characters
111 FIXME: The data at VALADDR is in target byte order. If gdb is ever
112 enhanced to be able to debug more than the single target it was compiled
113 for (specific CPU type and thus specific target byte ordering), then
114 either the print routines are going to have to take this into account,
115 or the data is going to have to be passed into here already converted
116 to the host byte ordering, whichever is more convenient. */
120 val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
, pretty
)
128 enum val_prettyprint pretty
;
130 if (pretty
== Val_pretty_default
)
132 pretty
= prettyprint_structs
? Val_prettyprint
: Val_no_prettyprint
;
137 /* Ensure that the type is complete and not just a stub. If the type is
138 only a stub and we can't find and substitute its complete type, then
139 print appropriate string and return. Typical types that my be stubs
140 are structs, unions, and C++ methods. */
142 check_stub_type (type
);
143 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
145 fprintf_filtered (stream
, "<incomplete type>");
150 return (LA_VAL_PRINT (type
, valaddr
, address
, stream
, format
, deref_ref
,
154 /* Print the value VAL in C-ish syntax on stream STREAM.
155 FORMAT is a format-letter, or 0 for print in natural format of data type.
156 If the object printed is a string pointer, returns
157 the number of string bytes printed. */
160 value_print (val
, stream
, format
, pretty
)
164 enum val_prettyprint pretty
;
166 register unsigned int n
, typelen
;
170 printf_filtered ("<address of value unknown>");
173 if (VALUE_OPTIMIZED_OUT (val
))
175 printf_filtered ("<value optimized out>");
179 /* A "repeated" value really contains several values in a row.
180 They are made by the @ operator.
181 Print such values as if they were arrays. */
183 if (VALUE_REPEATED (val
))
185 n
= VALUE_REPETITIONS (val
);
186 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
187 fprintf_filtered (stream
, "{");
188 /* Print arrays of characters using string syntax. */
189 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
191 LA_PRINT_STRING (stream
, VALUE_CONTENTS (val
), n
, 0);
194 value_print_array_elements (val
, stream
, format
, pretty
);
196 fprintf_filtered (stream
, "}");
197 return (n
* typelen
);
201 struct type
*type
= VALUE_TYPE (val
);
203 /* If it is a pointer, indicate what it points to.
205 Print type also if it is a reference.
207 C++: if it is a member pointer, we will take care
208 of that when we print it. */
209 if (TYPE_CODE (type
) == TYPE_CODE_PTR
||
210 TYPE_CODE (type
) == TYPE_CODE_REF
)
212 /* Hack: remove (char *) for char strings. Their
213 type is indicated by the quoted string anyway. */
214 if (TYPE_CODE (type
) == TYPE_CODE_PTR
&&
215 TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == sizeof(char) &&
216 TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_INT
&&
217 !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
223 fprintf_filtered (stream
, "(");
224 type_print (type
, "", stream
, -1);
225 fprintf_filtered (stream
, ") ");
228 return (val_print (type
, VALUE_CONTENTS (val
),
229 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
));
233 /* Called by various <lang>_val_print routines to print TYPE_CODE_INT's */
236 val_print_type_code_int (type
, valaddr
, stream
)
242 /* Pointer to first (i.e. lowest address) nonzero character. */
246 if (TYPE_LENGTH (type
) > sizeof (LONGEST
))
248 if (TYPE_UNSIGNED (type
))
250 /* First figure out whether the number in fact has zeros
251 in all its bytes more significant than least significant
252 sizeof (LONGEST) ones. */
253 len
= TYPE_LENGTH (type
);
255 #if TARGET_BYTE_ORDER == BIG_ENDIAN
257 len
> sizeof (LONGEST
) && p
< valaddr
+ TYPE_LENGTH (type
);
259 #else /* Little endian. */
260 first_addr
= valaddr
;
261 for (p
= valaddr
+ TYPE_LENGTH (type
) - 1;
262 len
> sizeof (LONGEST
) && p
>= valaddr
;
264 #endif /* Little endian. */
275 #if TARGET_BYTE_ORDER == BIG_ENDIAN
278 if (len
<= sizeof (LONGEST
))
280 /* The most significant bytes are zero, so we can just get
281 the least significant sizeof (LONGEST) bytes and print it
283 print_longest (stream
, 'u', 0,
284 extract_unsigned_integer (first_addr
,
289 /* It is big, so print it in hex. */
290 print_hex_chars (stream
, (unsigned char *) first_addr
, len
);
295 /* Signed. One could assume two's complement (a reasonable
296 assumption, I think) and do better than this. */
297 print_hex_chars (stream
, (unsigned char *) valaddr
,
303 #ifdef PRINT_TYPELESS_INTEGER
304 PRINT_TYPELESS_INTEGER (stream
, type
, unpack_long (type
, valaddr
));
306 print_longest (stream
, TYPE_UNSIGNED (type
) ? 'u' : 'd', 0,
307 unpack_long (type
, valaddr
));
312 /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
313 The raison d'etre of this function is to consolidate printing of LONG_LONG's
314 into this one function. Some platforms have long longs but don't have a
315 printf() that supports "ll" in the format string. We handle these by seeing
316 if the number is actually a long, and if not we just bail out and print the
317 number in hex. The format chars b,h,w,g are from
318 print_scalar_formatted(). USE_LOCAL says whether or not to call the
319 local formatting routine to get the format. */
322 print_longest (stream
, format
, use_local
, val_long
)
328 #if defined (CC_HAS_LONG_LONG) && !defined (PRINTF_HAS_LONG_LONG)
331 vtop
= val_long
>> (sizeof (long) * HOST_CHAR_BIT
);
332 vbot
= (long) val_long
;
334 if ((format
== 'd' && (val_long
< INT_MIN
|| val_long
> INT_MAX
))
335 || ((format
== 'u' || format
== 'x') && (unsigned long long)val_long
> UINT_MAX
))
337 fprintf_filtered (stream
, "0x%lx%08lx", vtop
, vbot
);
342 #ifdef PRINTF_HAS_LONG_LONG
346 fprintf_filtered (stream
,
347 use_local
? local_decimal_format_custom ("ll")
352 fprintf_filtered (stream
, "%llu", val_long
);
355 fprintf_filtered (stream
,
356 use_local
? local_hex_format_custom ("ll")
361 fprintf_filtered (stream
,
362 use_local
? local_octal_format_custom ("ll")
366 fprintf_filtered (stream
, local_hex_format_custom ("02ll"), val_long
);
369 fprintf_filtered (stream
, local_hex_format_custom ("04ll"), val_long
);
372 fprintf_filtered (stream
, local_hex_format_custom ("08ll"), val_long
);
375 fprintf_filtered (stream
, local_hex_format_custom ("016ll"), val_long
);
380 #else /* !PRINTF_HAS_LONG_LONG */
381 /* In the following it is important to coerce (val_long) to a long. It does
382 nothing if !LONG_LONG, but it will chop off the top half (which we know
383 we can ignore) if the host supports long longs. */
388 fprintf_filtered (stream
,
389 use_local
? local_decimal_format_custom ("l")
394 fprintf_filtered (stream
, "%lu", (unsigned long) val_long
);
397 fprintf_filtered (stream
,
398 use_local
? local_hex_format_custom ("l")
403 fprintf_filtered (stream
,
404 use_local
? local_octal_format_custom ("l")
409 fprintf_filtered (stream
, local_hex_format_custom ("02l"),
413 fprintf_filtered (stream
, local_hex_format_custom ("04l"),
417 fprintf_filtered (stream
, local_hex_format_custom ("08l"),
421 fprintf_filtered (stream
, local_hex_format_custom ("016l"),
427 #endif /* !PRINTF_HAS_LONG_LONG */
430 /* This used to be a macro, but I don't think it is called often enough
431 to merit such treatment. */
432 /* Convert a LONGEST to an int. This is used in contexts (e.g. number of
433 arguments to a function, number in a value history, register number, etc.)
434 where the value must not be larger than can fit in an int. */
441 /* This check is in case a system header has botched the
442 definition of INT_MIN, like on BSDI. */
443 if (sizeof (LONGEST
) <= sizeof (int))
446 if (arg
> INT_MAX
|| arg
< INT_MIN
)
447 error ("Value out of range.");
452 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
456 print_floating (valaddr
, type
, stream
)
463 unsigned len
= TYPE_LENGTH (type
);
465 #if defined (IEEE_FLOAT)
467 /* Check for NaN's. Note that this code does not depend on us being
468 on an IEEE conforming system. It only depends on the target
469 machine using IEEE representation. This means (a)
470 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
471 be defined for systems like the 68881, which uses IEEE
472 representation, but is not IEEE conforming. */
475 unsigned long low
, high
;
476 /* Is the sign bit 0? */
478 /* Is it is a NaN (i.e. the exponent is all ones and
479 the fraction is nonzero)? */
484 /* It's single precision. */
485 /* Assume that floating point byte order is the same as
486 integer byte order. */
487 low
= extract_unsigned_integer (valaddr
, 4);
488 nonnegative
= ((low
& 0x80000000) == 0);
489 is_nan
= ((((low
>> 23) & 0xFF) == 0xFF)
490 && 0 != (low
& 0x7FFFFF));
496 /* It's double precision. Get the high and low words. */
498 /* Assume that floating point byte order is the same as
499 integer byte order. */
500 #if TARGET_BYTE_ORDER == BIG_ENDIAN
501 low
= extract_unsigned_integer (valaddr
+ 4, 4);
502 high
= extract_unsigned_integer (valaddr
, 4);
504 low
= extract_unsigned_integer (valaddr
, 4);
505 high
= extract_unsigned_integer (valaddr
+ 4, 4);
507 nonnegative
= ((high
& 0x80000000) == 0);
508 is_nan
= (((high
>> 20) & 0x7ff) == 0x7ff
509 && ! ((((high
& 0xfffff) == 0)) && (low
== 0)));
513 /* Extended. We can't detect NaNs for extendeds yet. Also note
514 that currently extendeds get nuked to double in
515 REGISTER_CONVERTIBLE. */
520 /* The meaning of the sign and fraction is not defined by IEEE.
521 But the user might know what they mean. For example, they
522 (in an implementation-defined manner) distinguish between
523 signaling and quiet NaN's. */
525 fprintf_filtered (stream
, "-NaN(0x%lx%.8lx)" + nonnegative
,
528 fprintf_filtered (stream
, "-NaN(0x%lx)" + nonnegative
, low
);
532 #endif /* IEEE_FLOAT. */
534 doub
= unpack_double (type
, valaddr
, &inv
);
536 fprintf_filtered (stream
, "<invalid float value>");
538 fprintf_filtered (stream
, len
<= sizeof(float) ? "%.9g" : "%.17g", doub
);
541 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
544 print_hex_chars (stream
, valaddr
, len
)
546 unsigned char *valaddr
;
551 /* FIXME: We should be not printing leading zeroes in most cases. */
553 fprintf_filtered (stream
, local_hex_format_prefix ());
554 #if TARGET_BYTE_ORDER == BIG_ENDIAN
558 #else /* Little endian. */
559 for (p
= valaddr
+ len
- 1;
564 fprintf_filtered (stream
, "%02x", *p
);
566 fprintf_filtered (stream
, local_hex_format_suffix ());
569 /* Called by various <lang>_val_print routines to print elements of an
570 array in the form "<elem1>, <elem2>, <elem3>, ...".
572 (FIXME?) Assumes array element separator is a comma, which is correct
573 for all languages currently handled.
574 (FIXME?) Some languages have a notation for repeated array elements,
575 perhaps we should try to use that notation when appropriate.
579 val_print_array_elements (type
, valaddr
, address
, stream
, format
, deref_ref
,
588 enum val_prettyprint pretty
;
591 unsigned int things_printed
= 0;
593 struct type
*elttype
;
595 /* Position of the array element we are examining to see
596 whether it is repeated. */
598 /* Number of repetitions we have detected so far. */
601 elttype
= TYPE_TARGET_TYPE (type
);
602 eltlen
= TYPE_LENGTH (elttype
);
603 len
= TYPE_LENGTH (type
) / eltlen
;
605 for (; i
< len
&& things_printed
< print_max
; i
++)
609 if (prettyprint_arrays
)
611 fprintf_filtered (stream
, ",\n");
612 print_spaces_filtered (2 + 2 * recurse
, stream
);
616 fprintf_filtered (stream
, ", ");
619 wrap_here (n_spaces (2 + 2 * recurse
));
623 while ((rep1
< len
) &&
624 !memcmp (valaddr
+ i
* eltlen
, valaddr
+ rep1
* eltlen
, eltlen
))
630 if (reps
> repeat_count_threshold
)
632 val_print (elttype
, valaddr
+ i
* eltlen
, 0, stream
, format
,
633 deref_ref
, recurse
+ 1, pretty
);
634 fprintf_filtered (stream
, " <repeats %u times>", reps
);
636 things_printed
+= repeat_count_threshold
;
640 val_print (elttype
, valaddr
+ i
* eltlen
, 0, stream
, format
,
641 deref_ref
, recurse
+ 1, pretty
);
647 fprintf_filtered (stream
, "...");
652 value_print_array_elements (val
, stream
, format
, pretty
)
656 enum val_prettyprint pretty
;
658 unsigned int things_printed
= 0;
659 register unsigned int i
, n
, typelen
;
660 /* Position of the array elem we are examining to see if it is repeated. */
662 /* Number of repetitions we have detected so far. */
665 n
= VALUE_REPETITIONS (val
);
666 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
667 for (i
= 0; i
< n
&& things_printed
< print_max
; i
++)
671 fprintf_filtered (stream
, ", ");
677 while (rep1
< n
&& !memcmp (VALUE_CONTENTS (val
) + typelen
* i
,
678 VALUE_CONTENTS (val
) + typelen
* rep1
,
685 if (reps
> repeat_count_threshold
)
687 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
) + typelen
* i
,
688 VALUE_ADDRESS (val
) + typelen
* i
, stream
, format
, 1,
690 fprintf_unfiltered (stream
, " <repeats %u times>", reps
);
692 things_printed
+= repeat_count_threshold
;
696 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
) + typelen
* i
,
697 VALUE_ADDRESS (val
) + typelen
* i
, stream
, format
, 1,
704 fprintf_filtered (stream
, "...");
708 /* Print a string from the inferior, starting at ADDR and printing up to LEN
709 characters, to STREAM. If LEN is zero, printing stops at the first null
710 byte, otherwise printing proceeds (including null bytes) until either
711 print_max or LEN characters have been printed, whichever is smaller. */
714 val_print_string (addr
, len
, stream
)
719 int force_ellipsis
= 0; /* Force ellipsis to be printed if nonzero. */
720 int errcode
; /* Errno returned from bad reads. */
721 unsigned int fetchlimit
; /* Maximum number of bytes to fetch. */
722 unsigned int nfetch
; /* Bytes to fetch / bytes fetched. */
723 unsigned int chunksize
; /* Size of each fetch, in bytes. */
724 int bufsize
; /* Size of current fetch buffer. */
725 char *buffer
= NULL
; /* Dynamically growable fetch buffer. */
726 char *bufptr
; /* Pointer to next available byte in buffer. */
727 char *limit
; /* First location past end of fetch buffer. */
728 struct cleanup
*old_chain
= NULL
; /* Top of the old cleanup chain. */
729 char peekchar
; /* Place into which we can read one char. */
731 /* If errcode is non-zero, this is the address which failed to read
735 /* First we need to figure out the limit on the number of characters we are
736 going to attempt to fetch and print. This is actually pretty simple. If
737 LEN is nonzero, then the limit is the minimum of LEN and print_max. If
738 LEN is zero, then the limit is print_max. This is true regardless of
739 whether print_max is zero, UINT_MAX (unlimited), or something in between,
740 because finding the null byte (or available memory) is what actually
743 fetchlimit
= (len
== 0 ? print_max
: min (len
, print_max
));
745 /* Now decide how large of chunks to try to read in one operation. This
746 is also pretty simple. If LEN is nonzero, then we want fetchlimit bytes,
747 so we might as well read them all in one operation. If LEN is zero, we
748 are looking for a null terminator to end the fetching, so we might as
749 well read in blocks that are large enough to be efficient, but not so
750 large as to be slow if fetchlimit happens to be large. So we choose the
751 minimum of 8 and fetchlimit. We used to use 200 instead of 8 but
752 200 is way too big for remote debugging over a serial line. */
754 chunksize
= (len
== 0 ? min (8, fetchlimit
) : fetchlimit
);
756 /* Loop until we either have all the characters to print, or we encounter
757 some error, such as bumping into the end of the address space. */
762 /* Figure out how much to fetch this time, and grow the buffer to fit. */
763 nfetch
= min (chunksize
, fetchlimit
- bufsize
);
767 buffer
= (char *) xmalloc (bufsize
);
772 discard_cleanups (old_chain
);
773 buffer
= (char *) xrealloc (buffer
, bufsize
);
774 bufptr
= buffer
+ bufsize
- nfetch
;
776 old_chain
= make_cleanup (free
, buffer
);
778 /* Read as much as we can. */
779 nfetch
= target_read_memory_partial (addr
, bufptr
, nfetch
, &errcode
);
780 err_addr
= addr
+ nfetch
;
788 /* Scan this chunk for the null byte that terminates the string
789 to print. If found, we don't need to fetch any more. Note
790 that bufptr is explicitly left pointing at the next character
791 after the null byte, or at the next character after the end of
793 limit
= bufptr
+ nfetch
;
794 while (bufptr
< limit
)
798 if (bufptr
[-1] == '\0')
802 } while (errcode
== 0 /* no error */
803 && bufsize
< fetchlimit
/* no overrun */
804 && !(len
== 0 && *(bufptr
- 1) == '\0')); /* no null term */
806 /* bufptr and addr now point immediately beyond the last byte which we
807 consider part of the string (including a '\0' which ends the string). */
809 /* We now have either successfully filled the buffer to fetchlimit, or
810 terminated early due to an error or finding a null byte when LEN is
813 if (len
== 0 && bufptr
> buffer
&& *(bufptr
- 1) != '\0')
815 /* We didn't find a null terminator we were looking for. Attempt
816 to peek at the next character. If not successful, or it is not
817 a null byte, then force ellipsis to be printed. */
818 if (target_read_memory (addr
, &peekchar
, 1) != 0 || peekchar
!= '\0')
823 else if ((len
!= 0 && errcode
!= 0) || (len
> bufptr
- buffer
))
825 /* Getting an error when we have a requested length, or fetching less
826 than the number of characters actually requested, always make us
833 /* If we get an error before fetching anything, don't print a string.
834 But if we fetch something and then get an error, print the string
835 and then the error message. */
836 if (errcode
== 0 || bufptr
> buffer
)
840 fputs_filtered (" ", stream
);
842 LA_PRINT_STRING (stream
, buffer
, bufptr
- buffer
, force_ellipsis
);
849 fprintf_filtered (stream
, " <Address ");
850 print_address_numeric (addr
, stream
);
851 fprintf_filtered (stream
, " out of bounds>");
855 fprintf_filtered (stream
, " <Error reading address ");
856 print_address_numeric (addr
, stream
);
857 fprintf_filtered (stream
, ": %s>", safe_strerror (errcode
));
861 do_cleanups (old_chain
);
862 return (bufptr
- buffer
);
866 /* Validate an input or output radix setting, and make sure the user
867 knows what they really did here. Radix setting is confusing, e.g.
868 setting the input radix to "10" never changes it! */
872 set_input_radix (args
, from_tty
, c
)
875 struct cmd_list_element
*c
;
877 set_input_radix_1 (from_tty
, *(unsigned *)c
->var
);
882 set_input_radix_1 (from_tty
, radix
)
886 /* We don't currently disallow any input radix except 0 or 1, which don't
887 make any mathematical sense. In theory, we can deal with any input
888 radix greater than 1, even if we don't have unique digits for every
889 value from 0 to radix-1, but in practice we lose on large radix values.
890 We should either fix the lossage or restrict the radix range more.
895 error ("Nonsense input radix ``decimal %u''; input radix unchanged.",
901 printf_filtered ("Input radix now set to decimal %u, hex %x, octal %o.\n",
902 radix
, radix
, radix
);
908 set_output_radix (args
, from_tty
, c
)
911 struct cmd_list_element
*c
;
913 set_output_radix_1 (from_tty
, *(unsigned *)c
->var
);
917 set_output_radix_1 (from_tty
, radix
)
921 /* Validate the radix and disallow ones that we aren't prepared to
922 handle correctly, leaving the radix unchanged. */
926 output_format
= 'x'; /* hex */
929 output_format
= 0; /* decimal */
932 output_format
= 'o'; /* octal */
935 error ("Unsupported output radix ``decimal %u''; output radix unchanged.",
938 output_radix
= radix
;
941 printf_filtered ("Output radix now set to decimal %u, hex %x, octal %o.\n",
942 radix
, radix
, radix
);
946 /* Set both the input and output radix at once. Try to set the output radix
947 first, since it has the most restrictive range. An radix that is valid as
948 an output radix is also valid as an input radix.
950 It may be useful to have an unusual input radix. If the user wishes to
951 set an input radix that is not valid as an output radix, he needs to use
952 the 'set input-radix' command. */
955 set_radix (arg
, from_tty
)
961 radix
= (arg
== NULL
) ? 10 : parse_and_eval_address (arg
);
962 set_output_radix_1 (0, radix
);
963 set_input_radix_1 (0, radix
);
966 printf_filtered ("Input and output radices now set to decimal %u, hex %x, octal %o.\n",
967 radix
, radix
, radix
);
971 /* Show both the input and output radices. */
975 show_radix (arg
, from_tty
)
981 if (input_radix
== output_radix
)
983 printf_filtered ("Input and output radices set to decimal %u, hex %x, octal %o.\n",
984 input_radix
, input_radix
, input_radix
);
988 printf_filtered ("Input radix set to decimal %u, hex %x, octal %o.\n",
989 input_radix
, input_radix
, input_radix
);
990 printf_filtered ("Output radix set to decimal %u, hex %x, octal %o.\n",
991 output_radix
, output_radix
, output_radix
);
999 set_print (arg
, from_tty
)
1004 "\"set print\" must be followed by the name of a print subcommand.\n");
1005 help_list (setprintlist
, "set print ", -1, gdb_stdout
);
1010 show_print (args
, from_tty
)
1014 cmd_show_list (showprintlist
, from_tty
, "");
1018 _initialize_valprint ()
1020 struct cmd_list_element
*c
;
1022 add_prefix_cmd ("print", no_class
, set_print
,
1023 "Generic command for setting how things print.",
1024 &setprintlist
, "set print ", 0, &setlist
);
1025 add_alias_cmd ("p", "print", no_class
, 1, &setlist
);
1026 /* prefer set print to set prompt */
1027 add_alias_cmd ("pr", "print", no_class
, 1, &setlist
);
1029 add_prefix_cmd ("print", no_class
, show_print
,
1030 "Generic command for showing print settings.",
1031 &showprintlist
, "show print ", 0, &showlist
);
1032 add_alias_cmd ("p", "print", no_class
, 1, &showlist
);
1033 add_alias_cmd ("pr", "print", no_class
, 1, &showlist
);
1036 (add_set_cmd ("elements", no_class
, var_uinteger
, (char *)&print_max
,
1037 "Set limit on string chars or array elements to print.\n\
1038 \"set print elements 0\" causes there to be no limit.",
1043 (add_set_cmd ("repeats", no_class
, var_uinteger
,
1044 (char *)&repeat_count_threshold
,
1045 "Set threshold for repeated print elements.\n\
1046 \"set print repeats 0\" causes all elements to be individually printed.",
1051 (add_set_cmd ("pretty", class_support
, var_boolean
,
1052 (char *)&prettyprint_structs
,
1053 "Set prettyprinting of structures.",
1058 (add_set_cmd ("union", class_support
, var_boolean
, (char *)&unionprint
,
1059 "Set printing of unions interior to structures.",
1064 (add_set_cmd ("array", class_support
, var_boolean
,
1065 (char *)&prettyprint_arrays
,
1066 "Set prettyprinting of arrays.",
1071 (add_set_cmd ("address", class_support
, var_boolean
, (char *)&addressprint
,
1072 "Set printing of addresses.",
1076 c
= add_set_cmd ("input-radix", class_support
, var_uinteger
,
1077 (char *)&input_radix
,
1078 "Set default input radix for entering numbers.",
1080 add_show_from_set (c
, &showlist
);
1081 c
->function
.sfunc
= set_input_radix
;
1083 c
= add_set_cmd ("output-radix", class_support
, var_uinteger
,
1084 (char *)&output_radix
,
1085 "Set default output radix for printing of values.",
1087 add_show_from_set (c
, &showlist
);
1088 c
->function
.sfunc
= set_output_radix
;
1090 /* The "set radix" and "show radix" commands are special in that they are
1091 like normal set and show commands but allow two normally independent
1092 variables to be either set or shown with a single command. So the
1093 usual add_set_cmd() and add_show_from_set() commands aren't really
1095 add_cmd ("radix", class_support
, set_radix
,
1096 "Set default input and output number radices.\n\
1097 Use 'set input-radix' or 'set output-radix' to independently set each.\n\
1098 Without an argument, sets both radices back to the default value of 10.",
1100 add_cmd ("radix", class_support
, show_radix
,
1101 "Show the default input and output number radices.\n\
1102 Use 'show input-radix' or 'show output-radix' to independently show each.",
1105 /* Give people the defaults which they are used to. */
1106 prettyprint_structs
= 0;
1107 prettyprint_arrays
= 0;
1110 print_max
= PRINT_MAX_DEFAULT
;