1 /* Print values for GDB, the GNU debugger.
3 Copyright (C) 1986-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "gdb_string.h"
31 #include "floatformat.h"
33 #include "exceptions.h"
35 #include "python/python.h"
37 #include "gdb_obstack.h"
43 /* Maximum number of wchars returned from wchar_iterate. */
46 /* A convenience macro to compute the size of a wchar_t buffer containing X
48 #define WCHAR_BUFLEN(X) ((X) * sizeof (gdb_wchar_t))
50 /* Character buffer size saved while iterating over wchars. */
51 #define WCHAR_BUFLEN_MAX WCHAR_BUFLEN (MAX_WCHARS)
53 /* A structure to encapsulate state information from iterated
54 character conversions. */
55 struct converted_character
57 /* The number of characters converted. */
60 /* The result of the conversion. See charset.h for more. */
61 enum wchar_iterate_result result;
63 /* The (saved) converted character(s). */
64 gdb_wchar_t chars[WCHAR_BUFLEN_MAX];
66 /* The first converted target byte. */
69 /* The number of bytes converted. */
72 /* How many times this character(s) is repeated. */
76 typedef struct converted_character converted_character_d;
77 DEF_VEC_O (converted_character_d);
80 /* Prototypes for local functions */
82 static int partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
83 int len, int *errnoptr);
85 static void show_print (char *, int);
87 static void set_print (char *, int);
89 static void set_radix (char *, int);
91 static void show_radix (char *, int);
93 static void set_input_radix (char *, int, struct cmd_list_element *);
95 static void set_input_radix_1 (int, unsigned);
97 static void set_output_radix (char *, int, struct cmd_list_element *);
99 static void set_output_radix_1 (int, unsigned);
101 void _initialize_valprint (void);
103 #define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */
105 struct value_print_options user_print_options =
107 Val_prettyformat_default, /* prettyformat */
108 0, /* prettyformat_arrays */
109 0, /* prettyformat_structs */
112 1, /* addressprint */
114 PRINT_MAX_DEFAULT, /* print_max */
115 10, /* repeat_count_threshold */
116 0, /* output_format */
118 0, /* stop_print_at_null */
119 0, /* print_array_indexes */
121 1, /* static_field_print */
122 1, /* pascal_static_field_print */
128 /* Initialize *OPTS to be a copy of the user print options. */
130 get_user_print_options (struct value_print_options *opts)
132 *opts = user_print_options;
135 /* Initialize *OPTS to be a copy of the user print options, but with
136 pretty-formatting disabled. */
138 get_no_prettyformat_print_options (struct value_print_options *opts)
140 *opts = user_print_options;
141 opts->prettyformat = Val_no_prettyformat;
144 /* Initialize *OPTS to be a copy of the user print options, but using
145 FORMAT as the formatting option. */
147 get_formatted_print_options (struct value_print_options *opts,
150 *opts = user_print_options;
151 opts->format = format;
155 show_print_max (struct ui_file *file, int from_tty,
156 struct cmd_list_element *c, const char *value)
158 fprintf_filtered (file,
159 _("Limit on string chars or array "
160 "elements to print is %s.\n"),
165 /* Default input and output radixes, and output format letter. */
167 unsigned input_radix = 10;
169 show_input_radix (struct ui_file *file, int from_tty,
170 struct cmd_list_element *c, const char *value)
172 fprintf_filtered (file,
173 _("Default input radix for entering numbers is %s.\n"),
177 unsigned output_radix = 10;
179 show_output_radix (struct ui_file *file, int from_tty,
180 struct cmd_list_element *c, const char *value)
182 fprintf_filtered (file,
183 _("Default output radix for printing of values is %s.\n"),
187 /* By default we print arrays without printing the index of each element in
188 the array. This behavior can be changed by setting PRINT_ARRAY_INDEXES. */
191 show_print_array_indexes (struct ui_file *file, int from_tty,
192 struct cmd_list_element *c, const char *value)
194 fprintf_filtered (file, _("Printing of array indexes is %s.\n"), value);
197 /* Print repeat counts if there are more than this many repetitions of an
198 element in an array. Referenced by the low level language dependent
202 show_repeat_count_threshold (struct ui_file *file, int from_tty,
203 struct cmd_list_element *c, const char *value)
205 fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"),
209 /* If nonzero, stops printing of char arrays at first null. */
212 show_stop_print_at_null (struct ui_file *file, int from_tty,
213 struct cmd_list_element *c, const char *value)
215 fprintf_filtered (file,
216 _("Printing of char arrays to stop "
217 "at first null char is %s.\n"),
221 /* Controls pretty printing of structures. */
224 show_prettyformat_structs (struct ui_file *file, int from_tty,
225 struct cmd_list_element *c, const char *value)
227 fprintf_filtered (file, _("Pretty formatting of structures is %s.\n"), value);
230 /* Controls pretty printing of arrays. */
233 show_prettyformat_arrays (struct ui_file *file, int from_tty,
234 struct cmd_list_element *c, const char *value)
236 fprintf_filtered (file, _("Pretty formatting of arrays is %s.\n"), value);
239 /* If nonzero, causes unions inside structures or other unions to be
243 show_unionprint (struct ui_file *file, int from_tty,
244 struct cmd_list_element *c, const char *value)
246 fprintf_filtered (file,
247 _("Printing of unions interior to structures is %s.\n"),
251 /* If nonzero, causes machine addresses to be printed in certain contexts. */
254 show_addressprint (struct ui_file *file, int from_tty,
255 struct cmd_list_element *c, const char *value)
257 fprintf_filtered (file, _("Printing of addresses is %s.\n"), value);
261 show_symbol_print (struct ui_file *file, int from_tty,
262 struct cmd_list_element *c, const char *value)
264 fprintf_filtered (file,
265 _("Printing of symbols when printing pointers is %s.\n"),
271 /* A helper function for val_print. When printing in "summary" mode,
272 we want to print scalar arguments, but not aggregate arguments.
273 This function distinguishes between the two. */
276 scalar_type_p (struct type *type)
278 CHECK_TYPEDEF (type);
279 while (TYPE_CODE (type) == TYPE_CODE_REF)
281 type = TYPE_TARGET_TYPE (type);
282 CHECK_TYPEDEF (type);
284 switch (TYPE_CODE (type))
286 case TYPE_CODE_ARRAY:
287 case TYPE_CODE_STRUCT:
288 case TYPE_CODE_UNION:
290 case TYPE_CODE_STRING:
297 /* See its definition in value.h. */
300 valprint_check_validity (struct ui_file *stream,
303 const struct value *val)
305 CHECK_TYPEDEF (type);
307 if (TYPE_CODE (type) != TYPE_CODE_UNION
308 && TYPE_CODE (type) != TYPE_CODE_STRUCT
309 && TYPE_CODE (type) != TYPE_CODE_ARRAY)
311 if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
312 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
314 val_print_optimized_out (stream);
318 if (value_bits_synthetic_pointer (val, TARGET_CHAR_BIT * embedded_offset,
319 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
321 fputs_filtered (_("<synthetic pointer>"), stream);
325 if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
327 val_print_unavailable (stream);
336 val_print_optimized_out (struct ui_file *stream)
338 fprintf_filtered (stream, _("<optimized out>"));
342 val_print_unavailable (struct ui_file *stream)
344 fprintf_filtered (stream, _("<unavailable>"));
348 val_print_invalid_address (struct ui_file *stream)
350 fprintf_filtered (stream, _("<invalid address>"));
353 /* A generic val_print that is suitable for use by language
354 implementations of the la_val_print method. This function can
355 handle most type codes, though not all, notably exception
356 TYPE_CODE_UNION and TYPE_CODE_STRUCT, which must be implemented by
359 Most arguments are as to val_print.
361 The additional DECORATIONS argument can be used to customize the
362 output in some small, language-specific ways. */
365 generic_val_print (struct type *type, const gdb_byte *valaddr,
366 int embedded_offset, CORE_ADDR address,
367 struct ui_file *stream, int recurse,
368 const struct value *original_value,
369 const struct value_print_options *options,
370 const struct generic_val_print_decorations *decorations)
372 struct gdbarch *gdbarch = get_type_arch (type);
373 unsigned int i = 0; /* Number of characters printed. */
375 struct type *elttype, *unresolved_elttype;
376 struct type *unresolved_type = type;
380 CHECK_TYPEDEF (type);
381 switch (TYPE_CODE (type))
383 case TYPE_CODE_ARRAY:
384 unresolved_elttype = TYPE_TARGET_TYPE (type);
385 elttype = check_typedef (unresolved_elttype);
386 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
388 LONGEST low_bound, high_bound;
390 if (!get_array_bounds (type, &low_bound, &high_bound))
391 error (_("Could not determine the array high bound"));
393 if (options->prettyformat_arrays)
395 print_spaces_filtered (2 + 2 * recurse, stream);
398 fprintf_filtered (stream, "{");
399 val_print_array_elements (type, valaddr, embedded_offset,
401 recurse, original_value, options, 0);
402 fprintf_filtered (stream, "}");
405 /* Array of unspecified length: treat like pointer to first
407 addr = address + embedded_offset;
408 goto print_unpacked_pointer;
410 case TYPE_CODE_MEMBERPTR:
411 val_print_scalar_formatted (type, valaddr, embedded_offset,
412 original_value, options, 0, stream);
416 if (options->format && options->format != 's')
418 val_print_scalar_formatted (type, valaddr, embedded_offset,
419 original_value, options, 0, stream);
422 unresolved_elttype = TYPE_TARGET_TYPE (type);
423 elttype = check_typedef (unresolved_elttype);
425 addr = unpack_pointer (type, valaddr + embedded_offset);
426 print_unpacked_pointer:
428 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
430 /* Try to print what function it points to. */
431 print_function_pointer_address (options, gdbarch, addr, stream);
435 if (options->symbol_print)
436 print_address_demangle (options, gdbarch, addr, stream, demangle);
437 else if (options->addressprint)
438 fputs_filtered (paddress (gdbarch, addr), stream);
443 elttype = check_typedef (TYPE_TARGET_TYPE (type));
444 if (options->addressprint)
447 = extract_typed_address (valaddr + embedded_offset, type);
449 fprintf_filtered (stream, "@");
450 fputs_filtered (paddress (gdbarch, addr), stream);
451 if (options->deref_ref)
452 fputs_filtered (": ", stream);
454 /* De-reference the reference. */
455 if (options->deref_ref)
457 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
459 struct value *deref_val;
461 deref_val = coerce_ref_if_computed (original_value);
462 if (deref_val != NULL)
464 /* More complicated computed references are not supported. */
465 gdb_assert (embedded_offset == 0);
468 deref_val = value_at (TYPE_TARGET_TYPE (type),
469 unpack_pointer (type,
471 + embedded_offset)));
473 common_val_print (deref_val, stream, recurse, options,
477 fputs_filtered ("???", stream);
484 val_print_scalar_formatted (type, valaddr, embedded_offset,
485 original_value, options, 0, stream);
488 len = TYPE_NFIELDS (type);
489 val = unpack_long (type, valaddr + embedded_offset);
490 for (i = 0; i < len; i++)
493 if (val == TYPE_FIELD_ENUMVAL (type, i))
500 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
502 else if (TYPE_FLAG_ENUM (type))
506 /* We have a "flag" enum, so we try to decompose it into
507 pieces as appropriate. A flag enum has disjoint
508 constants by definition. */
509 fputs_filtered ("(", stream);
510 for (i = 0; i < len; ++i)
514 if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
517 fputs_filtered (" | ", stream);
520 val &= ~TYPE_FIELD_ENUMVAL (type, i);
521 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
525 if (first || val != 0)
528 fputs_filtered (" | ", stream);
529 fputs_filtered ("unknown: ", stream);
530 print_longest (stream, 'd', 0, val);
533 fputs_filtered (")", stream);
536 print_longest (stream, 'd', 0, val);
539 case TYPE_CODE_FLAGS:
541 val_print_scalar_formatted (type, valaddr, embedded_offset,
542 original_value, options, 0, stream);
544 val_print_type_code_flags (type, valaddr + embedded_offset,
549 case TYPE_CODE_METHOD:
552 val_print_scalar_formatted (type, valaddr, embedded_offset,
553 original_value, options, 0, stream);
556 /* FIXME, we should consider, at least for ANSI C language,
557 eliminating the distinction made between FUNCs and POINTERs
559 fprintf_filtered (stream, "{");
560 type_print (type, "", stream, -1);
561 fprintf_filtered (stream, "} ");
562 /* Try to print what function it points to, and its address. */
563 print_address_demangle (options, gdbarch, address, stream, demangle);
567 if (options->format || options->output_format)
569 struct value_print_options opts = *options;
570 opts.format = (options->format ? options->format
571 : options->output_format);
572 val_print_scalar_formatted (type, valaddr, embedded_offset,
573 original_value, &opts, 0, stream);
577 val = unpack_long (type, valaddr + embedded_offset);
579 fputs_filtered (decorations->false_name, stream);
581 fputs_filtered (decorations->true_name, stream);
583 print_longest (stream, 'd', 0, val);
587 case TYPE_CODE_RANGE:
588 /* FIXME: create_range_type does not set the unsigned bit in a
589 range type (I think it probably should copy it from the
590 target type), so we won't print values which are too large to
591 fit in a signed integer correctly. */
592 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
593 print with the target type, though, because the size of our
594 type and the target type might differ). */
599 if (options->format || options->output_format)
601 struct value_print_options opts = *options;
603 opts.format = (options->format ? options->format
604 : options->output_format);
605 val_print_scalar_formatted (type, valaddr, embedded_offset,
606 original_value, &opts, 0, stream);
609 val_print_type_code_int (type, valaddr + embedded_offset, stream);
613 if (options->format || options->output_format)
615 struct value_print_options opts = *options;
617 opts.format = (options->format ? options->format
618 : options->output_format);
619 val_print_scalar_formatted (type, valaddr, embedded_offset,
620 original_value, &opts, 0, stream);
624 val = unpack_long (type, valaddr + embedded_offset);
625 if (TYPE_UNSIGNED (type))
626 fprintf_filtered (stream, "%u", (unsigned int) val);
628 fprintf_filtered (stream, "%d", (int) val);
629 fputs_filtered (" ", stream);
630 LA_PRINT_CHAR (val, unresolved_type, stream);
637 val_print_scalar_formatted (type, valaddr, embedded_offset,
638 original_value, options, 0, stream);
642 print_floating (valaddr + embedded_offset, type, stream);
646 case TYPE_CODE_DECFLOAT:
648 val_print_scalar_formatted (type, valaddr, embedded_offset,
649 original_value, options, 0, stream);
651 print_decimal_floating (valaddr + embedded_offset,
656 fputs_filtered (decorations->void_name, stream);
659 case TYPE_CODE_ERROR:
660 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
663 case TYPE_CODE_UNDEF:
664 /* This happens (without TYPE_FLAG_STUB set) on systems which
665 don't use dbx xrefs (NO_DBX_XREFS in gcc) if a file has a
666 "struct foo *bar" and no complete type for struct foo in that
668 fprintf_filtered (stream, _("<incomplete type>"));
671 case TYPE_CODE_COMPLEX:
672 fprintf_filtered (stream, "%s", decorations->complex_prefix);
674 val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
675 valaddr, embedded_offset,
676 original_value, options, 0, stream);
678 print_floating (valaddr + embedded_offset,
679 TYPE_TARGET_TYPE (type),
681 fprintf_filtered (stream, "%s", decorations->complex_infix);
683 val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
686 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
690 print_floating (valaddr + embedded_offset
691 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
692 TYPE_TARGET_TYPE (type),
694 fprintf_filtered (stream, "%s", decorations->complex_suffix);
697 case TYPE_CODE_UNION:
698 case TYPE_CODE_STRUCT:
699 case TYPE_CODE_METHODPTR:
701 error (_("Unhandled type code %d in symbol table."),
707 /* Print using the given LANGUAGE the data of type TYPE located at
708 VALADDR + EMBEDDED_OFFSET (within GDB), which came from the
709 inferior at address ADDRESS + EMBEDDED_OFFSET, onto stdio stream
710 STREAM according to OPTIONS. VAL is the whole object that came
711 from ADDRESS. VALADDR must point to the head of VAL's contents
714 The language printers will pass down an adjusted EMBEDDED_OFFSET to
715 further helper subroutines as subfields of TYPE are printed. In
716 such cases, VALADDR is passed down unadjusted, as well as VAL, so
717 that VAL can be queried for metadata about the contents data being
718 printed, using EMBEDDED_OFFSET as an offset into VAL's contents
719 buffer. For example: "has this field been optimized out", or "I'm
720 printing an object while inspecting a traceframe; has this
721 particular piece of data been collected?".
723 RECURSE indicates the amount of indentation to supply before
724 continuation lines; this amount is roughly twice the value of
728 val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
729 CORE_ADDR address, struct ui_file *stream, int recurse,
730 const struct value *val,
731 const struct value_print_options *options,
732 const struct language_defn *language)
734 volatile struct gdb_exception except;
736 struct value_print_options local_opts = *options;
737 struct type *real_type = check_typedef (type);
739 if (local_opts.prettyformat == Val_prettyformat_default)
740 local_opts.prettyformat = (local_opts.prettyformat_structs
741 ? Val_prettyformat : Val_no_prettyformat);
745 /* Ensure that the type is complete and not just a stub. If the type is
746 only a stub and we can't find and substitute its complete type, then
747 print appropriate string and return. */
749 if (TYPE_STUB (real_type))
751 fprintf_filtered (stream, _("<incomplete type>"));
756 if (!valprint_check_validity (stream, real_type, embedded_offset, val))
761 ret = apply_val_pretty_printer (type, valaddr, embedded_offset,
762 address, stream, recurse,
763 val, options, language);
768 /* Handle summary mode. If the value is a scalar, print it;
769 otherwise, print an ellipsis. */
770 if (options->summary && !scalar_type_p (type))
772 fprintf_filtered (stream, "...");
776 TRY_CATCH (except, RETURN_MASK_ERROR)
778 language->la_val_print (type, valaddr, embedded_offset, address,
779 stream, recurse, val,
782 if (except.reason < 0)
783 fprintf_filtered (stream, _("<error reading variable>"));
786 /* Check whether the value VAL is printable. Return 1 if it is;
787 return 0 and print an appropriate error message to STREAM according to
788 OPTIONS if it is not. */
791 value_check_printable (struct value *val, struct ui_file *stream,
792 const struct value_print_options *options)
796 fprintf_filtered (stream, _("<address of value unknown>"));
800 if (value_entirely_optimized_out (val))
802 if (options->summary && !scalar_type_p (value_type (val)))
803 fprintf_filtered (stream, "...");
805 val_print_optimized_out (stream);
809 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION)
811 fprintf_filtered (stream, _("<internal function %s>"),
812 value_internal_function_name (val));
819 /* Print using the given LANGUAGE the value VAL onto stream STREAM according
822 This is a preferable interface to val_print, above, because it uses
823 GDB's value mechanism. */
826 common_val_print (struct value *val, struct ui_file *stream, int recurse,
827 const struct value_print_options *options,
828 const struct language_defn *language)
830 if (!value_check_printable (val, stream, options))
833 if (language->la_language == language_ada)
834 /* The value might have a dynamic type, which would cause trouble
835 below when trying to extract the value contents (since the value
836 size is determined from the type size which is unknown). So
837 get a fixed representation of our value. */
838 val = ada_to_fixed_value (val);
840 val_print (value_type (val), value_contents_for_printing (val),
841 value_embedded_offset (val), value_address (val),
843 val, options, language);
846 /* Print on stream STREAM the value VAL according to OPTIONS. The value
847 is printed using the current_language syntax. */
850 value_print (struct value *val, struct ui_file *stream,
851 const struct value_print_options *options)
853 if (!value_check_printable (val, stream, options))
858 int r = apply_val_pretty_printer (value_type (val),
859 value_contents_for_printing (val),
860 value_embedded_offset (val),
863 val, options, current_language);
869 LA_VALUE_PRINT (val, stream, options);
872 /* Called by various <lang>_val_print routines to print
873 TYPE_CODE_INT's. TYPE is the type. VALADDR is the address of the
874 value. STREAM is where to print the value. */
877 val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
878 struct ui_file *stream)
880 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
882 if (TYPE_LENGTH (type) > sizeof (LONGEST))
886 if (TYPE_UNSIGNED (type)
887 && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type),
890 print_longest (stream, 'u', 0, val);
894 /* Signed, or we couldn't turn an unsigned value into a
895 LONGEST. For signed values, one could assume two's
896 complement (a reasonable assumption, I think) and do
898 print_hex_chars (stream, (unsigned char *) valaddr,
899 TYPE_LENGTH (type), byte_order);
904 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0,
905 unpack_long (type, valaddr));
910 val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
911 struct ui_file *stream)
913 ULONGEST val = unpack_long (type, valaddr);
914 int bitpos, nfields = TYPE_NFIELDS (type);
916 fputs_filtered ("[ ", stream);
917 for (bitpos = 0; bitpos < nfields; bitpos++)
919 if (TYPE_FIELD_BITPOS (type, bitpos) != -1
920 && (val & ((ULONGEST)1 << bitpos)))
922 if (TYPE_FIELD_NAME (type, bitpos))
923 fprintf_filtered (stream, "%s ", TYPE_FIELD_NAME (type, bitpos));
925 fprintf_filtered (stream, "#%d ", bitpos);
928 fputs_filtered ("]", stream);
931 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
932 according to OPTIONS and SIZE on STREAM. Format i is not supported
935 This is how the elements of an array or structure are printed
939 val_print_scalar_formatted (struct type *type,
940 const gdb_byte *valaddr, int embedded_offset,
941 const struct value *val,
942 const struct value_print_options *options,
944 struct ui_file *stream)
946 gdb_assert (val != NULL);
947 gdb_assert (valaddr == value_contents_for_printing_const (val));
949 /* If we get here with a string format, try again without it. Go
950 all the way back to the language printers, which may call us
952 if (options->format == 's')
954 struct value_print_options opts = *options;
957 val_print (type, valaddr, embedded_offset, 0, stream, 0, val, &opts,
962 /* A scalar object that does not have all bits available can't be
963 printed, because all bits contribute to its representation. */
964 if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
965 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
966 val_print_optimized_out (stream);
967 else if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
968 val_print_unavailable (stream);
970 print_scalar_formatted (valaddr + embedded_offset, type,
971 options, size, stream);
974 /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
975 The raison d'etre of this function is to consolidate printing of
976 LONG_LONG's into this one function. The format chars b,h,w,g are
977 from print_scalar_formatted(). Numbers are printed using C
980 USE_C_FORMAT means to use C format in all cases. Without it,
981 'o' and 'x' format do not include the standard C radix prefix
984 Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL
985 and was intended to request formating according to the current
986 language and would be used for most integers that GDB prints. The
987 exceptional cases were things like protocols where the format of
988 the integer is a protocol thing, not a user-visible thing). The
989 parameter remains to preserve the information of what things might
990 be printed with language-specific format, should we ever resurrect
994 print_longest (struct ui_file *stream, int format, int use_c_format,
1002 val = int_string (val_long, 10, 1, 0, 1); break;
1004 val = int_string (val_long, 10, 0, 0, 1); break;
1006 val = int_string (val_long, 16, 0, 0, use_c_format); break;
1008 val = int_string (val_long, 16, 0, 2, 1); break;
1010 val = int_string (val_long, 16, 0, 4, 1); break;
1012 val = int_string (val_long, 16, 0, 8, 1); break;
1014 val = int_string (val_long, 16, 0, 16, 1); break;
1017 val = int_string (val_long, 8, 0, 0, use_c_format); break;
1019 internal_error (__FILE__, __LINE__,
1020 _("failed internal consistency check"));
1022 fputs_filtered (val, stream);
1025 /* This used to be a macro, but I don't think it is called often enough
1026 to merit such treatment. */
1027 /* Convert a LONGEST to an int. This is used in contexts (e.g. number of
1028 arguments to a function, number in a value history, register number, etc.)
1029 where the value must not be larger than can fit in an int. */
1032 longest_to_int (LONGEST arg)
1034 /* Let the compiler do the work. */
1035 int rtnval = (int) arg;
1037 /* Check for overflows or underflows. */
1038 if (sizeof (LONGEST) > sizeof (int))
1042 error (_("Value out of range."));
1048 /* Print a floating point value of type TYPE (not always a
1049 TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM. */
1052 print_floating (const gdb_byte *valaddr, struct type *type,
1053 struct ui_file *stream)
1057 const struct floatformat *fmt = NULL;
1058 unsigned len = TYPE_LENGTH (type);
1059 enum float_kind kind;
1061 /* If it is a floating-point, check for obvious problems. */
1062 if (TYPE_CODE (type) == TYPE_CODE_FLT)
1063 fmt = floatformat_from_type (type);
1066 kind = floatformat_classify (fmt, valaddr);
1067 if (kind == float_nan)
1069 if (floatformat_is_negative (fmt, valaddr))
1070 fprintf_filtered (stream, "-");
1071 fprintf_filtered (stream, "nan(");
1072 fputs_filtered ("0x", stream);
1073 fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
1074 fprintf_filtered (stream, ")");
1077 else if (kind == float_infinite)
1079 if (floatformat_is_negative (fmt, valaddr))
1080 fputs_filtered ("-", stream);
1081 fputs_filtered ("inf", stream);
1086 /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating()
1087 isn't necessarily a TYPE_CODE_FLT. Consequently, unpack_double
1088 needs to be used as that takes care of any necessary type
1089 conversions. Such conversions are of course direct to DOUBLEST
1090 and disregard any possible target floating point limitations.
1091 For instance, a u64 would be converted and displayed exactly on a
1092 host with 80 bit DOUBLEST but with loss of information on a host
1093 with 64 bit DOUBLEST. */
1095 doub = unpack_double (type, valaddr, &inv);
1098 fprintf_filtered (stream, "<invalid float value>");
1102 /* FIXME: kettenis/2001-01-20: The following code makes too much
1103 assumptions about the host and target floating point format. */
1105 /* NOTE: cagney/2002-02-03: Since the TYPE of what was passed in may
1106 not necessarily be a TYPE_CODE_FLT, the below ignores that and
1107 instead uses the type's length to determine the precision of the
1108 floating-point value being printed. */
1110 if (len < sizeof (double))
1111 fprintf_filtered (stream, "%.9g", (double) doub);
1112 else if (len == sizeof (double))
1113 fprintf_filtered (stream, "%.17g", (double) doub);
1115 #ifdef PRINTF_HAS_LONG_DOUBLE
1116 fprintf_filtered (stream, "%.35Lg", doub);
1118 /* This at least wins with values that are representable as
1120 fprintf_filtered (stream, "%.17g", (double) doub);
1125 print_decimal_floating (const gdb_byte *valaddr, struct type *type,
1126 struct ui_file *stream)
1128 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
1129 char decstr[MAX_DECIMAL_STRING];
1130 unsigned len = TYPE_LENGTH (type);
1132 decimal_to_string (valaddr, len, byte_order, decstr);
1133 fputs_filtered (decstr, stream);
1138 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
1139 unsigned len, enum bfd_endian byte_order)
1142 #define BITS_IN_BYTES 8
1148 /* Declared "int" so it will be signed.
1149 This ensures that right shift will shift in zeros. */
1151 const int mask = 0x080;
1153 /* FIXME: We should be not printing leading zeroes in most cases. */
1155 if (byte_order == BFD_ENDIAN_BIG)
1161 /* Every byte has 8 binary characters; peel off
1162 and print from the MSB end. */
1164 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
1166 if (*p & (mask >> i))
1171 fprintf_filtered (stream, "%1d", b);
1177 for (p = valaddr + len - 1;
1181 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
1183 if (*p & (mask >> i))
1188 fprintf_filtered (stream, "%1d", b);
1194 /* VALADDR points to an integer of LEN bytes.
1195 Print it in octal on stream or format it in buf. */
1198 print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
1199 unsigned len, enum bfd_endian byte_order)
1202 unsigned char octa1, octa2, octa3, carry;
1205 /* FIXME: We should be not printing leading zeroes in most cases. */
1208 /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track
1209 * the extra bits, which cycle every three bytes:
1211 * Byte side: 0 1 2 3
1213 * bit number 123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 |
1215 * Octal side: 0 1 carry 3 4 carry ...
1217 * Cycle number: 0 1 2
1219 * But of course we are printing from the high side, so we have to
1220 * figure out where in the cycle we are so that we end up with no
1221 * left over bits at the end.
1223 #define BITS_IN_OCTAL 3
1224 #define HIGH_ZERO 0340
1225 #define LOW_ZERO 0016
1226 #define CARRY_ZERO 0003
1227 #define HIGH_ONE 0200
1228 #define MID_ONE 0160
1229 #define LOW_ONE 0016
1230 #define CARRY_ONE 0001
1231 #define HIGH_TWO 0300
1232 #define MID_TWO 0070
1233 #define LOW_TWO 0007
1235 /* For 32 we start in cycle 2, with two bits and one bit carry;
1236 for 64 in cycle in cycle 1, with one bit and a two bit carry. */
1238 cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL;
1241 fputs_filtered ("0", stream);
1242 if (byte_order == BFD_ENDIAN_BIG)
1251 /* No carry in, carry out two bits. */
1253 octa1 = (HIGH_ZERO & *p) >> 5;
1254 octa2 = (LOW_ZERO & *p) >> 2;
1255 carry = (CARRY_ZERO & *p);
1256 fprintf_filtered (stream, "%o", octa1);
1257 fprintf_filtered (stream, "%o", octa2);
1261 /* Carry in two bits, carry out one bit. */
1263 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
1264 octa2 = (MID_ONE & *p) >> 4;
1265 octa3 = (LOW_ONE & *p) >> 1;
1266 carry = (CARRY_ONE & *p);
1267 fprintf_filtered (stream, "%o", octa1);
1268 fprintf_filtered (stream, "%o", octa2);
1269 fprintf_filtered (stream, "%o", octa3);
1273 /* Carry in one bit, no carry out. */
1275 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
1276 octa2 = (MID_TWO & *p) >> 3;
1277 octa3 = (LOW_TWO & *p);
1279 fprintf_filtered (stream, "%o", octa1);
1280 fprintf_filtered (stream, "%o", octa2);
1281 fprintf_filtered (stream, "%o", octa3);
1285 error (_("Internal error in octal conversion;"));
1289 cycle = cycle % BITS_IN_OCTAL;
1294 for (p = valaddr + len - 1;
1301 /* Carry out, no carry in */
1303 octa1 = (HIGH_ZERO & *p) >> 5;
1304 octa2 = (LOW_ZERO & *p) >> 2;
1305 carry = (CARRY_ZERO & *p);
1306 fprintf_filtered (stream, "%o", octa1);
1307 fprintf_filtered (stream, "%o", octa2);
1311 /* Carry in, carry out */
1313 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
1314 octa2 = (MID_ONE & *p) >> 4;
1315 octa3 = (LOW_ONE & *p) >> 1;
1316 carry = (CARRY_ONE & *p);
1317 fprintf_filtered (stream, "%o", octa1);
1318 fprintf_filtered (stream, "%o", octa2);
1319 fprintf_filtered (stream, "%o", octa3);
1323 /* Carry in, no carry out */
1325 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
1326 octa2 = (MID_TWO & *p) >> 3;
1327 octa3 = (LOW_TWO & *p);
1329 fprintf_filtered (stream, "%o", octa1);
1330 fprintf_filtered (stream, "%o", octa2);
1331 fprintf_filtered (stream, "%o", octa3);
1335 error (_("Internal error in octal conversion;"));
1339 cycle = cycle % BITS_IN_OCTAL;
1345 /* VALADDR points to an integer of LEN bytes.
1346 Print it in decimal on stream or format it in buf. */
1349 print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
1350 unsigned len, enum bfd_endian byte_order)
1353 #define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */
1354 #define CARRY_LEFT( x ) ((x) % TEN)
1355 #define SHIFT( x ) ((x) << 4)
1356 #define LOW_NIBBLE( x ) ( (x) & 0x00F)
1357 #define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
1360 unsigned char *digits;
1363 int i, j, decimal_digits;
1367 /* Base-ten number is less than twice as many digits
1368 as the base 16 number, which is 2 digits per byte. */
1370 decimal_len = len * 2 * 2;
1371 digits = xmalloc (decimal_len);
1373 for (i = 0; i < decimal_len; i++)
1378 /* Ok, we have an unknown number of bytes of data to be printed in
1381 * Given a hex number (in nibbles) as XYZ, we start by taking X and
1382 * decemalizing it as "x1 x2" in two decimal nibbles. Then we multiply
1383 * the nibbles by 16, add Y and re-decimalize. Repeat with Z.
1385 * The trick is that "digits" holds a base-10 number, but sometimes
1386 * the individual digits are > 10.
1388 * Outer loop is per nibble (hex digit) of input, from MSD end to
1391 decimal_digits = 0; /* Number of decimal digits so far */
1392 p = (byte_order == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1;
1394 while ((byte_order == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
1397 * Multiply current base-ten number by 16 in place.
1398 * Each digit was between 0 and 9, now is between
1401 for (j = 0; j < decimal_digits; j++)
1403 digits[j] = SHIFT (digits[j]);
1406 /* Take the next nibble off the input and add it to what
1407 * we've got in the LSB position. Bottom 'digit' is now
1408 * between 0 and 159.
1410 * "flip" is used to run this loop twice for each byte.
1414 /* Take top nibble. */
1416 digits[0] += HIGH_NIBBLE (*p);
1421 /* Take low nibble and bump our pointer "p". */
1423 digits[0] += LOW_NIBBLE (*p);
1424 if (byte_order == BFD_ENDIAN_BIG)
1431 /* Re-decimalize. We have to do this often enough
1432 * that we don't overflow, but once per nibble is
1433 * overkill. Easier this way, though. Note that the
1434 * carry is often larger than 10 (e.g. max initial
1435 * carry out of lowest nibble is 15, could bubble all
1436 * the way up greater than 10). So we have to do
1437 * the carrying beyond the last current digit.
1440 for (j = 0; j < decimal_len - 1; j++)
1444 /* "/" won't handle an unsigned char with
1445 * a value that if signed would be negative.
1446 * So extend to longword int via "dummy".
1449 carry = CARRY_OUT (dummy);
1450 digits[j] = CARRY_LEFT (dummy);
1452 if (j >= decimal_digits && carry == 0)
1455 * All higher digits are 0 and we
1456 * no longer have a carry.
1458 * Note: "j" is 0-based, "decimal_digits" is
1461 decimal_digits = j + 1;
1467 /* Ok, now "digits" is the decimal representation, with
1468 the "decimal_digits" actual digits. Print! */
1470 for (i = decimal_digits - 1; i >= 0; i--)
1472 fprintf_filtered (stream, "%1d", digits[i]);
1477 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
1480 print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
1481 unsigned len, enum bfd_endian byte_order)
1485 /* FIXME: We should be not printing leading zeroes in most cases. */
1487 fputs_filtered ("0x", stream);
1488 if (byte_order == BFD_ENDIAN_BIG)
1494 fprintf_filtered (stream, "%02x", *p);
1499 for (p = valaddr + len - 1;
1503 fprintf_filtered (stream, "%02x", *p);
1508 /* VALADDR points to a char integer of LEN bytes.
1509 Print it out in appropriate language form on stream.
1510 Omit any leading zero chars. */
1513 print_char_chars (struct ui_file *stream, struct type *type,
1514 const gdb_byte *valaddr,
1515 unsigned len, enum bfd_endian byte_order)
1519 if (byte_order == BFD_ENDIAN_BIG)
1522 while (p < valaddr + len - 1 && *p == 0)
1525 while (p < valaddr + len)
1527 LA_EMIT_CHAR (*p, type, stream, '\'');
1533 p = valaddr + len - 1;
1534 while (p > valaddr && *p == 0)
1537 while (p >= valaddr)
1539 LA_EMIT_CHAR (*p, type, stream, '\'');
1545 /* Print function pointer with inferior address ADDRESS onto stdio
1549 print_function_pointer_address (const struct value_print_options *options,
1550 struct gdbarch *gdbarch,
1552 struct ui_file *stream)
1555 = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
1558 /* If the function pointer is represented by a description, print
1559 the address of the description. */
1560 if (options->addressprint && func_addr != address)
1562 fputs_filtered ("@", stream);
1563 fputs_filtered (paddress (gdbarch, address), stream);
1564 fputs_filtered (": ", stream);
1566 print_address_demangle (options, gdbarch, func_addr, stream, demangle);
1570 /* Print on STREAM using the given OPTIONS the index for the element
1571 at INDEX of an array whose index type is INDEX_TYPE. */
1574 maybe_print_array_index (struct type *index_type, LONGEST index,
1575 struct ui_file *stream,
1576 const struct value_print_options *options)
1578 struct value *index_value;
1580 if (!options->print_array_indexes)
1583 index_value = value_from_longest (index_type, index);
1585 LA_PRINT_ARRAY_INDEX (index_value, stream, options);
1588 /* Called by various <lang>_val_print routines to print elements of an
1589 array in the form "<elem1>, <elem2>, <elem3>, ...".
1591 (FIXME?) Assumes array element separator is a comma, which is correct
1592 for all languages currently handled.
1593 (FIXME?) Some languages have a notation for repeated array elements,
1594 perhaps we should try to use that notation when appropriate. */
1597 val_print_array_elements (struct type *type,
1598 const gdb_byte *valaddr, int embedded_offset,
1599 CORE_ADDR address, struct ui_file *stream,
1601 const struct value *val,
1602 const struct value_print_options *options,
1605 unsigned int things_printed = 0;
1607 struct type *elttype, *index_type;
1609 /* Position of the array element we are examining to see
1610 whether it is repeated. */
1612 /* Number of repetitions we have detected so far. */
1614 LONGEST low_bound, high_bound;
1616 elttype = TYPE_TARGET_TYPE (type);
1617 eltlen = TYPE_LENGTH (check_typedef (elttype));
1618 index_type = TYPE_INDEX_TYPE (type);
1620 if (get_array_bounds (type, &low_bound, &high_bound))
1622 /* The array length should normally be HIGH_BOUND - LOW_BOUND + 1.
1623 But we have to be a little extra careful, because some languages
1624 such as Ada allow LOW_BOUND to be greater than HIGH_BOUND for
1625 empty arrays. In that situation, the array length is just zero,
1627 if (low_bound > high_bound)
1630 len = high_bound - low_bound + 1;
1634 warning (_("unable to get bounds of array, assuming null array"));
1639 annotate_array_section_begin (i, elttype);
1641 for (; i < len && things_printed < options->print_max; i++)
1645 if (options->prettyformat_arrays)
1647 fprintf_filtered (stream, ",\n");
1648 print_spaces_filtered (2 + 2 * recurse, stream);
1652 fprintf_filtered (stream, ", ");
1655 wrap_here (n_spaces (2 + 2 * recurse));
1656 maybe_print_array_index (index_type, i + low_bound,
1661 /* Only check for reps if repeat_count_threshold is not set to
1662 UINT_MAX (unlimited). */
1663 if (options->repeat_count_threshold < UINT_MAX)
1666 && value_available_contents_eq (val,
1667 embedded_offset + i * eltlen,
1678 if (reps > options->repeat_count_threshold)
1680 val_print (elttype, valaddr, embedded_offset + i * eltlen,
1681 address, stream, recurse + 1, val, options,
1683 annotate_elt_rep (reps);
1684 fprintf_filtered (stream, " <repeats %u times>", reps);
1685 annotate_elt_rep_end ();
1688 things_printed += options->repeat_count_threshold;
1692 val_print (elttype, valaddr, embedded_offset + i * eltlen,
1694 stream, recurse + 1, val, options, current_language);
1699 annotate_array_section_end ();
1702 fprintf_filtered (stream, "...");
1706 /* Read LEN bytes of target memory at address MEMADDR, placing the
1707 results in GDB's memory at MYADDR. Returns a count of the bytes
1708 actually read, and optionally an errno value in the location
1709 pointed to by ERRNOPTR if ERRNOPTR is non-null. */
1711 /* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this
1712 function be eliminated. */
1715 partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
1716 int len, int *errnoptr)
1718 int nread; /* Number of bytes actually read. */
1719 int errcode; /* Error from last read. */
1721 /* First try a complete read. */
1722 errcode = target_read_memory (memaddr, myaddr, len);
1730 /* Loop, reading one byte at a time until we get as much as we can. */
1731 for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
1733 errcode = target_read_memory (memaddr++, myaddr++, 1);
1735 /* If an error, the last read was unsuccessful, so adjust count. */
1741 if (errnoptr != NULL)
1743 *errnoptr = errcode;
1748 /* Read a string from the inferior, at ADDR, with LEN characters of WIDTH bytes
1749 each. Fetch at most FETCHLIMIT characters. BUFFER will be set to a newly
1750 allocated buffer containing the string, which the caller is responsible to
1751 free, and BYTES_READ will be set to the number of bytes read. Returns 0 on
1752 success, or errno on failure.
1754 If LEN > 0, reads exactly LEN characters (including eventual NULs in
1755 the middle or end of the string). If LEN is -1, stops at the first
1756 null character (not necessarily the first null byte) up to a maximum
1757 of FETCHLIMIT characters. Set FETCHLIMIT to UINT_MAX to read as many
1758 characters as possible from the string.
1760 Unless an exception is thrown, BUFFER will always be allocated, even on
1761 failure. In this case, some characters might have been read before the
1762 failure happened. Check BYTES_READ to recognize this situation.
1764 Note: There was a FIXME asking to make this code use target_read_string,
1765 but this function is more general (can read past null characters, up to
1766 given LEN). Besides, it is used much more often than target_read_string
1767 so it is more tested. Perhaps callers of target_read_string should use
1768 this function instead? */
1771 read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
1772 enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read)
1774 int found_nul; /* Non-zero if we found the nul char. */
1775 int errcode; /* Errno returned from bad reads. */
1776 unsigned int nfetch; /* Chars to fetch / chars fetched. */
1777 unsigned int chunksize; /* Size of each fetch, in chars. */
1778 gdb_byte *bufptr; /* Pointer to next available byte in
1780 gdb_byte *limit; /* First location past end of fetch buffer. */
1781 struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
1783 /* Decide how large of chunks to try to read in one operation. This
1784 is also pretty simple. If LEN >= zero, then we want fetchlimit chars,
1785 so we might as well read them all in one operation. If LEN is -1, we
1786 are looking for a NUL terminator to end the fetching, so we might as
1787 well read in blocks that are large enough to be efficient, but not so
1788 large as to be slow if fetchlimit happens to be large. So we choose the
1789 minimum of 8 and fetchlimit. We used to use 200 instead of 8 but
1790 200 is way too big for remote debugging over a serial line. */
1792 chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit);
1794 /* Loop until we either have all the characters, or we encounter
1795 some error, such as bumping into the end of the address space. */
1800 old_chain = make_cleanup (free_current_contents, buffer);
1804 *buffer = (gdb_byte *) xmalloc (len * width);
1807 nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
1809 addr += nfetch * width;
1810 bufptr += nfetch * width;
1814 unsigned long bufsize = 0;
1819 nfetch = min (chunksize, fetchlimit - bufsize);
1821 if (*buffer == NULL)
1822 *buffer = (gdb_byte *) xmalloc (nfetch * width);
1824 *buffer = (gdb_byte *) xrealloc (*buffer,
1825 (nfetch + bufsize) * width);
1827 bufptr = *buffer + bufsize * width;
1830 /* Read as much as we can. */
1831 nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode)
1834 /* Scan this chunk for the null character that terminates the string
1835 to print. If found, we don't need to fetch any more. Note
1836 that bufptr is explicitly left pointing at the next character
1837 after the null character, or at the next character after the end
1840 limit = bufptr + nfetch * width;
1841 while (bufptr < limit)
1845 c = extract_unsigned_integer (bufptr, width, byte_order);
1850 /* We don't care about any error which happened after
1851 the NUL terminator. */
1858 while (errcode == 0 /* no error */
1859 && bufptr - *buffer < fetchlimit * width /* no overrun */
1860 && !found_nul); /* haven't found NUL yet */
1863 { /* Length of string is really 0! */
1864 /* We always allocate *buffer. */
1865 *buffer = bufptr = xmalloc (1);
1869 /* bufptr and addr now point immediately beyond the last byte which we
1870 consider part of the string (including a '\0' which ends the string). */
1871 *bytes_read = bufptr - *buffer;
1875 discard_cleanups (old_chain);
1880 /* Return true if print_wchar can display W without resorting to a
1881 numeric escape, false otherwise. */
1884 wchar_printable (gdb_wchar_t w)
1886 return (gdb_iswprint (w)
1887 || w == LCST ('\a') || w == LCST ('\b')
1888 || w == LCST ('\f') || w == LCST ('\n')
1889 || w == LCST ('\r') || w == LCST ('\t')
1890 || w == LCST ('\v'));
1893 /* A helper function that converts the contents of STRING to wide
1894 characters and then appends them to OUTPUT. */
1897 append_string_as_wide (const char *string,
1898 struct obstack *output)
1900 for (; *string; ++string)
1902 gdb_wchar_t w = gdb_btowc (*string);
1903 obstack_grow (output, &w, sizeof (gdb_wchar_t));
1907 /* Print a wide character W to OUTPUT. ORIG is a pointer to the
1908 original (target) bytes representing the character, ORIG_LEN is the
1909 number of valid bytes. WIDTH is the number of bytes in a base
1910 characters of the type. OUTPUT is an obstack to which wide
1911 characters are emitted. QUOTER is a (narrow) character indicating
1912 the style of quotes surrounding the character to be printed.
1913 NEED_ESCAPE is an in/out flag which is used to track numeric
1914 escapes across calls. */
1917 print_wchar (gdb_wint_t w, const gdb_byte *orig,
1918 int orig_len, int width,
1919 enum bfd_endian byte_order,
1920 struct obstack *output,
1921 int quoter, int *need_escapep)
1923 int need_escape = *need_escapep;
1926 if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
1928 && w != LCST ('9'))))
1930 gdb_wchar_t wchar = w;
1932 if (w == gdb_btowc (quoter) || w == LCST ('\\'))
1933 obstack_grow_wstr (output, LCST ("\\"));
1934 obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
1941 obstack_grow_wstr (output, LCST ("\\a"));
1944 obstack_grow_wstr (output, LCST ("\\b"));
1947 obstack_grow_wstr (output, LCST ("\\f"));
1950 obstack_grow_wstr (output, LCST ("\\n"));
1953 obstack_grow_wstr (output, LCST ("\\r"));
1956 obstack_grow_wstr (output, LCST ("\\t"));
1959 obstack_grow_wstr (output, LCST ("\\v"));
1965 for (i = 0; i + width <= orig_len; i += width)
1970 value = extract_unsigned_integer (&orig[i], width,
1972 /* If the value fits in 3 octal digits, print it that
1973 way. Otherwise, print it as a hex escape. */
1975 xsnprintf (octal, sizeof (octal), "\\%.3o",
1976 (int) (value & 0777));
1978 xsnprintf (octal, sizeof (octal), "\\x%lx", (long) value);
1979 append_string_as_wide (octal, output);
1981 /* If we somehow have extra bytes, print them now. */
1982 while (i < orig_len)
1986 xsnprintf (octal, sizeof (octal), "\\%.3o", orig[i] & 0xff);
1987 append_string_as_wide (octal, output);
1998 /* Print the character C on STREAM as part of the contents of a
1999 literal string whose delimiter is QUOTER. ENCODING names the
2003 generic_emit_char (int c, struct type *type, struct ui_file *stream,
2004 int quoter, const char *encoding)
2006 enum bfd_endian byte_order
2007 = gdbarch_byte_order (get_type_arch (type));
2008 struct obstack wchar_buf, output;
2009 struct cleanup *cleanups;
2011 struct wchar_iterator *iter;
2012 int need_escape = 0;
2014 buf = alloca (TYPE_LENGTH (type));
2015 pack_long (buf, type, c);
2017 iter = make_wchar_iterator (buf, TYPE_LENGTH (type),
2018 encoding, TYPE_LENGTH (type));
2019 cleanups = make_cleanup_wchar_iterator (iter);
2021 /* This holds the printable form of the wchar_t data. */
2022 obstack_init (&wchar_buf);
2023 make_cleanup_obstack_free (&wchar_buf);
2029 const gdb_byte *buf;
2031 int print_escape = 1;
2032 enum wchar_iterate_result result;
2034 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
2039 /* If all characters are printable, print them. Otherwise,
2040 we're going to have to print an escape sequence. We
2041 check all characters because we want to print the target
2042 bytes in the escape sequence, and we don't know character
2043 boundaries there. */
2047 for (i = 0; i < num_chars; ++i)
2048 if (!wchar_printable (chars[i]))
2056 for (i = 0; i < num_chars; ++i)
2057 print_wchar (chars[i], buf, buflen,
2058 TYPE_LENGTH (type), byte_order,
2059 &wchar_buf, quoter, &need_escape);
2063 /* This handles the NUM_CHARS == 0 case as well. */
2065 print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type),
2066 byte_order, &wchar_buf, quoter, &need_escape);
2069 /* The output in the host encoding. */
2070 obstack_init (&output);
2071 make_cleanup_obstack_free (&output);
2073 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
2074 (gdb_byte *) obstack_base (&wchar_buf),
2075 obstack_object_size (&wchar_buf),
2076 sizeof (gdb_wchar_t), &output, translit_char);
2077 obstack_1grow (&output, '\0');
2079 fputs_filtered (obstack_base (&output), stream);
2081 do_cleanups (cleanups);
2084 /* Return the repeat count of the next character/byte in ITER,
2085 storing the result in VEC. */
2088 count_next_character (struct wchar_iterator *iter,
2089 VEC (converted_character_d) **vec)
2091 struct converted_character *current;
2093 if (VEC_empty (converted_character_d, *vec))
2095 struct converted_character tmp;
2099 = wchar_iterate (iter, &tmp.result, &chars, &tmp.buf, &tmp.buflen);
2100 if (tmp.num_chars > 0)
2102 gdb_assert (tmp.num_chars < MAX_WCHARS);
2103 memcpy (tmp.chars, chars, tmp.num_chars * sizeof (gdb_wchar_t));
2105 VEC_safe_push (converted_character_d, *vec, &tmp);
2108 current = VEC_last (converted_character_d, *vec);
2110 /* Count repeated characters or bytes. */
2111 current->repeat_count = 1;
2112 if (current->num_chars == -1)
2120 struct converted_character d;
2127 /* Get the next character. */
2129 = wchar_iterate (iter, &d.result, &chars, &d.buf, &d.buflen);
2131 /* If a character was successfully converted, save the character
2132 into the converted character. */
2133 if (d.num_chars > 0)
2135 gdb_assert (d.num_chars < MAX_WCHARS);
2136 memcpy (d.chars, chars, WCHAR_BUFLEN (d.num_chars));
2139 /* Determine if the current character is the same as this
2141 if (d.num_chars == current->num_chars && d.result == current->result)
2143 /* There are two cases to consider:
2145 1) Equality of converted character (num_chars > 0)
2146 2) Equality of non-converted character (num_chars == 0) */
2147 if ((current->num_chars > 0
2148 && memcmp (current->chars, d.chars,
2149 WCHAR_BUFLEN (current->num_chars)) == 0)
2150 || (current->num_chars == 0
2151 && current->buflen == d.buflen
2152 && memcmp (current->buf, d.buf, current->buflen) == 0))
2153 ++current->repeat_count;
2161 /* Push this next converted character onto the result vector. */
2162 repeat = current->repeat_count;
2163 VEC_safe_push (converted_character_d, *vec, &d);
2168 /* Print the characters in CHARS to the OBSTACK. QUOTE_CHAR is the quote
2169 character to use with string output. WIDTH is the size of the output
2170 character type. BYTE_ORDER is the the target byte order. OPTIONS
2171 is the user's print options. */
2174 print_converted_chars_to_obstack (struct obstack *obstack,
2175 VEC (converted_character_d) *chars,
2176 int quote_char, int width,
2177 enum bfd_endian byte_order,
2178 const struct value_print_options *options)
2181 struct converted_character *elem;
2182 enum {START, SINGLE, REPEAT, INCOMPLETE, FINISH} state, last;
2183 gdb_wchar_t wide_quote_char = gdb_btowc (quote_char);
2184 int need_escape = 0;
2186 /* Set the start state. */
2188 last = state = START;
2196 /* Nothing to do. */
2203 /* We are outputting a single character
2204 (< options->repeat_count_threshold). */
2208 /* We were outputting some other type of content, so we
2209 must output and a comma and a quote. */
2211 obstack_grow_wstr (obstack, LCST (", "));
2212 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2214 /* Output the character. */
2215 for (j = 0; j < elem->repeat_count; ++j)
2217 if (elem->result == wchar_iterate_ok)
2218 print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
2219 byte_order, obstack, quote_char, &need_escape);
2221 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
2222 byte_order, obstack, quote_char, &need_escape);
2232 /* We are outputting a character with a repeat count
2233 greater than options->repeat_count_threshold. */
2237 /* We were outputting a single string. Terminate the
2239 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2242 obstack_grow_wstr (obstack, LCST (", "));
2244 /* Output the character and repeat string. */
2245 obstack_grow_wstr (obstack, LCST ("'"));
2246 if (elem->result == wchar_iterate_ok)
2247 print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
2248 byte_order, obstack, quote_char, &need_escape);
2250 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
2251 byte_order, obstack, quote_char, &need_escape);
2252 obstack_grow_wstr (obstack, LCST ("'"));
2253 s = xstrprintf (_(" <repeats %u times>"), elem->repeat_count);
2254 for (j = 0; s[j]; ++j)
2256 gdb_wchar_t w = gdb_btowc (s[j]);
2257 obstack_grow (obstack, &w, sizeof (gdb_wchar_t));
2264 /* We are outputting an incomplete sequence. */
2267 /* If we were outputting a string of SINGLE characters,
2268 terminate the quote. */
2269 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2272 obstack_grow_wstr (obstack, LCST (", "));
2274 /* Output the incomplete sequence string. */
2275 obstack_grow_wstr (obstack, LCST ("<incomplete sequence "));
2276 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, byte_order,
2277 obstack, 0, &need_escape);
2278 obstack_grow_wstr (obstack, LCST (">"));
2280 /* We do not attempt to outupt anything after this. */
2285 /* All done. If we were outputting a string of SINGLE
2286 characters, the string must be terminated. Otherwise,
2287 REPEAT and INCOMPLETE are always left properly terminated. */
2289 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2294 /* Get the next element and state. */
2296 if (state != FINISH)
2298 elem = VEC_index (converted_character_d, chars, idx++);
2299 switch (elem->result)
2301 case wchar_iterate_ok:
2302 case wchar_iterate_invalid:
2303 if (elem->repeat_count > options->repeat_count_threshold)
2309 case wchar_iterate_incomplete:
2313 case wchar_iterate_eof:
2321 /* Print the character string STRING, printing at most LENGTH
2322 characters. LENGTH is -1 if the string is nul terminated. TYPE is
2323 the type of each character. OPTIONS holds the printing options;
2324 printing stops early if the number hits print_max; repeat counts
2325 are printed as appropriate. Print ellipses at the end if we had to
2326 stop before printing LENGTH characters, or if FORCE_ELLIPSES.
2327 QUOTE_CHAR is the character to print at each end of the string. If
2328 C_STYLE_TERMINATOR is true, and the last character is 0, then it is
2332 generic_printstr (struct ui_file *stream, struct type *type,
2333 const gdb_byte *string, unsigned int length,
2334 const char *encoding, int force_ellipses,
2335 int quote_char, int c_style_terminator,
2336 const struct value_print_options *options)
2338 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
2340 int width = TYPE_LENGTH (type);
2341 struct obstack wchar_buf, output;
2342 struct cleanup *cleanup;
2343 struct wchar_iterator *iter;
2345 struct converted_character *last;
2346 VEC (converted_character_d) *converted_chars;
2350 unsigned long current_char = 1;
2352 for (i = 0; current_char; ++i)
2355 current_char = extract_unsigned_integer (string + i * width,
2361 /* If the string was not truncated due to `set print elements', and
2362 the last byte of it is a null, we don't print that, in
2363 traditional C style. */
2364 if (c_style_terminator
2367 && (extract_unsigned_integer (string + (length - 1) * width,
2368 width, byte_order) == 0))
2373 fputs_filtered ("\"\"", stream);
2377 /* Arrange to iterate over the characters, in wchar_t form. */
2378 iter = make_wchar_iterator (string, length * width, encoding, width);
2379 cleanup = make_cleanup_wchar_iterator (iter);
2380 converted_chars = NULL;
2381 make_cleanup (VEC_cleanup (converted_character_d), &converted_chars);
2383 /* Convert characters until the string is over or the maximum
2384 number of printed characters has been reached. */
2386 while (i < options->print_max)
2392 /* Grab the next character and repeat count. */
2393 r = count_next_character (iter, &converted_chars);
2395 /* If less than zero, the end of the input string was reached. */
2399 /* Otherwise, add the count to the total print count and get
2400 the next character. */
2404 /* Get the last element and determine if the entire string was
2406 last = VEC_last (converted_character_d, converted_chars);
2407 finished = (last->result == wchar_iterate_eof);
2409 /* Ensure that CONVERTED_CHARS is terminated. */
2410 last->result = wchar_iterate_eof;
2412 /* WCHAR_BUF is the obstack we use to represent the string in
2414 obstack_init (&wchar_buf);
2415 make_cleanup_obstack_free (&wchar_buf);
2417 /* Print the output string to the obstack. */
2418 print_converted_chars_to_obstack (&wchar_buf, converted_chars, quote_char,
2419 width, byte_order, options);
2421 if (force_ellipses || !finished)
2422 obstack_grow_wstr (&wchar_buf, LCST ("..."));
2424 /* OUTPUT is where we collect `char's for printing. */
2425 obstack_init (&output);
2426 make_cleanup_obstack_free (&output);
2428 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
2429 (gdb_byte *) obstack_base (&wchar_buf),
2430 obstack_object_size (&wchar_buf),
2431 sizeof (gdb_wchar_t), &output, translit_char);
2432 obstack_1grow (&output, '\0');
2434 fputs_filtered (obstack_base (&output), stream);
2436 do_cleanups (cleanup);
2439 /* Print a string from the inferior, starting at ADDR and printing up to LEN
2440 characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing
2441 stops at the first null byte, otherwise printing proceeds (including null
2442 bytes) until either print_max or LEN characters have been printed,
2443 whichever is smaller. ENCODING is the name of the string's
2444 encoding. It can be NULL, in which case the target encoding is
2448 val_print_string (struct type *elttype, const char *encoding,
2449 CORE_ADDR addr, int len,
2450 struct ui_file *stream,
2451 const struct value_print_options *options)
2453 int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */
2454 int errcode; /* Errno returned from bad reads. */
2455 int found_nul; /* Non-zero if we found the nul char. */
2456 unsigned int fetchlimit; /* Maximum number of chars to print. */
2458 gdb_byte *buffer = NULL; /* Dynamically growable fetch buffer. */
2459 struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
2460 struct gdbarch *gdbarch = get_type_arch (elttype);
2461 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2462 int width = TYPE_LENGTH (elttype);
2464 /* First we need to figure out the limit on the number of characters we are
2465 going to attempt to fetch and print. This is actually pretty simple. If
2466 LEN >= zero, then the limit is the minimum of LEN and print_max. If
2467 LEN is -1, then the limit is print_max. This is true regardless of
2468 whether print_max is zero, UINT_MAX (unlimited), or something in between,
2469 because finding the null byte (or available memory) is what actually
2470 limits the fetch. */
2472 fetchlimit = (len == -1 ? options->print_max : min (len,
2473 options->print_max));
2475 errcode = read_string (addr, len, width, fetchlimit, byte_order,
2476 &buffer, &bytes_read);
2477 old_chain = make_cleanup (xfree, buffer);
2481 /* We now have either successfully filled the buffer to fetchlimit,
2482 or terminated early due to an error or finding a null char when
2485 /* Determine found_nul by looking at the last character read. */
2486 found_nul = extract_unsigned_integer (buffer + bytes_read - width, width,
2488 if (len == -1 && !found_nul)
2492 /* We didn't find a NUL terminator we were looking for. Attempt
2493 to peek at the next character. If not successful, or it is not
2494 a null byte, then force ellipsis to be printed. */
2496 peekbuf = (gdb_byte *) alloca (width);
2498 if (target_read_memory (addr, peekbuf, width) == 0
2499 && extract_unsigned_integer (peekbuf, width, byte_order) != 0)
2502 else if ((len >= 0 && errcode != 0) || (len > bytes_read / width))
2504 /* Getting an error when we have a requested length, or fetching less
2505 than the number of characters actually requested, always make us
2510 /* If we get an error before fetching anything, don't print a string.
2511 But if we fetch something and then get an error, print the string
2512 and then the error message. */
2513 if (errcode == 0 || bytes_read > 0)
2515 LA_PRINT_STRING (stream, elttype, buffer, bytes_read / width,
2516 encoding, force_ellipsis, options);
2523 fprintf_filtered (stream, "<Address ");
2524 fputs_filtered (paddress (gdbarch, addr), stream);
2525 fprintf_filtered (stream, " out of bounds>");
2529 fprintf_filtered (stream, "<Error reading address ");
2530 fputs_filtered (paddress (gdbarch, addr), stream);
2531 fprintf_filtered (stream, ": %s>", safe_strerror (errcode));
2536 do_cleanups (old_chain);
2538 return (bytes_read / width);
2542 /* The 'set input-radix' command writes to this auxiliary variable.
2543 If the requested radix is valid, INPUT_RADIX is updated; otherwise,
2544 it is left unchanged. */
2546 static unsigned input_radix_1 = 10;
2548 /* Validate an input or output radix setting, and make sure the user
2549 knows what they really did here. Radix setting is confusing, e.g.
2550 setting the input radix to "10" never changes it! */
2553 set_input_radix (char *args, int from_tty, struct cmd_list_element *c)
2555 set_input_radix_1 (from_tty, input_radix_1);
2559 set_input_radix_1 (int from_tty, unsigned radix)
2561 /* We don't currently disallow any input radix except 0 or 1, which don't
2562 make any mathematical sense. In theory, we can deal with any input
2563 radix greater than 1, even if we don't have unique digits for every
2564 value from 0 to radix-1, but in practice we lose on large radix values.
2565 We should either fix the lossage or restrict the radix range more.
2570 input_radix_1 = input_radix;
2571 error (_("Nonsense input radix ``decimal %u''; input radix unchanged."),
2574 input_radix_1 = input_radix = radix;
2577 printf_filtered (_("Input radix now set to "
2578 "decimal %u, hex %x, octal %o.\n"),
2579 radix, radix, radix);
2583 /* The 'set output-radix' command writes to this auxiliary variable.
2584 If the requested radix is valid, OUTPUT_RADIX is updated,
2585 otherwise, it is left unchanged. */
2587 static unsigned output_radix_1 = 10;
2590 set_output_radix (char *args, int from_tty, struct cmd_list_element *c)
2592 set_output_radix_1 (from_tty, output_radix_1);
2596 set_output_radix_1 (int from_tty, unsigned radix)
2598 /* Validate the radix and disallow ones that we aren't prepared to
2599 handle correctly, leaving the radix unchanged. */
2603 user_print_options.output_format = 'x'; /* hex */
2606 user_print_options.output_format = 0; /* decimal */
2609 user_print_options.output_format = 'o'; /* octal */
2612 output_radix_1 = output_radix;
2613 error (_("Unsupported output radix ``decimal %u''; "
2614 "output radix unchanged."),
2617 output_radix_1 = output_radix = radix;
2620 printf_filtered (_("Output radix now set to "
2621 "decimal %u, hex %x, octal %o.\n"),
2622 radix, radix, radix);
2626 /* Set both the input and output radix at once. Try to set the output radix
2627 first, since it has the most restrictive range. An radix that is valid as
2628 an output radix is also valid as an input radix.
2630 It may be useful to have an unusual input radix. If the user wishes to
2631 set an input radix that is not valid as an output radix, he needs to use
2632 the 'set input-radix' command. */
2635 set_radix (char *arg, int from_tty)
2639 radix = (arg == NULL) ? 10 : parse_and_eval_long (arg);
2640 set_output_radix_1 (0, radix);
2641 set_input_radix_1 (0, radix);
2644 printf_filtered (_("Input and output radices now set to "
2645 "decimal %u, hex %x, octal %o.\n"),
2646 radix, radix, radix);
2650 /* Show both the input and output radices. */
2653 show_radix (char *arg, int from_tty)
2657 if (input_radix == output_radix)
2659 printf_filtered (_("Input and output radices set to "
2660 "decimal %u, hex %x, octal %o.\n"),
2661 input_radix, input_radix, input_radix);
2665 printf_filtered (_("Input radix set to decimal "
2666 "%u, hex %x, octal %o.\n"),
2667 input_radix, input_radix, input_radix);
2668 printf_filtered (_("Output radix set to decimal "
2669 "%u, hex %x, octal %o.\n"),
2670 output_radix, output_radix, output_radix);
2677 set_print (char *arg, int from_tty)
2680 "\"set print\" must be followed by the name of a print subcommand.\n");
2681 help_list (setprintlist, "set print ", -1, gdb_stdout);
2685 show_print (char *args, int from_tty)
2687 cmd_show_list (showprintlist, from_tty, "");
2691 _initialize_valprint (void)
2693 add_prefix_cmd ("print", no_class, set_print,
2694 _("Generic command for setting how things print."),
2695 &setprintlist, "set print ", 0, &setlist);
2696 add_alias_cmd ("p", "print", no_class, 1, &setlist);
2697 /* Prefer set print to set prompt. */
2698 add_alias_cmd ("pr", "print", no_class, 1, &setlist);
2700 add_prefix_cmd ("print", no_class, show_print,
2701 _("Generic command for showing print settings."),
2702 &showprintlist, "show print ", 0, &showlist);
2703 add_alias_cmd ("p", "print", no_class, 1, &showlist);
2704 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
2706 add_setshow_uinteger_cmd ("elements", no_class,
2707 &user_print_options.print_max, _("\
2708 Set limit on string chars or array elements to print."), _("\
2709 Show limit on string chars or array elements to print."), _("\
2710 \"set print elements unlimited\" causes there to be no limit."),
2713 &setprintlist, &showprintlist);
2715 add_setshow_boolean_cmd ("null-stop", no_class,
2716 &user_print_options.stop_print_at_null, _("\
2717 Set printing of char arrays to stop at first null char."), _("\
2718 Show printing of char arrays to stop at first null char."), NULL,
2720 show_stop_print_at_null,
2721 &setprintlist, &showprintlist);
2723 add_setshow_uinteger_cmd ("repeats", no_class,
2724 &user_print_options.repeat_count_threshold, _("\
2725 Set threshold for repeated print elements."), _("\
2726 Show threshold for repeated print elements."), _("\
2727 \"set print repeats unlimited\" causes all elements to be individually printed."),
2729 show_repeat_count_threshold,
2730 &setprintlist, &showprintlist);
2732 add_setshow_boolean_cmd ("pretty", class_support,
2733 &user_print_options.prettyformat_structs, _("\
2734 Set pretty formatting of structures."), _("\
2735 Show pretty formatting of structures."), NULL,
2737 show_prettyformat_structs,
2738 &setprintlist, &showprintlist);
2740 add_setshow_boolean_cmd ("union", class_support,
2741 &user_print_options.unionprint, _("\
2742 Set printing of unions interior to structures."), _("\
2743 Show printing of unions interior to structures."), NULL,
2746 &setprintlist, &showprintlist);
2748 add_setshow_boolean_cmd ("array", class_support,
2749 &user_print_options.prettyformat_arrays, _("\
2750 Set pretty formatting of arrays."), _("\
2751 Show pretty formatting of arrays."), NULL,
2753 show_prettyformat_arrays,
2754 &setprintlist, &showprintlist);
2756 add_setshow_boolean_cmd ("address", class_support,
2757 &user_print_options.addressprint, _("\
2758 Set printing of addresses."), _("\
2759 Show printing of addresses."), NULL,
2762 &setprintlist, &showprintlist);
2764 add_setshow_boolean_cmd ("symbol", class_support,
2765 &user_print_options.symbol_print, _("\
2766 Set printing of symbol names when printing pointers."), _("\
2767 Show printing of symbol names when printing pointers."),
2770 &setprintlist, &showprintlist);
2772 add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1,
2774 Set default input radix for entering numbers."), _("\
2775 Show default input radix for entering numbers."), NULL,
2778 &setlist, &showlist);
2780 add_setshow_zuinteger_cmd ("output-radix", class_support, &output_radix_1,
2782 Set default output radix for printing of values."), _("\
2783 Show default output radix for printing of values."), NULL,
2786 &setlist, &showlist);
2788 /* The "set radix" and "show radix" commands are special in that
2789 they are like normal set and show commands but allow two normally
2790 independent variables to be either set or shown with a single
2791 command. So the usual deprecated_add_set_cmd() and [deleted]
2792 add_show_from_set() commands aren't really appropriate. */
2793 /* FIXME: i18n: With the new add_setshow_integer command, that is no
2794 longer true - show can display anything. */
2795 add_cmd ("radix", class_support, set_radix, _("\
2796 Set default input and output number radices.\n\
2797 Use 'set input-radix' or 'set output-radix' to independently set each.\n\
2798 Without an argument, sets both radices back to the default value of 10."),
2800 add_cmd ("radix", class_support, show_radix, _("\
2801 Show the default input and output number radices.\n\
2802 Use 'show input-radix' or 'show output-radix' to independently show each."),
2805 add_setshow_boolean_cmd ("array-indexes", class_support,
2806 &user_print_options.print_array_indexes, _("\
2807 Set printing of array indexes."), _("\
2808 Show printing of array indexes"), NULL, NULL, show_print_array_indexes,
2809 &setprintlist, &showprintlist);