GDB (xrefs)
Loading...
Searching...
No Matches
valprint.c
Go to the documentation of this file.
1/* Print values for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2023 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 "target-float.h"
31#include "extension.h"
32#include "ada-lang.h"
33#include "gdbsupport/gdb_obstack.h"
34#include "charset.h"
35#include "typeprint.h"
36#include <ctype.h>
37#include <algorithm>
38#include "gdbsupport/byte-vector.h"
39#include "cli/cli-option.h"
40#include "gdbarch.h"
41#include "cli/cli-style.h"
42#include "count-one-bits.h"
43#include "c-lang.h"
44#include "cp-abi.h"
45#include "inferior.h"
46#include "gdbsupport/selftest.h"
47#include "selftest-arch.h"
48
49/* Maximum number of wchars returned from wchar_iterate. */
50#define MAX_WCHARS 4
51
52/* A convenience macro to compute the size of a wchar_t buffer containing X
53 characters. */
54#define WCHAR_BUFLEN(X) ((X) * sizeof (gdb_wchar_t))
55
56/* Character buffer size saved while iterating over wchars. */
57#define WCHAR_BUFLEN_MAX WCHAR_BUFLEN (MAX_WCHARS)
58
59/* A structure to encapsulate state information from iterated
60 character conversions. */
62{
63 /* The number of characters converted. */
65
66 /* The result of the conversion. See charset.h for more. */
68
69 /* The (saved) converted character(s). */
71
72 /* The first converted target byte. */
73 const gdb_byte *buf;
74
75 /* The number of bytes converted. */
76 size_t buflen;
77
78 /* How many times this character(s) is repeated. */
80};
81
82/* Command lists for set/show print raw. */
85
86/* Prototypes for local functions */
87
88static void set_input_radix_1 (int, unsigned);
89
90static void set_output_radix_1 (int, unsigned);
91
92static void val_print_type_code_flags (struct type *type,
93 struct value *original_value,
94 int embedded_offset,
95 struct ui_file *stream);
96
97/* Start print_max at this value. */
98#define PRINT_MAX_DEFAULT 200
99
100/* Start print_max_chars at this value (meaning follow print_max). */
101#define PRINT_MAX_CHARS_DEFAULT PRINT_MAX_CHARS_ELEMENTS
102
103/* Start print_max_depth at this value. */
104#define PRINT_MAX_DEPTH_DEFAULT 20
105
107{
108 Val_prettyformat_default, /* prettyformat */
109 false, /* prettyformat_arrays */
110 false, /* prettyformat_structs */
111 false, /* vtblprint */
112 true, /* unionprint */
113 true, /* addressprint */
114 false, /* nibblesprint */
115 false, /* objectprint */
116 PRINT_MAX_DEFAULT, /* print_max */
117 PRINT_MAX_CHARS_DEFAULT, /* print_max_chars */
118 10, /* repeat_count_threshold */
119 0, /* output_format */
120 0, /* format */
121 true, /* memory_tag_violations */
122 false, /* stop_print_at_null */
123 false, /* print_array_indexes */
124 false, /* deref_ref */
125 true, /* static_field_print */
126 true, /* pascal_static_field_print */
127 false, /* raw */
128 false, /* summary */
129 true, /* symbol_print */
130 PRINT_MAX_DEPTH_DEFAULT, /* max_depth */
131};
132
133/* Initialize *OPTS to be a copy of the user print options. */
134void
139
140/* Initialize *OPTS to be a copy of the user print options, but with
141 pretty-formatting disabled. */
142void
144{
145 *opts = user_print_options;
146 opts->prettyformat = Val_no_prettyformat;
147}
148
149/* Initialize *OPTS to be a copy of the user print options, but using
150 FORMAT as the formatting option. */
151void
153 char format)
154{
155 *opts = user_print_options;
156 opts->format = format;
157}
158
159/* Implement 'show print elements'. */
160
161static void
162show_print_max (struct ui_file *file, int from_tty,
163 struct cmd_list_element *c, const char *value)
164{
166 (file,
168 ? _("Limit on array elements to print is %s.\n")
169 : _("Limit on string chars or array elements to print is %s.\n")),
170 value);
171}
172
173/* Implement 'show print characters'. */
174
175static void
176show_print_max_chars (struct ui_file *file, int from_tty,
177 struct cmd_list_element *c, const char *value)
178{
179 gdb_printf (file,
180 _("Limit on string characters to print is %s.\n"),
181 value);
182}
183
184/* Default input and output radixes, and output format letter. */
185
186unsigned input_radix = 10;
187static void
188show_input_radix (struct ui_file *file, int from_tty,
189 struct cmd_list_element *c, const char *value)
190{
191 gdb_printf (file,
192 _("Default input radix for entering numbers is %s.\n"),
193 value);
194}
195
196unsigned output_radix = 10;
197static void
198show_output_radix (struct ui_file *file, int from_tty,
199 struct cmd_list_element *c, const char *value)
200{
201 gdb_printf (file,
202 _("Default output radix for printing of values is %s.\n"),
203 value);
204}
205
206/* By default we print arrays without printing the index of each element in
207 the array. This behavior can be changed by setting PRINT_ARRAY_INDEXES. */
208
209static void
210show_print_array_indexes (struct ui_file *file, int from_tty,
211 struct cmd_list_element *c, const char *value)
212{
213 gdb_printf (file, _("Printing of array indexes is %s.\n"), value);
214}
215
216/* Print repeat counts if there are more than this many repetitions of an
217 element in an array. Referenced by the low level language dependent
218 print routines. */
219
220static void
221show_repeat_count_threshold (struct ui_file *file, int from_tty,
222 struct cmd_list_element *c, const char *value)
223{
224 gdb_printf (file, _("Threshold for repeated print elements is %s.\n"),
225 value);
226}
227
228/* If nonzero, prints memory tag violations for pointers. */
229
230static void
231show_memory_tag_violations (struct ui_file *file, int from_tty,
232 struct cmd_list_element *c, const char *value)
233{
234 gdb_printf (file,
235 _("Printing of memory tag violations is %s.\n"),
236 value);
237}
238
239/* If nonzero, stops printing of char arrays at first null. */
240
241static void
242show_stop_print_at_null (struct ui_file *file, int from_tty,
243 struct cmd_list_element *c, const char *value)
244{
245 gdb_printf (file,
246 _("Printing of char arrays to stop "
247 "at first null char is %s.\n"),
248 value);
249}
250
251/* Controls pretty printing of structures. */
252
253static void
254show_prettyformat_structs (struct ui_file *file, int from_tty,
255 struct cmd_list_element *c, const char *value)
256{
257 gdb_printf (file, _("Pretty formatting of structures is %s.\n"), value);
258}
259
260/* Controls pretty printing of arrays. */
261
262static void
263show_prettyformat_arrays (struct ui_file *file, int from_tty,
264 struct cmd_list_element *c, const char *value)
265{
266 gdb_printf (file, _("Pretty formatting of arrays is %s.\n"), value);
267}
268
269/* If nonzero, causes unions inside structures or other unions to be
270 printed. */
271
272static void
273show_unionprint (struct ui_file *file, int from_tty,
274 struct cmd_list_element *c, const char *value)
275{
276 gdb_printf (file,
277 _("Printing of unions interior to structures is %s.\n"),
278 value);
279}
280
281/* Controls the format of printing binary values. */
282
283static void
284show_nibbles (struct ui_file *file, int from_tty,
285 struct cmd_list_element *c, const char *value)
286{
287 gdb_printf (file,
288 _("Printing binary values in groups is %s.\n"),
289 value);
290}
291
292/* If nonzero, causes machine addresses to be printed in certain contexts. */
293
294static void
295show_addressprint (struct ui_file *file, int from_tty,
296 struct cmd_list_element *c, const char *value)
297{
298 gdb_printf (file, _("Printing of addresses is %s.\n"), value);
299}
300
301static void
302show_symbol_print (struct ui_file *file, int from_tty,
303 struct cmd_list_element *c, const char *value)
304{
305 gdb_printf (file,
306 _("Printing of symbols when printing pointers is %s.\n"),
307 value);
308}
309
310
311
312/* A helper function for val_print. When printing in "summary" mode,
313 we want to print scalar arguments, but not aggregate arguments.
314 This function distinguishes between the two. */
315
316int
318{
320 while (TYPE_IS_REFERENCE (type))
321 {
322 type = type->target_type ();
324 }
325 switch (type->code ())
326 {
327 case TYPE_CODE_ARRAY:
328 case TYPE_CODE_STRUCT:
329 case TYPE_CODE_UNION:
330 case TYPE_CODE_SET:
331 case TYPE_CODE_STRING:
332 return 0;
333 default:
334 return 1;
335 }
336}
337
338/* A helper function for val_print. When printing with limited depth we
339 want to print string and scalar arguments, but not aggregate arguments.
340 This function distinguishes between the two. */
341
342static bool
344 const struct language_defn *language)
345{
347 || language->is_string_type_p (type));
348}
349
350/* See valprint.h. */
351
352int
354 struct type *type,
355 LONGEST embedded_offset,
356 const struct value *val)
357{
359
361 {
363 return 0;
364 }
365
367 {
369 return 0;
370 }
371
372 if (type->code () != TYPE_CODE_UNION
373 && type->code () != TYPE_CODE_STRUCT
374 && type->code () != TYPE_CODE_ARRAY)
375 {
376 if (val->bits_any_optimized_out (TARGET_CHAR_BIT * embedded_offset,
377 TARGET_CHAR_BIT * type->length ()))
378 {
379 val_print_optimized_out (val, stream);
380 return 0;
381 }
382
383 if (val->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset,
384 TARGET_CHAR_BIT * type->length ()))
385 {
386 const int is_ref = type->code () == TYPE_CODE_REF;
387 int ref_is_addressable = 0;
388
389 if (is_ref)
390 {
391 const struct value *deref_val = coerce_ref_if_computed (val);
392
393 if (deref_val != NULL)
394 ref_is_addressable = deref_val->lval () == lval_memory;
395 }
396
397 if (!is_ref || !ref_is_addressable)
398 fputs_styled (_("<synthetic pointer>"), metadata_style.style (),
399 stream);
400
401 /* C++ references should be valid even if they're synthetic. */
402 return is_ref;
403 }
404
406 {
407 val_print_unavailable (stream);
408 return 0;
409 }
410 }
411
412 return 1;
413}
414
415void
416val_print_optimized_out (const struct value *val, struct ui_file *stream)
417{
418 if (val != NULL && val->lval () == lval_register)
419 val_print_not_saved (stream);
420 else
421 fprintf_styled (stream, metadata_style.style (), _("<optimized out>"));
422}
423
424void
426{
427 fprintf_styled (stream, metadata_style.style (), _("<not saved>"));
428}
429
430void
432{
433 fprintf_styled (stream, metadata_style.style (), _("<unavailable>"));
434}
435
436void
438{
439 fprintf_styled (stream, metadata_style.style (), _("<invalid address>"));
440}
441
442/* Print a pointer based on the type of its target.
443
444 Arguments to this functions are roughly the same as those in
445 generic_val_print. A difference is that ADDRESS is the address to print,
446 with embedded_offset already added. ELTTYPE represents
447 the pointed type after check_typedef. */
448
449static void
450print_unpacked_pointer (struct type *type, struct type *elttype,
451 CORE_ADDR address, struct ui_file *stream,
452 const struct value_print_options *options)
453{
454 struct gdbarch *gdbarch = type->arch ();
455
456 if (elttype->code () == TYPE_CODE_FUNC)
457 {
458 /* Try to print what function it points to. */
459 print_function_pointer_address (options, gdbarch, address, stream);
460 return;
461 }
462
463 if (options->symbol_print)
464 print_address_demangle (options, gdbarch, address, stream, demangle);
465 else if (options->addressprint)
466 gdb_puts (paddress (gdbarch, address), stream);
467}
468
469/* generic_val_print helper for TYPE_CODE_ARRAY. */
470
471static void
473 struct ui_file *stream, int recurse,
474 const struct value_print_options *options,
475 const struct
477{
478 struct type *type = check_typedef (val->type ());
479 struct type *unresolved_elttype = type->target_type ();
480 struct type *elttype = check_typedef (unresolved_elttype);
481
482 if (type->length () > 0 && unresolved_elttype->length () > 0)
483 {
484 LONGEST low_bound, high_bound;
485
486 if (!get_array_bounds (type, &low_bound, &high_bound))
487 error (_("Could not determine the array high bound"));
488
489 gdb_puts (decorations->array_start, stream);
490 value_print_array_elements (val, stream, recurse, options, 0);
491 gdb_puts (decorations->array_end, stream);
492 }
493 else
494 {
495 /* Array of unspecified length: treat like pointer to first elt. */
496 print_unpacked_pointer (type, elttype, val->address (),
497 stream, options);
498 }
499
500}
501
502/* generic_value_print helper for TYPE_CODE_PTR. */
503
504static void
505generic_value_print_ptr (struct value *val, struct ui_file *stream,
506 const struct value_print_options *options)
507{
508
509 if (options->format && options->format != 's')
510 value_print_scalar_formatted (val, options, 0, stream);
511 else
512 {
513 struct type *type = check_typedef (val->type ());
514 struct type *elttype = check_typedef (type->target_type ());
515 const gdb_byte *valaddr = val->contents_for_printing ().data ();
516 CORE_ADDR addr = unpack_pointer (type, valaddr);
517
518 print_unpacked_pointer (type, elttype, addr, stream, options);
519 }
520}
521
522
523/* Print '@' followed by the address contained in ADDRESS_BUFFER. */
524
525static void
526print_ref_address (struct type *type, const gdb_byte *address_buffer,
527 int embedded_offset, struct ui_file *stream)
528{
529 struct gdbarch *gdbarch = type->arch ();
530
531 if (address_buffer != NULL)
532 {
533 CORE_ADDR address
534 = extract_typed_address (address_buffer + embedded_offset, type);
535
536 gdb_printf (stream, "@");
537 gdb_puts (paddress (gdbarch, address), stream);
538 }
539 /* Else: we have a non-addressable value, such as a DW_AT_const_value. */
540}
541
542/* If VAL is addressable, return the value contents buffer of a value that
543 represents a pointer to VAL. Otherwise return NULL. */
544
545static const gdb_byte *
547{
548 gdb_assert (deref_val != NULL);
549
550 if (deref_val->lval () == lval_memory)
551 return value_addr (deref_val)->contents_for_printing ().data ();
552 else
553 {
554 /* We have a non-addressable value, such as a DW_AT_const_value. */
555 return NULL;
556 }
557}
558
559/* generic_val_print helper for TYPE_CODE_{RVALUE_,}REF. */
560
561static void
563 int embedded_offset, struct ui_file *stream, int recurse,
564 struct value *original_value,
565 const struct value_print_options *options)
566{
567 struct type *elttype = check_typedef (type->target_type ());
568 struct value *deref_val = NULL;
569 const bool value_is_synthetic
570 = original_value->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset,
571 TARGET_CHAR_BIT * type->length ());
572 const int must_coerce_ref = ((options->addressprint && value_is_synthetic)
573 || options->deref_ref);
574 const int type_is_defined = elttype->code () != TYPE_CODE_UNDEF;
575 const gdb_byte *valaddr = original_value->contents_for_printing ().data ();
576
577 if (must_coerce_ref && type_is_defined)
578 {
579 deref_val = coerce_ref_if_computed (original_value);
580
581 if (deref_val != NULL)
582 {
583 /* More complicated computed references are not supported. */
584 gdb_assert (embedded_offset == 0);
585 }
586 else
587 deref_val = value_at (type->target_type (),
588 unpack_pointer (type, valaddr + embedded_offset));
589 }
590 /* Else, original_value isn't a synthetic reference or we don't have to print
591 the reference's contents.
592
593 Notice that for references to TYPE_CODE_STRUCT, 'set print object on' will
594 cause original_value to be a not_lval instead of an lval_computed,
595 which will make value_bits_synthetic_pointer return false.
596 This happens because if options->objectprint is true, c_value_print will
597 overwrite original_value's contents with the result of coercing
598 the reference through value_addr, and then set its type back to
599 TYPE_CODE_REF. In that case we don't have to coerce the reference again;
600 we can simply treat it as non-synthetic and move on. */
601
602 if (options->addressprint)
603 {
604 const gdb_byte *address = (value_is_synthetic && type_is_defined
605 ? get_value_addr_contents (deref_val)
606 : valaddr);
607
609
610 if (options->deref_ref)
611 gdb_puts (": ", stream);
612 }
613
614 if (options->deref_ref)
615 {
616 if (type_is_defined)
617 common_val_print (deref_val, stream, recurse, options,
619 else
620 gdb_puts ("???", stream);
621 }
622}
623
624/* Helper function for generic_val_print_enum.
625 This is also used to print enums in TYPE_CODE_FLAGS values. */
626
627static void
628generic_val_print_enum_1 (struct type *type, LONGEST val,
629 struct ui_file *stream)
630{
631 unsigned int i;
632 unsigned int len;
633
634 len = type->num_fields ();
635 for (i = 0; i < len; i++)
636 {
637 QUIT;
638 if (val == type->field (i).loc_enumval ())
639 {
640 break;
641 }
642 }
643 if (i < len)
644 {
646 stream);
647 }
648 else if (type->is_flag_enum ())
649 {
650 int first = 1;
651
652 /* We have a "flag" enum, so we try to decompose it into pieces as
653 appropriate. The enum may have multiple enumerators representing
654 the same bit, in which case we choose to only print the first one
655 we find. */
656 for (i = 0; i < len; ++i)
657 {
658 QUIT;
659
660 ULONGEST enumval = type->field (i).loc_enumval ();
661 int nbits = count_one_bits_ll (enumval);
662
663 gdb_assert (nbits == 0 || nbits == 1);
664
665 if ((val & enumval) != 0)
666 {
667 if (first)
668 {
669 gdb_puts ("(", stream);
670 first = 0;
671 }
672 else
673 gdb_puts (" | ", stream);
674
675 val &= ~type->field (i).loc_enumval ();
676 fputs_styled (type->field (i).name (),
677 variable_name_style.style (), stream);
678 }
679 }
680
681 if (val != 0)
682 {
683 /* There are leftover bits, print them. */
684 if (first)
685 gdb_puts ("(", stream);
686 else
687 gdb_puts (" | ", stream);
688
689 gdb_puts ("unknown: 0x", stream);
690 print_longest (stream, 'x', 0, val);
691 gdb_puts (")", stream);
692 }
693 else if (first)
694 {
695 /* Nothing has been printed and the value is 0, the enum value must
696 have been 0. */
697 gdb_puts ("0", stream);
698 }
699 else
700 {
701 /* Something has been printed, close the parenthesis. */
702 gdb_puts (")", stream);
703 }
704 }
705 else
706 print_longest (stream, 'd', 0, val);
707}
708
709/* generic_val_print helper for TYPE_CODE_ENUM. */
710
711static void
713 int embedded_offset, struct ui_file *stream,
714 struct value *original_value,
715 const struct value_print_options *options)
716{
717 LONGEST val;
718 struct gdbarch *gdbarch = type->arch ();
720
721 gdb_assert (!options->format);
722
723 const gdb_byte *valaddr = original_value->contents_for_printing ().data ();
724
725 val = unpack_long (type, valaddr + embedded_offset * unit_size);
726
727 generic_val_print_enum_1 (type, val, stream);
728}
729
730/* generic_val_print helper for TYPE_CODE_FUNC and TYPE_CODE_METHOD. */
731
732static void
734 int embedded_offset, CORE_ADDR address,
735 struct ui_file *stream,
736 struct value *original_value,
737 const struct value_print_options *options)
738{
739 struct gdbarch *gdbarch = type->arch ();
740
741 gdb_assert (!options->format);
742
743 /* FIXME, we should consider, at least for ANSI C language,
744 eliminating the distinction made between FUNCs and POINTERs to
745 FUNCs. */
746 gdb_printf (stream, "{");
747 type_print (type, "", stream, -1);
748 gdb_printf (stream, "} ");
749 /* Try to print what function it points to, and its address. */
750 print_address_demangle (options, gdbarch, address, stream, demangle);
751}
752
753/* generic_value_print helper for TYPE_CODE_BOOL. */
754
755static void
757 (struct value *value, struct ui_file *stream,
758 const struct value_print_options *options,
759 const struct generic_val_print_decorations *decorations)
760{
761 if (options->format || options->output_format)
762 {
763 struct value_print_options opts = *options;
764 opts.format = (options->format ? options->format
765 : options->output_format);
766 value_print_scalar_formatted (value, &opts, 0, stream);
767 }
768 else
769 {
770 const gdb_byte *valaddr = value->contents_for_printing ().data ();
771 struct type *type = check_typedef (value->type ());
772 LONGEST val = unpack_long (type, valaddr);
773 if (val == 0)
774 gdb_puts (decorations->false_name, stream);
775 else if (val == 1)
776 gdb_puts (decorations->true_name, stream);
777 else
778 print_longest (stream, 'd', 0, val);
779 }
780}
781
782/* generic_value_print helper for TYPE_CODE_INT. */
783
784static void
785generic_value_print_int (struct value *val, struct ui_file *stream,
786 const struct value_print_options *options)
787{
788 struct value_print_options opts = *options;
789
790 opts.format = (options->format ? options->format
791 : options->output_format);
792 value_print_scalar_formatted (val, &opts, 0, stream);
793}
794
795/* generic_value_print helper for TYPE_CODE_CHAR. */
796
797static void
799 const struct value_print_options *options)
800{
801 if (options->format || options->output_format)
802 {
803 struct value_print_options opts = *options;
804
805 opts.format = (options->format ? options->format
806 : options->output_format);
807 value_print_scalar_formatted (value, &opts, 0, stream);
808 }
809 else
810 {
811 struct type *unresolved_type = value->type ();
812 struct type *type = check_typedef (unresolved_type);
813 const gdb_byte *valaddr = value->contents_for_printing ().data ();
814
815 LONGEST val = unpack_long (type, valaddr);
816 if (type->is_unsigned ())
817 gdb_printf (stream, "%u", (unsigned int) val);
818 else
819 gdb_printf (stream, "%d", (int) val);
820 gdb_puts (" ", stream);
821 current_language->printchar (val, unresolved_type, stream);
822 }
823}
824
825/* generic_val_print helper for TYPE_CODE_FLT and TYPE_CODE_DECFLOAT. */
826
827static void
828generic_val_print_float (struct type *type, struct ui_file *stream,
829 struct value *original_value,
830 const struct value_print_options *options)
831{
832 gdb_assert (!options->format);
833
834 const gdb_byte *valaddr = original_value->contents_for_printing ().data ();
835
836 print_floating (valaddr, type, stream);
837}
838
839/* generic_val_print helper for TYPE_CODE_FIXED_POINT. */
840
841static void
842generic_val_print_fixed_point (struct value *val, struct ui_file *stream,
843 const struct value_print_options *options)
844{
845 if (options->format)
846 value_print_scalar_formatted (val, options, 0, stream);
847 else
848 {
849 struct type *type = val->type ();
850
851 const gdb_byte *valaddr = val->contents_for_printing ().data ();
852 gdb_mpf f;
853
854 f.read_fixed_point (gdb::make_array_view (valaddr, type->length ()),
857
858 const char *fmt = type->length () < 4 ? "%.11Fg" : "%.17Fg";
859 std::string str = f.str (fmt);
860 gdb_printf (stream, "%s", str.c_str ());
861 }
862}
863
864/* generic_value_print helper for TYPE_CODE_COMPLEX. */
865
866static void
867generic_value_print_complex (struct value *val, struct ui_file *stream,
868 const struct value_print_options *options,
870 *decorations)
871{
872 gdb_printf (stream, "%s", decorations->complex_prefix);
873
874 struct value *real_part = value_real_part (val);
875 value_print_scalar_formatted (real_part, options, 0, stream);
876 gdb_printf (stream, "%s", decorations->complex_infix);
877
878 struct value *imag_part = value_imaginary_part (val);
879 value_print_scalar_formatted (imag_part, options, 0, stream);
880 gdb_printf (stream, "%s", decorations->complex_suffix);
881}
882
883/* generic_value_print helper for TYPE_CODE_MEMBERPTR. */
884
885static void
887 (struct value *val, struct ui_file *stream,
888 int recurse,
889 const struct value_print_options *options,
890 const struct generic_val_print_decorations *decorations)
891{
892 if (!options->format)
893 {
894 /* Member pointers are essentially specific to C++, and so if we
895 encounter one, we should print it according to C++ rules. */
896 struct type *type = check_typedef (val->type ());
897 const gdb_byte *valaddr = val->contents_for_printing ().data ();
898 cp_print_class_member (valaddr, type, stream, "&");
899 }
900 else
901 value_print_scalar_formatted (val, options, 0, stream);
902}
903
904/* See valprint.h. */
905
906void
907generic_value_print (struct value *val, struct ui_file *stream, int recurse,
908 const struct value_print_options *options,
909 const struct generic_val_print_decorations *decorations)
910{
911 struct type *type = val->type ();
912
914
917
918 /* Widen a subrange to its target type, then use that type's
919 printer. */
920 while (type->code () == TYPE_CODE_RANGE)
921 {
923 val = value_cast (type, val);
924 }
925
926 switch (type->code ())
927 {
928 case TYPE_CODE_ARRAY:
929 generic_val_print_array (val, stream, recurse, options, decorations);
930 break;
931
932 case TYPE_CODE_MEMBERPTR:
933 generic_value_print_memberptr (val, stream, recurse, options,
934 decorations);
935 break;
936
937 case TYPE_CODE_PTR:
938 generic_value_print_ptr (val, stream, options);
939 break;
940
941 case TYPE_CODE_REF:
942 case TYPE_CODE_RVALUE_REF:
943 generic_val_print_ref (type, 0, stream, recurse,
944 val, options);
945 break;
946
947 case TYPE_CODE_ENUM:
948 if (options->format)
949 value_print_scalar_formatted (val, options, 0, stream);
950 else
951 generic_val_print_enum (type, 0, stream, val, options);
952 break;
953
954 case TYPE_CODE_FLAGS:
955 if (options->format)
956 value_print_scalar_formatted (val, options, 0, stream);
957 else
958 val_print_type_code_flags (type, val, 0, stream);
959 break;
960
961 case TYPE_CODE_FUNC:
962 case TYPE_CODE_METHOD:
963 if (options->format)
964 value_print_scalar_formatted (val, options, 0, stream);
965 else
966 generic_val_print_func (type, 0, val->address (), stream,
967 val, options);
968 break;
969
970 case TYPE_CODE_BOOL:
971 generic_value_print_bool (val, stream, options, decorations);
972 break;
973
974 case TYPE_CODE_INT:
975 generic_value_print_int (val, stream, options);
976 break;
977
978 case TYPE_CODE_CHAR:
979 generic_value_print_char (val, stream, options);
980 break;
981
982 case TYPE_CODE_FLT:
983 case TYPE_CODE_DECFLOAT:
984 if (options->format)
985 value_print_scalar_formatted (val, options, 0, stream);
986 else
987 generic_val_print_float (type, stream, val, options);
988 break;
989
990 case TYPE_CODE_FIXED_POINT:
991 generic_val_print_fixed_point (val, stream, options);
992 break;
993
994 case TYPE_CODE_VOID:
995 gdb_puts (decorations->void_name, stream);
996 break;
997
998 case TYPE_CODE_ERROR:
999 gdb_printf (stream, "%s", TYPE_ERROR_NAME (type));
1000 break;
1001
1002 case TYPE_CODE_UNDEF:
1003 /* This happens (without TYPE_STUB set) on systems which don't use
1004 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1005 and no complete type for struct foo in that file. */
1006 fprintf_styled (stream, metadata_style.style (), _("<incomplete type>"));
1007 break;
1008
1009 case TYPE_CODE_COMPLEX:
1010 generic_value_print_complex (val, stream, options, decorations);
1011 break;
1012
1013 case TYPE_CODE_METHODPTR:
1015 stream);
1016 break;
1017
1018 case TYPE_CODE_UNION:
1019 case TYPE_CODE_STRUCT:
1020 default:
1021 error (_("Unhandled type code %d in symbol table."),
1022 type->code ());
1023 }
1024}
1025
1026/* Print using the given LANGUAGE the value VAL onto stream STREAM according
1027 to OPTIONS.
1028
1029 This is a preferable interface to val_print, above, because it uses
1030 GDB's value mechanism. */
1031
1032void
1033common_val_print (struct value *value, struct ui_file *stream, int recurse,
1034 const struct value_print_options *options,
1035 const struct language_defn *language)
1036{
1037 if (language->la_language == language_ada)
1038 /* The value might have a dynamic type, which would cause trouble
1039 below when trying to extract the value contents (since the value
1040 size is determined from the type size which is unknown). So
1041 get a fixed representation of our value. */
1043
1044 if (value->lazy ())
1045 value->fetch_lazy ();
1046
1047 struct value_print_options local_opts = *options;
1048 struct type *type = value->type ();
1049 struct type *real_type = check_typedef (type);
1050
1051 if (local_opts.prettyformat == Val_prettyformat_default)
1052 local_opts.prettyformat = (local_opts.prettyformat_structs
1054
1055 QUIT;
1056
1057 /* Ensure that the type is complete and not just a stub. If the type is
1058 only a stub and we can't find and substitute its complete type, then
1059 print appropriate string and return. */
1060
1061 if (real_type->is_stub ())
1062 {
1063 fprintf_styled (stream, metadata_style.style (), _("<incomplete type>"));
1064 return;
1065 }
1066
1067 if (!valprint_check_validity (stream, real_type, 0, value))
1068 return;
1069
1070 if (!options->raw)
1071 {
1072 if (apply_ext_lang_val_pretty_printer (value, stream, recurse, options,
1073 language))
1074 return;
1075 }
1076
1077 /* Handle summary mode. If the value is a scalar, print it;
1078 otherwise, print an ellipsis. */
1079 if (options->summary && !val_print_scalar_type_p (type))
1080 {
1081 gdb_printf (stream, "...");
1082 return;
1083 }
1084
1085 /* If this value is too deep then don't print it. */
1087 && val_print_check_max_depth (stream, recurse, options, language))
1088 return;
1089
1090 try
1091 {
1092 language->value_print_inner (value, stream, recurse, &local_opts);
1093 }
1094 catch (const gdb_exception_error &except)
1095 {
1097 _("<error reading variable: %s>"), except.what ());
1098 }
1099}
1100
1101/* See valprint.h. */
1102
1103bool
1104val_print_check_max_depth (struct ui_file *stream, int recurse,
1105 const struct value_print_options *options,
1106 const struct language_defn *language)
1107{
1108 if (options->max_depth > -1 && recurse >= options->max_depth)
1109 {
1110 gdb_assert (language->struct_too_deep_ellipsis () != NULL);
1111 gdb_puts (language->struct_too_deep_ellipsis (), stream);
1112 return true;
1113 }
1114
1115 return false;
1116}
1117
1118/* Check whether the value VAL is printable. Return 1 if it is;
1119 return 0 and print an appropriate error message to STREAM according to
1120 OPTIONS if it is not. */
1121
1122static int
1123value_check_printable (struct value *val, struct ui_file *stream,
1124 const struct value_print_options *options)
1125{
1126 if (val == 0)
1127 {
1129 _("<address of value unknown>"));
1130 return 0;
1131 }
1132
1133 if (val->entirely_optimized_out ())
1134 {
1135 if (options->summary && !val_print_scalar_type_p (val->type ()))
1136 gdb_printf (stream, "...");
1137 else
1138 val_print_optimized_out (val, stream);
1139 return 0;
1140 }
1141
1142 if (val->entirely_unavailable ())
1143 {
1144 if (options->summary && !val_print_scalar_type_p (val->type ()))
1145 gdb_printf (stream, "...");
1146 else
1147 val_print_unavailable (stream);
1148 return 0;
1149 }
1150
1151 if (val->type ()->code () == TYPE_CODE_INTERNAL_FUNCTION)
1152 {
1154 _("<internal function %s>"),
1156 return 0;
1157 }
1158
1159 if (type_not_associated (val->type ()))
1160 {
1161 val_print_not_associated (stream);
1162 return 0;
1163 }
1164
1165 if (type_not_allocated (val->type ()))
1166 {
1167 val_print_not_allocated (stream);
1168 return 0;
1169 }
1170
1171 return 1;
1172}
1173
1174/* See valprint.h. */
1175
1176void
1177common_val_print_checked (struct value *val, struct ui_file *stream,
1178 int recurse,
1179 const struct value_print_options *options,
1180 const struct language_defn *language)
1181{
1182 if (!value_check_printable (val, stream, options))
1183 return;
1184 common_val_print (val, stream, recurse, options, language);
1185}
1186
1187/* Print on stream STREAM the value VAL according to OPTIONS. The value
1188 is printed using the current_language syntax. */
1189
1190void
1191value_print (struct value *val, struct ui_file *stream,
1192 const struct value_print_options *options)
1193{
1194 scoped_value_mark free_values;
1195
1196 if (!value_check_printable (val, stream, options))
1197 return;
1198
1199 if (!options->raw)
1200 {
1201 int r
1202 = apply_ext_lang_val_pretty_printer (val, stream, 0, options,
1204
1205 if (r)
1206 return;
1207 }
1208
1209 current_language->value_print (val, stream, options);
1210}
1211
1212/* Meant to be used in debug sessions, so don't export it in a header file. */
1213extern void ATTRIBUTE_UNUSED debug_val (struct value *val);
1214
1215/* Print VAL. */
1216
1217void ATTRIBUTE_UNUSED
1218debug_val (struct value *val)
1219{
1222}
1223
1224static void
1225val_print_type_code_flags (struct type *type, struct value *original_value,
1226 int embedded_offset, struct ui_file *stream)
1227{
1228 const gdb_byte *valaddr = (original_value->contents_for_printing ().data ()
1229 + embedded_offset);
1230 ULONGEST val = unpack_long (type, valaddr);
1231 int field, nfields = type->num_fields ();
1232 struct gdbarch *gdbarch = type->arch ();
1233 struct type *bool_type = builtin_type (gdbarch)->builtin_bool;
1234
1235 gdb_puts ("[", stream);
1236 for (field = 0; field < nfields; field++)
1237 {
1238 if (type->field (field).name ()[0] != '\0')
1239 {
1240 struct type *field_type = type->field (field).type ();
1241
1242 if (field_type == bool_type
1243 /* We require boolean types here to be one bit wide. This is a
1244 problematic place to notify the user of an internal error
1245 though. Instead just fall through and print the field as an
1246 int. */
1247 && type->field (field).bitsize () == 1)
1248 {
1249 if (val & ((ULONGEST)1 << type->field (field).loc_bitpos ()))
1251 (stream, " %ps",
1253 type->field (field).name ()));
1254 }
1255 else
1256 {
1257 unsigned field_len = type->field (field).bitsize ();
1258 ULONGEST field_val = val >> type->field (field).loc_bitpos ();
1259
1260 if (field_len < sizeof (ULONGEST) * TARGET_CHAR_BIT)
1261 field_val &= ((ULONGEST) 1 << field_len) - 1;
1262 gdb_printf (stream, " %ps=",
1264 type->field (field).name ()));
1265 if (field_type->code () == TYPE_CODE_ENUM)
1266 generic_val_print_enum_1 (field_type, field_val, stream);
1267 else
1268 print_longest (stream, 'd', 0, field_val);
1269 }
1270 }
1271 }
1272 gdb_puts (" ]", stream);
1273}
1274
1275/* See valprint.h. */
1276
1277void
1279 const struct value_print_options *options,
1280 int size,
1281 struct ui_file *stream)
1282{
1283 struct type *type = check_typedef (val->type ());
1284
1285 gdb_assert (val != NULL);
1286
1287 /* If we get here with a string format, try again without it. Go
1288 all the way back to the language printers, which may call us
1289 again. */
1290 if (options->format == 's')
1291 {
1292 struct value_print_options opts = *options;
1293 opts.format = 0;
1294 opts.deref_ref = false;
1295 common_val_print (val, stream, 0, &opts, current_language);
1296 return;
1297 }
1298
1299 /* value_contents_for_printing fetches all VAL's contents. They are
1300 needed to check whether VAL is optimized-out or unavailable
1301 below. */
1302 const gdb_byte *valaddr = val->contents_for_printing ().data ();
1303
1304 /* A scalar object that does not have all bits available can't be
1305 printed, because all bits contribute to its representation. */
1306 if (val->bits_any_optimized_out (0,
1307 TARGET_CHAR_BIT * type->length ()))
1308 val_print_optimized_out (val, stream);
1309 else if (!val->bytes_available (0, type->length ()))
1310 val_print_unavailable (stream);
1311 else
1312 print_scalar_formatted (valaddr, type, options, size, stream);
1313}
1314
1315/* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
1316 The raison d'etre of this function is to consolidate printing of
1317 LONG_LONG's into this one function. The format chars b,h,w,g are
1318 from print_scalar_formatted(). Numbers are printed using C
1319 format.
1320
1321 USE_C_FORMAT means to use C format in all cases. Without it,
1322 'o' and 'x' format do not include the standard C radix prefix
1323 (leading 0 or 0x).
1324
1325 Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL
1326 and was intended to request formatting according to the current
1327 language and would be used for most integers that GDB prints. The
1328 exceptional cases were things like protocols where the format of
1329 the integer is a protocol thing, not a user-visible thing). The
1330 parameter remains to preserve the information of what things might
1331 be printed with language-specific format, should we ever resurrect
1332 that capability. */
1333
1334void
1335print_longest (struct ui_file *stream, int format, int use_c_format,
1336 LONGEST val_long)
1337{
1338 const char *val;
1339
1340 switch (format)
1341 {
1342 case 'd':
1343 val = int_string (val_long, 10, 1, 0, 1); break;
1344 case 'u':
1345 val = int_string (val_long, 10, 0, 0, 1); break;
1346 case 'x':
1347 val = int_string (val_long, 16, 0, 0, use_c_format); break;
1348 case 'b':
1349 val = int_string (val_long, 16, 0, 2, 1); break;
1350 case 'h':
1351 val = int_string (val_long, 16, 0, 4, 1); break;
1352 case 'w':
1353 val = int_string (val_long, 16, 0, 8, 1); break;
1354 case 'g':
1355 val = int_string (val_long, 16, 0, 16, 1); break;
1356 break;
1357 case 'o':
1358 val = int_string (val_long, 8, 0, 0, use_c_format); break;
1359 default:
1360 internal_error (_("failed internal consistency check"));
1361 }
1362 gdb_puts (val, stream);
1363}
1364
1365/* This used to be a macro, but I don't think it is called often enough
1366 to merit such treatment. */
1367/* Convert a LONGEST to an int. This is used in contexts (e.g. number of
1368 arguments to a function, number in a value history, register number, etc.)
1369 where the value must not be larger than can fit in an int. */
1370
1371int
1372longest_to_int (LONGEST arg)
1373{
1374 /* Let the compiler do the work. */
1375 int rtnval = (int) arg;
1376
1377 /* Check for overflows or underflows. */
1378 if (sizeof (LONGEST) > sizeof (int))
1379 {
1380 if (rtnval != arg)
1381 {
1382 error (_("Value out of range."));
1383 }
1384 }
1385 return (rtnval);
1386}
1387
1388/* Print a floating point value of floating-point type TYPE,
1389 pointed to in GDB by VALADDR, on STREAM. */
1390
1391void
1392print_floating (const gdb_byte *valaddr, struct type *type,
1393 struct ui_file *stream)
1394{
1395 std::string str = target_float_to_string (valaddr, type);
1396 gdb_puts (str.c_str (), stream);
1397}
1398
1399void
1400print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
1401 unsigned len, enum bfd_endian byte_order, bool zero_pad,
1402 const struct value_print_options *options)
1403{
1404 const gdb_byte *p;
1405 unsigned int i;
1406 int b;
1407 bool seen_a_one = false;
1408 const char *digit_separator = nullptr;
1409
1410 /* Declared "int" so it will be signed.
1411 This ensures that right shift will shift in zeros. */
1412
1413 const int mask = 0x080;
1414
1415 if (options->nibblesprint)
1416 digit_separator = current_language->get_digit_separator();
1417
1418 if (byte_order == BFD_ENDIAN_BIG)
1419 {
1420 for (p = valaddr;
1421 p < valaddr + len;
1422 p++)
1423 {
1424 /* Every byte has 8 binary characters; peel off
1425 and print from the MSB end. */
1426
1427 for (i = 0; i < (HOST_CHAR_BIT * sizeof (*p)); i++)
1428 {
1429 if (options->nibblesprint && seen_a_one && i % 4 == 0)
1430 gdb_putc (*digit_separator, stream);
1431
1432 if (*p & (mask >> i))
1433 b = '1';
1434 else
1435 b = '0';
1436
1437 if (zero_pad || seen_a_one || b == '1')
1438 gdb_putc (b, stream);
1439 else if (options->nibblesprint)
1440 {
1441 if ((0xf0 & (mask >> i) && (*p & 0xf0))
1442 || (0x0f & (mask >> i) && (*p & 0x0f)))
1443 gdb_putc (b, stream);
1444 }
1445
1446 if (b == '1')
1447 seen_a_one = true;
1448 }
1449 }
1450 }
1451 else
1452 {
1453 for (p = valaddr + len - 1;
1454 p >= valaddr;
1455 p--)
1456 {
1457 for (i = 0; i < (HOST_CHAR_BIT * sizeof (*p)); i++)
1458 {
1459 if (options->nibblesprint && seen_a_one && i % 4 == 0)
1460 gdb_putc (*digit_separator, stream);
1461
1462 if (*p & (mask >> i))
1463 b = '1';
1464 else
1465 b = '0';
1466
1467 if (zero_pad || seen_a_one || b == '1')
1468 gdb_putc (b, stream);
1469 else if (options->nibblesprint)
1470 {
1471 if ((0xf0 & (mask >> i) && (*p & 0xf0))
1472 || (0x0f & (mask >> i) && (*p & 0x0f)))
1473 gdb_putc (b, stream);
1474 }
1475
1476 if (b == '1')
1477 seen_a_one = true;
1478 }
1479 }
1480 }
1481
1482 /* When not zero-padding, ensure that something is printed when the
1483 input is 0. */
1484 if (!zero_pad && !seen_a_one)
1485 gdb_putc ('0', stream);
1486}
1487
1488/* A helper for print_octal_chars that emits a single octal digit,
1489 optionally suppressing it if is zero and updating SEEN_A_ONE. */
1490
1491static void
1492emit_octal_digit (struct ui_file *stream, bool *seen_a_one, int digit)
1493{
1494 if (*seen_a_one || digit != 0)
1495 gdb_printf (stream, "%o", digit);
1496 if (digit != 0)
1497 *seen_a_one = true;
1498}
1499
1500/* VALADDR points to an integer of LEN bytes.
1501 Print it in octal on stream or format it in buf. */
1502
1503void
1504print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
1505 unsigned len, enum bfd_endian byte_order)
1506{
1507 const gdb_byte *p;
1508 unsigned char octa1, octa2, octa3, carry;
1509 int cycle;
1510
1511 /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track
1512 * the extra bits, which cycle every three bytes:
1513 *
1514 * Byte side: 0 1 2 3
1515 * | | | |
1516 * bit number 123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 |
1517 *
1518 * Octal side: 0 1 carry 3 4 carry ...
1519 *
1520 * Cycle number: 0 1 2
1521 *
1522 * But of course we are printing from the high side, so we have to
1523 * figure out where in the cycle we are so that we end up with no
1524 * left over bits at the end.
1525 */
1526#define BITS_IN_OCTAL 3
1527#define HIGH_ZERO 0340
1528#define LOW_ZERO 0034
1529#define CARRY_ZERO 0003
1530 static_assert (HIGH_ZERO + LOW_ZERO + CARRY_ZERO == 0xff,
1531 "cycle zero constants are wrong");
1532#define HIGH_ONE 0200
1533#define MID_ONE 0160
1534#define LOW_ONE 0016
1535#define CARRY_ONE 0001
1536 static_assert (HIGH_ONE + MID_ONE + LOW_ONE + CARRY_ONE == 0xff,
1537 "cycle one constants are wrong");
1538#define HIGH_TWO 0300
1539#define MID_TWO 0070
1540#define LOW_TWO 0007
1541 static_assert (HIGH_TWO + MID_TWO + LOW_TWO == 0xff,
1542 "cycle two constants are wrong");
1543
1544 /* For 32 we start in cycle 2, with two bits and one bit carry;
1545 for 64 in cycle in cycle 1, with one bit and a two bit carry. */
1546
1547 cycle = (len * HOST_CHAR_BIT) % BITS_IN_OCTAL;
1548 carry = 0;
1549
1550 gdb_puts ("0", stream);
1551 bool seen_a_one = false;
1552 if (byte_order == BFD_ENDIAN_BIG)
1553 {
1554 for (p = valaddr;
1555 p < valaddr + len;
1556 p++)
1557 {
1558 switch (cycle)
1559 {
1560 case 0:
1561 /* No carry in, carry out two bits. */
1562
1563 octa1 = (HIGH_ZERO & *p) >> 5;
1564 octa2 = (LOW_ZERO & *p) >> 2;
1565 carry = (CARRY_ZERO & *p);
1566 emit_octal_digit (stream, &seen_a_one, octa1);
1567 emit_octal_digit (stream, &seen_a_one, octa2);
1568 break;
1569
1570 case 1:
1571 /* Carry in two bits, carry out one bit. */
1572
1573 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
1574 octa2 = (MID_ONE & *p) >> 4;
1575 octa3 = (LOW_ONE & *p) >> 1;
1576 carry = (CARRY_ONE & *p);
1577 emit_octal_digit (stream, &seen_a_one, octa1);
1578 emit_octal_digit (stream, &seen_a_one, octa2);
1579 emit_octal_digit (stream, &seen_a_one, octa3);
1580 break;
1581
1582 case 2:
1583 /* Carry in one bit, no carry out. */
1584
1585 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
1586 octa2 = (MID_TWO & *p) >> 3;
1587 octa3 = (LOW_TWO & *p);
1588 carry = 0;
1589 emit_octal_digit (stream, &seen_a_one, octa1);
1590 emit_octal_digit (stream, &seen_a_one, octa2);
1591 emit_octal_digit (stream, &seen_a_one, octa3);
1592 break;
1593
1594 default:
1595 error (_("Internal error in octal conversion;"));
1596 }
1597
1598 cycle++;
1599 cycle = cycle % BITS_IN_OCTAL;
1600 }
1601 }
1602 else
1603 {
1604 for (p = valaddr + len - 1;
1605 p >= valaddr;
1606 p--)
1607 {
1608 switch (cycle)
1609 {
1610 case 0:
1611 /* Carry out, no carry in */
1612
1613 octa1 = (HIGH_ZERO & *p) >> 5;
1614 octa2 = (LOW_ZERO & *p) >> 2;
1615 carry = (CARRY_ZERO & *p);
1616 emit_octal_digit (stream, &seen_a_one, octa1);
1617 emit_octal_digit (stream, &seen_a_one, octa2);
1618 break;
1619
1620 case 1:
1621 /* Carry in, carry out */
1622
1623 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
1624 octa2 = (MID_ONE & *p) >> 4;
1625 octa3 = (LOW_ONE & *p) >> 1;
1626 carry = (CARRY_ONE & *p);
1627 emit_octal_digit (stream, &seen_a_one, octa1);
1628 emit_octal_digit (stream, &seen_a_one, octa2);
1629 emit_octal_digit (stream, &seen_a_one, octa3);
1630 break;
1631
1632 case 2:
1633 /* Carry in, no carry out */
1634
1635 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
1636 octa2 = (MID_TWO & *p) >> 3;
1637 octa3 = (LOW_TWO & *p);
1638 carry = 0;
1639 emit_octal_digit (stream, &seen_a_one, octa1);
1640 emit_octal_digit (stream, &seen_a_one, octa2);
1641 emit_octal_digit (stream, &seen_a_one, octa3);
1642 break;
1643
1644 default:
1645 error (_("Internal error in octal conversion;"));
1646 }
1647
1648 cycle++;
1649 cycle = cycle % BITS_IN_OCTAL;
1650 }
1651 }
1652
1653}
1654
1655/* Possibly negate the integer represented by BYTES. It contains LEN
1656 bytes in the specified byte order. If the integer is negative,
1657 copy it into OUT_VEC, negate it, and return true. Otherwise, do
1658 nothing and return false. */
1659
1660static bool
1661maybe_negate_by_bytes (const gdb_byte *bytes, unsigned len,
1662 enum bfd_endian byte_order,
1663 gdb::byte_vector *out_vec)
1664{
1665 gdb_byte sign_byte;
1666 gdb_assert (len > 0);
1667 if (byte_order == BFD_ENDIAN_BIG)
1668 sign_byte = bytes[0];
1669 else
1670 sign_byte = bytes[len - 1];
1671 if ((sign_byte & 0x80) == 0)
1672 return false;
1673
1674 out_vec->resize (len);
1675
1676 /* Compute -x == 1 + ~x. */
1677 if (byte_order == BFD_ENDIAN_LITTLE)
1678 {
1679 unsigned carry = 1;
1680 for (unsigned i = 0; i < len; ++i)
1681 {
1682 unsigned tem = (0xff & ~bytes[i]) + carry;
1683 (*out_vec)[i] = tem & 0xff;
1684 carry = tem / 256;
1685 }
1686 }
1687 else
1688 {
1689 unsigned carry = 1;
1690 for (unsigned i = len; i > 0; --i)
1691 {
1692 unsigned tem = (0xff & ~bytes[i - 1]) + carry;
1693 (*out_vec)[i - 1] = tem & 0xff;
1694 carry = tem / 256;
1695 }
1696 }
1697
1698 return true;
1699}
1700
1701/* VALADDR points to an integer of LEN bytes.
1702 Print it in decimal on stream or format it in buf. */
1703
1704void
1705print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
1706 unsigned len, bool is_signed,
1707 enum bfd_endian byte_order)
1708{
1709#define TEN 10
1710#define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */
1711#define CARRY_LEFT( x ) ((x) % TEN)
1712#define SHIFT( x ) ((x) << 4)
1713#define LOW_NIBBLE( x ) ( (x) & 0x00F)
1714#define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
1715
1716 const gdb_byte *p;
1717 int carry;
1718 int decimal_len;
1719 int i, j, decimal_digits;
1720 int dummy;
1721 int flip;
1722
1723 gdb::byte_vector negated_bytes;
1724 if (is_signed
1725 && maybe_negate_by_bytes (valaddr, len, byte_order, &negated_bytes))
1726 {
1727 gdb_puts ("-", stream);
1728 valaddr = negated_bytes.data ();
1729 }
1730
1731 /* Base-ten number is less than twice as many digits
1732 as the base 16 number, which is 2 digits per byte. */
1733
1734 decimal_len = len * 2 * 2;
1735 std::vector<unsigned char> digits (decimal_len, 0);
1736
1737 /* Ok, we have an unknown number of bytes of data to be printed in
1738 * decimal.
1739 *
1740 * Given a hex number (in nibbles) as XYZ, we start by taking X and
1741 * decimalizing it as "x1 x2" in two decimal nibbles. Then we multiply
1742 * the nibbles by 16, add Y and re-decimalize. Repeat with Z.
1743 *
1744 * The trick is that "digits" holds a base-10 number, but sometimes
1745 * the individual digits are > 10.
1746 *
1747 * Outer loop is per nibble (hex digit) of input, from MSD end to
1748 * LSD end.
1749 */
1750 decimal_digits = 0; /* Number of decimal digits so far */
1751 p = (byte_order == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1;
1752 flip = 0;
1753 while ((byte_order == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
1754 {
1755 /*
1756 * Multiply current base-ten number by 16 in place.
1757 * Each digit was between 0 and 9, now is between
1758 * 0 and 144.
1759 */
1760 for (j = 0; j < decimal_digits; j++)
1761 {
1762 digits[j] = SHIFT (digits[j]);
1763 }
1764
1765 /* Take the next nibble off the input and add it to what
1766 * we've got in the LSB position. Bottom 'digit' is now
1767 * between 0 and 159.
1768 *
1769 * "flip" is used to run this loop twice for each byte.
1770 */
1771 if (flip == 0)
1772 {
1773 /* Take top nibble. */
1774
1775 digits[0] += HIGH_NIBBLE (*p);
1776 flip = 1;
1777 }
1778 else
1779 {
1780 /* Take low nibble and bump our pointer "p". */
1781
1782 digits[0] += LOW_NIBBLE (*p);
1783 if (byte_order == BFD_ENDIAN_BIG)
1784 p++;
1785 else
1786 p--;
1787 flip = 0;
1788 }
1789
1790 /* Re-decimalize. We have to do this often enough
1791 * that we don't overflow, but once per nibble is
1792 * overkill. Easier this way, though. Note that the
1793 * carry is often larger than 10 (e.g. max initial
1794 * carry out of lowest nibble is 15, could bubble all
1795 * the way up greater than 10). So we have to do
1796 * the carrying beyond the last current digit.
1797 */
1798 carry = 0;
1799 for (j = 0; j < decimal_len - 1; j++)
1800 {
1801 digits[j] += carry;
1802
1803 /* "/" won't handle an unsigned char with
1804 * a value that if signed would be negative.
1805 * So extend to longword int via "dummy".
1806 */
1807 dummy = digits[j];
1808 carry = CARRY_OUT (dummy);
1809 digits[j] = CARRY_LEFT (dummy);
1810
1811 if (j >= decimal_digits && carry == 0)
1812 {
1813 /*
1814 * All higher digits are 0 and we
1815 * no longer have a carry.
1816 *
1817 * Note: "j" is 0-based, "decimal_digits" is
1818 * 1-based.
1819 */
1820 decimal_digits = j + 1;
1821 break;
1822 }
1823 }
1824 }
1825
1826 /* Ok, now "digits" is the decimal representation, with
1827 the "decimal_digits" actual digits. Print! */
1828
1829 for (i = decimal_digits - 1; i > 0 && digits[i] == 0; --i)
1830 ;
1831
1832 for (; i >= 0; i--)
1833 {
1834 gdb_printf (stream, "%1d", digits[i]);
1835 }
1836}
1837
1838/* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
1839
1840void
1841print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
1842 unsigned len, enum bfd_endian byte_order,
1843 bool zero_pad)
1844{
1845 const gdb_byte *p;
1846
1847 gdb_puts ("0x", stream);
1848 if (byte_order == BFD_ENDIAN_BIG)
1849 {
1850 p = valaddr;
1851
1852 if (!zero_pad)
1853 {
1854 /* Strip leading 0 bytes, but be sure to leave at least a
1855 single byte at the end. */
1856 for (; p < valaddr + len - 1 && !*p; ++p)
1857 ;
1858 }
1859
1860 const gdb_byte *first = p;
1861 for (;
1862 p < valaddr + len;
1863 p++)
1864 {
1865 /* When not zero-padding, use a different format for the
1866 very first byte printed. */
1867 if (!zero_pad && p == first)
1868 gdb_printf (stream, "%x", *p);
1869 else
1870 gdb_printf (stream, "%02x", *p);
1871 }
1872 }
1873 else
1874 {
1875 p = valaddr + len - 1;
1876
1877 if (!zero_pad)
1878 {
1879 /* Strip leading 0 bytes, but be sure to leave at least a
1880 single byte at the end. */
1881 for (; p >= valaddr + 1 && !*p; --p)
1882 ;
1883 }
1884
1885 const gdb_byte *first = p;
1886 for (;
1887 p >= valaddr;
1888 p--)
1889 {
1890 /* When not zero-padding, use a different format for the
1891 very first byte printed. */
1892 if (!zero_pad && p == first)
1893 gdb_printf (stream, "%x", *p);
1894 else
1895 gdb_printf (stream, "%02x", *p);
1896 }
1897 }
1898}
1899
1900/* Print function pointer with inferior address ADDRESS onto stdio
1901 stream STREAM. */
1902
1903void
1905 struct gdbarch *gdbarch,
1906 CORE_ADDR address,
1907 struct ui_file *stream)
1908{
1909 CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr
1910 (gdbarch, address, current_inferior ()->top_target ());
1911
1912 /* If the function pointer is represented by a description, print
1913 the address of the description. */
1914 if (options->addressprint && func_addr != address)
1915 {
1916 gdb_puts ("@", stream);
1917 gdb_puts (paddress (gdbarch, address), stream);
1918 gdb_puts (": ", stream);
1919 }
1920 print_address_demangle (options, gdbarch, func_addr, stream, demangle);
1921}
1922
1923
1924/* Print on STREAM using the given OPTIONS the index for the element
1925 at INDEX of an array whose index type is INDEX_TYPE. */
1926
1927void
1928maybe_print_array_index (struct type *index_type, LONGEST index,
1929 struct ui_file *stream,
1930 const struct value_print_options *options)
1931{
1932 if (!options->print_array_indexes)
1933 return;
1934
1935 current_language->print_array_index (index_type, index, stream, options);
1936}
1937
1938/* See valprint.h. */
1939
1940void
1941value_print_array_elements (struct value *val, struct ui_file *stream,
1942 int recurse,
1943 const struct value_print_options *options,
1944 unsigned int i)
1945{
1946 unsigned int things_printed = 0;
1947 unsigned len;
1948 struct type *elttype, *index_type;
1949 /* Position of the array element we are examining to see
1950 whether it is repeated. */
1951 unsigned int rep1;
1952 /* Number of repetitions we have detected so far. */
1953 unsigned int reps;
1954 LONGEST low_bound, high_bound;
1955
1956 struct type *type = check_typedef (val->type ());
1957
1958 elttype = type->target_type ();
1959 unsigned bit_stride = type->bit_stride ();
1960 if (bit_stride == 0)
1961 bit_stride = 8 * check_typedef (elttype)->length ();
1963 if (index_type->code () == TYPE_CODE_RANGE)
1965
1966 if (get_array_bounds (type, &low_bound, &high_bound))
1967 {
1968 /* The array length should normally be HIGH_BOUND - LOW_BOUND +
1969 1. But we have to be a little extra careful, because some
1970 languages such as Ada allow LOW_BOUND to be greater than
1971 HIGH_BOUND for empty arrays. In that situation, the array
1972 length is just zero, not negative! */
1973 if (low_bound > high_bound)
1974 len = 0;
1975 else
1976 len = high_bound - low_bound + 1;
1977 }
1978 else
1979 {
1980 warning (_("unable to get bounds of array, assuming null array"));
1981 low_bound = 0;
1982 len = 0;
1983 }
1984
1985 annotate_array_section_begin (i, elttype);
1986
1987 for (; i < len && things_printed < options->print_max; i++)
1988 {
1989 scoped_value_mark free_values;
1990
1991 if (i != 0)
1992 {
1993 if (options->prettyformat_arrays)
1994 {
1995 gdb_printf (stream, ",\n");
1996 print_spaces (2 + 2 * recurse, stream);
1997 }
1998 else
1999 gdb_printf (stream, ", ");
2000 }
2001 else if (options->prettyformat_arrays)
2002 {
2003 gdb_printf (stream, "\n");
2004 print_spaces (2 + 2 * recurse, stream);
2005 }
2006 stream->wrap_here (2 + 2 * recurse);
2007 maybe_print_array_index (index_type, i + low_bound,
2008 stream, options);
2009
2010 struct value *element = val->from_component_bitsize (elttype,
2011 bit_stride * i,
2012 bit_stride);
2013 rep1 = i + 1;
2014 reps = 1;
2015 /* Only check for reps if repeat_count_threshold is not set to
2016 UINT_MAX (unlimited). */
2017 if (options->repeat_count_threshold < UINT_MAX)
2018 {
2019 bool unavailable = element->entirely_unavailable ();
2020 bool available = element->entirely_available ();
2021
2022 while (rep1 < len)
2023 {
2024 /* When printing large arrays this spot is called frequently, so
2025 clean up temporary values asap to prevent allocating a large
2026 amount of them. */
2027 scoped_value_mark free_values_inner;
2028 struct value *rep_elt
2029 = val->from_component_bitsize (elttype,
2030 rep1 * bit_stride,
2031 bit_stride);
2032 bool repeated = ((available
2033 && rep_elt->entirely_available ()
2034 && element->contents_eq (rep_elt))
2035 || (unavailable
2036 && rep_elt->entirely_unavailable ()));
2037 if (!repeated)
2038 break;
2039 ++reps;
2040 ++rep1;
2041 }
2042 }
2043
2044 common_val_print (element, stream, recurse + 1, options,
2046
2047 if (reps > options->repeat_count_threshold)
2048 {
2049 annotate_elt_rep (reps);
2050 gdb_printf (stream, " %p[<repeats %u times>%p]",
2051 metadata_style.style ().ptr (), reps, nullptr);
2053
2054 i = rep1 - 1;
2055 things_printed += options->repeat_count_threshold;
2056 }
2057 else
2058 {
2059 annotate_elt ();
2060 things_printed++;
2061 }
2062 }
2064 if (i < len)
2065 gdb_printf (stream, "...");
2066 if (options->prettyformat_arrays)
2067 {
2068 gdb_printf (stream, "\n");
2069 print_spaces (2 * recurse, stream);
2070 }
2071}
2072
2073/* Return true if print_wchar can display W without resorting to a
2074 numeric escape, false otherwise. */
2075
2076static int
2078{
2079 return (gdb_iswprint (w)
2080 || w == LCST ('\a') || w == LCST ('\b')
2081 || w == LCST ('\f') || w == LCST ('\n')
2082 || w == LCST ('\r') || w == LCST ('\t')
2083 || w == LCST ('\v'));
2084}
2085
2086/* A helper function that converts the contents of STRING to wide
2087 characters and then appends them to OUTPUT. */
2088
2089static void
2090append_string_as_wide (const char *string,
2091 struct obstack *output)
2092{
2093 for (; *string; ++string)
2094 {
2095 gdb_wchar_t w = gdb_btowc (*string);
2096 obstack_grow (output, &w, sizeof (gdb_wchar_t));
2097 }
2098}
2099
2100/* Print a wide character W to OUTPUT. ORIG is a pointer to the
2101 original (target) bytes representing the character, ORIG_LEN is the
2102 number of valid bytes. WIDTH is the number of bytes in a base
2103 characters of the type. OUTPUT is an obstack to which wide
2104 characters are emitted. QUOTER is a (narrow) character indicating
2105 the style of quotes surrounding the character to be printed.
2106 NEED_ESCAPE is an in/out flag which is used to track numeric
2107 escapes across calls. */
2108
2109static void
2110print_wchar (gdb_wint_t w, const gdb_byte *orig,
2111 int orig_len, int width,
2112 enum bfd_endian byte_order,
2113 struct obstack *output,
2114 int quoter, bool *need_escapep)
2115{
2116 bool need_escape = *need_escapep;
2117
2118 *need_escapep = false;
2119
2120 /* If any additional cases are added to this switch block, then the
2121 function wchar_printable will likely need updating too. */
2122 switch (w)
2123 {
2124 case LCST ('\a'):
2125 obstack_grow_wstr (output, LCST ("\\a"));
2126 break;
2127 case LCST ('\b'):
2128 obstack_grow_wstr (output, LCST ("\\b"));
2129 break;
2130 case LCST ('\f'):
2131 obstack_grow_wstr (output, LCST ("\\f"));
2132 break;
2133 case LCST ('\n'):
2134 obstack_grow_wstr (output, LCST ("\\n"));
2135 break;
2136 case LCST ('\r'):
2137 obstack_grow_wstr (output, LCST ("\\r"));
2138 break;
2139 case LCST ('\t'):
2140 obstack_grow_wstr (output, LCST ("\\t"));
2141 break;
2142 case LCST ('\v'):
2143 obstack_grow_wstr (output, LCST ("\\v"));
2144 break;
2145 default:
2146 {
2147 if (gdb_iswprint (w) && !(need_escape && gdb_iswxdigit (w)))
2148 {
2149 gdb_wchar_t wchar = w;
2150
2151 if (w == gdb_btowc (quoter) || w == LCST ('\\'))
2152 obstack_grow_wstr (output, LCST ("\\"));
2153 obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
2154 }
2155 else
2156 {
2157 int i;
2158
2159 for (i = 0; i + width <= orig_len; i += width)
2160 {
2161 char octal[30];
2162 ULONGEST value;
2163
2164 value = extract_unsigned_integer (&orig[i], width,
2165 byte_order);
2166 /* If the value fits in 3 octal digits, print it that
2167 way. Otherwise, print it as a hex escape. */
2168 if (value <= 0777)
2169 {
2170 xsnprintf (octal, sizeof (octal), "\\%.3o",
2171 (int) (value & 0777));
2172 *need_escapep = false;
2173 }
2174 else
2175 {
2176 xsnprintf (octal, sizeof (octal), "\\x%lx", (long) value);
2177 /* A hex escape might require the next character
2178 to be escaped, because, unlike with octal,
2179 hex escapes have no length limit. */
2180 *need_escapep = true;
2181 }
2182 append_string_as_wide (octal, output);
2183 }
2184 /* If we somehow have extra bytes, print them now. */
2185 while (i < orig_len)
2186 {
2187 char octal[5];
2188
2189 xsnprintf (octal, sizeof (octal), "\\%.3o", orig[i] & 0xff);
2190 *need_escapep = false;
2191 append_string_as_wide (octal, output);
2192 ++i;
2193 }
2194 }
2195 break;
2196 }
2197 }
2198}
2199
2200/* Print the character C on STREAM as part of the contents of a
2201 literal string whose delimiter is QUOTER. ENCODING names the
2202 encoding of C. */
2203
2204void
2205generic_emit_char (int c, struct type *type, struct ui_file *stream,
2206 int quoter, const char *encoding)
2207{
2208 enum bfd_endian byte_order
2210 gdb_byte *c_buf;
2211 bool need_escape = false;
2212
2213 c_buf = (gdb_byte *) alloca (type->length ());
2214 pack_long (c_buf, type, c);
2215
2216 wchar_iterator iter (c_buf, type->length (), encoding, type->length ());
2217
2218 /* This holds the printable form of the wchar_t data. */
2219 auto_obstack wchar_buf;
2220
2221 while (1)
2222 {
2223 int num_chars;
2224 gdb_wchar_t *chars;
2225 const gdb_byte *buf;
2226 size_t buflen;
2227 int print_escape = 1;
2228 enum wchar_iterate_result result;
2229
2230 num_chars = iter.iterate (&result, &chars, &buf, &buflen);
2231 if (num_chars < 0)
2232 break;
2233 if (num_chars > 0)
2234 {
2235 /* If all characters are printable, print them. Otherwise,
2236 we're going to have to print an escape sequence. We
2237 check all characters because we want to print the target
2238 bytes in the escape sequence, and we don't know character
2239 boundaries there. */
2240 int i;
2241
2242 print_escape = 0;
2243 for (i = 0; i < num_chars; ++i)
2244 if (!wchar_printable (chars[i]))
2245 {
2246 print_escape = 1;
2247 break;
2248 }
2249
2250 if (!print_escape)
2251 {
2252 for (i = 0; i < num_chars; ++i)
2253 print_wchar (chars[i], buf, buflen,
2254 type->length (), byte_order,
2255 &wchar_buf, quoter, &need_escape);
2256 }
2257 }
2258
2259 /* This handles the NUM_CHARS == 0 case as well. */
2260 if (print_escape)
2261 print_wchar (gdb_WEOF, buf, buflen, type->length (),
2262 byte_order, &wchar_buf, quoter, &need_escape);
2263 }
2264
2265 /* The output in the host encoding. */
2266 auto_obstack output;
2267
2269 (gdb_byte *) obstack_base (&wchar_buf),
2270 obstack_object_size (&wchar_buf),
2271 sizeof (gdb_wchar_t), &output, translit_char);
2272 obstack_1grow (&output, '\0');
2273
2274 gdb_puts ((const char *) obstack_base (&output), stream);
2275}
2276
2277/* Return the repeat count of the next character/byte in ITER,
2278 storing the result in VEC. */
2279
2280static int
2282 std::vector<converted_character> *vec)
2283{
2284 struct converted_character *current;
2285
2286 if (vec->empty ())
2287 {
2288 struct converted_character tmp;
2290
2291 tmp.num_chars
2292 = iter->iterate (&tmp.result, &chars, &tmp.buf, &tmp.buflen);
2293 if (tmp.num_chars > 0)
2294 {
2295 gdb_assert (tmp.num_chars < MAX_WCHARS);
2296 memcpy (tmp.chars, chars, tmp.num_chars * sizeof (gdb_wchar_t));
2297 }
2298 vec->push_back (tmp);
2299 }
2300
2301 current = &vec->back ();
2302
2303 /* Count repeated characters or bytes. */
2304 current->repeat_count = 1;
2305 if (current->num_chars == -1)
2306 {
2307 /* EOF */
2308 return -1;
2309 }
2310 else
2311 {
2313 struct converted_character d;
2314 int repeat;
2315
2316 d.repeat_count = 0;
2317
2318 while (1)
2319 {
2320 /* Get the next character. */
2321 d.num_chars = iter->iterate (&d.result, &chars, &d.buf, &d.buflen);
2322
2323 /* If a character was successfully converted, save the character
2324 into the converted character. */
2325 if (d.num_chars > 0)
2326 {
2327 gdb_assert (d.num_chars < MAX_WCHARS);
2328 memcpy (d.chars, chars, WCHAR_BUFLEN (d.num_chars));
2329 }
2330
2331 /* Determine if the current character is the same as this
2332 new character. */
2333 if (d.num_chars == current->num_chars && d.result == current->result)
2334 {
2335 /* There are two cases to consider:
2336
2337 1) Equality of converted character (num_chars > 0)
2338 2) Equality of non-converted character (num_chars == 0) */
2339 if ((current->num_chars > 0
2340 && memcmp (current->chars, d.chars,
2341 WCHAR_BUFLEN (current->num_chars)) == 0)
2342 || (current->num_chars == 0
2343 && current->buflen == d.buflen
2344 && memcmp (current->buf, d.buf, current->buflen) == 0))
2345 ++current->repeat_count;
2346 else
2347 break;
2348 }
2349 else
2350 break;
2351 }
2352
2353 /* Push this next converted character onto the result vector. */
2354 repeat = current->repeat_count;
2355 vec->push_back (d);
2356 return repeat;
2357 }
2358}
2359
2360/* Print the characters in CHARS to the OBSTACK. QUOTE_CHAR is the quote
2361 character to use with string output. WIDTH is the size of the output
2362 character type. BYTE_ORDER is the target byte order. OPTIONS
2363 is the user's print options. *FINISHED is set to 0 if we didn't print
2364 all the elements in CHARS. */
2365
2366static void
2367print_converted_chars_to_obstack (struct obstack *obstack,
2368 const std::vector<converted_character> &chars,
2369 int quote_char, int width,
2370 enum bfd_endian byte_order,
2371 const struct value_print_options *options,
2372 int *finished)
2373{
2374 unsigned int idx, num_elements;
2375 const converted_character *elem;
2376 enum {START, SINGLE, REPEAT, INCOMPLETE, FINISH} state, last;
2377 gdb_wchar_t wide_quote_char = gdb_btowc (quote_char);
2378 bool need_escape = false;
2379 const int print_max = options->print_max_chars > 0
2380 ? options->print_max_chars : options->print_max;
2381
2382 /* Set the start state. */
2383 idx = num_elements = 0;
2384 last = state = START;
2385 elem = NULL;
2386
2387 while (1)
2388 {
2389 switch (state)
2390 {
2391 case START:
2392 /* Nothing to do. */
2393 break;
2394
2395 case SINGLE:
2396 {
2397 int j;
2398
2399 /* We are outputting a single character
2400 (< options->repeat_count_threshold). */
2401
2402 if (last != SINGLE)
2403 {
2404 /* We were outputting some other type of content, so we
2405 must output and a comma and a quote. */
2406 if (last != START)
2407 obstack_grow_wstr (obstack, LCST (", "));
2408 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2409 }
2410 /* Output the character. */
2411 int repeat_count = elem->repeat_count;
2412 if (print_max < repeat_count + num_elements)
2413 {
2414 repeat_count = print_max - num_elements;
2415 *finished = 0;
2416 }
2417 for (j = 0; j < repeat_count; ++j)
2418 {
2419 if (elem->result == wchar_iterate_ok)
2420 print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
2421 byte_order, obstack, quote_char, &need_escape);
2422 else
2423 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
2424 byte_order, obstack, quote_char, &need_escape);
2425 num_elements += 1;
2426 }
2427 }
2428 break;
2429
2430 case REPEAT:
2431 {
2432 int j;
2433
2434 /* We are outputting a character with a repeat count
2435 greater than options->repeat_count_threshold. */
2436
2437 if (last == SINGLE)
2438 {
2439 /* We were outputting a single string. Terminate the
2440 string. */
2441 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2442 }
2443 if (last != START)
2444 obstack_grow_wstr (obstack, LCST (", "));
2445
2446 /* Output the character and repeat string. */
2447 obstack_grow_wstr (obstack, LCST ("'"));
2448 if (elem->result == wchar_iterate_ok)
2449 print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
2450 byte_order, obstack, quote_char, &need_escape);
2451 else
2452 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
2453 byte_order, obstack, quote_char, &need_escape);
2454 obstack_grow_wstr (obstack, LCST ("'"));
2455 std::string s = string_printf (_(" <repeats %u times>"),
2456 elem->repeat_count);
2457 num_elements += elem->repeat_count;
2458 for (j = 0; s[j]; ++j)
2459 {
2460 gdb_wchar_t w = gdb_btowc (s[j]);
2461 obstack_grow (obstack, &w, sizeof (gdb_wchar_t));
2462 }
2463 }
2464 break;
2465
2466 case INCOMPLETE:
2467 /* We are outputting an incomplete sequence. */
2468 if (last == SINGLE)
2469 {
2470 /* If we were outputting a string of SINGLE characters,
2471 terminate the quote. */
2472 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2473 }
2474 if (last != START)
2475 obstack_grow_wstr (obstack, LCST (", "));
2476
2477 /* Output the incomplete sequence string. */
2478 obstack_grow_wstr (obstack, LCST ("<incomplete sequence "));
2479 print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, byte_order,
2480 obstack, 0, &need_escape);
2481 obstack_grow_wstr (obstack, LCST (">"));
2482 num_elements += 1;
2483
2484 /* We do not attempt to output anything after this. */
2485 state = FINISH;
2486 break;
2487
2488 case FINISH:
2489 /* All done. If we were outputting a string of SINGLE
2490 characters, the string must be terminated. Otherwise,
2491 REPEAT and INCOMPLETE are always left properly terminated. */
2492 if (last == SINGLE)
2493 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
2494
2495 return;
2496 }
2497
2498 /* Get the next element and state. */
2499 last = state;
2500 if (state != FINISH)
2501 {
2502 elem = &chars[idx++];
2503 switch (elem->result)
2504 {
2505 case wchar_iterate_ok:
2507 if (elem->repeat_count > options->repeat_count_threshold)
2508 state = REPEAT;
2509 else
2510 state = SINGLE;
2511 break;
2512
2514 state = INCOMPLETE;
2515 break;
2516
2517 case wchar_iterate_eof:
2518 state = FINISH;
2519 break;
2520 }
2521 }
2522 }
2523}
2524
2525/* Print the character string STRING, printing at most LENGTH
2526 characters. LENGTH is -1 if the string is nul terminated. TYPE is
2527 the type of each character. OPTIONS holds the printing options;
2528 printing stops early if the number hits print_max_chars; repeat
2529 counts are printed as appropriate. Print ellipses at the end if we
2530 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
2531 QUOTE_CHAR is the character to print at each end of the string. If
2532 C_STYLE_TERMINATOR is true, and the last character is 0, then it is
2533 omitted. */
2534
2535void
2536generic_printstr (struct ui_file *stream, struct type *type,
2537 const gdb_byte *string, unsigned int length,
2538 const char *encoding, int force_ellipses,
2539 int quote_char, int c_style_terminator,
2540 const struct value_print_options *options)
2541{
2542 enum bfd_endian byte_order = type_byte_order (type);
2543 unsigned int i;
2544 int width = type->length ();
2545 int finished = 0;
2546 struct converted_character *last;
2547
2548 if (length == -1)
2549 {
2550 unsigned long current_char = 1;
2551
2552 for (i = 0; current_char; ++i)
2553 {
2554 QUIT;
2555 current_char = extract_unsigned_integer (string + i * width,
2556 width, byte_order);
2557 }
2558 length = i;
2559 }
2560
2561 /* If the string was not truncated due to `set print elements', and
2562 the last byte of it is a null, we don't print that, in
2563 traditional C style. */
2564 if (c_style_terminator
2565 && !force_ellipses
2566 && length > 0
2567 && (extract_unsigned_integer (string + (length - 1) * width,
2568 width, byte_order) == 0))
2569 length--;
2570
2571 if (length == 0)
2572 {
2573 gdb_printf (stream, "%c%c", quote_char, quote_char);
2574 return;
2575 }
2576
2577 /* Arrange to iterate over the characters, in wchar_t form. */
2578 wchar_iterator iter (string, length * width, encoding, width);
2579 std::vector<converted_character> converted_chars;
2580
2581 /* Convert characters until the string is over or the maximum
2582 number of printed characters has been reached. */
2583 i = 0;
2584 unsigned int print_max_chars = get_print_max_chars (options);
2585 while (i < print_max_chars)
2586 {
2587 int r;
2588
2589 QUIT;
2590
2591 /* Grab the next character and repeat count. */
2592 r = count_next_character (&iter, &converted_chars);
2593
2594 /* If less than zero, the end of the input string was reached. */
2595 if (r < 0)
2596 break;
2597
2598 /* Otherwise, add the count to the total print count and get
2599 the next character. */
2600 i += r;
2601 }
2602
2603 /* Get the last element and determine if the entire string was
2604 processed. */
2605 last = &converted_chars.back ();
2606 finished = (last->result == wchar_iterate_eof);
2607
2608 /* Ensure that CONVERTED_CHARS is terminated. */
2609 last->result = wchar_iterate_eof;
2610
2611 /* WCHAR_BUF is the obstack we use to represent the string in
2612 wchar_t form. */
2613 auto_obstack wchar_buf;
2614
2615 /* Print the output string to the obstack. */
2616 print_converted_chars_to_obstack (&wchar_buf, converted_chars, quote_char,
2617 width, byte_order, options, &finished);
2618
2619 if (force_ellipses || !finished)
2620 obstack_grow_wstr (&wchar_buf, LCST ("..."));
2621
2622 /* OUTPUT is where we collect `char's for printing. */
2623 auto_obstack output;
2624
2626 (gdb_byte *) obstack_base (&wchar_buf),
2627 obstack_object_size (&wchar_buf),
2628 sizeof (gdb_wchar_t), &output, translit_char);
2629 obstack_1grow (&output, '\0');
2630
2631 gdb_puts ((const char *) obstack_base (&output), stream);
2632}
2633
2634/* Print a string from the inferior, starting at ADDR and printing up to LEN
2635 characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing
2636 stops at the first null byte, otherwise printing proceeds (including null
2637 bytes) until either print_max_chars or LEN characters have been printed,
2638 whichever is smaller. ENCODING is the name of the string's
2639 encoding. It can be NULL, in which case the target encoding is
2640 assumed. */
2641
2642int
2643val_print_string (struct type *elttype, const char *encoding,
2644 CORE_ADDR addr, int len,
2645 struct ui_file *stream,
2646 const struct value_print_options *options)
2647{
2648 int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */
2649 int err; /* Non-zero if we got a bad read. */
2650 int found_nul; /* Non-zero if we found the nul char. */
2651 unsigned int fetchlimit; /* Maximum number of chars to print. */
2652 int bytes_read;
2653 gdb::unique_xmalloc_ptr<gdb_byte> buffer; /* Dynamically growable fetch buffer. */
2654 struct gdbarch *gdbarch = elttype->arch ();
2655 enum bfd_endian byte_order = type_byte_order (elttype);
2656 int width = elttype->length ();
2657
2658 /* First we need to figure out the limit on the number of characters we are
2659 going to attempt to fetch and print. This is actually pretty simple.
2660 If LEN >= zero, then the limit is the minimum of LEN and print_max_chars.
2661 If LEN is -1, then the limit is print_max_chars. This is true regardless
2662 of whether print_max_chars is zero, UINT_MAX (unlimited), or something in
2663 between, because finding the null byte (or available memory) is what
2664 actually limits the fetch. */
2665
2666 unsigned int print_max_chars = get_print_max_chars (options);
2667 fetchlimit = (len == -1
2668 ? print_max_chars
2669 : std::min ((unsigned) len, print_max_chars));
2670
2671 err = target_read_string (addr, len, width, fetchlimit,
2672 &buffer, &bytes_read);
2673
2674 addr += bytes_read;
2675
2676 /* We now have either successfully filled the buffer to fetchlimit,
2677 or terminated early due to an error or finding a null char when
2678 LEN is -1. */
2679
2680 /* Determine found_nul by looking at the last character read. */
2681 found_nul = 0;
2682 if (bytes_read >= width)
2683 found_nul = extract_unsigned_integer (buffer.get () + bytes_read - width,
2684 width, byte_order) == 0;
2685 if (len == -1 && !found_nul)
2686 {
2687 gdb_byte *peekbuf;
2688
2689 /* We didn't find a NUL terminator we were looking for. Attempt
2690 to peek at the next character. If not successful, or it is not
2691 a null byte, then force ellipsis to be printed. */
2692
2693 peekbuf = (gdb_byte *) alloca (width);
2694
2695 if (target_read_memory (addr, peekbuf, width) == 0
2696 && extract_unsigned_integer (peekbuf, width, byte_order) != 0)
2697 force_ellipsis = 1;
2698 }
2699 else if ((len >= 0 && err != 0) || (len > bytes_read / width))
2700 {
2701 /* Getting an error when we have a requested length, or fetching less
2702 than the number of characters actually requested, always make us
2703 print ellipsis. */
2704 force_ellipsis = 1;
2705 }
2706
2707 /* If we get an error before fetching anything, don't print a string.
2708 But if we fetch something and then get an error, print the string
2709 and then the error message. */
2710 if (err == 0 || bytes_read > 0)
2711 current_language->printstr (stream, elttype, buffer.get (),
2712 bytes_read / width,
2713 encoding, force_ellipsis, options);
2714
2715 if (err != 0)
2716 {
2717 std::string str = memory_error_message (TARGET_XFER_E_IO, gdbarch, addr);
2718
2719 gdb_printf (stream, _("<error: %ps>"),
2721 str.c_str ()));
2722 }
2723
2724 return (bytes_read / width);
2725}
2726
2727/* Handle 'show print max-depth'. */
2728
2729static void
2730show_print_max_depth (struct ui_file *file, int from_tty,
2731 struct cmd_list_element *c, const char *value)
2732{
2733 gdb_printf (file, _("Maximum print depth is %s.\n"), value);
2734}
2735
2736
2737/* The 'set input-radix' command writes to this auxiliary variable.
2738 If the requested radix is valid, INPUT_RADIX is updated; otherwise,
2739 it is left unchanged. */
2740
2741static unsigned input_radix_1 = 10;
2742
2743/* Validate an input or output radix setting, and make sure the user
2744 knows what they really did here. Radix setting is confusing, e.g.
2745 setting the input radix to "10" never changes it! */
2746
2747static void
2748set_input_radix (const char *args, int from_tty, struct cmd_list_element *c)
2749{
2750 set_input_radix_1 (from_tty, input_radix_1);
2751}
2752
2753static void
2754set_input_radix_1 (int from_tty, unsigned radix)
2755{
2756 /* We don't currently disallow any input radix except 0 or 1, which don't
2757 make any mathematical sense. In theory, we can deal with any input
2758 radix greater than 1, even if we don't have unique digits for every
2759 value from 0 to radix-1, but in practice we lose on large radix values.
2760 We should either fix the lossage or restrict the radix range more.
2761 (FIXME). */
2762
2763 if (radix < 2)
2764 {
2766 error (_("Nonsense input radix ``decimal %u''; input radix unchanged."),
2767 radix);
2768 }
2769 input_radix_1 = input_radix = radix;
2770 if (from_tty)
2771 {
2772 gdb_printf (_("Input radix now set to "
2773 "decimal %u, hex %x, octal %o.\n"),
2774 radix, radix, radix);
2775 }
2776}
2777
2778/* The 'set output-radix' command writes to this auxiliary variable.
2779 If the requested radix is valid, OUTPUT_RADIX is updated,
2780 otherwise, it is left unchanged. */
2781
2782static unsigned output_radix_1 = 10;
2783
2784static void
2785set_output_radix (const char *args, int from_tty, struct cmd_list_element *c)
2786{
2788}
2789
2790static void
2791set_output_radix_1 (int from_tty, unsigned radix)
2792{
2793 /* Validate the radix and disallow ones that we aren't prepared to
2794 handle correctly, leaving the radix unchanged. */
2795 switch (radix)
2796 {
2797 case 16:
2798 user_print_options.output_format = 'x'; /* hex */
2799 break;
2800 case 10:
2801 user_print_options.output_format = 0; /* decimal */
2802 break;
2803 case 8:
2804 user_print_options.output_format = 'o'; /* octal */
2805 break;
2806 default:
2808 error (_("Unsupported output radix ``decimal %u''; "
2809 "output radix unchanged."),
2810 radix);
2811 }
2812 output_radix_1 = output_radix = radix;
2813 if (from_tty)
2814 {
2815 gdb_printf (_("Output radix now set to "
2816 "decimal %u, hex %x, octal %o.\n"),
2817 radix, radix, radix);
2818 }
2819}
2820
2821/* Set both the input and output radix at once. Try to set the output radix
2822 first, since it has the most restrictive range. An radix that is valid as
2823 an output radix is also valid as an input radix.
2824
2825 It may be useful to have an unusual input radix. If the user wishes to
2826 set an input radix that is not valid as an output radix, he needs to use
2827 the 'set input-radix' command. */
2828
2829static void
2830set_radix (const char *arg, int from_tty)
2831{
2832 unsigned radix;
2833
2834 radix = (arg == NULL) ? 10 : parse_and_eval_long (arg);
2835 set_output_radix_1 (0, radix);
2836 set_input_radix_1 (0, radix);
2837 if (from_tty)
2838 {
2839 gdb_printf (_("Input and output radices now set to "
2840 "decimal %u, hex %x, octal %o.\n"),
2841 radix, radix, radix);
2842 }
2843}
2844
2845/* Show both the input and output radices. */
2846
2847static void
2848show_radix (const char *arg, int from_tty)
2849{
2850 if (from_tty)
2851 {
2853 {
2854 gdb_printf (_("Input and output radices set to "
2855 "decimal %u, hex %x, octal %o.\n"),
2857 }
2858 else
2859 {
2860 gdb_printf (_("Input radix set to decimal "
2861 "%u, hex %x, octal %o.\n"),
2863 gdb_printf (_("Output radix set to decimal "
2864 "%u, hex %x, octal %o.\n"),
2866 }
2867 }
2868}
2869
2870
2871/* Controls printing of vtbl's. */
2872static void
2873show_vtblprint (struct ui_file *file, int from_tty,
2874 struct cmd_list_element *c, const char *value)
2875{
2876 gdb_printf (file, _("\
2877Printing of C++ virtual function tables is %s.\n"),
2878 value);
2879}
2880
2881/* Controls looking up an object's derived type using what we find in
2882 its vtables. */
2883static void
2884show_objectprint (struct ui_file *file, int from_tty,
2885 struct cmd_list_element *c,
2886 const char *value)
2887{
2888 gdb_printf (file, _("\
2889Printing of object's derived type based on vtable info is %s.\n"),
2890 value);
2891}
2892
2893static void
2894show_static_field_print (struct ui_file *file, int from_tty,
2895 struct cmd_list_element *c,
2896 const char *value)
2897{
2898 gdb_printf (file,
2899 _("Printing of C++ static members is %s.\n"),
2900 value);
2901}
2902
2903
2904
2905/* A couple typedefs to make writing the options a bit more
2906 convenient. */
2914/* Extra literals supported with the `set print characters' and
2915 `print -characters' commands. */
2917 {
2918 { "elements", PRINT_MAX_CHARS_ELEMENTS },
2919 { "unlimited", PRINT_MAX_CHARS_UNLIMITED, 0 },
2920 { nullptr }
2921 };
2923/* Definitions of options for the "print" and "compile print"
2924 commands. */
2926
2928 "address",
2929 [] (value_print_options *opt) { return &opt->addressprint; },
2930 show_addressprint, /* show_cmd_cb */
2931 N_("Set printing of addresses."),
2932 N_("Show printing of addresses."),
2933 NULL, /* help_doc */
2934 },
2935
2937 "array",
2938 [] (value_print_options *opt) { return &opt->prettyformat_arrays; },
2939 show_prettyformat_arrays, /* show_cmd_cb */
2940 N_("Set pretty formatting of arrays."),
2941 N_("Show pretty formatting of arrays."),
2942 NULL, /* help_doc */
2943 },
2944
2946 "array-indexes",
2947 [] (value_print_options *opt) { return &opt->print_array_indexes; },
2948 show_print_array_indexes, /* show_cmd_cb */
2949 N_("Set printing of array indexes."),
2950 N_("Show printing of array indexes."),
2951 NULL, /* help_doc */
2952 },
2953
2955 "nibbles",
2956 [] (value_print_options *opt) { return &opt->nibblesprint; },
2957 show_nibbles, /* show_cmd_cb */
2958 N_("Set whether to print binary values in groups of four bits."),
2959 N_("Show whether to print binary values in groups of four bits."),
2960 NULL, /* help_doc */
2961 },
2962
2964 "characters",
2965 [] (value_print_options *opt) { return &opt->print_max_chars; },
2967 show_print_max_chars, /* show_cmd_cb */
2968 N_("Set limit on string chars to print."),
2969 N_("Show limit on string chars to print."),
2970 N_("\"elements\" causes the array element limit to be used.\n"
2971 "\"unlimited\" causes there to be no limit."),
2972 },
2973
2975 "elements",
2976 [] (value_print_options *opt) { return &opt->print_max; },
2978 show_print_max, /* show_cmd_cb */
2979 N_("Set limit on array elements to print."),
2980 N_("Show limit on array elements to print."),
2981 N_("\"unlimited\" causes there to be no limit.\n"
2982 "This setting also applies to string chars when \"print characters\"\n"
2983 "is set to \"elements\"."),
2984 },
2985
2987 "max-depth",
2988 [] (value_print_options *opt) { return &opt->max_depth; },
2990 show_print_max_depth, /* show_cmd_cb */
2991 N_("Set maximum print depth for nested structures, unions and arrays."),
2992 N_("Show maximum print depth for nested structures, unions, and arrays."),
2993 N_("When structures, unions, or arrays are nested beyond this depth then they\n\
2994will be replaced with either '{...}' or '(...)' depending on the language.\n\
2995Use \"unlimited\" to print the complete structure.")
2996 },
2997
2999 "memory-tag-violations",
3000 [] (value_print_options *opt) { return &opt->memory_tag_violations; },
3001 show_memory_tag_violations, /* show_cmd_cb */
3002 N_("Set printing of memory tag violations for pointers."),
3003 N_("Show printing of memory tag violations for pointers."),
3004 N_("Issue a warning when the printed value is a pointer\n\
3005whose logical tag doesn't match the allocation tag of the memory\n\
3006location it points to."),
3007 },
3008
3010 "null-stop",
3011 [] (value_print_options *opt) { return &opt->stop_print_at_null; },
3012 show_stop_print_at_null, /* show_cmd_cb */
3013 N_("Set printing of char arrays to stop at first null char."),
3014 N_("Show printing of char arrays to stop at first null char."),
3015 NULL, /* help_doc */
3016 },
3017
3019 "object",
3020 [] (value_print_options *opt) { return &opt->objectprint; },
3021 show_objectprint, /* show_cmd_cb */
3022 _("Set printing of C++ virtual function tables."),
3023 _("Show printing of C++ virtual function tables."),
3024 NULL, /* help_doc */
3025 },
3026
3028 "pretty",
3029 [] (value_print_options *opt) { return &opt->prettyformat_structs; },
3030 show_prettyformat_structs, /* show_cmd_cb */
3031 N_("Set pretty formatting of structures."),
3032 N_("Show pretty formatting of structures."),
3033 NULL, /* help_doc */
3034 },
3035
3037 "raw-values",
3038 [] (value_print_options *opt) { return &opt->raw; },
3039 NULL, /* show_cmd_cb */
3040 N_("Set whether to print values in raw form."),
3041 N_("Show whether to print values in raw form."),
3042 N_("If set, values are printed in raw form, bypassing any\n\
3043pretty-printers for that value.")
3044 },
3045
3047 "repeats",
3048 [] (value_print_options *opt) { return &opt->repeat_count_threshold; },
3050 show_repeat_count_threshold, /* show_cmd_cb */
3051 N_("Set threshold for repeated print elements."),
3052 N_("Show threshold for repeated print elements."),
3053 N_("\"unlimited\" causes all elements to be individually printed."),
3054 },
3055
3057 "static-members",
3058 [] (value_print_options *opt) { return &opt->static_field_print; },
3059 show_static_field_print, /* show_cmd_cb */
3060 N_("Set printing of C++ static members."),
3061 N_("Show printing of C++ static members."),
3062 NULL, /* help_doc */
3063 },
3064
3066 "symbol",
3067 [] (value_print_options *opt) { return &opt->symbol_print; },
3068 show_symbol_print, /* show_cmd_cb */
3069 N_("Set printing of symbol names when printing pointers."),
3070 N_("Show printing of symbol names when printing pointers."),
3071 NULL, /* help_doc */
3072 },
3073
3075 "union",
3076 [] (value_print_options *opt) { return &opt->unionprint; },
3077 show_unionprint, /* show_cmd_cb */
3078 N_("Set printing of unions interior to structures."),
3079 N_("Show printing of unions interior to structures."),
3080 NULL, /* help_doc */
3081 },
3082
3084 "vtbl",
3085 [] (value_print_options *opt) { return &opt->vtblprint; },
3086 show_vtblprint, /* show_cmd_cb */
3087 N_("Set printing of C++ virtual function tables."),
3088 N_("Show printing of C++ virtual function tables."),
3089 NULL, /* help_doc */
3090 },
3091};
3092
3097{
3098 return {{value_print_option_defs}, opts};
3099}
3100
3101#if GDB_SELF_TEST
3102
3103/* Test printing of TYPE_CODE_FLAGS values. */
3104
3105static void
3106test_print_flags (gdbarch *arch)
3107{
3108 type *flags_type = arch_flags_type (arch, "test_type", 32);
3109 type *field_type = builtin_type (arch)->builtin_uint32;
3110
3111 /* Value: 1010 1010
3112 Fields: CCCB BAAA */
3113 append_flags_type_field (flags_type, 0, 3, field_type, "A");
3114 append_flags_type_field (flags_type, 3, 2, field_type, "B");
3115 append_flags_type_field (flags_type, 5, 3, field_type, "C");
3116
3117 value *val = value::allocate (flags_type);
3118 gdb_byte *contents = val->contents_writeable ().data ();
3119 store_unsigned_integer (contents, 4, gdbarch_byte_order (arch), 0xaa);
3120
3121 string_file out;
3122 val_print_type_code_flags (flags_type, val, 0, &out);
3123 SELF_CHECK (out.string () == "[ A=2 B=1 C=5 ]");
3124}
3125
3126#endif
3128void _initialize_valprint ();
3129void
3131{
3132#if GDB_SELF_TEST
3133 selftests::register_test_foreach_arch ("print-flags", test_print_flags);
3134#endif
3135
3136 set_show_commands setshow_print_cmds
3137 = add_setshow_prefix_cmd ("print", no_class,
3138 _("Generic command for setting how things print."),
3139 _("Generic command for showing print settings."),
3141 &setlist, &showlist);
3142 add_alias_cmd ("p", setshow_print_cmds.set, no_class, 1, &setlist);
3143 /* Prefer set print to set prompt. */
3144 add_alias_cmd ("pr", setshow_print_cmds.set, no_class, 1, &setlist);
3145 add_alias_cmd ("p", setshow_print_cmds.show, no_class, 1, &showlist);
3146 add_alias_cmd ("pr", setshow_print_cmds.show, no_class, 1, &showlist);
3147
3148 set_show_commands setshow_print_raw_cmds
3150 ("raw", no_class,
3151 _("Generic command for setting what things to print in \"raw\" mode."),
3152 _("Generic command for showing \"print raw\" settings."),
3154 deprecate_cmd (setshow_print_raw_cmds.set, nullptr);
3155 deprecate_cmd (setshow_print_raw_cmds.show, nullptr);
3156
3160
3162 _("\
3163Set default input radix for entering numbers."), _("\
3164Show default input radix for entering numbers."), NULL,
3167 &setlist, &showlist);
3168
3170 _("\
3171Set default output radix for printing of values."), _("\
3172Show default output radix for printing of values."), NULL,
3175 &setlist, &showlist);
3176
3177 /* The "set radix" and "show radix" commands are special in that
3178 they are like normal set and show commands but allow two normally
3179 independent variables to be either set or shown with a single
3180 command. So the usual deprecated_add_set_cmd() and [deleted]
3181 add_show_from_set() commands aren't really appropriate. */
3182 /* FIXME: i18n: With the new add_setshow_integer command, that is no
3183 longer true - show can display anything. */
3184 add_cmd ("radix", class_support, set_radix, _("\
3185Set default input and output number radices.\n\
3186Use 'set input-radix' or 'set output-radix' to independently set each.\n\
3187Without an argument, sets both radices back to the default value of 10."),
3188 &setlist);
3189 add_cmd ("radix", class_support, show_radix, _("\
3190Show the default input and output number radices.\n\
3191Use 'show input-radix' or 'show output-radix' to independently show each."),
3192 &showlist);
3193}
struct value * ada_to_fixed_value(struct value *val)
Definition ada-lang.c:8773
void annotate_elt_rep_end(void)
Definition annotate.c:587
void annotate_array_section_begin(int idx, struct type *elttype)
Definition annotate.c:569
void annotate_elt(void)
Definition annotate.c:594
void annotate_array_section_end(void)
Definition annotate.c:601
void annotate_elt_rep(unsigned int repcount)
Definition annotate.c:580
void f()
Definition 1.cc:36
void cp_print_class_member(const gdb_byte *, struct type *, struct ui_file *, const char *)
const char * host_charset(void)
Definition charset.c:416
void convert_between_encodings(const char *from, const char *to, const gdb_byte *bytes, unsigned int num_bytes, int width, struct obstack *output, enum transliterations translit)
Definition charset.c:497
@ translit_char
Definition charset.h:48
wchar_iterate_result
Definition charset.h:75
@ wchar_iterate_eof
Definition charset.h:83
@ wchar_iterate_invalid
Definition charset.h:79
@ wchar_iterate_incomplete
Definition charset.h:81
@ wchar_iterate_ok
Definition charset.h:77
ui_file_style style() const
Definition cli-style.c:169
const std::string & string()
Definition ui-file.h:198
virtual void wrap_here(int indent)
Definition ui-file.h:119
int iterate(enum wchar_iterate_result *out_result, gdb_wchar_t **out_chars, const gdb_byte **ptr, size_t *len)
Definition charset.c:608
struct cmd_list_element * showlist
Definition cli-cmds.c:127
struct cmd_list_element * showprintlist
Definition cli-cmds.c:163
struct cmd_list_element * setprintlist
Definition cli-cmds.c:161
struct cmd_list_element * setlist
Definition cli-cmds.c:119
const literal_def pinteger_unlimited_literals[]
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
Definition cli-decode.c:294
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
Definition cli-decode.c:280
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
Definition cli-decode.c:428
const literal_def uinteger_unlimited_literals[]
set_show_commands add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
cli_style_option variable_name_style
cli_style_option metadata_style
@ class_support
Definition command.h:58
@ no_class
Definition command.h:53
std::string memory_error_message(enum target_xfer_status err, struct gdbarch *gdbarch, CORE_ADDR memaddr)
Definition corefile.c:163
void cplus_print_method_ptr(const gdb_byte *contents, struct type *type, struct ui_file *stream)
Definition cp-abi.c:129
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition defs.h:515
CORE_ADDR extract_typed_address(const gdb_byte *buf, struct type *type)
Definition findvar.c:152
language
Definition defs.h:211
@ language_ada
Definition defs.h:225
@ lval_memory
Definition defs.h:363
@ lval_register
Definition defs.h:365
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
#define QUIT
Definition defs.h:187
LONGEST parse_and_eval_long(const char *exp)
Definition eval.c:62
int apply_ext_lang_val_pretty_printer(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition extension.c:477
#define SINGLE
Definition f-exp.c:266
bool demangle
#define gdb_WEOF
Definition gdb_wchar.h:108
int gdb_wint_t
Definition gdb_wchar.h:102
char gdb_wchar_t
Definition gdb_wchar.h:101
#define gdb_iswxdigit
Definition gdb_wchar.h:106
#define gdb_iswprint
Definition gdb_wchar.h:105
#define LCST(X)
Definition gdb_wchar.h:110
#define gdb_btowc
Definition gdb_wchar.h:107
#define INTERMEDIATE_ENCODING
Definition gdb_wchar.h:117
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
int gdbarch_addressable_memory_unit_size(struct gdbarch *gdbarch)
Definition gdbarch.c:5300
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
Definition gdbarch.c:3135
enum bfd_endian type_byte_order(const struct type *type)
Definition gdbtypes.c:3900
struct type * arch_flags_type(struct gdbarch *gdbarch, const char *name, int bit)
Definition gdbtypes.c:5681
void append_flags_type_field(struct type *type, int start_bitpos, int nr_bits, struct type *field_type, const char *name)
Definition gdbtypes.c:5699
bool get_array_bounds(struct type *type, LONGEST *low_bound, LONGEST *high_bound)
Definition gdbtypes.c:1211
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
int type_not_associated(const struct type *type)
Definition gdbtypes.c:4372
bool is_fixed_point_type(struct type *type)
Definition gdbtypes.c:5861
int type_not_allocated(const struct type *type)
Definition gdbtypes.c:4361
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:2966
#define TYPE_IS_REFERENCE(t)
Definition gdbtypes.h:139
void print_scalar_formatted(const gdb_byte *, struct type *, const struct value_print_options *, int, struct ui_file *)
Definition printcmd.c:369
@ TYPE_CODE_UNDEF
Definition gdbtypes.h:83
#define TYPE_ERROR_NAME(type)
Definition gdbtypes.h:2066
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition gnu-nat.c:1789
unsigned dummy
Definition go32-nat.c:8
size_t size
Definition go32-nat.c:239
unsigned available
Definition go32-nat.c:7
struct inferior * current_inferior(void)
Definition inferior.c:55
const struct language_defn * current_language
Definition language.c:82
void add_setshow_cmds_for_options(command_class cmd_class, void *data, gdb::array_view< const option_def > options, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-option.c:794
void register_test_foreach_arch(const std::string &name, self_test_foreach_arch_function *function)
int print_address_demangle(const struct value_print_options *opts, struct gdbarch *gdbarch, CORE_ADDR addr, struct ui_file *stream, int do_demangle)
Definition printcmd.c:769
int value
Definition py-param.c:79
struct type * builtin_bool
Definition gdbtypes.h:2095
struct type * builtin_uint32
Definition gdbtypes.h:2120
gdb_wchar_t chars[WCHAR_BUFLEN_MAX]
Definition valprint.c:70
const gdb_byte * buf
Definition valprint.c:73
enum wchar_iterate_result result
Definition valprint.c:67
LONGEST loc_bitpos() const
Definition gdbtypes.h:611
LONGEST loc_enumval() const
Definition gdbtypes.h:623
const char * name() const
Definition gdbtypes.h:557
unsigned int bitsize() const
Definition gdbtypes.h:577
struct type * type() const
Definition gdbtypes.h:547
void read_fixed_point(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order, bool unsigned_p, const gdb_mpq &scaling_factor)
Definition gmp-utils.h:577
virtual void print_array_index(struct type *index_type, LONGEST index_value, struct ui_file *stream, const value_print_options *options) const
Definition language.c:561
virtual void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options) const
Definition language.c:587
virtual void printstr(struct ui_file *stream, struct type *elttype, const gdb_byte *string, unsigned int length, const char *encoding, int force_ellipses, const struct value_print_options *options) const
Definition c-lang.c:192
virtual void printchar(int ch, struct type *chtype, struct ui_file *stream) const
Definition c-lang.c:158
virtual const char * get_digit_separator() const
Definition language.h:287
cmd_list_element * set
Definition command.h:422
cmd_list_element * show
Definition command.h:422
struct type * target_type() const
Definition gdbtypes.h:1037
type_code code() const
Definition gdbtypes.h:956
ULONGEST length() const
Definition gdbtypes.h:983
struct field & field(int idx) const
Definition gdbtypes.h:1012
bool is_unsigned() const
Definition gdbtypes.h:1100
bool is_stub() const
Definition gdbtypes.h:1128
unsigned int num_fields() const
Definition gdbtypes.h:994
gdbarch * arch() const
Definition gdbtypes.c:273
ULONGEST bit_stride() const
Definition gdbtypes.h:1090
const gdb_mpq & fixed_point_scaling_factor()
Definition gdbtypes.c:5888
type * index_type() const
Definition gdbtypes.h:1032
struct type * fixed_point_type_base_type()
Definition gdbtypes.c:5873
bool is_flag_enum() const
Definition gdbtypes.h:1281
const ui_file_style * ptr() const
Definition ui-style.h:233
unsigned int print_max
Definition valprint.h:68
enum val_prettyformat prettyformat
Definition valprint.h:41
unsigned int repeat_count_threshold
Definition valprint.h:76
unsigned int print_max_chars
Definition valprint.h:72
bool prettyformat_structs
Definition valprint.h:47
Definition value.h:130
bool bits_any_optimized_out(int bit_offset, int bit_length) const
Definition value.c:201
bool lazy() const
Definition value.h:265
gdb::array_view< gdb_byte > contents_writeable()
Definition value.c:1271
static struct value * allocate(struct type *type)
Definition value.c:957
bool bytes_available(LONGEST offset, ULONGEST length) const
Definition value.c:187
struct value * from_component_bitsize(struct type *type, LONGEST bit_offset, LONGEST bit_length)
Definition value.c:3679
bool entirely_unavailable()
Definition value.h:506
LONGEST embedded_offset() const
Definition value.h:244
bool entirely_available()
Definition value.c:209
struct type * type() const
Definition value.h:180
bool entirely_optimized_out()
Definition value.h:529
bool contents_eq(LONGEST offset1, const struct value *val2, LONGEST offset2, LONGEST length) const
Definition value.c:693
enum lval_type lval() const
Definition value.h:332
void fetch_lazy()
Definition value.c:4001
CORE_ADDR address
Definition value.h:658
bool bits_synthetic_pointer(LONGEST offset, LONGEST length) const
Definition value.c:1339
gdb::array_view< const gdb_byte > contents_for_printing()
Definition value.c:1100
std::string target_float_to_string(const gdb_byte *addr, const struct type *type, const char *format)
int target_read_string(CORE_ADDR addr, int len, int width, unsigned int fetchlimit, gdb::unique_xmalloc_ptr< gdb_byte > *buffer, int *bytes_read)
Definition target.c:65
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1785
@ TARGET_XFER_E_IO
Definition target.h:232
void val_print_not_allocated(struct ui_file *stream)
Definition typeprint.c:898
void val_print_not_associated(struct ui_file *stream)
Definition typeprint.c:906
void type_print(struct type *type, const char *varstring, struct ui_file *stream, int show)
Definition typeprint.c:388
static styled_string_s * styled_string(const ui_file_style &style, const char *str, styled_string_s &&tmp={})
Definition ui-out.h:151
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3166
void print_spaces(int n, struct ui_file *stream)
Definition utils.c:1968
void gdb_putc(int c)
Definition utils.c:1862
void fprintf_styled(struct ui_file *stream, const ui_file_style &style, const char *format,...)
Definition utils.c:1898
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
void fputs_styled(const char *linebuffer, const ui_file_style &style, struct ui_file *stream)
Definition utils.c:1817
void gdb_flush(struct ui_file *stream)
Definition utils.c:1498
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1809
#define gdb_stdlog
Definition utils.h:190
struct value * value_at(struct type *type, CORE_ADDR addr)
Definition valops.c:1015
struct value * value_addr(struct value *arg1)
Definition valops.c:1551
struct value * value_cast(struct type *type, struct value *arg2)
Definition valops.c:403
struct value * value_real_part(struct value *value)
Definition valops.c:4116
struct value * value_imaginary_part(struct value *value)
Definition valops.c:4128
#define LOW_NIBBLE( x)
static void show_stop_print_at_null(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:242
static void generic_value_print_ptr(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:505
#define PRINT_MAX_CHARS_DEFAULT
Definition valprint.c:101
static void show_repeat_count_threshold(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:221
void get_formatted_print_options(struct value_print_options *opts, char format)
Definition valprint.c:152
#define HIGH_ONE
static void generic_val_print_fixed_point(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:842
void generic_value_print(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct generic_val_print_decorations *decorations)
Definition valprint.c:907
#define LOW_TWO
static void generic_value_print_bool(struct value *value, struct ui_file *stream, const struct value_print_options *options, const struct generic_val_print_decorations *decorations)
Definition valprint.c:757
static void show_nibbles(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:284
static void set_output_radix_1(int, unsigned)
Definition valprint.c:2791
static void generic_val_print_enum_1(struct type *type, LONGEST val, struct ui_file *stream)
Definition valprint.c:628
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:1191
unsigned output_radix
Definition valprint.c:196
static void show_print_array_indexes(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:210
void get_no_prettyformat_print_options(struct value_print_options *opts)
Definition valprint.c:143
void generic_emit_char(int c, struct type *type, struct ui_file *stream, int quoter, const char *encoding)
Definition valprint.c:2205
#define CARRY_OUT( x)
void value_print_scalar_formatted(struct value *val, const struct value_print_options *options, int size, struct ui_file *stream)
Definition valprint.c:1278
void print_decimal_chars(struct ui_file *stream, const gdb_byte *valaddr, unsigned len, bool is_signed, enum bfd_endian byte_order)
Definition valprint.c:1705
void val_print_unavailable(struct ui_file *stream)
Definition valprint.c:431
static void show_memory_tag_violations(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:231
#define LOW_ZERO
static void generic_val_print_enum(struct type *type, int embedded_offset, struct ui_file *stream, struct value *original_value, const struct value_print_options *options)
Definition valprint.c:712
static void print_converted_chars_to_obstack(struct obstack *obstack, const std::vector< converted_character > &chars, int quote_char, int width, enum bfd_endian byte_order, const struct value_print_options *options, int *finished)
Definition valprint.c:2367
void print_octal_chars(struct ui_file *stream, const gdb_byte *valaddr, unsigned len, enum bfd_endian byte_order)
Definition valprint.c:1504
static void generic_val_print_func(struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, struct value *original_value, const struct value_print_options *options)
Definition valprint.c:733
#define CARRY_LEFT(x)
void _initialize_valprint()
Definition valprint.c:3127
int valprint_check_validity(struct ui_file *stream, struct type *type, LONGEST embedded_offset, const struct value *val)
Definition valprint.c:353
#define PRINT_MAX_DEFAULT
Definition valprint.c:98
static void show_addressprint(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:295
int val_print_scalar_type_p(struct type *type)
Definition valprint.c:317
static bool val_print_scalar_or_string_type_p(struct type *type, const struct language_defn *language)
Definition valprint.c:343
gdb::option::option_def_group make_value_print_options_def_group(value_print_options *opts)
Definition valprint.c:3093
static void generic_value_print_char(struct value *value, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:798
static void show_print_max(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:162
static const literal_def print_characters_literals[]
Definition valprint.c:2913
static void show_vtblprint(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:2873
static unsigned input_radix_1
Definition valprint.c:2741
unsigned input_radix
Definition valprint.c:186
struct cmd_list_element * showprintrawlist
Definition valprint.c:84
static void emit_octal_digit(struct ui_file *stream, bool *seen_a_one, int digit)
Definition valprint.c:1492
#define CARRY_ZERO
void val_print_optimized_out(const struct value *val, struct ui_file *stream)
Definition valprint.c:416
#define MID_ONE
int longest_to_int(LONGEST arg)
Definition valprint.c:1372
bool val_print_check_max_depth(struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition valprint.c:1104
static const gdb::option::option_def value_print_option_defs[]
Definition valprint.c:2922
static void print_unpacked_pointer(struct type *type, struct type *elttype, CORE_ADDR address, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:450
static void generic_value_print_complex(struct value *val, struct ui_file *stream, const struct value_print_options *options, const struct generic_val_print_decorations *decorations)
Definition valprint.c:867
#define WCHAR_BUFLEN(X)
Definition valprint.c:54
static void generic_val_print_array(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct generic_val_print_decorations *decorations)
Definition valprint.c:472
void ATTRIBUTE_UNUSED debug_val(struct value *val)
Definition valprint.c:1218
#define MID_TWO
static unsigned output_radix_1
Definition valprint.c:2782
static bool maybe_negate_by_bytes(const gdb_byte *bytes, unsigned len, enum bfd_endian byte_order, gdb::byte_vector *out_vec)
Definition valprint.c:1661
void val_print_invalid_address(struct ui_file *stream)
Definition valprint.c:437
static void generic_value_print_int(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:785
#define CARRY_ONE
int val_print_string(struct type *elttype, const char *encoding, CORE_ADDR addr, int len, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:2643
#define WCHAR_BUFLEN_MAX
Definition valprint.c:57
#define PRINT_MAX_DEPTH_DEFAULT
Definition valprint.c:104
static void show_output_radix(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:198
void get_user_print_options(struct value_print_options *opts)
Definition valprint.c:135
static void set_input_radix_1(int, unsigned)
Definition valprint.c:2754
void common_val_print_checked(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition valprint.c:1177
#define HIGH_ZERO
static void show_radix(const char *arg, int from_tty)
Definition valprint.c:2848
static void show_print_max_depth(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:2730
static void generic_val_print_ref(struct type *type, int embedded_offset, struct ui_file *stream, int recurse, struct value *original_value, const struct value_print_options *options)
Definition valprint.c:562
static void show_static_field_print(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:2894
static void set_input_radix(const char *args, int from_tty, struct cmd_list_element *c)
Definition valprint.c:2748
static void generic_val_print_float(struct type *type, struct ui_file *stream, struct value *original_value, const struct value_print_options *options)
Definition valprint.c:828
static int value_check_printable(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:1123
static void show_unionprint(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:273
void print_hex_chars(struct ui_file *stream, const gdb_byte *valaddr, unsigned len, enum bfd_endian byte_order, bool zero_pad)
Definition valprint.c:1841
void print_floating(const gdb_byte *valaddr, struct type *type, struct ui_file *stream)
Definition valprint.c:1392
#define HIGH_NIBBLE(x)
static void append_string_as_wide(const char *string, struct obstack *output)
Definition valprint.c:2090
static void print_wchar(gdb_wint_t w, const gdb_byte *orig, int orig_len, int width, enum bfd_endian byte_order, struct obstack *output, int quoter, bool *need_escapep)
Definition valprint.c:2110
static void show_print_max_chars(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:176
void value_print_array_elements(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, unsigned int i)
Definition valprint.c:1941
void print_longest(struct ui_file *stream, int format, int use_c_format, LONGEST val_long)
Definition valprint.c:1335
static int wchar_printable(gdb_wchar_t w)
Definition valprint.c:2077
void common_val_print(struct value *value, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct language_defn *language)
Definition valprint.c:1033
static void set_output_radix(const char *args, int from_tty, struct cmd_list_element *c)
Definition valprint.c:2785
void print_function_pointer_address(const struct value_print_options *options, struct gdbarch *gdbarch, CORE_ADDR address, struct ui_file *stream)
Definition valprint.c:1904
static void show_prettyformat_arrays(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:263
static void val_print_type_code_flags(struct type *type, struct value *original_value, int embedded_offset, struct ui_file *stream)
Definition valprint.c:1225
#define HIGH_TWO
void print_binary_chars(struct ui_file *stream, const gdb_byte *valaddr, unsigned len, enum bfd_endian byte_order, bool zero_pad, const struct value_print_options *options)
Definition valprint.c:1400
struct value_print_options user_print_options
Definition valprint.c:106
void maybe_print_array_index(struct type *index_type, LONGEST index, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:1928
static void show_input_radix(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:188
static void print_ref_address(struct type *type, const gdb_byte *address_buffer, int embedded_offset, struct ui_file *stream)
Definition valprint.c:526
static const gdb_byte * get_value_addr_contents(struct value *deref_val)
Definition valprint.c:546
static void set_radix(const char *arg, int from_tty)
Definition valprint.c:2830
#define LOW_ONE
#define SHIFT(x)
struct cmd_list_element * setprintrawlist
Definition valprint.c:83
static int count_next_character(wchar_iterator *iter, std::vector< converted_character > *vec)
Definition valprint.c:2281
void val_print_not_saved(struct ui_file *stream)
Definition valprint.c:425
#define MAX_WCHARS
Definition valprint.c:50
void generic_printstr(struct ui_file *stream, struct type *type, const gdb_byte *string, unsigned int length, const char *encoding, int force_ellipses, int quote_char, int c_style_terminator, const struct value_print_options *options)
Definition valprint.c:2536
#define BITS_IN_OCTAL
static void show_objectprint(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:2884
static void show_symbol_print(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:302
static void show_prettyformat_structs(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition valprint.c:254
static void generic_value_print_memberptr(struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options, const struct generic_val_print_decorations *decorations)
Definition valprint.c:887
#define PRINT_MAX_CHARS_ELEMENTS
Definition valprint.h:123
@ Val_prettyformat_default
Definition valprint.h:33
@ Val_prettyformat
Definition valprint.h:31
@ Val_no_prettyformat
Definition valprint.h:30
static unsigned int get_print_max_chars(const struct value_print_options *options)
Definition valprint.h:131
#define PRINT_MAX_CHARS_UNLIMITED
Definition valprint.h:126
struct value * coerce_ref_if_computed(const struct value *arg)
Definition value.c:3707
CORE_ADDR unpack_pointer(struct type *type, const gdb_byte *valaddr)
Definition value.c:2843
const char * value_internal_function_name(struct value *val)
Definition value.c:2305
void pack_long(gdb_byte *buf, struct type *type, LONGEST num)
Definition value.c:3327
LONGEST unpack_long(struct type *type, const gdb_byte *valaddr)
Definition value.c:2753