Bug Summary

File:src/gnu/usr.bin/binutils/gdb/cp-valprint.c
Warning:line 427, column 7
Value stored to 'fields_seen' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name cp-valprint.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/binutils/obj/gdb -resource-dir /usr/local/lib/clang/13.0.0 -D PIE_DEFAULT=1 -I . -I /usr/src/gnu/usr.bin/binutils/gdb -I /usr/src/gnu/usr.bin/binutils/gdb/config -D LOCALEDIR="/usr/share/locale" -D HAVE_CONFIG_H -I /usr/src/gnu/usr.bin/binutils/gdb/../include/opcode -I ../bfd -I /usr/src/gnu/usr.bin/binutils/gdb/../bfd -I /usr/src/gnu/usr.bin/binutils/gdb/../include -I ../intl -I /usr/src/gnu/usr.bin/binutils/gdb/../intl -D MI_OUT=1 -D TUI=1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/gnu/usr.bin/binutils/obj/gdb -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -fcommon -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/gnu/usr.bin/binutils/gdb/cp-valprint.c
1/* Support for printing C++ values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23#include "defs.h"
24#include "gdb_obstack.h"
25#include "symtab.h"
26#include "gdbtypes.h"
27#include "expression.h"
28#include "value.h"
29#include "command.h"
30#include "gdbcmd.h"
31#include "demangle.h"
32#include "annotate.h"
33#include "gdb_string.h"
34#include "c-lang.h"
35#include "target.h"
36#include "cp-abi.h"
37#include "valprint.h"
38
39int vtblprint; /* Controls printing of vtbl's */
40int objectprint; /* Controls looking up an object's derived type
41 using what we find in its vtables. */
42int static_field_print; /* Controls printing of static fields. */
43
44static struct obstack dont_print_vb_obstack;
45static struct obstack dont_print_statmem_obstack;
46
47extern void _initialize_cp_valprint (void);
48
49static void cp_print_static_field (struct type *, struct value *,
50 struct ui_file *, int, int,
51 enum val_prettyprint);
52
53static void cp_print_value (struct type *, struct type *, char *, int,
54 CORE_ADDR, struct ui_file *, int, int,
55 enum val_prettyprint, struct type **);
56
57static void cp_print_hpacc_virtual_table_entries (struct type *, int *,
58 struct value *,
59 struct ui_file *, int,
60 int,
61 enum val_prettyprint);
62
63
64void
65cp_print_class_method (char *valaddr,
66 struct type *type,
67 struct ui_file *stream)
68{
69 struct type *domain;
70 struct fn_field *f = NULL((void*)0);
71 int j = 0;
72 int len2;
73 int offset;
74 char *kind = "";
75 CORE_ADDR addr;
76 struct symbol *sym;
77 unsigned len;
78 unsigned int i;
79 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)(type)->main_type->target_type);
80
81 domain = TYPE_DOMAIN_TYPE (target_type)(target_type)->main_type->vptr_basetype;
82 if (domain == (struct type *) NULL((void*)0))
83 {
84 fprintf_filtered (stream, "<unknown>");
85 return;
86 }
87 addr = unpack_pointer (type, valaddr);
88 if (METHOD_PTR_IS_VIRTUAL (addr)((addr) & 0x80000000))
89 {
90 offset = METHOD_PTR_TO_VOFFSET (addr)(~0x80000000 & (addr));
91 len = TYPE_NFN_FIELDS (domain)(domain)->main_type->type_specific.cplus_stuff->nfn_fields;
92 for (i = 0; i < len; i++)
93 {
94 f = TYPE_FN_FIELDLIST1 (domain, i)(domain)->main_type->type_specific.cplus_stuff->fn_fieldlists
[i].fn_fields
;
95 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i)(domain)->main_type->type_specific.cplus_stuff->fn_fieldlists
[i].length
;
96
97 check_stub_method_group (domain, i);
98 for (j = 0; j < len2; j++)
99 {
100 if (TYPE_FN_FIELD_VOFFSET (f, j)((f)[j].voffset-2) == offset)
101 {
102 kind = "virtual ";
103 goto common;
104 }
105 }
106 }
107 }
108 else
109 {
110 sym = find_pc_function (addr);
111 if (sym == 0)
112 {
113 /* 1997-08-01 Currently unsupported with HP aCC */
114 if (deprecated_hp_som_som_object_present)
115 {
116 fputs_filtered ("?? <not supported with HP aCC>", stream);
117 return;
118 }
119 error ("invalid pointer to member function");
120 }
121 len = TYPE_NFN_FIELDS (domain)(domain)->main_type->type_specific.cplus_stuff->nfn_fields;
122 for (i = 0; i < len; i++)
123 {
124 f = TYPE_FN_FIELDLIST1 (domain, i)(domain)->main_type->type_specific.cplus_stuff->fn_fieldlists
[i].fn_fields
;
125 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i)(domain)->main_type->type_specific.cplus_stuff->fn_fieldlists
[i].length
;
126
127 check_stub_method_group (domain, i);
128 for (j = 0; j < len2; j++)
129 {
130 if (strcmp (DEPRECATED_SYMBOL_NAME (sym)(sym)->ginfo.name, TYPE_FN_FIELD_PHYSNAME (f, j)(f)[j].physname)
131 == 0)
132 goto common;
133 }
134 }
135 }
136 common:
137 if (i < len)
138 {
139 char *demangled_name;
140
141 fprintf_filtered (stream, "&");
142 fputs_filtered (kind, stream);
143 demangled_name = cplus_demangle (TYPE_FN_FIELD_PHYSNAME (f, j)(f)[j].physname,
144 DMGL_ANSI(1 << 1) | DMGL_PARAMS(1 << 0));
145 if (demangled_name == NULL((void*)0))
146 fprintf_filtered (stream, "<badly mangled name %s>",
147 TYPE_FN_FIELD_PHYSNAME (f, j)(f)[j].physname);
148 else
149 {
150 fputs_filtered (demangled_name, stream);
151 xfree (demangled_name);
152 }
153 }
154 else
155 {
156 fprintf_filtered (stream, "(");
157 type_print (type, "", stream, -1);
158 fprintf_filtered (stream, ") %d", (int) addr >> 3);
159 }
160}
161
162/* GCC versions after 2.4.5 use this. */
163const char vtbl_ptr_name[] = "__vtbl_ptr_type";
164
165/* HP aCC uses different names. */
166const char hpacc_vtbl_ptr_name[] = "__vfp";
167const char hpacc_vtbl_ptr_type_name[] = "__vftyp";
168
169/* Return truth value for assertion that TYPE is of the type
170 "pointer to virtual function". */
171
172int
173cp_is_vtbl_ptr_type (struct type *type)
174{
175 char *typename = type_name_no_tag (type);
176
177 return (typename != NULL((void*)0) && !strcmp (typename, vtbl_ptr_name));
178}
179
180/* Return truth value for the assertion that TYPE is of the type
181 "pointer to virtual function table". */
182
183int
184cp_is_vtbl_member (struct type *type)
185{
186 /* With older versions of g++, the vtbl field pointed to an array
187 of structures. Nowadays it points directly to the structure. */
188 if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR)
189 {
190 type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type;
191 if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY)
192 {
193 type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type;
194 if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT /* if not using thunks */
195 || TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR) /* if using thunks */
196 {
197 /* Virtual functions tables are full of pointers
198 to virtual functions. */
199 return cp_is_vtbl_ptr_type (type);
200 }
201 }
202 else if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT) /* if not using thunks */
203 {
204 return cp_is_vtbl_ptr_type (type);
205 }
206 else if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR) /* if using thunks */
207 {
208 /* The type name of the thunk pointer is NULL when using dwarf2.
209 We could test for a pointer to a function, but there is
210 no type info for the virtual table either, so it wont help. */
211 return cp_is_vtbl_ptr_type (type);
212 }
213 }
214 return 0;
215}
216
217/* Mutually recursive subroutines of cp_print_value and c_val_print to
218 print out a structure's fields: cp_print_value_fields and cp_print_value.
219
220 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
221 same meanings as in cp_print_value and c_val_print.
222
223 2nd argument REAL_TYPE is used to carry over the type of the derived
224 class across the recursion to base classes.
225
226 DONT_PRINT is an array of baseclass types that we
227 should not print, or zero if called from top level. */
228
229void
230cp_print_value_fields (struct type *type, struct type *real_type, char *valaddr,
231 int offset, CORE_ADDR address, struct ui_file *stream,
232 int format, int recurse, enum val_prettyprint pretty,
233 struct type **dont_print_vb, int dont_print_statmem)
234{
235 int i, len, n_baseclasses;
236 struct obstack tmp_obstack;
237 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack)((&dont_print_statmem_obstack)->next_free);
238 int fields_seen = 0;
239
240 CHECK_TYPEDEF (type)(type) = check_typedef (type);
241
242 fprintf_filtered (stream, "{");
243 len = TYPE_NFIELDS (type)(type)->main_type->nfields;
244 n_baseclasses = TYPE_N_BASECLASSES (type)(type)->main_type->type_specific.cplus_stuff->n_baseclasses;
245
246 /* First, print out baseclasses such that we don't print
247 duplicates of virtual baseclasses. */
248
249 if (n_baseclasses > 0)
250 cp_print_value (type, real_type, valaddr, offset, address, stream,
251 format, recurse + 1, pretty, dont_print_vb);
252
253 /* Second, print out data fields */
254
255 /* If there are no data fields, or if the only field is the
256 * vtbl pointer, skip this part */
257 if ((len == n_baseclasses)
258 || ((len - n_baseclasses == 1)
259 && TYPE_HAS_VTABLE (type)(((type)->main_type->type_specific.cplus_stuff->runtime_ptr
) && (((type)->main_type->type_specific.cplus_stuff
->runtime_ptr)->has_vtable))
260 && strncmp (TYPE_FIELD_NAME (type, n_baseclasses)(((type)->main_type->fields[n_baseclasses]).name),
261 hpacc_vtbl_ptr_name, 5) == 0)
262 || !len)
263 fprintf_filtered (stream, "<No data fields>");
264 else
265 {
266 if (dont_print_statmem == 0)
267 {
268 /* If we're at top level, carve out a completely fresh
269 chunk of the obstack and use that until this particular
270 invocation returns. */
271 tmp_obstack = dont_print_statmem_obstack;
272 obstack_finish (&dont_print_statmem_obstack)__extension__ ({ struct obstack *__o1 = (&dont_print_statmem_obstack
); void *value; value = (void *) __o1->object_base; if (__o1
->next_free == value) __o1->maybe_empty_object = 1; __o1
->next_free = (((((__o1->next_free) - (char *) 0)+__o1->
alignment_mask) & ~ (__o1->alignment_mask)) + (char *)
0); if (__o1->next_free - (char *)__o1->chunk > __o1
->chunk_limit - (char *)__o1->chunk) __o1->next_free
= __o1->chunk_limit; __o1->object_base = __o1->next_free
; value; })
;
273 }
274
275 for (i = n_baseclasses; i < len; i++)
276 {
277 /* If requested, skip printing of static fields. */
278 if (!static_field_print && TYPE_FIELD_STATIC (type, i)((type)->main_type->fields[i].static_kind != 0))
279 continue;
280
281 /* If a vtable pointer appears, we'll print it out later */
282 if (TYPE_HAS_VTABLE (type)(((type)->main_type->type_specific.cplus_stuff->runtime_ptr
) && (((type)->main_type->type_specific.cplus_stuff
->runtime_ptr)->has_vtable))
283 && strncmp (TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name), hpacc_vtbl_ptr_name,
284 5) == 0)
285 continue;
286
287 if (fields_seen)
288 fprintf_filtered (stream, ", ");
289 else if (n_baseclasses > 0)
290 {
291 if (pretty)
292 {
293 fprintf_filtered (stream, "\n");
294 print_spaces_filtered (2 + 2 * recurse, stream);
295 fputs_filtered ("members of ", stream);
296 fputs_filtered (type_name_no_tag (type), stream);
297 fputs_filtered (": ", stream);
298 }
299 }
300 fields_seen = 1;
301
302 if (pretty)
303 {
304 fprintf_filtered (stream, "\n");
305 print_spaces_filtered (2 + 2 * recurse, stream);
306 }
307 else
308 {
309 wrap_here (n_spaces (2 + 2 * recurse));
310 }
311 if (inspect_it)
312 {
313 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i))((((type)->main_type->fields[i]).type))->main_type->
code
== TYPE_CODE_PTR)
314 fputs_filtered ("\"( ptr \"", stream);
315 else
316 fputs_filtered ("\"( nodef \"", stream);
317 if (TYPE_FIELD_STATIC (type, i)((type)->main_type->fields[i].static_kind != 0))
318 fputs_filtered ("static ", stream);
319 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name),
320 language_cplus,
321 DMGL_PARAMS(1 << 0) | DMGL_ANSI(1 << 1));
322 fputs_filtered ("\" \"", stream);
323 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name),
324 language_cplus,
325 DMGL_PARAMS(1 << 0) | DMGL_ANSI(1 << 1));
326 fputs_filtered ("\") \"", stream);
327 }
328 else
329 {
330 annotate_field_begin (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type));
331
332 if (TYPE_FIELD_STATIC (type, i)((type)->main_type->fields[i].static_kind != 0))
333 fputs_filtered ("static ", stream);
334 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name),
335 language_cplus,
336 DMGL_PARAMS(1 << 0) | DMGL_ANSI(1 << 1));
337 annotate_field_name_end ();
338 /* do not print leading '=' in case of anonymous unions */
339 if (strcmp (TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name), ""))
340 fputs_filtered (" = ", stream);
341 annotate_field_value ();
342 }
343
344 if (!TYPE_FIELD_STATIC (type, i)((type)->main_type->fields[i].static_kind != 0) && TYPE_FIELD_PACKED (type, i)((((type)->main_type->fields[i]).bitsize)!=0))
345 {
346 struct value *v;
347
348 /* Bitfields require special handling, especially due to byte
349 order problems. */
350 if (TYPE_FIELD_IGNORE (type, i)((type)->main_type->type_specific.cplus_stuff->ignore_field_bits
== ((void*)0) ? 0 : (((type)->main_type->type_specific
.cplus_stuff->ignore_field_bits)[((i))>>3] & (1 <<
(((i))&7))))
)
351 {
352 fputs_filtered ("<optimized out or zero length>", stream);
353 }
354 else
355 {
356 v = value_from_longest
357 (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type),
358 unpack_field_as_long (type, valaddr + offset, i));
359
360 val_print (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type), VALUE_CONTENTS (v)((void)((v)->lazy && value_fetch_lazy(v)), ((char *
) (v)->aligner.contents + (v)->embedded_offset))
,
361 0, 0, stream, format, 0, recurse + 1, pretty);
362 }
363 }
364 else
365 {
366 if (TYPE_FIELD_IGNORE (type, i)((type)->main_type->type_specific.cplus_stuff->ignore_field_bits
== ((void*)0) ? 0 : (((type)->main_type->type_specific
.cplus_stuff->ignore_field_bits)[((i))>>3] & (1 <<
(((i))&7))))
)
367 {
368 fputs_filtered ("<optimized out or zero length>", stream);
369 }
370 else if (TYPE_FIELD_STATIC (type, i)((type)->main_type->fields[i].static_kind != 0))
371 {
372 struct value *v = value_static_field (type, i);
373 if (v == NULL((void*)0))
374 fputs_filtered ("<optimized out>", stream);
375 else
376 cp_print_static_field (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type), v,
377 stream, format, recurse + 1,
378 pretty);
379 }
380 else
381 {
382 val_print (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type),
383 valaddr, offset + TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos) / 8,
384 address + TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos) / 8,
385 stream, format, 0, recurse + 1, pretty);
386 }
387 }
388 annotate_field_end ();
389 }
390
391 if (dont_print_statmem == 0)
392 {
393 /* Free the space used to deal with the printing
394 of the members from top level. */
395 obstack_free (&dont_print_statmem_obstack, last_dont_print)__extension__ ({ struct obstack *__o = (&dont_print_statmem_obstack
); void *__obj = (last_dont_print); if (__obj > (void *)__o
->chunk && __obj < (void *)__o->chunk_limit)
__o->next_free = __o->object_base = __obj; else (obstack_free
) (__o, __obj); })
;
396 dont_print_statmem_obstack = tmp_obstack;
397 }
398
399 if (pretty)
400 {
401 fprintf_filtered (stream, "\n");
402 print_spaces_filtered (2 * recurse, stream);
403 }
404 } /* if there are data fields */
405 /* Now print out the virtual table pointer if there is one */
406 if (TYPE_HAS_VTABLE (type)(((type)->main_type->type_specific.cplus_stuff->runtime_ptr
) && (((type)->main_type->type_specific.cplus_stuff
->runtime_ptr)->has_vtable))
407 && strncmp (TYPE_FIELD_NAME (type, n_baseclasses)(((type)->main_type->fields[n_baseclasses]).name),
408 hpacc_vtbl_ptr_name, 5) == 0)
409 {
410 struct value *v;
411 /* First get the virtual table pointer and print it out */
412
413#if 0
414 fputs_filtered ("__vfp = ", stream);
415#endif
416
417 fputs_filtered (", Virtual table at ", stream);
418
419 /* pai: FIXME 32x64 problem? */
420 /* Not sure what the best notation is in the case where there is no
421 baseclass name. */
422 v = value_from_pointer (lookup_pointer_type (builtin_type_unsigned_long),
423 *(unsigned long *) (valaddr + offset));
424
425 val_print (VALUE_TYPE (v)(v)->type, VALUE_CONTENTS (v)((void)((v)->lazy && value_fetch_lazy(v)), ((char *
) (v)->aligner.contents + (v)->embedded_offset))
, 0, 0,
426 stream, format, 0, recurse + 1, pretty);
427 fields_seen = 1;
Value stored to 'fields_seen' is never read
428
429 if (vtblprint)
430 {
431 /* Print out function pointers in vtable. */
432
433 /* FIXME: then-clause is for non-RRBC layout of virtual
434 * table. The RRBC case in the else-clause is yet to be
435 * implemented. The if (1) below should be changed to a
436 * test for whether the executable we have was compiled
437 * with a version of HP aCC that doesn't have RRBC
438 * support. */
439
440 if (1)
441 {
442 /* no RRBC support; function pointers embedded directly
443 in vtable */
444
445 int vfuncs = count_virtual_fns (real_type);
446
447 fputs_filtered (" {", stream);
448
449 /* FIXME : doesn't work at present */
450#if 0
451 fprintf_filtered (stream, "%d entr%s: ", vfuncs,
452 vfuncs == 1 ? "y" : "ies");
453#else
454 fputs_filtered ("not implemented", stream);
455
456
457#endif
458
459 /* recursive function that prints all virtual function entries */
460#if 0
461 cp_print_hpacc_virtual_table_entries (real_type, &vfuncs, v,
462 stream, format, recurse,
463 pretty);
464#endif
465 fputs_filtered ("}", stream);
466 } /* non-RRBC case */
467 else
468 {
469 /* FIXME -- see comments above */
470 /* RRBC support present; function pointers are found
471 * by indirection through the class segment entries. */
472
473
474 } /* RRBC case */
475 } /* if vtblprint */
476
477 if (pretty)
478 {
479 fprintf_filtered (stream, "\n");
480 print_spaces_filtered (2 * recurse, stream);
481 }
482
483 } /* if vtable exists */
484
485 fprintf_filtered (stream, "}");
486}
487
488/* Special val_print routine to avoid printing multiple copies of virtual
489 baseclasses. */
490
491static void
492cp_print_value (struct type *type, struct type *real_type, char *valaddr,
493 int offset, CORE_ADDR address, struct ui_file *stream,
494 int format, int recurse, enum val_prettyprint pretty,
495 struct type **dont_print_vb)
496{
497 struct obstack tmp_obstack;
498 struct type **last_dont_print
499 = (struct type **) obstack_next_free (&dont_print_vb_obstack)((&dont_print_vb_obstack)->next_free);
500 int i, n_baseclasses = TYPE_N_BASECLASSES (type)(type)->main_type->type_specific.cplus_stuff->n_baseclasses;
501 int thisoffset;
502 struct type *thistype;
503
504 if (dont_print_vb == 0)
505 {
506 /* If we're at top level, carve out a completely fresh
507 chunk of the obstack and use that until this particular
508 invocation returns. */
509 tmp_obstack = dont_print_vb_obstack;
510 /* Bump up the high-water mark. Now alpha is omega. */
511 obstack_finish (&dont_print_vb_obstack)__extension__ ({ struct obstack *__o1 = (&dont_print_vb_obstack
); void *value; value = (void *) __o1->object_base; if (__o1
->next_free == value) __o1->maybe_empty_object = 1; __o1
->next_free = (((((__o1->next_free) - (char *) 0)+__o1->
alignment_mask) & ~ (__o1->alignment_mask)) + (char *)
0); if (__o1->next_free - (char *)__o1->chunk > __o1
->chunk_limit - (char *)__o1->chunk) __o1->next_free
= __o1->chunk_limit; __o1->object_base = __o1->next_free
; value; })
;
512 }
513
514 for (i = 0; i < n_baseclasses; i++)
515 {
516 int boffset;
517 int skip;
518 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)(type)->main_type->fields[i].type);
519 char *basename = TYPE_NAME (baseclass)(baseclass)->main_type->name;
520 char *base_valaddr;
521
522 if (BASETYPE_VIA_VIRTUAL (type, i)((type)->main_type->type_specific.cplus_stuff->virtual_field_bits
== ((void*)0) ? 0 : (((type)->main_type->type_specific
.cplus_stuff->virtual_field_bits)[((i))>>3] & (1
<< (((i))&7))))
)
523 {
524 struct type **first_dont_print
525 = (struct type **) obstack_base (&dont_print_vb_obstack)((&dont_print_vb_obstack)->object_base);
526
527 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)((&dont_print_vb_obstack)->next_free)
528 - first_dont_print;
529
530 while (--j >= 0)
531 if (baseclass == first_dont_print[j])
532 goto flush_it;
533
534 obstack_ptr_grow (&dont_print_vb_obstack, baseclass)__extension__ ({ struct obstack *__o = (&dont_print_vb_obstack
); if (__o->next_free + sizeof (void *) > __o->chunk_limit
) _obstack_newchunk (__o, sizeof (void *)); __extension__ ({ struct
obstack *__o1 = (__o); *(const void **) __o1->next_free =
(baseclass); __o1->next_free += sizeof (const void *); (void
) 0; }); })
;
535 }
536
537 thisoffset = offset;
538 thistype = real_type;
539 if (TYPE_HAS_VTABLE (type)(((type)->main_type->type_specific.cplus_stuff->runtime_ptr
) && (((type)->main_type->type_specific.cplus_stuff
->runtime_ptr)->has_vtable))
&& BASETYPE_VIA_VIRTUAL (type, i)((type)->main_type->type_specific.cplus_stuff->virtual_field_bits
== ((void*)0) ? 0 : (((type)->main_type->type_specific
.cplus_stuff->virtual_field_bits)[((i))>>3] & (1
<< (((i))&7))))
)
540 {
541 /* Assume HP/Taligent runtime convention */
542 find_rt_vbase_offset (type, TYPE_BASECLASS (type, i)(type)->main_type->fields[i].type,
543 valaddr, offset, &boffset, &skip);
544 if (skip >= 0)
545 error ("Virtual base class offset not found from vtable while"
546 " printing");
547 base_valaddr = valaddr;
548 }
549 else
550 {
551 boffset = baseclass_offset (type, i,
552 valaddr + offset,
553 address);
554 skip = ((boffset == -1) || (boffset + offset) < 0) ? 1 : -1;
555
556 if (BASETYPE_VIA_VIRTUAL (type, i)((type)->main_type->type_specific.cplus_stuff->virtual_field_bits
== ((void*)0) ? 0 : (((type)->main_type->type_specific
.cplus_stuff->virtual_field_bits)[((i))>>3] & (1
<< (((i))&7))))
)
557 {
558 /* The virtual base class pointer might have been
559 clobbered by the user program. Make sure that it
560 still points to a valid memory location. */
561
562 if (boffset != -1
563 && ((boffset + offset) < 0
564 || (boffset + offset) >= TYPE_LENGTH (type)(type)->length))
565 {
566 /* FIXME (alloca): unsafe if baseclass is really really large. */
567 base_valaddr = (char *) alloca (TYPE_LENGTH (baseclass))__builtin_alloca((baseclass)->length);
568 if (target_read_memory (address + boffset, base_valaddr,
569 TYPE_LENGTH (baseclass)(baseclass)->length) != 0)
570 skip = 1;
571 address = address + boffset;
572 thisoffset = 0;
573 boffset = 0;
574 thistype = baseclass;
575 }
576 else
577 base_valaddr = valaddr;
578 }
579 else
580 base_valaddr = valaddr;
581 }
582
583 /* now do the printing */
584 if (pretty)
585 {
586 fprintf_filtered (stream, "\n");
587 print_spaces_filtered (2 * recurse, stream);
588 }
589 fputs_filtered ("<", stream);
590 /* Not sure what the best notation is in the case where there is no
591 baseclass name. */
592 fputs_filtered (basename ? basename : "", stream);
593 fputs_filtered ("> = ", stream);
594
595
596 if (skip >= 1)
597 fprintf_filtered (stream, "<invalid address>");
598 else
599 cp_print_value_fields (baseclass, thistype, base_valaddr,
600 thisoffset + boffset, address + boffset,
601 stream, format,
602 recurse, pretty,
603 ((struct type **)
604 obstack_base (&dont_print_vb_obstack)((&dont_print_vb_obstack)->object_base)),
605 0);
606 fputs_filtered (", ", stream);
607
608 flush_it:
609 ;
610 }
611
612 if (dont_print_vb == 0)
613 {
614 /* Free the space used to deal with the printing
615 of this type from top level. */
616 obstack_free (&dont_print_vb_obstack, last_dont_print)__extension__ ({ struct obstack *__o = (&dont_print_vb_obstack
); void *__obj = (last_dont_print); if (__obj > (void *)__o
->chunk && __obj < (void *)__o->chunk_limit)
__o->next_free = __o->object_base = __obj; else (obstack_free
) (__o, __obj); })
;
617 /* Reset watermark so that we can continue protecting
618 ourselves from whatever we were protecting ourselves. */
619 dont_print_vb_obstack = tmp_obstack;
620 }
621}
622
623/* Print value of a static member.
624 To avoid infinite recursion when printing a class that contains
625 a static instance of the class, we keep the addresses of all printed
626 static member classes in an obstack and refuse to print them more
627 than once.
628
629 VAL contains the value to print, TYPE, STREAM, RECURSE, and PRETTY
630 have the same meanings as in c_val_print. */
631
632static void
633cp_print_static_field (struct type *type,
634 struct value *val,
635 struct ui_file *stream,
636 int format,
637 int recurse,
638 enum val_prettyprint pretty)
639{
640 if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT)
641 {
642 CORE_ADDR *first_dont_print;
643 int i;
644
645 first_dont_print
646 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack)((&dont_print_statmem_obstack)->object_base);
647 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)((&dont_print_statmem_obstack)->next_free)
648 - first_dont_print;
649
650 while (--i >= 0)
651 {
652 if (VALUE_ADDRESS (val)(val)->location.address == first_dont_print[i])
653 {
654 fputs_filtered ("<same as static member of an already"
655 " seen type>",
656 stream);
657 return;
658 }
659 }
660
661 obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val),__extension__ ({ struct obstack *__o = (&dont_print_statmem_obstack
); int __len = (sizeof (CORE_ADDR)); if (__o->next_free + __len
> __o->chunk_limit) _obstack_newchunk (__o, __len); memcpy
((__o->next_free), (((char *) &(val)->location.address
)), (__len)); __o->next_free += __len; (void) 0; })
662 sizeof (CORE_ADDR))__extension__ ({ struct obstack *__o = (&dont_print_statmem_obstack
); int __len = (sizeof (CORE_ADDR)); if (__o->next_free + __len
> __o->chunk_limit) _obstack_newchunk (__o, __len); memcpy
((__o->next_free), (((char *) &(val)->location.address
)), (__len)); __o->next_free += __len; (void) 0; })
;
663
664 CHECK_TYPEDEF (type)(type) = check_typedef (type);
665 cp_print_value_fields (type, type, VALUE_CONTENTS_ALL (val)((void) ((val)->lazy && value_fetch_lazy(val)), ((
char *) (val)->aligner.contents))
,
666 VALUE_EMBEDDED_OFFSET (val)((val)->embedded_offset), VALUE_ADDRESS (val)(val)->location.address,
667 stream, format, recurse, pretty, NULL((void*)0), 1);
668 return;
669 }
670 val_print (type, VALUE_CONTENTS_ALL (val)((void) ((val)->lazy && value_fetch_lazy(val)), ((
char *) (val)->aligner.contents))
,
671 VALUE_EMBEDDED_OFFSET (val)((val)->embedded_offset), VALUE_ADDRESS (val)(val)->location.address,
672 stream, format, 0, recurse, pretty);
673}
674
675void
676cp_print_class_member (char *valaddr, struct type *domain,
677 struct ui_file *stream, char *prefix)
678{
679
680 /* VAL is a byte offset into the structure type DOMAIN.
681 Find the name of the field for that offset and
682 print it. */
683 int extra = 0;
684 int bits = 0;
685 unsigned int i;
686 unsigned len = TYPE_NFIELDS (domain)(domain)->main_type->nfields;
687
688 /* @@ Make VAL into bit offset */
689
690 /* Note: HP aCC generates offsets that are the real byte offsets added
691 to a constant bias 0x20000000 (1 << 29). This constant bias gets
692 shifted out in the code below -- joyous happenstance! */
693
694 /* Note: HP cfront uses a constant bias of 1; if we support this
695 compiler ever, we will have to adjust the computation below */
696
697 LONGESTlong val = unpack_long (builtin_type_int, valaddr) << 3;
698 for (i = TYPE_N_BASECLASSES (domain)(domain)->main_type->type_specific.cplus_stuff->n_baseclasses; i < len; i++)
699 {
700 int bitpos = TYPE_FIELD_BITPOS (domain, i)(((domain)->main_type->fields[i]).loc.bitpos);
701 QUIT{ if (quit_flag) quit (); if (deprecated_interactive_hook) deprecated_interactive_hook
(); }
;
702 if (val == bitpos)
703 break;
704 if (val < bitpos && i != 0)
705 {
706 /* Somehow pointing into a field. */
707 i -= 1;
708 extra = (val - TYPE_FIELD_BITPOS (domain, i)(((domain)->main_type->fields[i]).loc.bitpos));
709 if (extra & 0x7)
710 bits = 1;
711 else
712 extra >>= 3;
713 break;
714 }
715 }
716 if (i < len)
717 {
718 char *name;
719 fputs_filtered (prefix, stream);
720 name = type_name_no_tag (domain);
721 if (name)
722 fputs_filtered (name, stream);
723 else
724 c_type_print_base (domain, stream, 0, 0);
725 fprintf_filtered (stream, "::");
726 fputs_filtered (TYPE_FIELD_NAME (domain, i)(((domain)->main_type->fields[i]).name), stream);
727 if (extra)
728 fprintf_filtered (stream, " + %d bytes", extra);
729 if (bits)
730 fprintf_filtered (stream, " (offset in bits)");
731 }
732 else
733 fprintf_filtered (stream, "%ld", (long) (val >> 3));
734}
735
736
737/* This function prints out virtual table entries for a class; it
738 * recurses on the base classes to find all virtual functions
739 * available in a class.
740 *
741 * pai/1997-05-21 Note: As the name suggests, it's currently
742 * implemented for HP aCC runtime only. g++ objects are handled
743 * differently and I have made no attempt to fold that logic in
744 * here. The runtime layout is different for the two cases. Also,
745 * this currently has only the code for non-RRBC layouts generated by
746 * the HP aCC compiler; RRBC code is stubbed out and will have to be
747 * added later. */
748
749
750static void
751cp_print_hpacc_virtual_table_entries (struct type *type, int *vfuncs,
752 struct value *v, struct ui_file *stream,
753 int format, int recurse,
754 enum val_prettyprint pretty)
755{
756 int fn, oi;
757
758 /* pai: FIXME this function doesn't work. It should handle a given
759 * virtual function only once (latest redefinition in class hierarchy)
760 */
761
762 /* Recursion on other classes that can share the same vtable */
763 struct type *pbc = primary_base_class (type);
764 if (pbc)
765 cp_print_hpacc_virtual_table_entries (pbc, vfuncs, v, stream, format,
766 recurse, pretty);
767
768 /* Now deal with vfuncs declared in this class */
769 for (fn = 0; fn < TYPE_NFN_FIELDS (type)(type)->main_type->type_specific.cplus_stuff->nfn_fields; fn++)
770 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (type, fn)(type)->main_type->type_specific.cplus_stuff->fn_fieldlists
[fn].length
; oi++)
771 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (type, fn), oi)(((type)->main_type->type_specific.cplus_stuff->fn_fieldlists
[fn].fn_fields)[oi].voffset > 1)
)
772 {
773 char *vf_name;
774 const char *field_physname;
775
776 /* virtual function offset */
777 int vx = (TYPE_FN_FIELD_VOFFSET (TYPE_FN_FIELDLIST1 (type, fn), oi)(((type)->main_type->type_specific.cplus_stuff->fn_fieldlists
[fn].fn_fields)[oi].voffset-2)
778 - 1);
779
780 /* Get the address of the vfunction entry */
781 struct value *vf = value_copy (v);
782 if (VALUE_LAZY (vf)(vf)->lazy)
783 (void) value_fetch_lazy (vf);
784 /* adjust by offset */
785 vf->aligner.contents[0] += 4 * (HP_ACC_VFUNC_START4 + vx);
786 vf = value_ind (vf); /* get the entry */
787 VALUE_TYPE (vf)(vf)->type = VALUE_TYPE (v)(v)->type; /* make it a pointer */
788
789 /* print out the entry */
790 val_print (VALUE_TYPE (vf)(vf)->type, VALUE_CONTENTS (vf)((void)((vf)->lazy && value_fetch_lazy(vf)), ((char
*) (vf)->aligner.contents + (vf)->embedded_offset))
, 0, 0,
791 stream, format, 0, recurse + 1, pretty);
792 field_physname
793 = TYPE_FN_FIELD_PHYSNAME (TYPE_FN_FIELDLIST1 (type, fn), oi)((type)->main_type->type_specific.cplus_stuff->fn_fieldlists
[fn].fn_fields)[oi].physname
;
794 /* pai: (temp) FIXME Maybe this should be DMGL_ANSI */
795 vf_name = cplus_demangle (field_physname, DMGL_ARM(1 << 11));
796 fprintf_filtered (stream, " %s", vf_name);
797 if (--(*vfuncs) > 0)
798 fputs_filtered (", ", stream);
799 }
800}
801
802
803
804void
805_initialize_cp_valprint (void)
806{
807 deprecated_add_show_from_set
808 (add_set_cmd ("static-members", class_support, var_boolean,
809 (char *) &static_field_print,
810 "Set printing of C++ static members.",
811 &setprintlist),
812 &showprintlist);
813 /* Turn on printing of static fields. */
814 static_field_print = 1;
815
816 deprecated_add_show_from_set
817 (add_set_cmd ("vtbl", class_support, var_boolean, (char *) &vtblprint,
818 "Set printing of C++ virtual function tables.",
819 &setprintlist),
820 &showprintlist);
821
822 deprecated_add_show_from_set
823 (add_set_cmd ("object", class_support, var_boolean, (char *) &objectprint,
824 "Set printing of object's derived type based on vtable info.",
825 &setprintlist),
826 &showprintlist);
827
828 /* Give people the defaults which they are used to. */
829 objectprint = 0;
830 vtblprint = 0;
831 obstack_begin (&dont_print_vb_obstack, 32 * sizeof (struct type *))_obstack_begin ((&dont_print_vb_obstack), (32 * sizeof (struct
type *)), 0, (void *(*) (long)) xmalloc, (void (*) (void *))
xfree)
;
832 obstack_specify_allocation (&dont_print_statmem_obstack,_obstack_begin ((&dont_print_statmem_obstack), (32 * sizeof
(CORE_ADDR)), (sizeof (CORE_ADDR)), (void *(*) (long)) (xmalloc
), (void (*) (void *)) (xfree))
833 32 * sizeof (CORE_ADDR), sizeof (CORE_ADDR),_obstack_begin ((&dont_print_statmem_obstack), (32 * sizeof
(CORE_ADDR)), (sizeof (CORE_ADDR)), (void *(*) (long)) (xmalloc
), (void (*) (void *)) (xfree))
834 xmalloc, xfree)_obstack_begin ((&dont_print_statmem_obstack), (32 * sizeof
(CORE_ADDR)), (sizeof (CORE_ADDR)), (void *(*) (long)) (xmalloc
), (void (*) (void *)) (xfree))
;
835}