7442ec0743e1bafcb41eba747b2ee8562ed8cd73
[deliverable/binutils-gdb.git] / gdb / cp-valprint.c
1 /* Support for printing C++ values for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2021 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 "gdb_obstack.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "expression.h"
25 #include "value.h"
26 #include "command.h"
27 #include "gdbcmd.h"
28 #include "demangle.h"
29 #include "annotate.h"
30 #include "c-lang.h"
31 #include "target.h"
32 #include "cp-abi.h"
33 #include "valprint.h"
34 #include "cp-support.h"
35 #include "language.h"
36 #include "extension.h"
37 #include "typeprint.h"
38 #include "gdbsupport/byte-vector.h"
39 #include "gdbarch.h"
40 #include "cli/cli-style.h"
41 #include "gdbsupport/selftest.h"
42 #include "selftest-arch.h"
43
44 static struct obstack dont_print_vb_obstack;
45 static struct obstack dont_print_statmem_obstack;
46 static struct obstack dont_print_stat_array_obstack;
47
48 static void cp_print_static_field (struct type *, struct value *,
49 struct ui_file *, int,
50 const struct value_print_options *);
51
52 static void cp_print_value (struct value *, struct ui_file *,
53 int, const struct value_print_options *,
54 struct type **);
55
56
57 /* GCC versions after 2.4.5 use this. */
58 const char vtbl_ptr_name[] = "__vtbl_ptr_type";
59
60 /* Return truth value for assertion that TYPE is of the type
61 "pointer to virtual function". */
62
63 int
64 cp_is_vtbl_ptr_type (struct type *type)
65 {
66 const char *type_name = type->name ();
67
68 return (type_name != NULL && !strcmp (type_name, vtbl_ptr_name));
69 }
70
71 /* Return truth value for the assertion that TYPE is of the type
72 "pointer to virtual function table". */
73
74 int
75 cp_is_vtbl_member (struct type *type)
76 {
77 /* With older versions of g++, the vtbl field pointed to an array of
78 structures. Nowadays it points directly to the structure. */
79 if (type->code () == TYPE_CODE_PTR)
80 {
81 type = TYPE_TARGET_TYPE (type);
82 if (type->code () == TYPE_CODE_ARRAY)
83 {
84 type = TYPE_TARGET_TYPE (type);
85 if (type->code () == TYPE_CODE_STRUCT /* if not using thunks */
86 || type->code () == TYPE_CODE_PTR) /* if using thunks */
87 {
88 /* Virtual functions tables are full of pointers
89 to virtual functions. */
90 return cp_is_vtbl_ptr_type (type);
91 }
92 }
93 else if (type->code () == TYPE_CODE_STRUCT) /* if not using thunks */
94 {
95 return cp_is_vtbl_ptr_type (type);
96 }
97 else if (type->code () == TYPE_CODE_PTR) /* if using thunks */
98 {
99 /* The type name of the thunk pointer is NULL when using
100 dwarf2. We could test for a pointer to a function, but
101 there is no type info for the virtual table either, so it
102 wont help. */
103 return cp_is_vtbl_ptr_type (type);
104 }
105 }
106 return 0;
107 }
108
109 /* Mutually recursive subroutines of cp_print_value and c_val_print to
110 print out a structure's fields: cp_print_value_fields and
111 cp_print_value.
112
113 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the same
114 meanings as in cp_print_value and c_val_print.
115
116 2nd argument REAL_TYPE is used to carry over the type of the
117 derived class across the recursion to base classes.
118
119 DONT_PRINT is an array of baseclass types that we should not print,
120 or zero if called from top level. */
121
122 void
123 cp_print_value_fields (struct value *val, struct ui_file *stream,
124 int recurse, const struct value_print_options *options,
125 struct type **dont_print_vb,
126 int dont_print_statmem)
127 {
128 int i, len, n_baseclasses;
129 int fields_seen = 0;
130 static int last_set_recurse = -1;
131
132 struct type *type = check_typedef (value_type (val));
133
134 if (recurse == 0)
135 {
136 /* Any object can be left on obstacks only during an unexpected
137 error. */
138
139 if (obstack_object_size (&dont_print_statmem_obstack) > 0)
140 {
141 obstack_free (&dont_print_statmem_obstack, NULL);
142 obstack_begin (&dont_print_statmem_obstack,
143 32 * sizeof (CORE_ADDR));
144 }
145 if (obstack_object_size (&dont_print_stat_array_obstack) > 0)
146 {
147 obstack_free (&dont_print_stat_array_obstack, NULL);
148 obstack_begin (&dont_print_stat_array_obstack,
149 32 * sizeof (struct type *));
150 }
151 }
152
153 fprintf_filtered (stream, "{");
154 len = type->num_fields ();
155 n_baseclasses = TYPE_N_BASECLASSES (type);
156
157 /* First, print out baseclasses such that we don't print
158 duplicates of virtual baseclasses. */
159
160 if (n_baseclasses > 0)
161 cp_print_value (val, stream, recurse + 1, options, dont_print_vb);
162
163 /* Second, print out data fields */
164
165 /* If there are no data fields, skip this part */
166 if (len == n_baseclasses || !len)
167 fprintf_styled (stream, metadata_style.style (), "<No data fields>");
168 else
169 {
170 size_t statmem_obstack_initial_size = 0;
171 size_t stat_array_obstack_initial_size = 0;
172 struct type *vptr_basetype = NULL;
173 int vptr_fieldno;
174
175 if (dont_print_statmem == 0)
176 {
177 statmem_obstack_initial_size =
178 obstack_object_size (&dont_print_statmem_obstack);
179
180 if (last_set_recurse != recurse)
181 {
182 stat_array_obstack_initial_size =
183 obstack_object_size (&dont_print_stat_array_obstack);
184
185 last_set_recurse = recurse;
186 }
187 }
188
189 vptr_fieldno = get_vptr_fieldno (type, &vptr_basetype);
190 for (i = n_baseclasses; i < len; i++)
191 {
192 const gdb_byte *valaddr = value_contents_for_printing (val);
193
194 /* If requested, skip printing of static fields. */
195 if (!options->static_field_print
196 && field_is_static (&type->field (i)))
197 continue;
198
199 if (fields_seen)
200 {
201 fputs_filtered (",", stream);
202 if (!options->prettyformat)
203 fputs_filtered (" ", stream);
204 }
205 else if (n_baseclasses > 0)
206 {
207 if (options->prettyformat)
208 {
209 fprintf_filtered (stream, "\n");
210 print_spaces_filtered (2 + 2 * recurse, stream);
211 fputs_filtered ("members of ", stream);
212 fputs_filtered (type->name (), stream);
213 fputs_filtered (":", stream);
214 }
215 }
216 fields_seen = 1;
217
218 if (options->prettyformat)
219 {
220 fprintf_filtered (stream, "\n");
221 print_spaces_filtered (2 + 2 * recurse, stream);
222 }
223 else
224 {
225 wrap_here (n_spaces (2 + 2 * recurse));
226 }
227
228 annotate_field_begin (type->field (i).type ());
229
230 if (field_is_static (&type->field (i)))
231 {
232 fputs_filtered ("static ", stream);
233 fprintf_symbol_filtered (stream,
234 TYPE_FIELD_NAME (type, i),
235 current_language->la_language,
236 DMGL_PARAMS | DMGL_ANSI);
237 }
238 else
239 fputs_styled (TYPE_FIELD_NAME (type, i),
240 variable_name_style.style (), stream);
241 annotate_field_name_end ();
242
243 /* We tweak various options in a few cases below. */
244 value_print_options options_copy = *options;
245 value_print_options *opts = &options_copy;
246
247 /* Do not print leading '=' in case of anonymous
248 unions. */
249 if (strcmp (TYPE_FIELD_NAME (type, i), ""))
250 fputs_filtered (" = ", stream);
251 else
252 {
253 /* If this is an anonymous field then we want to consider it
254 as though it is at its parent's depth when it comes to the
255 max print depth. */
256 if (opts->max_depth != -1 && opts->max_depth < INT_MAX)
257 ++opts->max_depth;
258 }
259 annotate_field_value ();
260
261 if (!field_is_static (&type->field (i))
262 && TYPE_FIELD_PACKED (type, i))
263 {
264 struct value *v;
265
266 /* Bitfields require special handling, especially due to
267 byte order problems. */
268 if (TYPE_FIELD_IGNORE (type, i))
269 {
270 fputs_styled ("<optimized out or zero length>",
271 metadata_style.style (), stream);
272 }
273 else if (value_bits_synthetic_pointer (val,
274 TYPE_FIELD_BITPOS (type,
275 i),
276 TYPE_FIELD_BITSIZE (type,
277 i)))
278 {
279 fputs_styled (_("<synthetic pointer>"),
280 metadata_style.style (), stream);
281 }
282 else
283 {
284 opts->deref_ref = 0;
285
286 v = value_field_bitfield (type, i, valaddr,
287 value_embedded_offset (val), val);
288
289 common_val_print (v, stream, recurse + 1,
290 opts, current_language);
291 }
292 }
293 else
294 {
295 if (TYPE_FIELD_IGNORE (type, i))
296 {
297 fputs_styled ("<optimized out or zero length>",
298 metadata_style.style (), stream);
299 }
300 else if (field_is_static (&type->field (i)))
301 {
302 try
303 {
304 struct value *v = value_static_field (type, i);
305
306 cp_print_static_field (type->field (i).type (),
307 v, stream, recurse + 1,
308 opts);
309 }
310 catch (const gdb_exception_error &ex)
311 {
312 fprintf_styled (stream, metadata_style.style (),
313 _("<error reading variable: %s>"),
314 ex.what ());
315 }
316 }
317 else if (i == vptr_fieldno && type == vptr_basetype)
318 {
319 int i_offset = TYPE_FIELD_BITPOS (type, i) / 8;
320 struct type *i_type = type->field (i).type ();
321
322 if (valprint_check_validity (stream, i_type, i_offset, val))
323 {
324 CORE_ADDR addr;
325
326 i_offset += value_embedded_offset (val);
327 addr = extract_typed_address (valaddr + i_offset, i_type);
328 print_function_pointer_address (opts,
329 type->arch (),
330 addr, stream);
331 }
332 }
333 else
334 {
335 struct value *v = value_primitive_field (val, 0, i, type);
336 opts->deref_ref = 0;
337 common_val_print (v, stream, recurse + 1, opts,
338 current_language);
339 }
340 }
341 annotate_field_end ();
342 }
343
344 if (dont_print_statmem == 0)
345 {
346 size_t obstack_final_size =
347 obstack_object_size (&dont_print_statmem_obstack);
348
349 if (obstack_final_size > statmem_obstack_initial_size)
350 {
351 /* In effect, a pop of the printed-statics stack. */
352 size_t shrink_bytes
353 = statmem_obstack_initial_size - obstack_final_size;
354 obstack_blank_fast (&dont_print_statmem_obstack, shrink_bytes);
355 }
356
357 if (last_set_recurse != recurse)
358 {
359 obstack_final_size =
360 obstack_object_size (&dont_print_stat_array_obstack);
361
362 if (obstack_final_size > stat_array_obstack_initial_size)
363 {
364 void *free_to_ptr =
365 (char *) obstack_next_free (&dont_print_stat_array_obstack)
366 - (obstack_final_size
367 - stat_array_obstack_initial_size);
368
369 obstack_free (&dont_print_stat_array_obstack,
370 free_to_ptr);
371 }
372 last_set_recurse = -1;
373 }
374 }
375
376 if (options->prettyformat)
377 {
378 fprintf_filtered (stream, "\n");
379 print_spaces_filtered (2 * recurse, stream);
380 }
381 } /* if there are data fields */
382
383 fprintf_filtered (stream, "}");
384 }
385
386 /* Special val_print routine to avoid printing multiple copies of
387 virtual baseclasses. */
388
389 static void
390 cp_print_value (struct value *val, struct ui_file *stream,
391 int recurse, const struct value_print_options *options,
392 struct type **dont_print_vb)
393 {
394 struct type *type = check_typedef (value_type (val));
395 CORE_ADDR address = value_address (val);
396 struct type **last_dont_print
397 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
398 struct obstack tmp_obstack = dont_print_vb_obstack;
399 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
400 const gdb_byte *valaddr = value_contents_for_printing (val);
401
402 if (dont_print_vb == 0)
403 {
404 /* If we're at top level, carve out a completely fresh chunk of
405 the obstack and use that until this particular invocation
406 returns. */
407 /* Bump up the high-water mark. Now alpha is omega. */
408 obstack_finish (&dont_print_vb_obstack);
409 }
410
411 for (i = 0; i < n_baseclasses; i++)
412 {
413 LONGEST boffset = 0;
414 int skip = 0;
415 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
416 const char *basename = baseclass->name ();
417 struct value *base_val = NULL;
418
419 if (BASETYPE_VIA_VIRTUAL (type, i))
420 {
421 struct type **first_dont_print
422 = (struct type **) obstack_base (&dont_print_vb_obstack);
423
424 int j = (struct type **)
425 obstack_next_free (&dont_print_vb_obstack) - first_dont_print;
426
427 while (--j >= 0)
428 if (baseclass == first_dont_print[j])
429 goto flush_it;
430
431 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
432 }
433
434 try
435 {
436 boffset = baseclass_offset (type, i, valaddr,
437 value_embedded_offset (val),
438 address, val);
439 }
440 catch (const gdb_exception_error &ex)
441 {
442 if (ex.error == NOT_AVAILABLE_ERROR)
443 skip = -1;
444 else
445 skip = 1;
446 }
447
448 if (skip == 0)
449 {
450 if (BASETYPE_VIA_VIRTUAL (type, i))
451 {
452 /* The virtual base class pointer might have been
453 clobbered by the user program. Make sure that it
454 still points to a valid memory location. */
455
456 if (boffset < 0 || boffset >= TYPE_LENGTH (type))
457 {
458 gdb::byte_vector buf (TYPE_LENGTH (baseclass));
459
460 if (target_read_memory (address + boffset, buf.data (),
461 TYPE_LENGTH (baseclass)) != 0)
462 skip = 1;
463 base_val = value_from_contents_and_address (baseclass,
464 buf.data (),
465 address + boffset);
466 baseclass = value_type (base_val);
467 boffset = 0;
468 }
469 else
470 {
471 base_val = val;
472 }
473 }
474 else
475 {
476 base_val = val;
477 }
478 }
479
480 /* Now do the printing. */
481 if (options->prettyformat)
482 {
483 fprintf_filtered (stream, "\n");
484 print_spaces_filtered (2 * recurse, stream);
485 }
486 fputs_filtered ("<", stream);
487 /* Not sure what the best notation is in the case where there is
488 no baseclass name. */
489 fputs_filtered (basename ? basename : "", stream);
490 fputs_filtered ("> = ", stream);
491
492 if (skip < 0)
493 val_print_unavailable (stream);
494 else if (skip > 0)
495 val_print_invalid_address (stream);
496 else
497 {
498 int result = 0;
499
500 if (!val_print_check_max_depth (stream, recurse, options,
501 current_language))
502 {
503 struct value *baseclass_val = value_primitive_field (val, 0,
504 i, type);
505
506 /* Attempt to run an extension language pretty-printer on the
507 baseclass if possible. */
508 if (!options->raw)
509 result
510 = apply_ext_lang_val_pretty_printer (baseclass_val, stream,
511 recurse, options,
512 current_language);
513
514 if (!result)
515 cp_print_value_fields (baseclass_val, stream, recurse, options,
516 ((struct type **)
517 obstack_base (&dont_print_vb_obstack)),
518 0);
519 }
520 }
521 fputs_filtered (", ", stream);
522
523 flush_it:
524 ;
525 }
526
527 if (dont_print_vb == 0)
528 {
529 /* Free the space used to deal with the printing
530 of this type from top level. */
531 obstack_free (&dont_print_vb_obstack, last_dont_print);
532 /* Reset watermark so that we can continue protecting
533 ourselves from whatever we were protecting ourselves. */
534 dont_print_vb_obstack = tmp_obstack;
535 }
536 }
537
538 /* Print value of a static member. To avoid infinite recursion when
539 printing a class that contains a static instance of the class, we
540 keep the addresses of all printed static member classes in an
541 obstack and refuse to print them more than once.
542
543 VAL contains the value to print, TYPE, STREAM, RECURSE, and OPTIONS
544 have the same meanings as in c_val_print. */
545
546 static void
547 cp_print_static_field (struct type *type,
548 struct value *val,
549 struct ui_file *stream,
550 int recurse,
551 const struct value_print_options *options)
552 {
553 struct value_print_options opts;
554
555 if (value_entirely_optimized_out (val))
556 {
557 val_print_optimized_out (val, stream);
558 return;
559 }
560
561 struct type *real_type = check_typedef (type);
562 if (real_type->code () == TYPE_CODE_STRUCT)
563 {
564 CORE_ADDR *first_dont_print;
565 CORE_ADDR addr = value_address (val);
566 int i;
567
568 first_dont_print
569 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
570 i = obstack_object_size (&dont_print_statmem_obstack)
571 / sizeof (CORE_ADDR);
572
573 while (--i >= 0)
574 {
575 if (addr == first_dont_print[i])
576 {
577 fputs_styled (_("<same as static member of an already"
578 " seen type>"),
579 metadata_style.style (), stream);
580 return;
581 }
582 }
583
584 obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
585 sizeof (CORE_ADDR));
586 cp_print_value_fields (val, stream, recurse, options, NULL, 1);
587 return;
588 }
589
590 if (real_type->code () == TYPE_CODE_ARRAY)
591 {
592 struct type **first_dont_print;
593 int i;
594 struct type *target_type = TYPE_TARGET_TYPE (type);
595
596 first_dont_print
597 = (struct type **) obstack_base (&dont_print_stat_array_obstack);
598 i = obstack_object_size (&dont_print_stat_array_obstack)
599 / sizeof (struct type *);
600
601 while (--i >= 0)
602 {
603 if (target_type == first_dont_print[i])
604 {
605 fputs_styled (_("<same as static member of an already"
606 " seen type>"),
607 metadata_style.style (), stream);
608 return;
609 }
610 }
611
612 obstack_grow (&dont_print_stat_array_obstack,
613 (char *) &target_type,
614 sizeof (struct type *));
615 }
616
617 opts = *options;
618 opts.deref_ref = 0;
619 common_val_print (val, stream, recurse, &opts, current_language);
620 }
621
622 /* Find the field in *SELF, or its non-virtual base classes, with
623 bit offset OFFSET. Set *SELF to the containing type and *FIELDNO
624 to the containing field number. If OFFSET is not exactly at the
625 start of some field, set *SELF to NULL. */
626
627 static void
628 cp_find_class_member (struct type **self_p, int *fieldno,
629 LONGEST offset)
630 {
631 struct type *self;
632 unsigned int i;
633 unsigned len;
634
635 *self_p = check_typedef (*self_p);
636 self = *self_p;
637 len = self->num_fields ();
638
639 for (i = TYPE_N_BASECLASSES (self); i < len; i++)
640 {
641 LONGEST bitpos = TYPE_FIELD_BITPOS (self, i);
642
643 QUIT;
644 if (offset == bitpos)
645 {
646 *fieldno = i;
647 return;
648 }
649 }
650
651 for (i = 0; i < TYPE_N_BASECLASSES (self); i++)
652 {
653 LONGEST bitpos = TYPE_FIELD_BITPOS (self, i);
654 LONGEST bitsize = 8 * TYPE_LENGTH (self->field (i).type ());
655
656 if (offset >= bitpos && offset < bitpos + bitsize)
657 {
658 *self_p = self->field (i).type ();
659 cp_find_class_member (self_p, fieldno, offset - bitpos);
660 return;
661 }
662 }
663
664 *self_p = NULL;
665 }
666
667 void
668 cp_print_class_member (const gdb_byte *valaddr, struct type *type,
669 struct ui_file *stream, const char *prefix)
670 {
671 enum bfd_endian byte_order = type_byte_order (type);
672
673 /* VAL is a byte offset into the structure type SELF_TYPE.
674 Find the name of the field for that offset and
675 print it. */
676 struct type *self_type = TYPE_SELF_TYPE (type);
677 LONGEST val;
678 int fieldno;
679
680 val = extract_signed_integer (valaddr,
681 TYPE_LENGTH (type),
682 byte_order);
683
684 /* Pointers to data members are usually byte offsets into an object.
685 Because a data member can have offset zero, and a NULL pointer to
686 member must be distinct from any valid non-NULL pointer to
687 member, either the value is biased or the NULL value has a
688 special representation; both are permitted by ISO C++. HP aCC
689 used a bias of 0x20000000; HP cfront used a bias of 1; g++ 3.x
690 and other compilers which use the Itanium ABI use -1 as the NULL
691 value. GDB only supports that last form; to add support for
692 another form, make this into a cp-abi hook. */
693
694 if (val == -1)
695 {
696 fprintf_filtered (stream, "NULL");
697 return;
698 }
699
700 cp_find_class_member (&self_type, &fieldno, val << 3);
701
702 if (self_type != NULL)
703 {
704 const char *name;
705
706 fputs_filtered (prefix, stream);
707 name = self_type->name ();
708 if (name)
709 fputs_filtered (name, stream);
710 else
711 c_type_print_base (self_type, stream, 0, 0, &type_print_raw_options);
712 fprintf_filtered (stream, "::");
713 fputs_styled (TYPE_FIELD_NAME (self_type, fieldno),
714 variable_name_style.style (), stream);
715 }
716 else
717 fprintf_filtered (stream, "%ld", (long) val);
718 }
719
720 #if GDB_SELF_TEST
721
722 /* Test printing of TYPE_CODE_STRUCT values. */
723
724 static void
725 test_print_fields (gdbarch *arch)
726 {
727 struct field *f;
728 type *uint8_type = builtin_type (arch)->builtin_uint8;
729 type *bool_type = builtin_type (arch)->builtin_bool;
730 type *the_struct = arch_composite_type (arch, NULL, TYPE_CODE_STRUCT);
731 TYPE_LENGTH (the_struct) = 4;
732
733 /* Value: 1110 1001
734 Fields: C-BB B-A- */
735 if (gdbarch_byte_order (arch) == BFD_ENDIAN_LITTLE)
736 {
737 f = append_composite_type_field_raw (the_struct, "A", bool_type);
738 SET_FIELD_BITPOS (*f, 1);
739 FIELD_BITSIZE (*f) = 1;
740 f = append_composite_type_field_raw (the_struct, "B", uint8_type);
741 SET_FIELD_BITPOS (*f, 3);
742 FIELD_BITSIZE (*f) = 3;
743 f = append_composite_type_field_raw (the_struct, "C", bool_type);
744 SET_FIELD_BITPOS (*f, 7);
745 FIELD_BITSIZE (*f) = 1;
746 }
747 /* According to the logic commented in "make_gdb_type_struct ()" of
748 * target-descriptions.c, bit positions are numbered differently for
749 * little and big endians. */
750 else
751 {
752 f = append_composite_type_field_raw (the_struct, "A", bool_type);
753 SET_FIELD_BITPOS (*f, 30);
754 FIELD_BITSIZE (*f) = 1;
755 f = append_composite_type_field_raw (the_struct, "B", uint8_type);
756 SET_FIELD_BITPOS (*f, 26);
757 FIELD_BITSIZE (*f) = 3;
758 f = append_composite_type_field_raw (the_struct, "C", bool_type);
759 SET_FIELD_BITPOS (*f, 24);
760 FIELD_BITSIZE (*f) = 1;
761 }
762
763 value *val = allocate_value (the_struct);
764 gdb_byte *contents = value_contents_writeable (val);
765 store_unsigned_integer (contents, TYPE_LENGTH (value_enclosing_type (val)),
766 gdbarch_byte_order (arch), 0xe9);
767
768 string_file out;
769 struct value_print_options opts;
770 get_no_prettyformat_print_options (&opts);
771 cp_print_value_fields(val, &out, 0, &opts, NULL, 0);
772 SELF_CHECK (out.string () == "{A = false, B = 5, C = true}");
773
774 out.clear();
775 opts.format = 'x';
776 cp_print_value_fields(val, &out, 0, &opts, NULL, 0);
777 SELF_CHECK (out.string () == "{A = 0x0, B = 0x5, C = 0x1}");
778 }
779
780 #endif
781
782
783 void _initialize_cp_valprint ();
784 void
785 _initialize_cp_valprint ()
786 {
787 #if GDB_SELF_TEST
788 selftests::register_test_foreach_arch ("print-fields", test_print_fields);
789 #endif
790
791 obstack_begin (&dont_print_stat_array_obstack,
792 32 * sizeof (struct type *));
793 obstack_begin (&dont_print_statmem_obstack,
794 32 * sizeof (CORE_ADDR));
795 obstack_begin (&dont_print_vb_obstack,
796 32 * sizeof (struct type *));
797 }
This page took 0.043053 seconds and 3 git commands to generate.