*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / cp-valprint.c
CommitLineData
c906108c 1/* Support for printing C++ values for GDB, the GNU debugger.
a2bd3dcd 2
6aba47ca 3 Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4c38e0a4 4 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010
9b254dd1 5 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
04ea0df1 23#include "gdb_obstack.h"
c906108c
SS
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "expression.h"
27#include "value.h"
28#include "command.h"
29#include "gdbcmd.h"
30#include "demangle.h"
31#include "annotate.h"
32#include "gdb_string.h"
33#include "c-lang.h"
34#include "target.h"
b9d652ac 35#include "cp-abi.h"
973177d3 36#include "valprint.h"
d3cbe7ef 37#include "cp-support.h"
cf309262 38#include "language.h"
a6bac58e 39#include "python/python.h"
c906108c 40
920d2a44 41/* Controls printing of vtbl's */
920d2a44
AC
42static void
43show_vtblprint (struct ui_file *file, int from_tty,
44 struct cmd_list_element *c, const char *value)
45{
46 fprintf_filtered (file, _("\
47Printing of C++ virtual function tables is %s.\n"),
48 value);
49}
50
51/* Controls looking up an object's derived type using what we find in
52 its vtables. */
920d2a44
AC
53static void
54show_objectprint (struct ui_file *file, int from_tty,
55 struct cmd_list_element *c,
56 const char *value)
57{
58 fprintf_filtered (file, _("\
59Printing of object's derived type based on vtable info is %s.\n"),
60 value);
61}
62
920d2a44
AC
63static void
64show_static_field_print (struct ui_file *file, int from_tty,
65 struct cmd_list_element *c, const char *value)
66{
67 fprintf_filtered (file, _("Printing of C++ static members is %s.\n"),
68 value);
69}
70
c906108c
SS
71
72static struct obstack dont_print_vb_obstack;
73static struct obstack dont_print_statmem_obstack;
74
a14ed312 75extern void _initialize_cp_valprint (void);
392a587b 76
6943961c 77static void cp_print_static_field (struct type *, struct value *,
79a45b7d
TT
78 struct ui_file *, int,
79 const struct value_print_options *);
c906108c 80
fc1a4b47 81static void cp_print_value (struct type *, struct type *, const gdb_byte *,
79a45b7d
TT
82 int, CORE_ADDR, struct ui_file *, int,
83 const struct value_print_options *, struct type **);
c906108c 84
c906108c 85
8343f86c 86/* GCC versions after 2.4.5 use this. */
2c63a960 87const char vtbl_ptr_name[] = "__vtbl_ptr_type";
c906108c 88
c906108c
SS
89/* Return truth value for assertion that TYPE is of the type
90 "pointer to virtual function". */
91
92int
fba45db2 93cp_is_vtbl_ptr_type (struct type *type)
c906108c
SS
94{
95 char *typename = type_name_no_tag (type);
96
8343f86c 97 return (typename != NULL && !strcmp (typename, vtbl_ptr_name));
c906108c
SS
98}
99
100/* Return truth value for the assertion that TYPE is of the type
101 "pointer to virtual function table". */
102
103int
fba45db2 104cp_is_vtbl_member (struct type *type)
c906108c 105{
0e5e3ea6
PS
106 /* With older versions of g++, the vtbl field pointed to an array
107 of structures. Nowadays it points directly to the structure. */
c906108c
SS
108 if (TYPE_CODE (type) == TYPE_CODE_PTR)
109 {
110 type = TYPE_TARGET_TYPE (type);
111 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
112 {
113 type = TYPE_TARGET_TYPE (type);
c5aa993b
JM
114 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* if not using thunks */
115 || TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */
c906108c
SS
116 {
117 /* Virtual functions tables are full of pointers
c5aa993b 118 to virtual functions. */
c906108c
SS
119 return cp_is_vtbl_ptr_type (type);
120 }
121 }
0e5e3ea6
PS
122 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT) /* if not using thunks */
123 {
124 return cp_is_vtbl_ptr_type (type);
125 }
126 else if (TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */
127 {
128 /* The type name of the thunk pointer is NULL when using dwarf2.
129 We could test for a pointer to a function, but there is
130 no type info for the virtual table either, so it wont help. */
131 return cp_is_vtbl_ptr_type (type);
132 }
c906108c
SS
133 }
134 return 0;
135}
136
137/* Mutually recursive subroutines of cp_print_value and c_val_print to
138 print out a structure's fields: cp_print_value_fields and cp_print_value.
c5aa993b 139
79a45b7d 140 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
c906108c
SS
141 same meanings as in cp_print_value and c_val_print.
142
143 2nd argument REAL_TYPE is used to carry over the type of the derived
144 class across the recursion to base classes.
145
146 DONT_PRINT is an array of baseclass types that we
147 should not print, or zero if called from top level. */
148
149void
a2bd3dcd 150cp_print_value_fields (struct type *type, struct type *real_type,
fc1a4b47 151 const gdb_byte *valaddr, int offset, CORE_ADDR address,
79a45b7d
TT
152 struct ui_file *stream, int recurse,
153 const struct value_print_options *options,
154 struct type **dont_print_vb, int dont_print_statmem)
c906108c
SS
155{
156 int i, len, n_baseclasses;
c906108c
SS
157 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
158 int fields_seen = 0;
159
160 CHECK_TYPEDEF (type);
161
162 fprintf_filtered (stream, "{");
163 len = TYPE_NFIELDS (type);
164 n_baseclasses = TYPE_N_BASECLASSES (type);
165
166 /* First, print out baseclasses such that we don't print
167 duplicates of virtual baseclasses. */
168
169 if (n_baseclasses > 0)
170 cp_print_value (type, real_type, valaddr, offset, address, stream,
79a45b7d 171 recurse + 1, options, dont_print_vb);
c906108c
SS
172
173 /* Second, print out data fields */
174
086280be
UW
175 /* If there are no data fields, skip this part */
176 if (len == n_baseclasses || !len)
c906108c
SS
177 fprintf_filtered (stream, "<No data fields>");
178 else
179 {
c1b6e682
DJ
180 struct obstack tmp_obstack = dont_print_statmem_obstack;
181
c906108c
SS
182 if (dont_print_statmem == 0)
183 {
184 /* If we're at top level, carve out a completely fresh
185 chunk of the obstack and use that until this particular
186 invocation returns. */
c906108c
SS
187 obstack_finish (&dont_print_statmem_obstack);
188 }
189
190 for (i = n_baseclasses; i < len; i++)
191 {
192 /* If requested, skip printing of static fields. */
79a45b7d 193 if (!options->static_field_print
d6a843b5 194 && field_is_static (&TYPE_FIELD (type, i)))
c906108c
SS
195 continue;
196
c906108c
SS
197 if (fields_seen)
198 fprintf_filtered (stream, ", ");
199 else if (n_baseclasses > 0)
200 {
79a45b7d 201 if (options->pretty)
c906108c
SS
202 {
203 fprintf_filtered (stream, "\n");
204 print_spaces_filtered (2 + 2 * recurse, stream);
205 fputs_filtered ("members of ", stream);
206 fputs_filtered (type_name_no_tag (type), stream);
207 fputs_filtered (": ", stream);
208 }
209 }
210 fields_seen = 1;
211
79a45b7d 212 if (options->pretty)
c906108c
SS
213 {
214 fprintf_filtered (stream, "\n");
215 print_spaces_filtered (2 + 2 * recurse, stream);
216 }
c5aa993b 217 else
c906108c
SS
218 {
219 wrap_here (n_spaces (2 + 2 * recurse));
220 }
79a45b7d 221 if (options->inspect_it)
c906108c
SS
222 {
223 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
224 fputs_filtered ("\"( ptr \"", stream);
225 else
226 fputs_filtered ("\"( nodef \"", stream);
d6a843b5 227 if (field_is_static (&TYPE_FIELD (type, i)))
c906108c
SS
228 fputs_filtered ("static ", stream);
229 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
cf309262 230 current_language->la_language,
c906108c
SS
231 DMGL_PARAMS | DMGL_ANSI);
232 fputs_filtered ("\" \"", stream);
233 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
cf309262 234 current_language->la_language,
c906108c
SS
235 DMGL_PARAMS | DMGL_ANSI);
236 fputs_filtered ("\") \"", stream);
237 }
238 else
239 {
240 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
241
d6a843b5 242 if (field_is_static (&TYPE_FIELD (type, i)))
c906108c
SS
243 fputs_filtered ("static ", stream);
244 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
cf309262 245 current_language->la_language,
c906108c
SS
246 DMGL_PARAMS | DMGL_ANSI);
247 annotate_field_name_end ();
248 /* do not print leading '=' in case of anonymous unions */
249 if (strcmp (TYPE_FIELD_NAME (type, i), ""))
250 fputs_filtered (" = ", stream);
251 annotate_field_value ();
252 }
253
d6a843b5
JK
254 if (!field_is_static (&TYPE_FIELD (type, i))
255 && TYPE_FIELD_PACKED (type, i))
c906108c 256 {
6943961c 257 struct value *v;
c906108c
SS
258
259 /* Bitfields require special handling, especially due to byte
c5aa993b 260 order problems. */
c906108c
SS
261 if (TYPE_FIELD_IGNORE (type, i))
262 {
c5aa993b 263 fputs_filtered ("<optimized out or zero length>", stream);
c906108c
SS
264 }
265 else
266 {
79a45b7d
TT
267 struct value_print_options opts = *options;
268 opts.deref_ref = 0;
2c63a960
JB
269 v = value_from_longest
270 (TYPE_FIELD_TYPE (type, i),
271 unpack_field_as_long (type, valaddr + offset, i));
c906108c 272
79a45b7d 273 common_val_print (v, stream, recurse + 1, &opts,
d8ca156b 274 current_language);
c906108c
SS
275 }
276 }
277 else
278 {
279 if (TYPE_FIELD_IGNORE (type, i))
280 {
c5aa993b 281 fputs_filtered ("<optimized out or zero length>", stream);
c906108c 282 }
d6a843b5 283 else if (field_is_static (&TYPE_FIELD (type, i)))
c906108c 284 {
6943961c 285 struct value *v = value_static_field (type, i);
c906108c
SS
286 if (v == NULL)
287 fputs_filtered ("<optimized out>", stream);
288 else
289 cp_print_static_field (TYPE_FIELD_TYPE (type, i), v,
79a45b7d 290 stream, recurse + 1, options);
c906108c
SS
291 }
292 else
293 {
79a45b7d
TT
294 struct value_print_options opts = *options;
295 opts.deref_ref = 0;
c5aa993b 296 val_print (TYPE_FIELD_TYPE (type, i),
2c63a960 297 valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8,
edf3d5f3 298 address,
79a45b7d 299 stream, recurse + 1, &opts,
d8ca156b 300 current_language);
c906108c
SS
301 }
302 }
303 annotate_field_end ();
304 }
305
306 if (dont_print_statmem == 0)
307 {
308 /* Free the space used to deal with the printing
309 of the members from top level. */
310 obstack_free (&dont_print_statmem_obstack, last_dont_print);
311 dont_print_statmem_obstack = tmp_obstack;
312 }
313
79a45b7d 314 if (options->pretty)
c906108c
SS
315 {
316 fprintf_filtered (stream, "\n");
317 print_spaces_filtered (2 * recurse, stream);
318 }
c5aa993b 319 } /* if there are data fields */
c5aa993b 320
c906108c
SS
321 fprintf_filtered (stream, "}");
322}
323
edf3d5f3
TT
324/* Like cp_print_value_fields, but find the runtime type of the object
325 and pass it as the `real_type' argument to cp_print_value_fields.
326 This function is a hack to work around the fact that
327 common_val_print passes the embedded offset to val_print, but not
328 the enclosing type. */
329
330void
331cp_print_value_fields_rtti (struct type *type,
332 const gdb_byte *valaddr, int offset,
333 CORE_ADDR address,
334 struct ui_file *stream, int recurse,
335 const struct value_print_options *options,
336 struct type **dont_print_vb, int dont_print_statmem)
337{
338 struct value *value;
339 int full, top, using_enc;
340 struct type *real_type;
341
342 /* Ugh, we have to convert back to a value here. */
343 value = value_from_contents_and_address (type, valaddr + offset,
344 address + offset);
345 /* We don't actually care about most of the result here -- just the
346 type. We already have the correct offset, due to how val_print
347 was initially called. */
348 real_type = value_rtti_type (value, &full, &top, &using_enc);
349 if (!real_type)
350 real_type = type;
351
352 cp_print_value_fields (type, real_type, valaddr, offset,
353 address, stream, recurse, options,
354 dont_print_vb, dont_print_statmem);
355}
356
c906108c
SS
357/* Special val_print routine to avoid printing multiple copies of virtual
358 baseclasses. */
359
360static void
a2bd3dcd 361cp_print_value (struct type *type, struct type *real_type,
fc1a4b47 362 const gdb_byte *valaddr, int offset, CORE_ADDR address,
79a45b7d
TT
363 struct ui_file *stream, int recurse,
364 const struct value_print_options *options,
365 struct type **dont_print_vb)
c906108c 366{
c906108c 367 struct type **last_dont_print
2c63a960 368 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
c1b6e682 369 struct obstack tmp_obstack = dont_print_vb_obstack;
c906108c 370 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
b9d652ac
DJ
371 int thisoffset;
372 struct type *thistype;
c906108c
SS
373
374 if (dont_print_vb == 0)
375 {
376 /* If we're at top level, carve out a completely fresh
c5aa993b
JM
377 chunk of the obstack and use that until this particular
378 invocation returns. */
c906108c
SS
379 /* Bump up the high-water mark. Now alpha is omega. */
380 obstack_finish (&dont_print_vb_obstack);
381 }
382
383 for (i = 0; i < n_baseclasses; i++)
384 {
385 int boffset;
386 int skip;
387 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
388 char *basename = TYPE_NAME (baseclass);
fc1a4b47 389 const gdb_byte *base_valaddr;
c906108c
SS
390
391 if (BASETYPE_VIA_VIRTUAL (type, i))
392 {
393 struct type **first_dont_print
2c63a960 394 = (struct type **) obstack_base (&dont_print_vb_obstack);
c906108c 395
c5aa993b 396 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
2c63a960 397 - first_dont_print;
c906108c
SS
398
399 while (--j >= 0)
400 if (baseclass == first_dont_print[j])
401 goto flush_it;
402
403 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
404 }
405
b9d652ac
DJ
406 thisoffset = offset;
407 thistype = real_type;
086280be 408
edf3d5f3 409 boffset = baseclass_offset (type, i, valaddr + offset, address + offset);
086280be
UW
410 skip = ((boffset == -1) || (boffset + offset) < 0) ? 1 : -1;
411
412 if (BASETYPE_VIA_VIRTUAL (type, i))
c5aa993b 413 {
086280be
UW
414 /* The virtual base class pointer might have been
415 clobbered by the user program. Make sure that it
416 still points to a valid memory location. */
c906108c 417
086280be
UW
418 if (boffset != -1
419 && ((boffset + offset) < 0
edf3d5f3 420 || (boffset + offset) >= TYPE_LENGTH (real_type)))
c5aa993b 421 {
086280be
UW
422 /* FIXME (alloca): unsafe if baseclass is really really large. */
423 gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
424 base_valaddr = buf;
425 if (target_read_memory (address + boffset, buf,
426 TYPE_LENGTH (baseclass)) != 0)
427 skip = 1;
428 address = address + boffset;
429 thisoffset = 0;
430 boffset = 0;
431 thistype = baseclass;
c5aa993b
JM
432 }
433 else
434 base_valaddr = valaddr;
c906108c 435 }
086280be
UW
436 else
437 base_valaddr = valaddr;
c906108c
SS
438
439 /* now do the printing */
79a45b7d 440 if (options->pretty)
c906108c
SS
441 {
442 fprintf_filtered (stream, "\n");
443 print_spaces_filtered (2 * recurse, stream);
444 }
445 fputs_filtered ("<", stream);
446 /* Not sure what the best notation is in the case where there is no
c5aa993b 447 baseclass name. */
c906108c
SS
448 fputs_filtered (basename ? basename : "", stream);
449 fputs_filtered ("> = ", stream);
450
451
452 if (skip >= 1)
453 fprintf_filtered (stream, "<invalid address>");
454 else
a6bac58e
TT
455 {
456 int result = 0;
457
458 /* Attempt to run the Python pretty-printers on the
459 baseclass if possible. */
460 if (!options->raw)
461 result = apply_val_pretty_printer (baseclass, base_valaddr,
462 thisoffset + boffset,
edf3d5f3 463 address,
a6bac58e
TT
464 stream, recurse,
465 options,
466 current_language);
467
468 if (!result)
469 cp_print_value_fields (baseclass, thistype, base_valaddr,
edf3d5f3 470 thisoffset + boffset, address,
a6bac58e
TT
471 stream, recurse, options,
472 ((struct type **)
473 obstack_base (&dont_print_vb_obstack)),
474 0);
475 }
c906108c
SS
476 fputs_filtered (", ", stream);
477
478 flush_it:
479 ;
480 }
481
482 if (dont_print_vb == 0)
483 {
484 /* Free the space used to deal with the printing
c5aa993b 485 of this type from top level. */
c906108c
SS
486 obstack_free (&dont_print_vb_obstack, last_dont_print);
487 /* Reset watermark so that we can continue protecting
c5aa993b 488 ourselves from whatever we were protecting ourselves. */
c906108c
SS
489 dont_print_vb_obstack = tmp_obstack;
490 }
491}
492
493/* Print value of a static member.
494 To avoid infinite recursion when printing a class that contains
495 a static instance of the class, we keep the addresses of all printed
496 static member classes in an obstack and refuse to print them more
497 than once.
498
79a45b7d 499 VAL contains the value to print, TYPE, STREAM, RECURSE, and OPTIONS
c906108c
SS
500 have the same meanings as in c_val_print. */
501
502static void
2c63a960 503cp_print_static_field (struct type *type,
6943961c 504 struct value *val,
2c63a960 505 struct ui_file *stream,
2c63a960 506 int recurse,
79a45b7d 507 const struct value_print_options *options)
c906108c 508{
79a45b7d 509 struct value_print_options opts;
c906108c
SS
510 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
511 {
512 CORE_ADDR *first_dont_print;
42ae5230 513 CORE_ADDR addr;
c906108c
SS
514 int i;
515
516 first_dont_print
c5aa993b
JM
517 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
518 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
c906108c
SS
519 - first_dont_print;
520
521 while (--i >= 0)
522 {
42ae5230 523 if (value_address (val) == first_dont_print[i])
c906108c 524 {
2c63a960
JB
525 fputs_filtered ("<same as static member of an already"
526 " seen type>",
c906108c
SS
527 stream);
528 return;
529 }
530 }
531
42ae5230
TT
532 addr = value_address (val);
533 obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
c906108c
SS
534 sizeof (CORE_ADDR));
535
536 CHECK_TYPEDEF (type);
edf3d5f3
TT
537 cp_print_value_fields (type, value_enclosing_type (val),
538 value_contents_all (val),
42ae5230 539 value_embedded_offset (val), addr,
79a45b7d 540 stream, recurse, options, NULL, 1);
c906108c
SS
541 return;
542 }
79a45b7d
TT
543
544 opts = *options;
545 opts.deref_ref = 0;
46615f07 546 val_print (type, value_contents_all (val),
42ae5230 547 value_embedded_offset (val), value_address (val),
79a45b7d 548 stream, recurse, &opts, current_language);
c906108c
SS
549}
550
0d5de010
DJ
551
552/* Find the field in *DOMAIN, or its non-virtual base classes, with bit offset
553 OFFSET. Set *DOMAIN to the containing type and *FIELDNO to the containing
554 field number. If OFFSET is not exactly at the start of some field, set
555 *DOMAIN to NULL. */
556
2c0b251b 557static void
0d5de010
DJ
558cp_find_class_member (struct type **domain_p, int *fieldno,
559 LONGEST offset)
560{
561 struct type *domain;
562 unsigned int i;
563 unsigned len;
564
565 *domain_p = check_typedef (*domain_p);
566 domain = *domain_p;
567 len = TYPE_NFIELDS (domain);
568
569 for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
570 {
571 LONGEST bitpos = TYPE_FIELD_BITPOS (domain, i);
572
573 QUIT;
574 if (offset == bitpos)
575 {
576 *fieldno = i;
577 return;
578 }
579 }
580
581 for (i = 0; i < TYPE_N_BASECLASSES (domain); i++)
582 {
583 LONGEST bitpos = TYPE_FIELD_BITPOS (domain, i);
584 LONGEST bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (domain, i));
585
586 if (offset >= bitpos && offset < bitpos + bitsize)
587 {
588 *domain_p = TYPE_FIELD_TYPE (domain, i);
589 cp_find_class_member (domain_p, fieldno, offset - bitpos);
590 return;
591 }
592 }
593
594 *domain_p = NULL;
595}
596
c906108c 597void
ad4820ab 598cp_print_class_member (const gdb_byte *valaddr, struct type *type,
fba45db2 599 struct ui_file *stream, char *prefix)
c906108c 600{
e17a4113
UW
601 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
602
c906108c
SS
603 /* VAL is a byte offset into the structure type DOMAIN.
604 Find the name of the field for that offset and
605 print it. */
ad4820ab 606 struct type *domain = TYPE_DOMAIN_TYPE (type);
e17a4113 607 LONGEST val;
0d5de010 608 unsigned int fieldno;
c906108c 609
e17a4113
UW
610 val = extract_signed_integer (valaddr, TYPE_LENGTH (type), byte_order);
611
0d5de010
DJ
612 /* Pointers to data members are usually byte offsets into an object.
613 Because a data member can have offset zero, and a NULL pointer to
614 member must be distinct from any valid non-NULL pointer to
615 member, either the value is biased or the NULL value has a
616 special representation; both are permitted by ISO C++. HP aCC
617 used a bias of 0x20000000; HP cfront used a bias of 1; g++ 3.x
618 and other compilers which use the Itanium ABI use -1 as the NULL
619 value. GDB only supports that last form; to add support for
620 another form, make this into a cp-abi hook. */
c906108c 621
0d5de010 622 if (val == -1)
c906108c 623 {
0d5de010
DJ
624 fprintf_filtered (stream, "NULL");
625 return;
c906108c 626 }
0d5de010
DJ
627
628 cp_find_class_member (&domain, &fieldno, val << 3);
629
630 if (domain != NULL)
c906108c
SS
631 {
632 char *name;
306d9ac5 633 fputs_filtered (prefix, stream);
c906108c
SS
634 name = type_name_no_tag (domain);
635 if (name)
c5aa993b 636 fputs_filtered (name, stream);
c906108c
SS
637 else
638 c_type_print_base (domain, stream, 0, 0);
639 fprintf_filtered (stream, "::");
0d5de010 640 fputs_filtered (TYPE_FIELD_NAME (domain, fieldno), stream);
c906108c
SS
641 }
642 else
0d5de010 643 fprintf_filtered (stream, "%ld", (long) val);
c906108c
SS
644}
645
646
c906108c 647void
fba45db2 648_initialize_cp_valprint (void)
c906108c 649{
5bf193a2 650 add_setshow_boolean_cmd ("static-members", class_support,
79a45b7d 651 &user_print_options.static_field_print, _("\
5bf193a2
AC
652Set printing of C++ static members."), _("\
653Show printing of C++ static members."), NULL,
654 NULL,
920d2a44 655 show_static_field_print,
5bf193a2 656 &setprintlist, &showprintlist);
c906108c 657
79a45b7d
TT
658 add_setshow_boolean_cmd ("vtbl", class_support,
659 &user_print_options.vtblprint, _("\
5bf193a2
AC
660Set printing of C++ virtual function tables."), _("\
661Show printing of C++ virtual function tables."), NULL,
662 NULL,
920d2a44 663 show_vtblprint,
5bf193a2
AC
664 &setprintlist, &showprintlist);
665
79a45b7d
TT
666 add_setshow_boolean_cmd ("object", class_support,
667 &user_print_options.objectprint, _("\
5bf193a2
AC
668Set printing of object's derived type based on vtable info."), _("\
669Show printing of object's derived type based on vtable info."), NULL,
670 NULL,
920d2a44 671 show_objectprint,
5bf193a2 672 &setprintlist, &showprintlist);
c906108c 673
c906108c
SS
674 obstack_begin (&dont_print_vb_obstack, 32 * sizeof (struct type *));
675 obstack_specify_allocation (&dont_print_statmem_obstack,
676 32 * sizeof (CORE_ADDR), sizeof (CORE_ADDR),
b8c9b27d 677 xmalloc, xfree);
c906108c 678}
This page took 0.655409 seconds and 4 git commands to generate.