9551e20e23f3f9d917f81ca472a77bb27b3ceb82
[deliverable/binutils-gdb.git] / gdb / valprint.c
1 /* Print values for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "value.h"
24 #include "gdbcore.h"
25 #include "gdbcmd.h"
26 #include "target.h"
27 #include "language.h"
28 #include "annotate.h"
29 #include "valprint.h"
30 #include "floatformat.h"
31 #include "doublest.h"
32 #include "dfp.h"
33 #include "extension.h"
34 #include "ada-lang.h"
35 #include "gdb_obstack.h"
36 #include "charset.h"
37 #include <ctype.h>
38
39 /* Maximum number of wchars returned from wchar_iterate. */
40 #define MAX_WCHARS 4
41
42 /* A convenience macro to compute the size of a wchar_t buffer containing X
43 characters. */
44 #define WCHAR_BUFLEN(X) ((X) * sizeof (gdb_wchar_t))
45
46 /* Character buffer size saved while iterating over wchars. */
47 #define WCHAR_BUFLEN_MAX WCHAR_BUFLEN (MAX_WCHARS)
48
49 /* A structure to encapsulate state information from iterated
50 character conversions. */
51 struct converted_character
52 {
53 /* The number of characters converted. */
54 int num_chars;
55
56 /* The result of the conversion. See charset.h for more. */
57 enum wchar_iterate_result result;
58
59 /* The (saved) converted character(s). */
60 gdb_wchar_t chars[WCHAR_BUFLEN_MAX];
61
62 /* The first converted target byte. */
63 const gdb_byte *buf;
64
65 /* The number of bytes converted. */
66 size_t buflen;
67
68 /* How many times this character(s) is repeated. */
69 int repeat_count;
70 };
71
72 typedef struct converted_character converted_character_d;
73 DEF_VEC_O (converted_character_d);
74
75 /* Command lists for set/show print raw. */
76 struct cmd_list_element *setprintrawlist;
77 struct cmd_list_element *showprintrawlist;
78
79 /* Prototypes for local functions */
80
81 static int partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
82 int len, int *errptr);
83
84 static void show_print (char *, int);
85
86 static void set_print (char *, int);
87
88 static void set_radix (char *, int);
89
90 static void show_radix (char *, int);
91
92 static void set_input_radix (char *, int, struct cmd_list_element *);
93
94 static void set_input_radix_1 (int, unsigned);
95
96 static void set_output_radix (char *, int, struct cmd_list_element *);
97
98 static void set_output_radix_1 (int, unsigned);
99
100 void _initialize_valprint (void);
101
102 #define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */
103
104 struct value_print_options user_print_options =
105 {
106 Val_prettyformat_default, /* prettyformat */
107 0, /* prettyformat_arrays */
108 0, /* prettyformat_structs */
109 0, /* vtblprint */
110 1, /* unionprint */
111 1, /* addressprint */
112 0, /* objectprint */
113 PRINT_MAX_DEFAULT, /* print_max */
114 10, /* repeat_count_threshold */
115 0, /* output_format */
116 0, /* format */
117 0, /* stop_print_at_null */
118 0, /* print_array_indexes */
119 0, /* deref_ref */
120 1, /* static_field_print */
121 1, /* pascal_static_field_print */
122 0, /* raw */
123 0, /* summary */
124 1 /* symbol_print */
125 };
126
127 /* Initialize *OPTS to be a copy of the user print options. */
128 void
129 get_user_print_options (struct value_print_options *opts)
130 {
131 *opts = user_print_options;
132 }
133
134 /* Initialize *OPTS to be a copy of the user print options, but with
135 pretty-formatting disabled. */
136 void
137 get_no_prettyformat_print_options (struct value_print_options *opts)
138 {
139 *opts = user_print_options;
140 opts->prettyformat = Val_no_prettyformat;
141 }
142
143 /* Initialize *OPTS to be a copy of the user print options, but using
144 FORMAT as the formatting option. */
145 void
146 get_formatted_print_options (struct value_print_options *opts,
147 char format)
148 {
149 *opts = user_print_options;
150 opts->format = format;
151 }
152
153 static void
154 show_print_max (struct ui_file *file, int from_tty,
155 struct cmd_list_element *c, const char *value)
156 {
157 fprintf_filtered (file,
158 _("Limit on string chars or array "
159 "elements to print is %s.\n"),
160 value);
161 }
162
163
164 /* Default input and output radixes, and output format letter. */
165
166 unsigned input_radix = 10;
167 static void
168 show_input_radix (struct ui_file *file, int from_tty,
169 struct cmd_list_element *c, const char *value)
170 {
171 fprintf_filtered (file,
172 _("Default input radix for entering numbers is %s.\n"),
173 value);
174 }
175
176 unsigned output_radix = 10;
177 static void
178 show_output_radix (struct ui_file *file, int from_tty,
179 struct cmd_list_element *c, const char *value)
180 {
181 fprintf_filtered (file,
182 _("Default output radix for printing of values is %s.\n"),
183 value);
184 }
185
186 /* By default we print arrays without printing the index of each element in
187 the array. This behavior can be changed by setting PRINT_ARRAY_INDEXES. */
188
189 static void
190 show_print_array_indexes (struct ui_file *file, int from_tty,
191 struct cmd_list_element *c, const char *value)
192 {
193 fprintf_filtered (file, _("Printing of array indexes is %s.\n"), value);
194 }
195
196 /* Print repeat counts if there are more than this many repetitions of an
197 element in an array. Referenced by the low level language dependent
198 print routines. */
199
200 static void
201 show_repeat_count_threshold (struct ui_file *file, int from_tty,
202 struct cmd_list_element *c, const char *value)
203 {
204 fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"),
205 value);
206 }
207
208 /* If nonzero, stops printing of char arrays at first null. */
209
210 static void
211 show_stop_print_at_null (struct ui_file *file, int from_tty,
212 struct cmd_list_element *c, const char *value)
213 {
214 fprintf_filtered (file,
215 _("Printing of char arrays to stop "
216 "at first null char is %s.\n"),
217 value);
218 }
219
220 /* Controls pretty printing of structures. */
221
222 static void
223 show_prettyformat_structs (struct ui_file *file, int from_tty,
224 struct cmd_list_element *c, const char *value)
225 {
226 fprintf_filtered (file, _("Pretty formatting of structures is %s.\n"), value);
227 }
228
229 /* Controls pretty printing of arrays. */
230
231 static void
232 show_prettyformat_arrays (struct ui_file *file, int from_tty,
233 struct cmd_list_element *c, const char *value)
234 {
235 fprintf_filtered (file, _("Pretty formatting of arrays is %s.\n"), value);
236 }
237
238 /* If nonzero, causes unions inside structures or other unions to be
239 printed. */
240
241 static void
242 show_unionprint (struct ui_file *file, int from_tty,
243 struct cmd_list_element *c, const char *value)
244 {
245 fprintf_filtered (file,
246 _("Printing of unions interior to structures is %s.\n"),
247 value);
248 }
249
250 /* If nonzero, causes machine addresses to be printed in certain contexts. */
251
252 static void
253 show_addressprint (struct ui_file *file, int from_tty,
254 struct cmd_list_element *c, const char *value)
255 {
256 fprintf_filtered (file, _("Printing of addresses is %s.\n"), value);
257 }
258
259 static void
260 show_symbol_print (struct ui_file *file, int from_tty,
261 struct cmd_list_element *c, const char *value)
262 {
263 fprintf_filtered (file,
264 _("Printing of symbols when printing pointers is %s.\n"),
265 value);
266 }
267
268 \f
269
270 /* A helper function for val_print. When printing in "summary" mode,
271 we want to print scalar arguments, but not aggregate arguments.
272 This function distinguishes between the two. */
273
274 int
275 val_print_scalar_type_p (struct type *type)
276 {
277 type = check_typedef (type);
278 while (TYPE_CODE (type) == TYPE_CODE_REF)
279 {
280 type = TYPE_TARGET_TYPE (type);
281 type = check_typedef (type);
282 }
283 switch (TYPE_CODE (type))
284 {
285 case TYPE_CODE_ARRAY:
286 case TYPE_CODE_STRUCT:
287 case TYPE_CODE_UNION:
288 case TYPE_CODE_SET:
289 case TYPE_CODE_STRING:
290 return 0;
291 default:
292 return 1;
293 }
294 }
295
296 /* See its definition in value.h. */
297
298 int
299 valprint_check_validity (struct ui_file *stream,
300 struct type *type,
301 int embedded_offset,
302 const struct value *val)
303 {
304 type = check_typedef (type);
305
306 if (TYPE_CODE (type) != TYPE_CODE_UNION
307 && TYPE_CODE (type) != TYPE_CODE_STRUCT
308 && TYPE_CODE (type) != TYPE_CODE_ARRAY)
309 {
310 if (value_bits_any_optimized_out (val,
311 TARGET_CHAR_BIT * embedded_offset,
312 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
313 {
314 val_print_optimized_out (val, stream);
315 return 0;
316 }
317
318 if (value_bits_synthetic_pointer (val, TARGET_CHAR_BIT * embedded_offset,
319 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
320 {
321 fputs_filtered (_("<synthetic pointer>"), stream);
322 return 0;
323 }
324
325 if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
326 {
327 val_print_unavailable (stream);
328 return 0;
329 }
330 }
331
332 return 1;
333 }
334
335 void
336 val_print_optimized_out (const struct value *val, struct ui_file *stream)
337 {
338 if (val != NULL && value_lval_const (val) == lval_register)
339 val_print_not_saved (stream);
340 else
341 fprintf_filtered (stream, _("<optimized out>"));
342 }
343
344 void
345 val_print_not_saved (struct ui_file *stream)
346 {
347 fprintf_filtered (stream, _("<not saved>"));
348 }
349
350 void
351 val_print_unavailable (struct ui_file *stream)
352 {
353 fprintf_filtered (stream, _("<unavailable>"));
354 }
355
356 void
357 val_print_invalid_address (struct ui_file *stream)
358 {
359 fprintf_filtered (stream, _("<invalid address>"));
360 }
361
362 /* Print a pointer based on the type of its target.
363
364 Arguments to this functions are roughly the same as those in
365 generic_val_print. A difference is that ADDRESS is the address to print,
366 with embedded_offset already added. ELTTYPE represents
367 the pointed type after check_typedef. */
368
369 static void
370 print_unpacked_pointer (struct type *type, struct type *elttype,
371 CORE_ADDR address, struct ui_file *stream,
372 const struct value_print_options *options)
373 {
374 struct gdbarch *gdbarch = get_type_arch (type);
375
376 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
377 {
378 /* Try to print what function it points to. */
379 print_function_pointer_address (options, gdbarch, address, stream);
380 return;
381 }
382
383 if (options->symbol_print)
384 print_address_demangle (options, gdbarch, address, stream, demangle);
385 else if (options->addressprint)
386 fputs_filtered (paddress (gdbarch, address), stream);
387 }
388
389 /* generic_val_print helper for TYPE_CODE_ARRAY. */
390
391 static void
392 generic_val_print_array (struct type *type, const gdb_byte *valaddr,
393 int embedded_offset, CORE_ADDR address,
394 struct ui_file *stream, int recurse,
395 const struct value *original_value,
396 const struct value_print_options *options)
397 {
398 struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
399 struct type *elttype = check_typedef (unresolved_elttype);
400
401 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
402 {
403 LONGEST low_bound, high_bound;
404
405 if (!get_array_bounds (type, &low_bound, &high_bound))
406 error (_("Could not determine the array high bound"));
407
408 if (options->prettyformat_arrays)
409 {
410 print_spaces_filtered (2 + 2 * recurse, stream);
411 }
412
413 fprintf_filtered (stream, "{");
414 val_print_array_elements (type, valaddr, embedded_offset,
415 address, stream,
416 recurse, original_value, options, 0);
417 fprintf_filtered (stream, "}");
418 }
419 else
420 {
421 /* Array of unspecified length: treat like pointer to first elt. */
422 print_unpacked_pointer (type, elttype, address + embedded_offset, stream,
423 options);
424 }
425
426 }
427
428 /* generic_val_print helper for TYPE_CODE_PTR. */
429
430 static void
431 generic_val_print_ptr (struct type *type, const gdb_byte *valaddr,
432 int embedded_offset, struct ui_file *stream,
433 const struct value *original_value,
434 const struct value_print_options *options)
435 {
436 if (options->format && options->format != 's')
437 {
438 val_print_scalar_formatted (type, valaddr, embedded_offset,
439 original_value, options, 0, stream);
440 }
441 else
442 {
443 struct type *unresolved_elttype = TYPE_TARGET_TYPE(type);
444 struct type *elttype = check_typedef (unresolved_elttype);
445 CORE_ADDR addr = unpack_pointer (type, valaddr + embedded_offset);
446
447 print_unpacked_pointer (type, elttype, addr, stream, options);
448 }
449 }
450
451
452 /* generic_val_print helper for TYPE_CODE_MEMBERPTR. */
453
454 static void
455 generic_val_print_memberptr (struct type *type, const gdb_byte *valaddr,
456 int embedded_offset, struct ui_file *stream,
457 const struct value *original_value,
458 const struct value_print_options *options)
459 {
460 val_print_scalar_formatted (type, valaddr, embedded_offset,
461 original_value, options, 0, stream);
462 }
463
464 /* generic_val_print helper for TYPE_CODE_REF. */
465
466 static void
467 generic_val_print_ref (struct type *type, const gdb_byte *valaddr,
468 int embedded_offset, struct ui_file *stream, int recurse,
469 const struct value *original_value,
470 const struct value_print_options *options)
471 {
472 struct gdbarch *gdbarch = get_type_arch (type);
473 struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
474
475 if (options->addressprint)
476 {
477 CORE_ADDR addr
478 = extract_typed_address (valaddr + embedded_offset, type);
479
480 fprintf_filtered (stream, "@");
481 fputs_filtered (paddress (gdbarch, addr), stream);
482 if (options->deref_ref)
483 fputs_filtered (": ", stream);
484 }
485 /* De-reference the reference. */
486 if (options->deref_ref)
487 {
488 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
489 {
490 struct value *deref_val;
491
492 deref_val = coerce_ref_if_computed (original_value);
493 if (deref_val != NULL)
494 {
495 /* More complicated computed references are not supported. */
496 gdb_assert (embedded_offset == 0);
497 }
498 else
499 deref_val = value_at (TYPE_TARGET_TYPE (type),
500 unpack_pointer (type,
501 (valaddr
502 + embedded_offset)));
503
504 common_val_print (deref_val, stream, recurse, options,
505 current_language);
506 }
507 else
508 fputs_filtered ("???", stream);
509 }
510 }
511
512 /* generic_val_print helper for TYPE_CODE_ENUM. */
513
514 static void
515 generic_val_print_enum (struct type *type, const gdb_byte *valaddr,
516 int embedded_offset, struct ui_file *stream,
517 const struct value *original_value,
518 const struct value_print_options *options)
519 {
520 unsigned int i;
521 unsigned int len;
522 LONGEST val;
523
524 if (options->format)
525 {
526 val_print_scalar_formatted (type, valaddr, embedded_offset,
527 original_value, options, 0, stream);
528 return;
529 }
530 len = TYPE_NFIELDS (type);
531 val = unpack_long (type, valaddr + embedded_offset);
532 for (i = 0; i < len; i++)
533 {
534 QUIT;
535 if (val == TYPE_FIELD_ENUMVAL (type, i))
536 {
537 break;
538 }
539 }
540 if (i < len)
541 {
542 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
543 }
544 else if (TYPE_FLAG_ENUM (type))
545 {
546 int first = 1;
547
548 /* We have a "flag" enum, so we try to decompose it into
549 pieces as appropriate. A flag enum has disjoint
550 constants by definition. */
551 fputs_filtered ("(", stream);
552 for (i = 0; i < len; ++i)
553 {
554 QUIT;
555
556 if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
557 {
558 if (!first)
559 fputs_filtered (" | ", stream);
560 first = 0;
561
562 val &= ~TYPE_FIELD_ENUMVAL (type, i);
563 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
564 }
565 }
566
567 if (first || val != 0)
568 {
569 if (!first)
570 fputs_filtered (" | ", stream);
571 fputs_filtered ("unknown: ", stream);
572 print_longest (stream, 'd', 0, val);
573 }
574
575 fputs_filtered (")", stream);
576 }
577 else
578 print_longest (stream, 'd', 0, val);
579 }
580
581 /* generic_val_print helper for TYPE_CODE_FLAGS. */
582
583 static void
584 generic_val_print_flags (struct type *type, const gdb_byte *valaddr,
585 int embedded_offset, struct ui_file *stream,
586 const struct value *original_value,
587 const struct value_print_options *options)
588
589 {
590 if (options->format)
591 val_print_scalar_formatted (type, valaddr, embedded_offset, original_value,
592 options, 0, stream);
593 else
594 val_print_type_code_flags (type, valaddr + embedded_offset, stream);
595 }
596
597 /* generic_val_print helper for TYPE_CODE_FUNC and TYPE_CODE_METHOD. */
598
599 static void
600 generic_val_print_func (struct type *type, const gdb_byte *valaddr,
601 int embedded_offset, CORE_ADDR address,
602 struct ui_file *stream,
603 const struct value *original_value,
604 const struct value_print_options *options)
605 {
606 struct gdbarch *gdbarch = get_type_arch (type);
607
608 if (options->format)
609 {
610 val_print_scalar_formatted (type, valaddr, embedded_offset,
611 original_value, options, 0, stream);
612 }
613 else
614 {
615 /* FIXME, we should consider, at least for ANSI C language,
616 eliminating the distinction made between FUNCs and POINTERs
617 to FUNCs. */
618 fprintf_filtered (stream, "{");
619 type_print (type, "", stream, -1);
620 fprintf_filtered (stream, "} ");
621 /* Try to print what function it points to, and its address. */
622 print_address_demangle (options, gdbarch, address, stream, demangle);
623 }
624 }
625
626 /* generic_val_print helper for TYPE_CODE_BOOL. */
627
628 static void
629 generic_val_print_bool (struct type *type, const gdb_byte *valaddr,
630 int embedded_offset, struct ui_file *stream,
631 const struct value *original_value,
632 const struct value_print_options *options,
633 const struct generic_val_print_decorations *decorations)
634 {
635 LONGEST val;
636
637 if (options->format || options->output_format)
638 {
639 struct value_print_options opts = *options;
640 opts.format = (options->format ? options->format
641 : options->output_format);
642 val_print_scalar_formatted (type, valaddr, embedded_offset,
643 original_value, &opts, 0, stream);
644 }
645 else
646 {
647 val = unpack_long (type, valaddr + embedded_offset);
648 if (val == 0)
649 fputs_filtered (decorations->false_name, stream);
650 else if (val == 1)
651 fputs_filtered (decorations->true_name, stream);
652 else
653 print_longest (stream, 'd', 0, val);
654 }
655 }
656
657 /* A generic val_print that is suitable for use by language
658 implementations of the la_val_print method. This function can
659 handle most type codes, though not all, notably exception
660 TYPE_CODE_UNION and TYPE_CODE_STRUCT, which must be implemented by
661 the caller.
662
663 Most arguments are as to val_print.
664
665 The additional DECORATIONS argument can be used to customize the
666 output in some small, language-specific ways. */
667
668 void
669 generic_val_print (struct type *type, const gdb_byte *valaddr,
670 int embedded_offset, CORE_ADDR address,
671 struct ui_file *stream, int recurse,
672 const struct value *original_value,
673 const struct value_print_options *options,
674 const struct generic_val_print_decorations *decorations)
675 {
676 struct type *unresolved_type = type;
677 LONGEST val;
678
679 type = check_typedef (type);
680 switch (TYPE_CODE (type))
681 {
682 case TYPE_CODE_ARRAY:
683 generic_val_print_array (type, valaddr, embedded_offset, address, stream,
684 recurse, original_value, options);
685 break;
686
687 case TYPE_CODE_MEMBERPTR:
688 generic_val_print_memberptr (type, valaddr, embedded_offset, stream,
689 original_value, options);
690 break;
691
692 case TYPE_CODE_PTR:
693 generic_val_print_ptr (type, valaddr, embedded_offset, stream,
694 original_value, options);
695 break;
696
697 case TYPE_CODE_REF:
698 generic_val_print_ref (type, valaddr, embedded_offset, stream, recurse,
699 original_value, options);
700 break;
701
702 case TYPE_CODE_ENUM:
703 generic_val_print_enum (type, valaddr, embedded_offset, stream,
704 original_value, options);
705 break;
706
707 case TYPE_CODE_FLAGS:
708 generic_val_print_flags (type, valaddr, embedded_offset, stream,
709 original_value, options);
710 break;
711
712 case TYPE_CODE_FUNC:
713 case TYPE_CODE_METHOD:
714 generic_val_print_func (type, valaddr, embedded_offset, address, stream,
715 original_value, options);
716 break;
717
718 case TYPE_CODE_BOOL:
719 generic_val_print_bool (type, valaddr, embedded_offset, stream,
720 original_value, options, decorations);
721 break;
722
723 case TYPE_CODE_RANGE:
724 /* FIXME: create_static_range_type does not set the unsigned bit in a
725 range type (I think it probably should copy it from the
726 target type), so we won't print values which are too large to
727 fit in a signed integer correctly. */
728 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
729 print with the target type, though, because the size of our
730 type and the target type might differ). */
731
732 /* FALLTHROUGH */
733
734 case TYPE_CODE_INT:
735 if (options->format || options->output_format)
736 {
737 struct value_print_options opts = *options;
738
739 opts.format = (options->format ? options->format
740 : options->output_format);
741 val_print_scalar_formatted (type, valaddr, embedded_offset,
742 original_value, &opts, 0, stream);
743 }
744 else
745 val_print_type_code_int (type, valaddr + embedded_offset, stream);
746 break;
747
748 case TYPE_CODE_CHAR:
749 if (options->format || options->output_format)
750 {
751 struct value_print_options opts = *options;
752
753 opts.format = (options->format ? options->format
754 : options->output_format);
755 val_print_scalar_formatted (type, valaddr, embedded_offset,
756 original_value, &opts, 0, stream);
757 }
758 else
759 {
760 val = unpack_long (type, valaddr + embedded_offset);
761 if (TYPE_UNSIGNED (type))
762 fprintf_filtered (stream, "%u", (unsigned int) val);
763 else
764 fprintf_filtered (stream, "%d", (int) val);
765 fputs_filtered (" ", stream);
766 LA_PRINT_CHAR (val, unresolved_type, stream);
767 }
768 break;
769
770 case TYPE_CODE_FLT:
771 if (options->format)
772 {
773 val_print_scalar_formatted (type, valaddr, embedded_offset,
774 original_value, options, 0, stream);
775 }
776 else
777 {
778 print_floating (valaddr + embedded_offset, type, stream);
779 }
780 break;
781
782 case TYPE_CODE_DECFLOAT:
783 if (options->format)
784 val_print_scalar_formatted (type, valaddr, embedded_offset,
785 original_value, options, 0, stream);
786 else
787 print_decimal_floating (valaddr + embedded_offset,
788 type, stream);
789 break;
790
791 case TYPE_CODE_VOID:
792 fputs_filtered (decorations->void_name, stream);
793 break;
794
795 case TYPE_CODE_ERROR:
796 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
797 break;
798
799 case TYPE_CODE_UNDEF:
800 /* This happens (without TYPE_FLAG_STUB set) on systems which
801 don't use dbx xrefs (NO_DBX_XREFS in gcc) if a file has a
802 "struct foo *bar" and no complete type for struct foo in that
803 file. */
804 fprintf_filtered (stream, _("<incomplete type>"));
805 break;
806
807 case TYPE_CODE_COMPLEX:
808 fprintf_filtered (stream, "%s", decorations->complex_prefix);
809 if (options->format)
810 val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
811 valaddr, embedded_offset,
812 original_value, options, 0, stream);
813 else
814 print_floating (valaddr + embedded_offset,
815 TYPE_TARGET_TYPE (type),
816 stream);
817 fprintf_filtered (stream, "%s", decorations->complex_infix);
818 if (options->format)
819 val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
820 valaddr,
821 embedded_offset
822 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
823 original_value,
824 options, 0, stream);
825 else
826 print_floating (valaddr + embedded_offset
827 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
828 TYPE_TARGET_TYPE (type),
829 stream);
830 fprintf_filtered (stream, "%s", decorations->complex_suffix);
831 break;
832
833 case TYPE_CODE_UNION:
834 case TYPE_CODE_STRUCT:
835 case TYPE_CODE_METHODPTR:
836 default:
837 error (_("Unhandled type code %d in symbol table."),
838 TYPE_CODE (type));
839 }
840 gdb_flush (stream);
841 }
842
843 /* Print using the given LANGUAGE the data of type TYPE located at
844 VALADDR + EMBEDDED_OFFSET (within GDB), which came from the
845 inferior at address ADDRESS + EMBEDDED_OFFSET, onto stdio stream
846 STREAM according to OPTIONS. VAL is the whole object that came
847 from ADDRESS. VALADDR must point to the head of VAL's contents
848 buffer.
849
850 The language printers will pass down an adjusted EMBEDDED_OFFSET to
851 further helper subroutines as subfields of TYPE are printed. In
852 such cases, VALADDR is passed down unadjusted, as well as VAL, so
853 that VAL can be queried for metadata about the contents data being
854 printed, using EMBEDDED_OFFSET as an offset into VAL's contents
855 buffer. For example: "has this field been optimized out", or "I'm
856 printing an object while inspecting a traceframe; has this
857 particular piece of data been collected?".
858
859 RECURSE indicates the amount of indentation to supply before
860 continuation lines; this amount is roughly twice the value of
861 RECURSE. */
862
863 void
864 val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
865 CORE_ADDR address, struct ui_file *stream, int recurse,
866 const struct value *val,
867 const struct value_print_options *options,
868 const struct language_defn *language)
869 {
870 int ret = 0;
871 struct value_print_options local_opts = *options;
872 struct type *real_type = check_typedef (type);
873
874 if (local_opts.prettyformat == Val_prettyformat_default)
875 local_opts.prettyformat = (local_opts.prettyformat_structs
876 ? Val_prettyformat : Val_no_prettyformat);
877
878 QUIT;
879
880 /* Ensure that the type is complete and not just a stub. If the type is
881 only a stub and we can't find and substitute its complete type, then
882 print appropriate string and return. */
883
884 if (TYPE_STUB (real_type))
885 {
886 fprintf_filtered (stream, _("<incomplete type>"));
887 gdb_flush (stream);
888 return;
889 }
890
891 if (!valprint_check_validity (stream, real_type, embedded_offset, val))
892 return;
893
894 if (!options->raw)
895 {
896 ret = apply_ext_lang_val_pretty_printer (type, valaddr, embedded_offset,
897 address, stream, recurse,
898 val, options, language);
899 if (ret)
900 return;
901 }
902
903 /* Handle summary mode. If the value is a scalar, print it;
904 otherwise, print an ellipsis. */
905 if (options->summary && !val_print_scalar_type_p (type))
906 {
907 fprintf_filtered (stream, "...");
908 return;
909 }
910
911 TRY
912 {
913 language->la_val_print (type, valaddr, embedded_offset, address,
914 stream, recurse, val,
915 &local_opts);
916 }
917 CATCH (except, RETURN_MASK_ERROR)
918 {
919 fprintf_filtered (stream, _("<error reading variable>"));
920 }
921 END_CATCH
922 }
923
924 /* Check whether the value VAL is printable. Return 1 if it is;
925 return 0 and print an appropriate error message to STREAM according to
926 OPTIONS if it is not. */
927
928 static int
929 value_check_printable (struct value *val, struct ui_file *stream,
930 const struct value_print_options *options)
931 {
932 if (val == 0)
933 {
934 fprintf_filtered (stream, _("<address of value unknown>"));
935 return 0;
936 }
937
938 if (value_entirely_optimized_out (val))
939 {
940 if (options->summary && !val_print_scalar_type_p (value_type (val)))
941 fprintf_filtered (stream, "...");
942 else
943 val_print_optimized_out (val, stream);
944 return 0;
945 }
946
947 if (value_entirely_unavailable (val))
948 {
949 if (options->summary && !val_print_scalar_type_p (value_type (val)))
950 fprintf_filtered (stream, "...");
951 else
952 val_print_unavailable (stream);
953 return 0;
954 }
955
956 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION)
957 {
958 fprintf_filtered (stream, _("<internal function %s>"),
959 value_internal_function_name (val));
960 return 0;
961 }
962
963 return 1;
964 }
965
966 /* Print using the given LANGUAGE the value VAL onto stream STREAM according
967 to OPTIONS.
968
969 This is a preferable interface to val_print, above, because it uses
970 GDB's value mechanism. */
971
972 void
973 common_val_print (struct value *val, struct ui_file *stream, int recurse,
974 const struct value_print_options *options,
975 const struct language_defn *language)
976 {
977 if (!value_check_printable (val, stream, options))
978 return;
979
980 if (language->la_language == language_ada)
981 /* The value might have a dynamic type, which would cause trouble
982 below when trying to extract the value contents (since the value
983 size is determined from the type size which is unknown). So
984 get a fixed representation of our value. */
985 val = ada_to_fixed_value (val);
986
987 val_print (value_type (val), value_contents_for_printing (val),
988 value_embedded_offset (val), value_address (val),
989 stream, recurse,
990 val, options, language);
991 }
992
993 /* Print on stream STREAM the value VAL according to OPTIONS. The value
994 is printed using the current_language syntax. */
995
996 void
997 value_print (struct value *val, struct ui_file *stream,
998 const struct value_print_options *options)
999 {
1000 if (!value_check_printable (val, stream, options))
1001 return;
1002
1003 if (!options->raw)
1004 {
1005 int r
1006 = apply_ext_lang_val_pretty_printer (value_type (val),
1007 value_contents_for_printing (val),
1008 value_embedded_offset (val),
1009 value_address (val),
1010 stream, 0,
1011 val, options, current_language);
1012
1013 if (r)
1014 return;
1015 }
1016
1017 LA_VALUE_PRINT (val, stream, options);
1018 }
1019
1020 /* Called by various <lang>_val_print routines to print
1021 TYPE_CODE_INT's. TYPE is the type. VALADDR is the address of the
1022 value. STREAM is where to print the value. */
1023
1024 void
1025 val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
1026 struct ui_file *stream)
1027 {
1028 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
1029
1030 if (TYPE_LENGTH (type) > sizeof (LONGEST))
1031 {
1032 LONGEST val;
1033
1034 if (TYPE_UNSIGNED (type)
1035 && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type),
1036 byte_order, &val))
1037 {
1038 print_longest (stream, 'u', 0, val);
1039 }
1040 else
1041 {
1042 /* Signed, or we couldn't turn an unsigned value into a
1043 LONGEST. For signed values, one could assume two's
1044 complement (a reasonable assumption, I think) and do
1045 better than this. */
1046 print_hex_chars (stream, (unsigned char *) valaddr,
1047 TYPE_LENGTH (type), byte_order);
1048 }
1049 }
1050 else
1051 {
1052 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0,
1053 unpack_long (type, valaddr));
1054 }
1055 }
1056
1057 void
1058 val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
1059 struct ui_file *stream)
1060 {
1061 ULONGEST val = unpack_long (type, valaddr);
1062 int bitpos, nfields = TYPE_NFIELDS (type);
1063
1064 fputs_filtered ("[ ", stream);
1065 for (bitpos = 0; bitpos < nfields; bitpos++)
1066 {
1067 if (TYPE_FIELD_BITPOS (type, bitpos) != -1
1068 && (val & ((ULONGEST)1 << bitpos)))
1069 {
1070 if (TYPE_FIELD_NAME (type, bitpos))
1071 fprintf_filtered (stream, "%s ", TYPE_FIELD_NAME (type, bitpos));
1072 else
1073 fprintf_filtered (stream, "#%d ", bitpos);
1074 }
1075 }
1076 fputs_filtered ("]", stream);
1077 }
1078
1079 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
1080 according to OPTIONS and SIZE on STREAM. Format i is not supported
1081 at this level.
1082
1083 This is how the elements of an array or structure are printed
1084 with a format. */
1085
1086 void
1087 val_print_scalar_formatted (struct type *type,
1088 const gdb_byte *valaddr, int embedded_offset,
1089 const struct value *val,
1090 const struct value_print_options *options,
1091 int size,
1092 struct ui_file *stream)
1093 {
1094 gdb_assert (val != NULL);
1095 gdb_assert (valaddr == value_contents_for_printing_const (val));
1096
1097 /* If we get here with a string format, try again without it. Go
1098 all the way back to the language printers, which may call us
1099 again. */
1100 if (options->format == 's')
1101 {
1102 struct value_print_options opts = *options;
1103 opts.format = 0;
1104 opts.deref_ref = 0;
1105 val_print (type, valaddr, embedded_offset, 0, stream, 0, val, &opts,
1106 current_language);
1107 return;
1108 }
1109
1110 /* A scalar object that does not have all bits available can't be
1111 printed, because all bits contribute to its representation. */
1112 if (value_bits_any_optimized_out (val,
1113 TARGET_CHAR_BIT * embedded_offset,
1114 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
1115 val_print_optimized_out (val, stream);
1116 else if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
1117 val_print_unavailable (stream);
1118 else
1119 print_scalar_formatted (valaddr + embedded_offset, type,
1120 options, size, stream);
1121 }
1122
1123 /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
1124 The raison d'etre of this function is to consolidate printing of
1125 LONG_LONG's into this one function. The format chars b,h,w,g are
1126 from print_scalar_formatted(). Numbers are printed using C
1127 format.
1128
1129 USE_C_FORMAT means to use C format in all cases. Without it,
1130 'o' and 'x' format do not include the standard C radix prefix
1131 (leading 0 or 0x).
1132
1133 Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL
1134 and was intended to request formating according to the current
1135 language and would be used for most integers that GDB prints. The
1136 exceptional cases were things like protocols where the format of
1137 the integer is a protocol thing, not a user-visible thing). The
1138 parameter remains to preserve the information of what things might
1139 be printed with language-specific format, should we ever resurrect
1140 that capability. */
1141
1142 void
1143 print_longest (struct ui_file *stream, int format, int use_c_format,
1144 LONGEST val_long)
1145 {
1146 const char *val;
1147
1148 switch (format)
1149 {
1150 case 'd':
1151 val = int_string (val_long, 10, 1, 0, 1); break;
1152 case 'u':
1153 val = int_string (val_long, 10, 0, 0, 1); break;
1154 case 'x':
1155 val = int_string (val_long, 16, 0, 0, use_c_format); break;
1156 case 'b':
1157 val = int_string (val_long, 16, 0, 2, 1); break;
1158 case 'h':
1159 val = int_string (val_long, 16, 0, 4, 1); break;
1160 case 'w':
1161 val = int_string (val_long, 16, 0, 8, 1); break;
1162 case 'g':
1163 val = int_string (val_long, 16, 0, 16, 1); break;
1164 break;
1165 case 'o':
1166 val = int_string (val_long, 8, 0, 0, use_c_format); break;
1167 default:
1168 internal_error (__FILE__, __LINE__,
1169 _("failed internal consistency check"));
1170 }
1171 fputs_filtered (val, stream);
1172 }
1173
1174 /* This used to be a macro, but I don't think it is called often enough
1175 to merit such treatment. */
1176 /* Convert a LONGEST to an int. This is used in contexts (e.g. number of
1177 arguments to a function, number in a value history, register number, etc.)
1178 where the value must not be larger than can fit in an int. */
1179
1180 int
1181 longest_to_int (LONGEST arg)
1182 {
1183 /* Let the compiler do the work. */
1184 int rtnval = (int) arg;
1185
1186 /* Check for overflows or underflows. */
1187 if (sizeof (LONGEST) > sizeof (int))
1188 {
1189 if (rtnval != arg)
1190 {
1191 error (_("Value out of range."));
1192 }
1193 }
1194 return (rtnval);
1195 }
1196
1197 /* Print a floating point value of type TYPE (not always a
1198 TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM. */
1199
1200 void
1201 print_floating (const gdb_byte *valaddr, struct type *type,
1202 struct ui_file *stream)
1203 {
1204 DOUBLEST doub;
1205 int inv;
1206 const struct floatformat *fmt = NULL;
1207 unsigned len = TYPE_LENGTH (type);
1208 enum float_kind kind;
1209
1210 /* If it is a floating-point, check for obvious problems. */
1211 if (TYPE_CODE (type) == TYPE_CODE_FLT)
1212 fmt = floatformat_from_type (type);
1213 if (fmt != NULL)
1214 {
1215 kind = floatformat_classify (fmt, valaddr);
1216 if (kind == float_nan)
1217 {
1218 if (floatformat_is_negative (fmt, valaddr))
1219 fprintf_filtered (stream, "-");
1220 fprintf_filtered (stream, "nan(");
1221 fputs_filtered ("0x", stream);
1222 fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
1223 fprintf_filtered (stream, ")");
1224 return;
1225 }
1226 else if (kind == float_infinite)
1227 {
1228 if (floatformat_is_negative (fmt, valaddr))
1229 fputs_filtered ("-", stream);
1230 fputs_filtered ("inf", stream);
1231 return;
1232 }
1233 }
1234
1235 /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating()
1236 isn't necessarily a TYPE_CODE_FLT. Consequently, unpack_double
1237 needs to be used as that takes care of any necessary type
1238 conversions. Such conversions are of course direct to DOUBLEST
1239 and disregard any possible target floating point limitations.
1240 For instance, a u64 would be converted and displayed exactly on a
1241 host with 80 bit DOUBLEST but with loss of information on a host
1242 with 64 bit DOUBLEST. */
1243
1244 doub = unpack_double (type, valaddr, &inv);
1245 if (inv)
1246 {
1247 fprintf_filtered (stream, "<invalid float value>");
1248 return;
1249 }
1250
1251 /* FIXME: kettenis/2001-01-20: The following code makes too much
1252 assumptions about the host and target floating point format. */
1253
1254 /* NOTE: cagney/2002-02-03: Since the TYPE of what was passed in may
1255 not necessarily be a TYPE_CODE_FLT, the below ignores that and
1256 instead uses the type's length to determine the precision of the
1257 floating-point value being printed. */
1258
1259 if (len < sizeof (double))
1260 fprintf_filtered (stream, "%.9g", (double) doub);
1261 else if (len == sizeof (double))
1262 fprintf_filtered (stream, "%.17g", (double) doub);
1263 else
1264 #ifdef PRINTF_HAS_LONG_DOUBLE
1265 fprintf_filtered (stream, "%.35Lg", doub);
1266 #else
1267 /* This at least wins with values that are representable as
1268 doubles. */
1269 fprintf_filtered (stream, "%.17g", (double) doub);
1270 #endif
1271 }
1272
1273 void
1274 print_decimal_floating (const gdb_byte *valaddr, struct type *type,
1275 struct ui_file *stream)
1276 {
1277 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
1278 char decstr[MAX_DECIMAL_STRING];
1279 unsigned len = TYPE_LENGTH (type);
1280
1281 decimal_to_string (valaddr, len, byte_order, decstr);
1282 fputs_filtered (decstr, stream);
1283 return;
1284 }
1285
1286 void
1287 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
1288 unsigned len, enum bfd_endian byte_order)
1289 {
1290
1291 #define BITS_IN_BYTES 8
1292
1293 const gdb_byte *p;
1294 unsigned int i;
1295 int b;
1296
1297 /* Declared "int" so it will be signed.
1298 This ensures that right shift will shift in zeros. */
1299
1300 const int mask = 0x080;
1301
1302 /* FIXME: We should be not printing leading zeroes in most cases. */
1303
1304 if (byte_order == BFD_ENDIAN_BIG)
1305 {
1306 for (p = valaddr;
1307 p < valaddr + len;
1308 p++)
1309 {
1310 /* Every byte has 8 binary characters; peel off
1311 and print from the MSB end. */
1312
1313 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
1314 {
1315 if (*p & (mask >> i))
1316 b = 1;
1317 else
1318 b = 0;
1319
1320 fprintf_filtered (stream, "%1d", b);
1321 }
1322 }
1323 }
1324 else
1325 {
1326 for (p = valaddr + len - 1;
1327 p >= valaddr;
1328 p--)
1329 {
1330 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
1331 {
1332 if (*p & (mask >> i))
1333 b = 1;
1334 else
1335 b = 0;
1336
1337 fprintf_filtered (stream, "%1d", b);
1338 }
1339 }
1340 }
1341 }
1342
1343 /* VALADDR points to an integer of LEN bytes.
1344 Print it in octal on stream or format it in buf. */
1345
1346 void
1347 print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
1348 unsigned len, enum bfd_endian byte_order)
1349 {
1350 const gdb_byte *p;
1351 unsigned char octa1, octa2, octa3, carry;
1352 int cycle;
1353
1354 /* FIXME: We should be not printing leading zeroes in most cases. */
1355
1356
1357 /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track
1358 * the extra bits, which cycle every three bytes:
1359 *
1360 * Byte side: 0 1 2 3
1361 * | | | |
1362 * bit number 123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 |
1363 *
1364 * Octal side: 0 1 carry 3 4 carry ...
1365 *
1366 * Cycle number: 0 1 2
1367 *
1368 * But of course we are printing from the high side, so we have to
1369 * figure out where in the cycle we are so that we end up with no
1370 * left over bits at the end.
1371 */
1372 #define BITS_IN_OCTAL 3
1373 #define HIGH_ZERO 0340
1374 #define LOW_ZERO 0016
1375 #define CARRY_ZERO 0003
1376 #define HIGH_ONE 0200
1377 #define MID_ONE 0160
1378 #define LOW_ONE 0016
1379 #define CARRY_ONE 0001
1380 #define HIGH_TWO 0300
1381 #define MID_TWO 0070
1382 #define LOW_TWO 0007
1383
1384 /* For 32 we start in cycle 2, with two bits and one bit carry;
1385 for 64 in cycle in cycle 1, with one bit and a two bit carry. */
1386
1387 cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL;
1388 carry = 0;
1389
1390 fputs_filtered ("0", stream);
1391 if (byte_order == BFD_ENDIAN_BIG)
1392 {
1393 for (p = valaddr;
1394 p < valaddr + len;
1395 p++)
1396 {
1397 switch (cycle)
1398 {
1399 case 0:
1400 /* No carry in, carry out two bits. */
1401
1402 octa1 = (HIGH_ZERO & *p) >> 5;
1403 octa2 = (LOW_ZERO & *p) >> 2;
1404 carry = (CARRY_ZERO & *p);
1405 fprintf_filtered (stream, "%o", octa1);
1406 fprintf_filtered (stream, "%o", octa2);
1407 break;
1408
1409 case 1:
1410 /* Carry in two bits, carry out one bit. */
1411
1412 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
1413 octa2 = (MID_ONE & *p) >> 4;
1414 octa3 = (LOW_ONE & *p) >> 1;
1415 carry = (CARRY_ONE & *p);
1416 fprintf_filtered (stream, "%o", octa1);
1417 fprintf_filtered (stream, "%o", octa2);
1418 fprintf_filtered (stream, "%o", octa3);
1419 break;
1420
1421 case 2:
1422 /* Carry in one bit, no carry out. */
1423
1424 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
1425 octa2 = (MID_TWO & *p) >> 3;
1426 octa3 = (LOW_TWO & *p);
1427 carry = 0;
1428 fprintf_filtered (stream, "%o", octa1);
1429 fprintf_filtered (stream, "%o", octa2);
1430 fprintf_filtered (stream, "%o", octa3);
1431 break;
1432
1433 default:
1434 error (_("Internal error in octal conversion;"));
1435 }
1436
1437 cycle++;
1438 cycle = cycle % BITS_IN_OCTAL;
1439 }
1440 }
1441 else
1442 {
1443 for (p = valaddr + len - 1;
1444 p >= valaddr;
1445 p--)
1446 {
1447 switch (cycle)
1448 {
1449 case 0:
1450 /* Carry out, no carry in */
1451
1452 octa1 = (HIGH_ZERO & *p) >> 5;
1453 octa2 = (LOW_ZERO & *p) >> 2;
1454 carry = (CARRY_ZERO & *p);
1455 fprintf_filtered (stream, "%o", octa1);
1456 fprintf_filtered (stream, "%o", octa2);
1457 break;
1458
1459 case 1:
1460 /* Carry in, carry out */
1461
1462 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
1463 octa2 = (MID_ONE & *p) >> 4;
1464 octa3 = (LOW_ONE & *p) >> 1;
1465 carry = (CARRY_ONE & *p);
1466 fprintf_filtered (stream, "%o", octa1);
1467 fprintf_filtered (stream, "%o", octa2);
1468 fprintf_filtered (stream, "%o", octa3);
1469 break;
1470
1471 case 2:
1472 /* Carry in, no carry out */
1473
1474 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
1475 octa2 = (MID_TWO & *p) >> 3;
1476 octa3 = (LOW_TWO & *p);
1477 carry = 0;
1478 fprintf_filtered (stream, "%o", octa1);
1479 fprintf_filtered (stream, "%o", octa2);
1480 fprintf_filtered (stream, "%o", octa3);
1481 break;
1482
1483 default:
1484 error (_("Internal error in octal conversion;"));
1485 }
1486
1487 cycle++;
1488 cycle = cycle % BITS_IN_OCTAL;
1489 }
1490 }
1491
1492 }
1493
1494 /* VALADDR points to an integer of LEN bytes.
1495 Print it in decimal on stream or format it in buf. */
1496
1497 void
1498 print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
1499 unsigned len, enum bfd_endian byte_order)
1500 {
1501 #define TEN 10
1502 #define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */
1503 #define CARRY_LEFT( x ) ((x) % TEN)
1504 #define SHIFT( x ) ((x) << 4)
1505 #define LOW_NIBBLE( x ) ( (x) & 0x00F)
1506 #define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
1507
1508 const gdb_byte *p;
1509 unsigned char *digits;
1510 int carry;
1511 int decimal_len;
1512 int i, j, decimal_digits;
1513 int dummy;
1514 int flip;
1515
1516 /* Base-ten number is less than twice as many digits
1517 as the base 16 number, which is 2 digits per byte. */
1518
1519 decimal_len = len * 2 * 2;
1520 digits = xmalloc (decimal_len);
1521
1522 for (i = 0; i < decimal_len; i++)
1523 {
1524 digits[i] = 0;
1525 }
1526
1527 /* Ok, we have an unknown number of bytes of data to be printed in
1528 * decimal.
1529 *
1530 * Given a hex number (in nibbles) as XYZ, we start by taking X and
1531 * decemalizing it as "x1 x2" in two decimal nibbles. Then we multiply
1532 * the nibbles by 16, add Y and re-decimalize. Repeat with Z.
1533 *
1534 * The trick is that "digits" holds a base-10 number, but sometimes
1535 * the individual digits are > 10.
1536 *
1537 * Outer loop is per nibble (hex digit) of input, from MSD end to
1538 * LSD end.
1539 */
1540 decimal_digits = 0; /* Number of decimal digits so far */
1541 p = (byte_order == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1;
1542 flip = 0;
1543 while ((byte_order == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
1544 {
1545 /*
1546 * Multiply current base-ten number by 16 in place.
1547 * Each digit was between 0 and 9, now is between
1548 * 0 and 144.
1549 */
1550 for (j = 0; j < decimal_digits; j++)
1551 {
1552 digits[j] = SHIFT (digits[j]);
1553 }
1554
1555 /* Take the next nibble off the input and add it to what
1556 * we've got in the LSB position. Bottom 'digit' is now
1557 * between 0 and 159.
1558 *
1559 * "flip" is used to run this loop twice for each byte.
1560 */
1561 if (flip == 0)
1562 {
1563 /* Take top nibble. */
1564
1565 digits[0] += HIGH_NIBBLE (*p);
1566 flip = 1;
1567 }
1568 else
1569 {
1570 /* Take low nibble and bump our pointer "p". */
1571
1572 digits[0] += LOW_NIBBLE (*p);
1573 if (byte_order == BFD_ENDIAN_BIG)
1574 p++;
1575 else
1576 p--;
1577 flip = 0;
1578 }
1579
1580 /* Re-decimalize. We have to do this often enough
1581 * that we don't overflow, but once per nibble is
1582 * overkill. Easier this way, though. Note that the
1583 * carry is often larger than 10 (e.g. max initial
1584 * carry out of lowest nibble is 15, could bubble all
1585 * the way up greater than 10). So we have to do
1586 * the carrying beyond the last current digit.
1587 */
1588 carry = 0;
1589 for (j = 0; j < decimal_len - 1; j++)
1590 {
1591 digits[j] += carry;
1592
1593 /* "/" won't handle an unsigned char with
1594 * a value that if signed would be negative.
1595 * So extend to longword int via "dummy".
1596 */
1597 dummy = digits[j];
1598 carry = CARRY_OUT (dummy);
1599 digits[j] = CARRY_LEFT (dummy);
1600
1601 if (j >= decimal_digits && carry == 0)
1602 {
1603 /*
1604 * All higher digits are 0 and we
1605 * no longer have a carry.
1606 *
1607 * Note: "j" is 0-based, "decimal_digits" is
1608 * 1-based.
1609 */
1610 decimal_digits = j + 1;
1611 break;
1612 }
1613 }
1614 }
1615
1616 /* Ok, now "digits" is the decimal representation, with
1617 the "decimal_digits" actual digits. Print! */
1618
1619 for (i = decimal_digits - 1; i >= 0; i--)
1620 {
1621 fprintf_filtered (stream, "%1d", digits[i]);
1622 }
1623 xfree (digits);
1624 }
1625
1626 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
1627
1628 void
1629 print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
1630 unsigned len, enum bfd_endian byte_order)
1631 {
1632 const gdb_byte *p;
1633
1634 /* FIXME: We should be not printing leading zeroes in most cases. */
1635
1636 fputs_filtered ("0x", stream);
1637 if (byte_order == BFD_ENDIAN_BIG)
1638 {
1639 for (p = valaddr;
1640 p < valaddr + len;
1641 p++)
1642 {
1643 fprintf_filtered (stream, "%02x", *p);
1644 }
1645 }
1646 else
1647 {
1648 for (p = valaddr + len - 1;
1649 p >= valaddr;
1650 p--)
1651 {
1652 fprintf_filtered (stream, "%02x", *p);
1653 }
1654 }
1655 }
1656
1657 /* VALADDR points to a char integer of LEN bytes.
1658 Print it out in appropriate language form on stream.
1659 Omit any leading zero chars. */
1660
1661 void
1662 print_char_chars (struct ui_file *stream, struct type *type,
1663 const gdb_byte *valaddr,
1664 unsigned len, enum bfd_endian byte_order)
1665 {
1666 const gdb_byte *p;
1667
1668 if (byte_order == BFD_ENDIAN_BIG)
1669 {
1670 p = valaddr;
1671 while (p < valaddr + len - 1 && *p == 0)
1672 ++p;
1673
1674 while (p < valaddr + len)
1675 {
1676 LA_EMIT_CHAR (*p, type, stream, '\'');
1677 ++p;
1678 }
1679 }
1680 else
1681 {
1682 p = valaddr + len - 1;
1683 while (p > valaddr && *p == 0)
1684 --p;
1685
1686 while (p >= valaddr)
1687 {
1688 LA_EMIT_CHAR (*p, type, stream, '\'');
1689 --p;
1690 }
1691 }
1692 }
1693
1694 /* Print function pointer with inferior address ADDRESS onto stdio
1695 stream STREAM. */
1696
1697 void
1698 print_function_pointer_address (const struct value_print_options *options,
1699 struct gdbarch *gdbarch,
1700 CORE_ADDR address,
1701 struct ui_file *stream)
1702 {
1703 CORE_ADDR func_addr
1704 = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
1705 &current_target);
1706
1707 /* If the function pointer is represented by a description, print
1708 the address of the description. */
1709 if (options->addressprint && func_addr != address)
1710 {
1711 fputs_filtered ("@", stream);
1712 fputs_filtered (paddress (gdbarch, address), stream);
1713 fputs_filtered (": ", stream);
1714 }
1715 print_address_demangle (options, gdbarch, func_addr, stream, demangle);
1716 }
1717
1718
1719 /* Print on STREAM using the given OPTIONS the index for the element
1720 at INDEX of an array whose index type is INDEX_TYPE. */
1721
1722 void
1723 maybe_print_array_index (struct type *index_type, LONGEST index,
1724 struct ui_file *stream,
1725 const struct value_print_options *options)
1726 {
1727 struct value *index_value;
1728
1729 if (!options->print_array_indexes)
1730 return;
1731
1732 index_value = value_from_longest (index_type, index);
1733
1734 LA_PRINT_ARRAY_INDEX (index_value, stream, options);
1735 }
1736
1737 /* Called by various <lang>_val_print routines to print elements of an
1738 array in the form "<elem1>, <elem2>, <elem3>, ...".
1739
1740 (FIXME?) Assumes array element separator is a comma, which is correct
1741 for all languages currently handled.
1742 (FIXME?) Some languages have a notation for repeated array elements,
1743 perhaps we should try to use that notation when appropriate. */
1744
1745 void
1746 val_print_array_elements (struct type *type,
1747 const gdb_byte *valaddr, int embedded_offset,
1748 CORE_ADDR address, struct ui_file *stream,
1749 int recurse,
1750 const struct value *val,
1751 const struct value_print_options *options,
1752 unsigned int i)
1753 {
1754 unsigned int things_printed = 0;
1755 unsigned len;
1756 struct type *elttype, *index_type, *base_index_type;
1757 unsigned eltlen;
1758 /* Position of the array element we are examining to see
1759 whether it is repeated. */
1760 unsigned int rep1;
1761 /* Number of repetitions we have detected so far. */
1762 unsigned int reps;
1763 LONGEST low_bound, high_bound;
1764 LONGEST low_pos, high_pos;
1765
1766 elttype = TYPE_TARGET_TYPE (type);
1767 eltlen = TYPE_LENGTH (check_typedef (elttype));
1768 index_type = TYPE_INDEX_TYPE (type);
1769
1770 if (get_array_bounds (type, &low_bound, &high_bound))
1771 {
1772 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
1773 base_index_type = TYPE_TARGET_TYPE (index_type);
1774 else
1775 base_index_type = index_type;
1776
1777 /* Non-contiguous enumerations types can by used as index types
1778 in some languages (e.g. Ada). In this case, the array length
1779 shall be computed from the positions of the first and last
1780 literal in the enumeration type, and not from the values
1781 of these literals. */
1782 if (!discrete_position (base_index_type, low_bound, &low_pos)
1783 || !discrete_position (base_index_type, high_bound, &high_pos))
1784 {
1785 warning (_("unable to get positions in array, use bounds instead"));
1786 low_pos = low_bound;
1787 high_pos = high_bound;
1788 }
1789
1790 /* The array length should normally be HIGH_POS - LOW_POS + 1.
1791 But we have to be a little extra careful, because some languages
1792 such as Ada allow LOW_POS to be greater than HIGH_POS for
1793 empty arrays. In that situation, the array length is just zero,
1794 not negative! */
1795 if (low_pos > high_pos)
1796 len = 0;
1797 else
1798 len = high_pos - low_pos + 1;
1799 }
1800 else
1801 {
1802 warning (_("unable to get bounds of array, assuming null array"));
1803 low_bound = 0;
1804 len = 0;
1805 }
1806
1807 annotate_array_section_begin (i, elttype);
1808
1809 for (; i < len && things_printed < options->print_max; i++)
1810 {
1811 if (i != 0)
1812 {
1813 if (options->prettyformat_arrays)
1814 {
1815 fprintf_filtered (stream, ",\n");
1816 print_spaces_filtered (2 + 2 * recurse, stream);
1817 }
1818 else
1819 {
1820 fprintf_filtered (stream, ", ");
1821 }
1822 }
1823 wrap_here (n_spaces (2 + 2 * recurse));
1824 maybe_print_array_index (index_type, i + low_bound,
1825 stream, options);
1826
1827 rep1 = i + 1;
1828 reps = 1;
1829 /* Only check for reps if repeat_count_threshold is not set to
1830 UINT_MAX (unlimited). */
1831 if (options->repeat_count_threshold < UINT_MAX)
1832 {
1833 while (rep1 < len
1834 && value_contents_eq (val,
1835 embedded_offset + i * eltlen,
1836 val,
1837 (embedded_offset
1838 + rep1 * eltlen),
1839 eltlen))
1840 {
1841 ++reps;
1842 ++rep1;
1843 }
1844 }
1845
1846 if (reps > options->repeat_count_threshold)
1847 {
1848 val_print (elttype, valaddr, embedded_offset + i * eltlen,
1849 address, stream, recurse + 1, val, options,
1850 current_language);
1851 annotate_elt_rep (reps);
1852 fprintf_filtered (stream, " <repeats %u times>", reps);
1853 annotate_elt_rep_end ();
1854
1855 i = rep1 - 1;
1856 things_printed += options->repeat_count_threshold;
1857 }
1858 else
1859 {
1860 val_print (elttype, valaddr, embedded_offset + i * eltlen,
1861 address,
1862 stream, recurse + 1, val, options, current_language);
1863 annotate_elt ();
1864 things_printed++;
1865 }
1866 }
1867 annotate_array_section_end ();
1868 if (i < len)
1869 {
1870 fprintf_filtered (stream, "...");
1871 }
1872 }
1873
1874 /* Read LEN bytes of target memory at address MEMADDR, placing the
1875 results in GDB's memory at MYADDR. Returns a count of the bytes
1876 actually read, and optionally a target_xfer_status value in the
1877 location pointed to by ERRPTR if ERRPTR is non-null. */
1878
1879 /* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this
1880 function be eliminated. */
1881
1882 static int
1883 partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
1884 int len, int *errptr)
1885 {
1886 int nread; /* Number of bytes actually read. */
1887 int errcode; /* Error from last read. */
1888
1889 /* First try a complete read. */
1890 errcode = target_read_memory (memaddr, myaddr, len);
1891 if (errcode == 0)
1892 {
1893 /* Got it all. */
1894 nread = len;
1895 }
1896 else
1897 {
1898 /* Loop, reading one byte at a time until we get as much as we can. */
1899 for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
1900 {
1901 errcode = target_read_memory (memaddr++, myaddr++, 1);
1902 }
1903 /* If an error, the last read was unsuccessful, so adjust count. */
1904 if (errcode != 0)
1905 {
1906 nread--;
1907 }
1908 }
1909 if (errptr != NULL)
1910 {
1911 *errptr = errcode;
1912 }
1913 return (nread);
1914 }
1915
1916 /* Read a string from the inferior, at ADDR, with LEN characters of WIDTH bytes
1917 each. Fetch at most FETCHLIMIT characters. BUFFER will be set to a newly
1918 allocated buffer containing the string, which the caller is responsible to
1919 free, and BYTES_READ will be set to the number of bytes read. Returns 0 on
1920 success, or a target_xfer_status on failure.
1921
1922 If LEN > 0, reads the lesser of LEN or FETCHLIMIT characters
1923 (including eventual NULs in the middle or end of the string).
1924
1925 If LEN is -1, stops at the first null character (not necessarily
1926 the first null byte) up to a maximum of FETCHLIMIT characters. Set
1927 FETCHLIMIT to UINT_MAX to read as many characters as possible from
1928 the string.
1929
1930 Unless an exception is thrown, BUFFER will always be allocated, even on
1931 failure. In this case, some characters might have been read before the
1932 failure happened. Check BYTES_READ to recognize this situation.
1933
1934 Note: There was a FIXME asking to make this code use target_read_string,
1935 but this function is more general (can read past null characters, up to
1936 given LEN). Besides, it is used much more often than target_read_string
1937 so it is more tested. Perhaps callers of target_read_string should use
1938 this function instead? */
1939
1940 int
1941 read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
1942 enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read)
1943 {
1944 int errcode; /* Errno returned from bad reads. */
1945 unsigned int nfetch; /* Chars to fetch / chars fetched. */
1946 gdb_byte *bufptr; /* Pointer to next available byte in
1947 buffer. */
1948 struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
1949
1950 /* Loop until we either have all the characters, or we encounter
1951 some error, such as bumping into the end of the address space. */
1952
1953 *buffer = NULL;
1954
1955 old_chain = make_cleanup (free_current_contents, buffer);
1956
1957 if (len > 0)
1958 {
1959 /* We want fetchlimit chars, so we might as well read them all in
1960 one operation. */
1961 unsigned int fetchlen = min (len, fetchlimit);
1962
1963 *buffer = (gdb_byte *) xmalloc (fetchlen * width);
1964 bufptr = *buffer;
1965
1966 nfetch = partial_memory_read (addr, bufptr, fetchlen * width, &errcode)
1967 / width;
1968 addr += nfetch * width;
1969 bufptr += nfetch * width;
1970 }
1971 else if (len == -1)
1972 {
1973 unsigned long bufsize = 0;
1974 unsigned int chunksize; /* Size of each fetch, in chars. */
1975 int found_nul; /* Non-zero if we found the nul char. */
1976 gdb_byte *limit; /* First location past end of fetch buffer. */
1977
1978 found_nul = 0;
1979 /* We are looking for a NUL terminator to end the fetching, so we
1980 might as well read in blocks that are large enough to be efficient,
1981 but not so large as to be slow if fetchlimit happens to be large.
1982 So we choose the minimum of 8 and fetchlimit. We used to use 200
1983 instead of 8 but 200 is way too big for remote debugging over a
1984 serial line. */
1985 chunksize = min (8, fetchlimit);
1986
1987 do
1988 {
1989 QUIT;
1990 nfetch = min (chunksize, fetchlimit - bufsize);
1991
1992 if (*buffer == NULL)
1993 *buffer = (gdb_byte *) xmalloc (nfetch * width);
1994 else
1995 *buffer = (gdb_byte *) xrealloc (*buffer,
1996 (nfetch + bufsize) * width);
1997
1998 bufptr = *buffer + bufsize * width;
1999 bufsize += nfetch;
2000
2001 /* Read as much as we can. */
2002 nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode)
2003 / width;
2004
2005 /* Scan this chunk for the null character that terminates the string
2006 to print. If found, we don't need to fetch any more. Note
2007 that bufptr is explicitly left pointing at the next character
2008 after the null character, or at the next character after the end
2009 of the buffer. */
2010
2011 limit = bufptr + nfetch * width;
2012 while (bufptr < limit)
2013 {
2014 unsigned long c;
2015
2016 c = extract_unsigned_integer (bufptr, width, byte_order);
2017 addr += width;
2018 bufptr += width;
2019 if (c == 0)
2020 {
2021 /* We don't care about any error which happened after
2022 the NUL terminator. */
2023 errcode = 0;
2024 found_nul = 1;
2025 break;
2026 }
2027 }
2028 }
2029 while (errcode == 0 /* no error */
2030 && bufptr - *buffer < fetchlimit * width /* no overrun */
2031 && !found_nul); /* haven't found NUL yet */
2032 }
2033 else
2034 { /* Length of string is really 0! */
2035 /* We always allocate *buffer. */
2036 *buffer = bufptr = xmalloc (1);
2037 errcode = 0;
2038 }
2039
2040 /* bufptr and addr now point immediately beyond the last byte which we
2041 consider part of the string (including a '\0' which ends the string). */
2042 *bytes_read = bufptr - *buffer;
2043
2044 QUIT;
2045
2046 discard_cleanups (old_chain);
2047
2048 return errcode;
2049 }
2050
2051 /* Return true if print_wchar can display W without resorting to a
2052 numeric escape, false otherwise. */
2053
2054 static int
2055 wchar_printable (gdb_wchar_t w)
2056 {
2057 return (gdb_iswprint (w)
2058 || w == LCST ('\a') || w == LCST ('\b')
2059 || w == LCST ('\f') || w == LCST ('\n')
2060 || w == LCST ('\r') || w == LCST ('\t')
2061 || w == LCST ('\v'));
2062 }
2063
2064 /* A helper function that converts the contents of STRING to wide
2065 characters and then appends them to OUTPUT. */
2066
2067 static void
2068 append_string_as_wide (const char *string,
2069 struct obstack *output)
2070 {
2071 for (; *string; ++string)
2072 {
2073 gdb_wchar_t w = gdb_btowc (*string);
2074 obstack_grow (output, &w, sizeof (gdb_wchar_t));
2075 }
2076 }
2077
2078 /* Print a wide character W to OUTPUT. ORIG is a pointer to the
2079 original (target) bytes representing the character, ORIG_LEN is the
2080 number of valid bytes. WIDTH is the number of bytes in a base
2081 characters of the type. OUTPUT is an obstack to which wide
2082 characters are emitted. QUOTER is a (narrow) character indicating
2083 the style of quotes surrounding the character to be printed.
2084 NEED_ESCAPE is an in/out flag which is used to track numeric
2085 escapes across calls. */
2086
2087 static void
2088 print_wchar (gdb_wint_t w, const gdb_byte *orig,
2089 int orig_len, int width,
2090 enum bfd_endian byte_order,
2091 struct obstack *output,
2092 int quoter, int *need_escapep)
2093 {
2094 int need_escape = *need_escapep;
2095
2096 *need_escapep = 0;
2097
2098 /* iswprint implementation on Windows returns 1 for tab character.
2099 In order to avoid different printout on this host, we explicitly
2100 use wchar_printable function. */
2101 switch (w)
2102 {
2103 case LCST ('\a'):
2104 obstack_grow_wstr (output, LCST ("\\a"));
2105 break;
2106 case LCST ('\b'):
2107 obstack_grow_wstr (output, LCST ("\\b"));
2108 break;
2109 case LCST ('\f'):
2110 obstack_grow_wstr (output, LCST ("\\f"));
2111 break;
2112 case LCST ('\n'):
2113 obstack_grow_wstr (output, LCST ("\\n"));
2114 break;
2115 case LCST ('\r'):
2116 obstack_grow_wstr (output, LCST ("\\r"));
2117 break;
2118 case LCST ('\t'):
2119 obstack_grow_wstr (output, LCST ("\\t"));
2120 break;
2121 case LCST ('\v'):
2122 obstack_grow_wstr (output, LCST ("\\v"));
2123 break;
2124 default:
2125 {
2126 if (wchar_printable (w) && (!need_escape || (!gdb_iswdigit (w)
2127 && w != LCST ('8')
2128 && w != LCST ('9'))))
2129 {
2130 gdb_wchar_t wchar = w;
2131
2132 if (w == gdb_btowc (quoter) || w == LCST ('\\'))
2133 obstack_grow_wstr (output, LCST ("\\"));
2134 obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
2135 }
2136 else
2137 {
2138 int i;
2139
2140 for (i = 0; i + width <= orig_len; i += width)
2141 {
2142 char octal[30];
2143 ULONGEST value;
2144
2145 value = extract_unsigned_integer (&orig[i], width,
2146 byte_order);
2147 /* If the value fits in 3 octal digits, print it that
2148 way. Otherwise, print it as a hex escape. */
2149 if (value <= 0777)
2150 xsnprintf (octal, sizeof (octal), "\\%.3o",
2151 (int) (value & 0777));
2152 else
2153 xsnprintf (octal, sizeof (octal), "\\x%lx", (long) value);
2154 append_string_as_wide (octal, output);
2155 }
2156 /* If we somehow have extra bytes, print them now. */
2157 while (i < orig_len)
2158 {
2159 char octal[5];
2160
2161 xsnprintf (octal, sizeof (octal), "\\%.3o", orig[i] & 0xff);
2162 append_string_as_wide (octal, output);
2163 ++i;
2164 }
2165
2166 *need_escapep = 1;
2167 }
2168 break;
2169 }
2170 }
2171 }
2172
2173 /* Print the character C on STREAM as part of the contents of a
2174 literal string whose delimiter is QUOTER. ENCODING names the
2175 encoding of C. */
2176
2177 void
2178 generic_emit_char (int c, struct type *type, struct ui_file *stream,
2179 int quoter, const char *encoding)
2180 {
2181 enum bfd_endian byte_order
2182 = gdbarch_byte_order (get_type_arch (type));
2183 struct obstack wchar_buf, output;
2184 struct cleanup *cleanups;
2185 gdb_byte *buf;
2186 struct wchar_iterator *iter;
2187 int need_escape = 0;
2188
2189 buf = alloca (TYPE_LENGTH (type));
2190 pack_long (buf, type, c);
2191
2192 iter = make_wchar_iterator (buf, TYPE_LENGTH (type),
2193 encoding, TYPE_LENGTH (type));
2194 cleanups = make_cleanup_wchar_iterator (iter);
2195
2196 /* This holds the printable form of the wchar_t data. */
2197 obstack_init (&wchar_buf);
2198 make_cleanup_obstack_free (&wchar_buf);
2199
2200 while (1)
2201 {
2202 int num_chars;
2203 gdb_wchar_t *chars;
2204 const gdb_byte *buf;
2205 size_t buflen;
2206 int print_escape = 1;
2207 enum wchar_iterate_result result;
2208
2209 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
2210 if (num_chars < 0)
2211 break;
2212 if (num_chars > 0)
2213 {
2214 /* If all characters are printable, print them. Otherwise,
2215 we're going to have to print an escape sequence. We
2216 check all characters because we want to print the target
2217 bytes in the escape sequence, and we don't know character
2218 boundaries there. */
2219 int i;
2220
2221 print_escape = 0;
2222 for (i = 0; i < num_chars; ++i)
2223 if (!wchar_printable (chars[i]))
2224 {
2225 print_escape = 1;
2226 break;
2227 }
2228
2229 if (!print_escape)
2230 {
2231 for (i = 0; i < num_chars; ++i)
2232 print_wchar (chars[i], buf, buflen,
2233 TYPE_LENGTH (type), byte_order,
2234 &wchar_buf, quoter, &need_escape);
2235 }
2236 }
2237
2238 /* This handles the NUM_CHARS == 0 case as well. */
2239 if (print_escape)
2240 print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type),
2241 byte_order, &wchar_buf, quoter, &need_escape);
2242 }
2243
2244 /* The output in the host encoding. */
2245 obstack_init (&output);
2246 make_cleanup_obstack_free (&output);
2247
2248 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
2249 (gdb_byte *) obstack_base (&wchar_buf),
2250 obstack_object_size (&wchar_buf),
2251 sizeof (gdb_wchar_t), &output, translit_char);
2252 obstack_1grow (&output, '\0');
2253
2254 fputs_filtered (obstack_base (&output), stream);
2255
2256 do_cleanups (cleanups);
2257 }
2258
2259 /* Return the repeat count of the next character/byte in ITER,
2260 storing the result in VEC. */
2261
2262 static int
2263 count_next_character (struct wchar_iterator *iter,
2264 VEC (converted_character_d) **vec)
2265 {
2266 struct converted_character *current;
2267
2268 if (VEC_empty (converted_character_d, *vec))
2269 {
2270 struct converted_character tmp;
2271 gdb_wchar_t *chars;
2272
2273 tmp.num_chars
2274 = wchar_iterate (iter, &tmp.result, &chars, &tmp.buf, &tmp.buflen);
2275 if (tmp.num_chars > 0)
2276 {
2277 gdb_assert (tmp.num_chars < MAX_WCHARS);
2278 memcpy (tmp.chars, chars, tmp.num_chars * sizeof (gdb_wchar_t));
2279 }
2280 VEC_safe_push (converted_character_d, *vec, &tmp);
2281 }
2282
2283 current = VEC_last (converted_character_d, *vec);
2284
2285 /* Count repeated characters or bytes. */
2286 current->repeat_count = 1;
2287 if (current->num_chars == -1)
2288 {
2289 /* EOF */
2290 return -1;
2291 }
2292 else
2293 {
2294 gdb_wchar_t *chars;
2295 struct converted_character d;
2296 int repeat;
2297
2298 d.repeat_count = 0;
2299
2300 while (1)
2301 {
2302 /* Get the next character. */
2303 d.num_chars
2304 = wchar_iterate (iter, &d.result, &chars, &d.buf, &d.buflen);
2305
2306 /* If a character was successfully converted, save the character
2307 into the converted character. */
2308 if (d.num_chars > 0)
2309 {
2310 gdb_assert (d.num_chars < MAX_WCHARS);
2311 memcpy (d.chars, chars, WCHAR_BUFLEN (d.num_chars));
2312 }
2313
2314 /* Determine if the current character is the same as this
2315 new character. */
2316 if (d.num_chars == current->num_chars && d.result == current->result)
2317 {
2318 /* There are two cases to consider:
2319
2320 1) Equality of converted character (num_chars > 0)
2321 2) Equality of non-converted character (num_chars == 0) */
2322 if ((current->num_chars > 0
2323 && memcmp (current->chars, d.chars,
2324 WCHAR_BUFLEN (current->num_chars)) == 0)
2325 || (current->num_chars == 0
2326 && current->buflen == d.buflen
2327 && memcmp (current->buf, d.buf, current->buflen) == 0))
2328 ++current->repeat_count;
2329 else
2330 break;
2331 }
2332 else
2333 break;
2334 }
2335
2336 /* Push this next converted character onto the result vector. */
2337 repeat = current->repeat_count;
2338 VEC_safe_push (converted_character_d, *vec, &d);
2339 return repeat;
2340 }
2341 }
2342
2343 /* Print the characters in CHARS to the OBSTACK. QUOTE_CHAR is the quote
2344 character to use with string output. WIDTH is the size of the output
2345 character type. BYTE_ORDER is the the target byte order. OPTIONS
2346 is the user's print options. */
2347
2348 static void
2349 print_converted_chars_to_obstack (struct obstack *obstack,
2350 VEC (converted_character_d) *chars,
2351 int quote_char, int width,
2352 enum bfd_endian byte_order,
2353 const struct value_print_options *options)
2354 {
2355 unsigned int idx;
2356 struct converted_character *elem;
2357 enum {START, SINGLE, REPEAT, INCOMPLETE, FINISH} state, last;
2358 gdb_wchar_t wide_quote_char = gdb_btowc (quote_char);
2359 int need_escape = 0;
2360
2361 /* Set the start state. */
2362 idx = 0;
2363 last = state = START;
2364 elem = NULL;
2365
2366 while (1)
2367 {
2368 switch (state)
2369 {
2370 case START:
2371 /* Nothing to do. */
2372 break;
2373
2374 case SINGLE:
2375 {
2376 int j;
2377
2378 /* We are outputting a single character
2379 (< options->repeat_count_threshold). */
2380
2381 if (last != SINGLE)
2382 {
2383 /* We were outputting some other type of content, so we
2384 must output and a comma and a quote. */
2385 if (last != START)
2386 obstack_grow_wstr (obstack, LCST (", "));
2387 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2388 }
2389 /* Output the character. */
2390 for (j = 0; j < elem->repeat_count; ++j)
2391 {
2392 if (elem->result == wchar_iterate_ok)
2393 print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
2394 byte_order, obstack, quote_char, &need_escape);
2395 else
2396 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
2397 byte_order, obstack, quote_char, &need_escape);
2398 }
2399 }
2400 break;
2401
2402 case REPEAT:
2403 {
2404 int j;
2405 char *s;
2406
2407 /* We are outputting a character with a repeat count
2408 greater than options->repeat_count_threshold. */
2409
2410 if (last == SINGLE)
2411 {
2412 /* We were outputting a single string. Terminate the
2413 string. */
2414 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2415 }
2416 if (last != START)
2417 obstack_grow_wstr (obstack, LCST (", "));
2418
2419 /* Output the character and repeat string. */
2420 obstack_grow_wstr (obstack, LCST ("'"));
2421 if (elem->result == wchar_iterate_ok)
2422 print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
2423 byte_order, obstack, quote_char, &need_escape);
2424 else
2425 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
2426 byte_order, obstack, quote_char, &need_escape);
2427 obstack_grow_wstr (obstack, LCST ("'"));
2428 s = xstrprintf (_(" <repeats %u times>"), elem->repeat_count);
2429 for (j = 0; s[j]; ++j)
2430 {
2431 gdb_wchar_t w = gdb_btowc (s[j]);
2432 obstack_grow (obstack, &w, sizeof (gdb_wchar_t));
2433 }
2434 xfree (s);
2435 }
2436 break;
2437
2438 case INCOMPLETE:
2439 /* We are outputting an incomplete sequence. */
2440 if (last == SINGLE)
2441 {
2442 /* If we were outputting a string of SINGLE characters,
2443 terminate the quote. */
2444 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2445 }
2446 if (last != START)
2447 obstack_grow_wstr (obstack, LCST (", "));
2448
2449 /* Output the incomplete sequence string. */
2450 obstack_grow_wstr (obstack, LCST ("<incomplete sequence "));
2451 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, byte_order,
2452 obstack, 0, &need_escape);
2453 obstack_grow_wstr (obstack, LCST (">"));
2454
2455 /* We do not attempt to outupt anything after this. */
2456 state = FINISH;
2457 break;
2458
2459 case FINISH:
2460 /* All done. If we were outputting a string of SINGLE
2461 characters, the string must be terminated. Otherwise,
2462 REPEAT and INCOMPLETE are always left properly terminated. */
2463 if (last == SINGLE)
2464 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2465
2466 return;
2467 }
2468
2469 /* Get the next element and state. */
2470 last = state;
2471 if (state != FINISH)
2472 {
2473 elem = VEC_index (converted_character_d, chars, idx++);
2474 switch (elem->result)
2475 {
2476 case wchar_iterate_ok:
2477 case wchar_iterate_invalid:
2478 if (elem->repeat_count > options->repeat_count_threshold)
2479 state = REPEAT;
2480 else
2481 state = SINGLE;
2482 break;
2483
2484 case wchar_iterate_incomplete:
2485 state = INCOMPLETE;
2486 break;
2487
2488 case wchar_iterate_eof:
2489 state = FINISH;
2490 break;
2491 }
2492 }
2493 }
2494 }
2495
2496 /* Print the character string STRING, printing at most LENGTH
2497 characters. LENGTH is -1 if the string is nul terminated. TYPE is
2498 the type of each character. OPTIONS holds the printing options;
2499 printing stops early if the number hits print_max; repeat counts
2500 are printed as appropriate. Print ellipses at the end if we had to
2501 stop before printing LENGTH characters, or if FORCE_ELLIPSES.
2502 QUOTE_CHAR is the character to print at each end of the string. If
2503 C_STYLE_TERMINATOR is true, and the last character is 0, then it is
2504 omitted. */
2505
2506 void
2507 generic_printstr (struct ui_file *stream, struct type *type,
2508 const gdb_byte *string, unsigned int length,
2509 const char *encoding, int force_ellipses,
2510 int quote_char, int c_style_terminator,
2511 const struct value_print_options *options)
2512 {
2513 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
2514 unsigned int i;
2515 int width = TYPE_LENGTH (type);
2516 struct obstack wchar_buf, output;
2517 struct cleanup *cleanup;
2518 struct wchar_iterator *iter;
2519 int finished = 0;
2520 struct converted_character *last;
2521 VEC (converted_character_d) *converted_chars;
2522
2523 if (length == -1)
2524 {
2525 unsigned long current_char = 1;
2526
2527 for (i = 0; current_char; ++i)
2528 {
2529 QUIT;
2530 current_char = extract_unsigned_integer (string + i * width,
2531 width, byte_order);
2532 }
2533 length = i;
2534 }
2535
2536 /* If the string was not truncated due to `set print elements', and
2537 the last byte of it is a null, we don't print that, in
2538 traditional C style. */
2539 if (c_style_terminator
2540 && !force_ellipses
2541 && length > 0
2542 && (extract_unsigned_integer (string + (length - 1) * width,
2543 width, byte_order) == 0))
2544 length--;
2545
2546 if (length == 0)
2547 {
2548 fputs_filtered ("\"\"", stream);
2549 return;
2550 }
2551
2552 /* Arrange to iterate over the characters, in wchar_t form. */
2553 iter = make_wchar_iterator (string, length * width, encoding, width);
2554 cleanup = make_cleanup_wchar_iterator (iter);
2555 converted_chars = NULL;
2556 make_cleanup (VEC_cleanup (converted_character_d), &converted_chars);
2557
2558 /* Convert characters until the string is over or the maximum
2559 number of printed characters has been reached. */
2560 i = 0;
2561 while (i < options->print_max)
2562 {
2563 int r;
2564
2565 QUIT;
2566
2567 /* Grab the next character and repeat count. */
2568 r = count_next_character (iter, &converted_chars);
2569
2570 /* If less than zero, the end of the input string was reached. */
2571 if (r < 0)
2572 break;
2573
2574 /* Otherwise, add the count to the total print count and get
2575 the next character. */
2576 i += r;
2577 }
2578
2579 /* Get the last element and determine if the entire string was
2580 processed. */
2581 last = VEC_last (converted_character_d, converted_chars);
2582 finished = (last->result == wchar_iterate_eof);
2583
2584 /* Ensure that CONVERTED_CHARS is terminated. */
2585 last->result = wchar_iterate_eof;
2586
2587 /* WCHAR_BUF is the obstack we use to represent the string in
2588 wchar_t form. */
2589 obstack_init (&wchar_buf);
2590 make_cleanup_obstack_free (&wchar_buf);
2591
2592 /* Print the output string to the obstack. */
2593 print_converted_chars_to_obstack (&wchar_buf, converted_chars, quote_char,
2594 width, byte_order, options);
2595
2596 if (force_ellipses || !finished)
2597 obstack_grow_wstr (&wchar_buf, LCST ("..."));
2598
2599 /* OUTPUT is where we collect `char's for printing. */
2600 obstack_init (&output);
2601 make_cleanup_obstack_free (&output);
2602
2603 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
2604 (gdb_byte *) obstack_base (&wchar_buf),
2605 obstack_object_size (&wchar_buf),
2606 sizeof (gdb_wchar_t), &output, translit_char);
2607 obstack_1grow (&output, '\0');
2608
2609 fputs_filtered (obstack_base (&output), stream);
2610
2611 do_cleanups (cleanup);
2612 }
2613
2614 /* Print a string from the inferior, starting at ADDR and printing up to LEN
2615 characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing
2616 stops at the first null byte, otherwise printing proceeds (including null
2617 bytes) until either print_max or LEN characters have been printed,
2618 whichever is smaller. ENCODING is the name of the string's
2619 encoding. It can be NULL, in which case the target encoding is
2620 assumed. */
2621
2622 int
2623 val_print_string (struct type *elttype, const char *encoding,
2624 CORE_ADDR addr, int len,
2625 struct ui_file *stream,
2626 const struct value_print_options *options)
2627 {
2628 int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */
2629 int errcode; /* Errno returned from bad reads. */
2630 int found_nul; /* Non-zero if we found the nul char. */
2631 unsigned int fetchlimit; /* Maximum number of chars to print. */
2632 int bytes_read;
2633 gdb_byte *buffer = NULL; /* Dynamically growable fetch buffer. */
2634 struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
2635 struct gdbarch *gdbarch = get_type_arch (elttype);
2636 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2637 int width = TYPE_LENGTH (elttype);
2638
2639 /* First we need to figure out the limit on the number of characters we are
2640 going to attempt to fetch and print. This is actually pretty simple. If
2641 LEN >= zero, then the limit is the minimum of LEN and print_max. If
2642 LEN is -1, then the limit is print_max. This is true regardless of
2643 whether print_max is zero, UINT_MAX (unlimited), or something in between,
2644 because finding the null byte (or available memory) is what actually
2645 limits the fetch. */
2646
2647 fetchlimit = (len == -1 ? options->print_max : min (len,
2648 options->print_max));
2649
2650 errcode = read_string (addr, len, width, fetchlimit, byte_order,
2651 &buffer, &bytes_read);
2652 old_chain = make_cleanup (xfree, buffer);
2653
2654 addr += bytes_read;
2655
2656 /* We now have either successfully filled the buffer to fetchlimit,
2657 or terminated early due to an error or finding a null char when
2658 LEN is -1. */
2659
2660 /* Determine found_nul by looking at the last character read. */
2661 found_nul = 0;
2662 if (bytes_read >= width)
2663 found_nul = extract_unsigned_integer (buffer + bytes_read - width, width,
2664 byte_order) == 0;
2665 if (len == -1 && !found_nul)
2666 {
2667 gdb_byte *peekbuf;
2668
2669 /* We didn't find a NUL terminator we were looking for. Attempt
2670 to peek at the next character. If not successful, or it is not
2671 a null byte, then force ellipsis to be printed. */
2672
2673 peekbuf = (gdb_byte *) alloca (width);
2674
2675 if (target_read_memory (addr, peekbuf, width) == 0
2676 && extract_unsigned_integer (peekbuf, width, byte_order) != 0)
2677 force_ellipsis = 1;
2678 }
2679 else if ((len >= 0 && errcode != 0) || (len > bytes_read / width))
2680 {
2681 /* Getting an error when we have a requested length, or fetching less
2682 than the number of characters actually requested, always make us
2683 print ellipsis. */
2684 force_ellipsis = 1;
2685 }
2686
2687 /* If we get an error before fetching anything, don't print a string.
2688 But if we fetch something and then get an error, print the string
2689 and then the error message. */
2690 if (errcode == 0 || bytes_read > 0)
2691 {
2692 LA_PRINT_STRING (stream, elttype, buffer, bytes_read / width,
2693 encoding, force_ellipsis, options);
2694 }
2695
2696 if (errcode != 0)
2697 {
2698 char *str;
2699
2700 str = memory_error_message (errcode, gdbarch, addr);
2701 make_cleanup (xfree, str);
2702
2703 fprintf_filtered (stream, "<error: ");
2704 fputs_filtered (str, stream);
2705 fprintf_filtered (stream, ">");
2706 }
2707
2708 gdb_flush (stream);
2709 do_cleanups (old_chain);
2710
2711 return (bytes_read / width);
2712 }
2713 \f
2714
2715 /* The 'set input-radix' command writes to this auxiliary variable.
2716 If the requested radix is valid, INPUT_RADIX is updated; otherwise,
2717 it is left unchanged. */
2718
2719 static unsigned input_radix_1 = 10;
2720
2721 /* Validate an input or output radix setting, and make sure the user
2722 knows what they really did here. Radix setting is confusing, e.g.
2723 setting the input radix to "10" never changes it! */
2724
2725 static void
2726 set_input_radix (char *args, int from_tty, struct cmd_list_element *c)
2727 {
2728 set_input_radix_1 (from_tty, input_radix_1);
2729 }
2730
2731 static void
2732 set_input_radix_1 (int from_tty, unsigned radix)
2733 {
2734 /* We don't currently disallow any input radix except 0 or 1, which don't
2735 make any mathematical sense. In theory, we can deal with any input
2736 radix greater than 1, even if we don't have unique digits for every
2737 value from 0 to radix-1, but in practice we lose on large radix values.
2738 We should either fix the lossage or restrict the radix range more.
2739 (FIXME). */
2740
2741 if (radix < 2)
2742 {
2743 input_radix_1 = input_radix;
2744 error (_("Nonsense input radix ``decimal %u''; input radix unchanged."),
2745 radix);
2746 }
2747 input_radix_1 = input_radix = radix;
2748 if (from_tty)
2749 {
2750 printf_filtered (_("Input radix now set to "
2751 "decimal %u, hex %x, octal %o.\n"),
2752 radix, radix, radix);
2753 }
2754 }
2755
2756 /* The 'set output-radix' command writes to this auxiliary variable.
2757 If the requested radix is valid, OUTPUT_RADIX is updated,
2758 otherwise, it is left unchanged. */
2759
2760 static unsigned output_radix_1 = 10;
2761
2762 static void
2763 set_output_radix (char *args, int from_tty, struct cmd_list_element *c)
2764 {
2765 set_output_radix_1 (from_tty, output_radix_1);
2766 }
2767
2768 static void
2769 set_output_radix_1 (int from_tty, unsigned radix)
2770 {
2771 /* Validate the radix and disallow ones that we aren't prepared to
2772 handle correctly, leaving the radix unchanged. */
2773 switch (radix)
2774 {
2775 case 16:
2776 user_print_options.output_format = 'x'; /* hex */
2777 break;
2778 case 10:
2779 user_print_options.output_format = 0; /* decimal */
2780 break;
2781 case 8:
2782 user_print_options.output_format = 'o'; /* octal */
2783 break;
2784 default:
2785 output_radix_1 = output_radix;
2786 error (_("Unsupported output radix ``decimal %u''; "
2787 "output radix unchanged."),
2788 radix);
2789 }
2790 output_radix_1 = output_radix = radix;
2791 if (from_tty)
2792 {
2793 printf_filtered (_("Output radix now set to "
2794 "decimal %u, hex %x, octal %o.\n"),
2795 radix, radix, radix);
2796 }
2797 }
2798
2799 /* Set both the input and output radix at once. Try to set the output radix
2800 first, since it has the most restrictive range. An radix that is valid as
2801 an output radix is also valid as an input radix.
2802
2803 It may be useful to have an unusual input radix. If the user wishes to
2804 set an input radix that is not valid as an output radix, he needs to use
2805 the 'set input-radix' command. */
2806
2807 static void
2808 set_radix (char *arg, int from_tty)
2809 {
2810 unsigned radix;
2811
2812 radix = (arg == NULL) ? 10 : parse_and_eval_long (arg);
2813 set_output_radix_1 (0, radix);
2814 set_input_radix_1 (0, radix);
2815 if (from_tty)
2816 {
2817 printf_filtered (_("Input and output radices now set to "
2818 "decimal %u, hex %x, octal %o.\n"),
2819 radix, radix, radix);
2820 }
2821 }
2822
2823 /* Show both the input and output radices. */
2824
2825 static void
2826 show_radix (char *arg, int from_tty)
2827 {
2828 if (from_tty)
2829 {
2830 if (input_radix == output_radix)
2831 {
2832 printf_filtered (_("Input and output radices set to "
2833 "decimal %u, hex %x, octal %o.\n"),
2834 input_radix, input_radix, input_radix);
2835 }
2836 else
2837 {
2838 printf_filtered (_("Input radix set to decimal "
2839 "%u, hex %x, octal %o.\n"),
2840 input_radix, input_radix, input_radix);
2841 printf_filtered (_("Output radix set to decimal "
2842 "%u, hex %x, octal %o.\n"),
2843 output_radix, output_radix, output_radix);
2844 }
2845 }
2846 }
2847 \f
2848
2849 static void
2850 set_print (char *arg, int from_tty)
2851 {
2852 printf_unfiltered (
2853 "\"set print\" must be followed by the name of a print subcommand.\n");
2854 help_list (setprintlist, "set print ", all_commands, gdb_stdout);
2855 }
2856
2857 static void
2858 show_print (char *args, int from_tty)
2859 {
2860 cmd_show_list (showprintlist, from_tty, "");
2861 }
2862
2863 static void
2864 set_print_raw (char *arg, int from_tty)
2865 {
2866 printf_unfiltered (
2867 "\"set print raw\" must be followed by the name of a \"print raw\" subcommand.\n");
2868 help_list (setprintrawlist, "set print raw ", all_commands, gdb_stdout);
2869 }
2870
2871 static void
2872 show_print_raw (char *args, int from_tty)
2873 {
2874 cmd_show_list (showprintrawlist, from_tty, "");
2875 }
2876
2877 \f
2878 void
2879 _initialize_valprint (void)
2880 {
2881 add_prefix_cmd ("print", no_class, set_print,
2882 _("Generic command for setting how things print."),
2883 &setprintlist, "set print ", 0, &setlist);
2884 add_alias_cmd ("p", "print", no_class, 1, &setlist);
2885 /* Prefer set print to set prompt. */
2886 add_alias_cmd ("pr", "print", no_class, 1, &setlist);
2887
2888 add_prefix_cmd ("print", no_class, show_print,
2889 _("Generic command for showing print settings."),
2890 &showprintlist, "show print ", 0, &showlist);
2891 add_alias_cmd ("p", "print", no_class, 1, &showlist);
2892 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
2893
2894 add_prefix_cmd ("raw", no_class, set_print_raw,
2895 _("\
2896 Generic command for setting what things to print in \"raw\" mode."),
2897 &setprintrawlist, "set print raw ", 0, &setprintlist);
2898 add_prefix_cmd ("raw", no_class, show_print_raw,
2899 _("Generic command for showing \"print raw\" settings."),
2900 &showprintrawlist, "show print raw ", 0, &showprintlist);
2901
2902 add_setshow_uinteger_cmd ("elements", no_class,
2903 &user_print_options.print_max, _("\
2904 Set limit on string chars or array elements to print."), _("\
2905 Show limit on string chars or array elements to print."), _("\
2906 \"set print elements unlimited\" causes there to be no limit."),
2907 NULL,
2908 show_print_max,
2909 &setprintlist, &showprintlist);
2910
2911 add_setshow_boolean_cmd ("null-stop", no_class,
2912 &user_print_options.stop_print_at_null, _("\
2913 Set printing of char arrays to stop at first null char."), _("\
2914 Show printing of char arrays to stop at first null char."), NULL,
2915 NULL,
2916 show_stop_print_at_null,
2917 &setprintlist, &showprintlist);
2918
2919 add_setshow_uinteger_cmd ("repeats", no_class,
2920 &user_print_options.repeat_count_threshold, _("\
2921 Set threshold for repeated print elements."), _("\
2922 Show threshold for repeated print elements."), _("\
2923 \"set print repeats unlimited\" causes all elements to be individually printed."),
2924 NULL,
2925 show_repeat_count_threshold,
2926 &setprintlist, &showprintlist);
2927
2928 add_setshow_boolean_cmd ("pretty", class_support,
2929 &user_print_options.prettyformat_structs, _("\
2930 Set pretty formatting of structures."), _("\
2931 Show pretty formatting of structures."), NULL,
2932 NULL,
2933 show_prettyformat_structs,
2934 &setprintlist, &showprintlist);
2935
2936 add_setshow_boolean_cmd ("union", class_support,
2937 &user_print_options.unionprint, _("\
2938 Set printing of unions interior to structures."), _("\
2939 Show printing of unions interior to structures."), NULL,
2940 NULL,
2941 show_unionprint,
2942 &setprintlist, &showprintlist);
2943
2944 add_setshow_boolean_cmd ("array", class_support,
2945 &user_print_options.prettyformat_arrays, _("\
2946 Set pretty formatting of arrays."), _("\
2947 Show pretty formatting of arrays."), NULL,
2948 NULL,
2949 show_prettyformat_arrays,
2950 &setprintlist, &showprintlist);
2951
2952 add_setshow_boolean_cmd ("address", class_support,
2953 &user_print_options.addressprint, _("\
2954 Set printing of addresses."), _("\
2955 Show printing of addresses."), NULL,
2956 NULL,
2957 show_addressprint,
2958 &setprintlist, &showprintlist);
2959
2960 add_setshow_boolean_cmd ("symbol", class_support,
2961 &user_print_options.symbol_print, _("\
2962 Set printing of symbol names when printing pointers."), _("\
2963 Show printing of symbol names when printing pointers."),
2964 NULL, NULL,
2965 show_symbol_print,
2966 &setprintlist, &showprintlist);
2967
2968 add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1,
2969 _("\
2970 Set default input radix for entering numbers."), _("\
2971 Show default input radix for entering numbers."), NULL,
2972 set_input_radix,
2973 show_input_radix,
2974 &setlist, &showlist);
2975
2976 add_setshow_zuinteger_cmd ("output-radix", class_support, &output_radix_1,
2977 _("\
2978 Set default output radix for printing of values."), _("\
2979 Show default output radix for printing of values."), NULL,
2980 set_output_radix,
2981 show_output_radix,
2982 &setlist, &showlist);
2983
2984 /* The "set radix" and "show radix" commands are special in that
2985 they are like normal set and show commands but allow two normally
2986 independent variables to be either set or shown with a single
2987 command. So the usual deprecated_add_set_cmd() and [deleted]
2988 add_show_from_set() commands aren't really appropriate. */
2989 /* FIXME: i18n: With the new add_setshow_integer command, that is no
2990 longer true - show can display anything. */
2991 add_cmd ("radix", class_support, set_radix, _("\
2992 Set default input and output number radices.\n\
2993 Use 'set input-radix' or 'set output-radix' to independently set each.\n\
2994 Without an argument, sets both radices back to the default value of 10."),
2995 &setlist);
2996 add_cmd ("radix", class_support, show_radix, _("\
2997 Show the default input and output number radices.\n\
2998 Use 'show input-radix' or 'show output-radix' to independently show each."),
2999 &showlist);
3000
3001 add_setshow_boolean_cmd ("array-indexes", class_support,
3002 &user_print_options.print_array_indexes, _("\
3003 Set printing of array indexes."), _("\
3004 Show printing of array indexes"), NULL, NULL, show_print_array_indexes,
3005 &setprintlist, &showprintlist);
3006 }
This page took 0.093814 seconds and 4 git commands to generate.