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