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