Commit | Line | Data |
---|---|---|
373a8247 | 1 | /* Support for printing Pascal values for GDB, the GNU debugger. |
5bcca90b | 2 | |
0b302171 JB |
3 | Copyright (C) 2000-2001, 2003, 2005-2012 Free Software Foundation, |
4 | Inc. | |
373a8247 PM |
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
373a8247 PM |
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 | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
373a8247 PM |
20 | |
21 | /* This file is derived from c-valprint.c */ | |
22 | ||
23 | #include "defs.h" | |
04ea0df1 | 24 | #include "gdb_obstack.h" |
373a8247 PM |
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 "gdbcore.h" | |
32 | #include "demangle.h" | |
33 | #include "valprint.h" | |
3172dc30 | 34 | #include "typeprint.h" |
373a8247 PM |
35 | #include "language.h" |
36 | #include "target.h" | |
37 | #include "annotate.h" | |
38 | #include "p-lang.h" | |
eb43544b | 39 | #include "cp-abi.h" |
d3cbe7ef | 40 | #include "cp-support.h" |
8af8e3bc | 41 | #include "exceptions.h" |
373a8247 PM |
42 | \f |
43 | ||
e88acd96 TT |
44 | /* Decorations for Pascal. */ |
45 | ||
46 | static const struct generic_val_print_decorations p_decorations = | |
47 | { | |
48 | "", | |
49 | " + ", | |
50 | " * I", | |
51 | "true", | |
52 | "false", | |
53 | "void" | |
54 | }; | |
55 | ||
32b72a42 | 56 | /* See val_print for a description of the various parameters of this |
d3eab38a | 57 | function; they are identical. */ |
373a8247 | 58 | |
d3eab38a | 59 | void |
fc1a4b47 | 60 | pascal_val_print (struct type *type, const gdb_byte *valaddr, |
a2bd3dcd | 61 | int embedded_offset, CORE_ADDR address, |
79a45b7d | 62 | struct ui_file *stream, int recurse, |
0e03807e | 63 | const struct value *original_value, |
79a45b7d | 64 | const struct value_print_options *options) |
373a8247 | 65 | { |
5af949e3 | 66 | struct gdbarch *gdbarch = get_type_arch (type); |
e17a4113 | 67 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
52f0bd74 | 68 | unsigned int i = 0; /* Number of characters printed */ |
373a8247 | 69 | unsigned len; |
df178451 | 70 | LONGEST low_bound, high_bound; |
373a8247 PM |
71 | struct type *elttype; |
72 | unsigned eltlen; | |
5598ce11 | 73 | int length_pos, length_size, string_pos; |
6c7a06a3 | 74 | struct type *char_type; |
373a8247 PM |
75 | LONGEST val; |
76 | CORE_ADDR addr; | |
b012acdd | 77 | int want_space = 0; |
373a8247 PM |
78 | |
79 | CHECK_TYPEDEF (type); | |
80 | switch (TYPE_CODE (type)) | |
81 | { | |
82 | case TYPE_CODE_ARRAY: | |
6ced1581 | 83 | if (get_array_bounds (type, &low_bound, &high_bound)) |
373a8247 | 84 | { |
8148cf8d | 85 | len = high_bound - low_bound + 1; |
373a8247 PM |
86 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); |
87 | eltlen = TYPE_LENGTH (elttype); | |
79a45b7d | 88 | if (options->prettyprint_arrays) |
373a8247 PM |
89 | { |
90 | print_spaces_filtered (2 + 2 * recurse, stream); | |
91 | } | |
6e354e5e PM |
92 | /* If 's' format is used, try to print out as string. |
93 | If no format is given, print as string if element type | |
94 | is of TYPE_CODE_CHAR and element size is 1,2 or 4. */ | |
95 | if (options->format == 's' | |
96 | || ((eltlen == 1 || eltlen == 2 || eltlen == 4) | |
97 | && TYPE_CODE (elttype) == TYPE_CODE_CHAR | |
98 | && options->format == 0)) | |
373a8247 PM |
99 | { |
100 | /* If requested, look for the first null char and only print | |
101 | elements up to it. */ | |
79a45b7d | 102 | if (options->stop_print_at_null) |
373a8247 PM |
103 | { |
104 | unsigned int temp_len; | |
105 | ||
0df8b418 | 106 | /* Look for a NULL char. */ |
373a8247 | 107 | for (temp_len = 0; |
58159490 | 108 | extract_unsigned_integer (valaddr + embedded_offset + |
e17a4113 UW |
109 | temp_len * eltlen, eltlen, |
110 | byte_order) | |
79a45b7d | 111 | && temp_len < len && temp_len < options->print_max; |
373a8247 PM |
112 | temp_len++); |
113 | len = temp_len; | |
114 | } | |
115 | ||
6c7a06a3 | 116 | LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), |
be759fcf | 117 | valaddr + embedded_offset, len, NULL, 0, |
6c7a06a3 | 118 | options); |
373a8247 PM |
119 | i = len; |
120 | } | |
121 | else | |
122 | { | |
123 | fprintf_filtered (stream, "{"); | |
124 | /* If this is a virtual function table, print the 0th | |
125 | entry specially, and the rest of the members normally. */ | |
126 | if (pascal_object_is_vtbl_ptr_type (elttype)) | |
127 | { | |
128 | i = 1; | |
129 | fprintf_filtered (stream, "%d vtable entries", len - 1); | |
130 | } | |
131 | else | |
132 | { | |
133 | i = 0; | |
134 | } | |
490f124f | 135 | val_print_array_elements (type, valaddr, embedded_offset, |
3e43a32a MS |
136 | address, stream, recurse, |
137 | original_value, options, i); | |
373a8247 PM |
138 | fprintf_filtered (stream, "}"); |
139 | } | |
140 | break; | |
141 | } | |
142 | /* Array of unspecified length: treat like pointer to first elt. */ | |
13163d80 | 143 | addr = address + embedded_offset; |
373a8247 PM |
144 | goto print_unpacked_pointer; |
145 | ||
146 | case TYPE_CODE_PTR: | |
79a45b7d | 147 | if (options->format && options->format != 's') |
373a8247 | 148 | { |
ab2188aa PA |
149 | val_print_scalar_formatted (type, valaddr, embedded_offset, |
150 | original_value, options, 0, stream); | |
373a8247 PM |
151 | break; |
152 | } | |
79a45b7d | 153 | if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) |
373a8247 PM |
154 | { |
155 | /* Print the unmangled name if desired. */ | |
156 | /* Print vtable entry - we only get here if we ARE using | |
0df8b418 | 157 | -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ |
b276f1bb | 158 | /* Extract the address, assume that it is unsigned. */ |
e17a4113 UW |
159 | addr = extract_unsigned_integer (valaddr + embedded_offset, |
160 | TYPE_LENGTH (type), byte_order); | |
edf0c1b7 | 161 | print_address_demangle (options, gdbarch, addr, stream, demangle); |
373a8247 PM |
162 | break; |
163 | } | |
91e8df85 | 164 | check_typedef (TYPE_TARGET_TYPE (type)); |
e13eedd5 PM |
165 | |
166 | addr = unpack_pointer (type, valaddr + embedded_offset); | |
167 | print_unpacked_pointer: | |
168 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
169 | ||
170 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
373a8247 | 171 | { |
e13eedd5 | 172 | /* Try to print what function it points to. */ |
edf0c1b7 | 173 | print_address_demangle (options, gdbarch, addr, stream, demangle); |
d3eab38a | 174 | return; |
e13eedd5 | 175 | } |
373a8247 | 176 | |
e13eedd5 PM |
177 | if (options->addressprint && options->format != 's') |
178 | { | |
179 | fputs_filtered (paddress (gdbarch, addr), stream); | |
b012acdd | 180 | want_space = 1; |
e13eedd5 | 181 | } |
373a8247 | 182 | |
e13eedd5 PM |
183 | /* For a pointer to char or unsigned char, also print the string |
184 | pointed to, unless pointer is null. */ | |
185 | if (((TYPE_LENGTH (elttype) == 1 | |
186 | && (TYPE_CODE (elttype) == TYPE_CODE_INT | |
187 | || TYPE_CODE (elttype) == TYPE_CODE_CHAR)) | |
188 | || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4) | |
189 | && TYPE_CODE (elttype) == TYPE_CODE_CHAR)) | |
190 | && (options->format == 0 || options->format == 's') | |
191 | && addr != 0) | |
192 | { | |
b012acdd TT |
193 | if (want_space) |
194 | fputs_filtered (" ", stream); | |
0df8b418 | 195 | /* No wide string yet. */ |
09ca9e2e | 196 | i = val_print_string (elttype, NULL, addr, -1, stream, options); |
e13eedd5 | 197 | } |
0df8b418 | 198 | /* Also for pointers to pascal strings. */ |
e13eedd5 PM |
199 | /* Note: this is Free Pascal specific: |
200 | as GDB does not recognize stabs pascal strings | |
201 | Pascal strings are mapped to records | |
0df8b418 | 202 | with lowercase names PM. */ |
e13eedd5 PM |
203 | if (is_pascal_string_type (elttype, &length_pos, &length_size, |
204 | &string_pos, &char_type, NULL) | |
205 | && addr != 0) | |
206 | { | |
207 | ULONGEST string_length; | |
208 | void *buffer; | |
ad3bbd48 | 209 | |
b012acdd TT |
210 | if (want_space) |
211 | fputs_filtered (" ", stream); | |
e13eedd5 PM |
212 | buffer = xmalloc (length_size); |
213 | read_memory (addr + length_pos, buffer, length_size); | |
214 | string_length = extract_unsigned_integer (buffer, length_size, | |
215 | byte_order); | |
216 | xfree (buffer); | |
09ca9e2e TT |
217 | i = val_print_string (char_type, NULL, |
218 | addr + string_pos, string_length, | |
219 | stream, options); | |
e13eedd5 PM |
220 | } |
221 | else if (pascal_object_is_vtbl_member (type)) | |
222 | { | |
0df8b418 | 223 | /* Print vtbl's nicely. */ |
3e43a32a MS |
224 | CORE_ADDR vt_address = unpack_pointer (type, |
225 | valaddr + embedded_offset); | |
e13eedd5 | 226 | struct minimal_symbol *msymbol = |
ad3bbd48 MS |
227 | lookup_minimal_symbol_by_pc (vt_address); |
228 | ||
e13eedd5 PM |
229 | if ((msymbol != NULL) |
230 | && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol))) | |
373a8247 | 231 | { |
b012acdd TT |
232 | if (want_space) |
233 | fputs_filtered (" ", stream); | |
234 | fputs_filtered ("<", stream); | |
e13eedd5 PM |
235 | fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); |
236 | fputs_filtered (">", stream); | |
b012acdd | 237 | want_space = 1; |
373a8247 | 238 | } |
e13eedd5 | 239 | if (vt_address && options->vtblprint) |
373a8247 | 240 | { |
e13eedd5 PM |
241 | struct value *vt_val; |
242 | struct symbol *wsym = (struct symbol *) NULL; | |
243 | struct type *wtype; | |
244 | struct block *block = (struct block *) NULL; | |
245 | int is_this_fld; | |
373a8247 | 246 | |
b012acdd TT |
247 | if (want_space) |
248 | fputs_filtered (" ", stream); | |
249 | ||
e13eedd5 PM |
250 | if (msymbol != NULL) |
251 | wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block, | |
252 | VAR_DOMAIN, &is_this_fld); | |
253 | ||
254 | if (wsym) | |
373a8247 | 255 | { |
e13eedd5 | 256 | wtype = SYMBOL_TYPE (wsym); |
373a8247 | 257 | } |
e13eedd5 | 258 | else |
373a8247 | 259 | { |
e13eedd5 PM |
260 | wtype = TYPE_TARGET_TYPE (type); |
261 | } | |
262 | vt_val = value_at (wtype, vt_address); | |
263 | common_val_print (vt_val, stream, recurse + 1, options, | |
264 | current_language); | |
265 | if (options->pretty) | |
266 | { | |
267 | fprintf_filtered (stream, "\n"); | |
268 | print_spaces_filtered (2 + 2 * recurse, stream); | |
373a8247 PM |
269 | } |
270 | } | |
373a8247 | 271 | } |
e13eedd5 | 272 | |
d3eab38a | 273 | return; |
373a8247 | 274 | |
373a8247 | 275 | case TYPE_CODE_REF: |
e88acd96 TT |
276 | case TYPE_CODE_ENUM: |
277 | case TYPE_CODE_FLAGS: | |
278 | case TYPE_CODE_FUNC: | |
279 | case TYPE_CODE_RANGE: | |
280 | case TYPE_CODE_INT: | |
281 | case TYPE_CODE_FLT: | |
282 | case TYPE_CODE_VOID: | |
283 | case TYPE_CODE_ERROR: | |
284 | case TYPE_CODE_UNDEF: | |
285 | case TYPE_CODE_BOOL: | |
286 | case TYPE_CODE_CHAR: | |
287 | generic_val_print (type, valaddr, embedded_offset, address, | |
288 | stream, recurse, original_value, options, | |
289 | &p_decorations); | |
373a8247 PM |
290 | break; |
291 | ||
292 | case TYPE_CODE_UNION: | |
79a45b7d | 293 | if (recurse && !options->unionprint) |
373a8247 PM |
294 | { |
295 | fprintf_filtered (stream, "{...}"); | |
296 | break; | |
297 | } | |
298 | /* Fall through. */ | |
299 | case TYPE_CODE_STRUCT: | |
79a45b7d | 300 | if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) |
373a8247 PM |
301 | { |
302 | /* Print the unmangled name if desired. */ | |
303 | /* Print vtable entry - we only get here if NOT using | |
0df8b418 | 304 | -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */ |
b276f1bb AC |
305 | /* Extract the address, assume that it is unsigned. */ |
306 | print_address_demangle | |
edf0c1b7 | 307 | (options, gdbarch, |
3e43a32a MS |
308 | extract_unsigned_integer (valaddr + embedded_offset |
309 | + TYPE_FIELD_BITPOS (type, | |
310 | VTBL_FNADDR_OFFSET) / 8, | |
311 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, | |
312 | VTBL_FNADDR_OFFSET)), | |
313 | byte_order), | |
b276f1bb | 314 | stream, demangle); |
373a8247 PM |
315 | } |
316 | else | |
317 | { | |
5598ce11 | 318 | if (is_pascal_string_type (type, &length_pos, &length_size, |
6c7a06a3 | 319 | &string_pos, &char_type, NULL)) |
373a8247 | 320 | { |
3e43a32a MS |
321 | len = extract_unsigned_integer (valaddr + embedded_offset |
322 | + length_pos, length_size, | |
323 | byte_order); | |
6ced1581 | 324 | LA_PRINT_STRING (stream, char_type, |
be759fcf PM |
325 | valaddr + embedded_offset + string_pos, |
326 | len, NULL, 0, options); | |
373a8247 PM |
327 | } |
328 | else | |
490f124f | 329 | pascal_object_print_value_fields (type, valaddr, embedded_offset, |
3e43a32a MS |
330 | address, stream, recurse, |
331 | original_value, options, | |
332 | NULL, 0); | |
373a8247 PM |
333 | } |
334 | break; | |
335 | ||
373a8247 PM |
336 | case TYPE_CODE_BITSTRING: |
337 | case TYPE_CODE_SET: | |
338 | elttype = TYPE_INDEX_TYPE (type); | |
339 | CHECK_TYPEDEF (elttype); | |
74a9bb82 | 340 | if (TYPE_STUB (elttype)) |
373a8247 PM |
341 | { |
342 | fprintf_filtered (stream, "<incomplete type>"); | |
343 | gdb_flush (stream); | |
344 | break; | |
345 | } | |
346 | else | |
347 | { | |
348 | struct type *range = elttype; | |
349 | LONGEST low_bound, high_bound; | |
350 | int i; | |
351 | int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING; | |
352 | int need_comma = 0; | |
353 | ||
354 | if (is_bitstring) | |
355 | fputs_filtered ("B'", stream); | |
356 | else | |
357 | fputs_filtered ("[", stream); | |
358 | ||
359 | i = get_discrete_bounds (range, &low_bound, &high_bound); | |
7a081a30 PM |
360 | if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0) |
361 | { | |
362 | /* If we know the size of the set type, we can figure out the | |
363 | maximum value. */ | |
364 | i = 0; | |
365 | high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1; | |
366 | TYPE_HIGH_BOUND (range) = high_bound; | |
367 | } | |
373a8247 PM |
368 | maybe_bad_bstring: |
369 | if (i < 0) | |
370 | { | |
371 | fputs_filtered ("<error value>", stream); | |
372 | goto done; | |
373 | } | |
374 | ||
375 | for (i = low_bound; i <= high_bound; i++) | |
376 | { | |
3e43a32a MS |
377 | int element = value_bit_index (type, |
378 | valaddr + embedded_offset, i); | |
ad3bbd48 | 379 | |
373a8247 PM |
380 | if (element < 0) |
381 | { | |
382 | i = element; | |
383 | goto maybe_bad_bstring; | |
384 | } | |
385 | if (is_bitstring) | |
386 | fprintf_filtered (stream, "%d", element); | |
387 | else if (element) | |
388 | { | |
389 | if (need_comma) | |
390 | fputs_filtered (", ", stream); | |
391 | print_type_scalar (range, i, stream); | |
392 | need_comma = 1; | |
393 | ||
3e43a32a MS |
394 | if (i + 1 <= high_bound |
395 | && value_bit_index (type, | |
396 | valaddr + embedded_offset, ++i)) | |
373a8247 PM |
397 | { |
398 | int j = i; | |
ad3bbd48 | 399 | |
373a8247 PM |
400 | fputs_filtered ("..", stream); |
401 | while (i + 1 <= high_bound | |
3e43a32a MS |
402 | && value_bit_index (type, |
403 | valaddr + embedded_offset, | |
404 | ++i)) | |
373a8247 PM |
405 | j = i; |
406 | print_type_scalar (range, j, stream); | |
407 | } | |
408 | } | |
409 | } | |
410 | done: | |
411 | if (is_bitstring) | |
412 | fputs_filtered ("'", stream); | |
413 | else | |
414 | fputs_filtered ("]", stream); | |
415 | } | |
416 | break; | |
417 | ||
373a8247 | 418 | default: |
3e43a32a MS |
419 | error (_("Invalid pascal type code %d in symbol table."), |
420 | TYPE_CODE (type)); | |
373a8247 PM |
421 | } |
422 | gdb_flush (stream); | |
373a8247 PM |
423 | } |
424 | \f | |
8e069a98 | 425 | void |
79a45b7d TT |
426 | pascal_value_print (struct value *val, struct ui_file *stream, |
427 | const struct value_print_options *options) | |
373a8247 | 428 | { |
df407dfe | 429 | struct type *type = value_type (val); |
278582cb PM |
430 | struct value_print_options opts = *options; |
431 | ||
432 | opts.deref_ref = 1; | |
373a8247 PM |
433 | |
434 | /* If it is a pointer, indicate what it points to. | |
435 | ||
436 | Print type also if it is a reference. | |
437 | ||
438 | Object pascal: if it is a member pointer, we will take care | |
439 | of that when we print it. */ | |
b20a3440 PM |
440 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
441 | || TYPE_CODE (type) == TYPE_CODE_REF) | |
373a8247 PM |
442 | { |
443 | /* Hack: remove (char *) for char strings. Their | |
0df8b418 | 444 | type is indicated by the quoted string anyway. */ |
6ced1581 | 445 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
b20a3440 PM |
446 | && TYPE_NAME (type) == NULL |
447 | && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL | |
6314a349 | 448 | && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0) |
373a8247 | 449 | { |
0df8b418 | 450 | /* Print nothing. */ |
373a8247 PM |
451 | } |
452 | else | |
453 | { | |
454 | fprintf_filtered (stream, "("); | |
455 | type_print (type, "", stream, -1); | |
456 | fprintf_filtered (stream, ") "); | |
457 | } | |
458 | } | |
8e069a98 | 459 | common_val_print (val, stream, 0, &opts, current_language); |
373a8247 PM |
460 | } |
461 | ||
462 | ||
920d2a44 AC |
463 | static void |
464 | show_pascal_static_field_print (struct ui_file *file, int from_tty, | |
465 | struct cmd_list_element *c, const char *value) | |
466 | { | |
467 | fprintf_filtered (file, _("Printing of pascal static members is %s.\n"), | |
468 | value); | |
469 | } | |
373a8247 PM |
470 | |
471 | static struct obstack dont_print_vb_obstack; | |
472 | static struct obstack dont_print_statmem_obstack; | |
473 | ||
806048c6 | 474 | static void pascal_object_print_static_field (struct value *, |
79a45b7d TT |
475 | struct ui_file *, int, |
476 | const struct value_print_options *); | |
373a8247 | 477 | |
fc1a4b47 | 478 | static void pascal_object_print_value (struct type *, const gdb_byte *, |
490f124f | 479 | int, |
79a45b7d | 480 | CORE_ADDR, struct ui_file *, int, |
0e03807e | 481 | const struct value *, |
79a45b7d | 482 | const struct value_print_options *, |
a2bd3dcd | 483 | struct type **); |
373a8247 | 484 | |
373a8247 PM |
485 | /* It was changed to this after 2.4.5. */ |
486 | const char pascal_vtbl_ptr_name[] = | |
487 | {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0}; | |
488 | ||
489 | /* Return truth value for assertion that TYPE is of the type | |
490 | "pointer to virtual function". */ | |
491 | ||
492 | int | |
fba45db2 | 493 | pascal_object_is_vtbl_ptr_type (struct type *type) |
373a8247 | 494 | { |
0d5cff50 | 495 | const char *typename = type_name_no_tag (type); |
373a8247 PM |
496 | |
497 | return (typename != NULL | |
6314a349 | 498 | && strcmp (typename, pascal_vtbl_ptr_name) == 0); |
373a8247 PM |
499 | } |
500 | ||
501 | /* Return truth value for the assertion that TYPE is of the type | |
502 | "pointer to virtual function table". */ | |
503 | ||
504 | int | |
fba45db2 | 505 | pascal_object_is_vtbl_member (struct type *type) |
373a8247 PM |
506 | { |
507 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
508 | { | |
509 | type = TYPE_TARGET_TYPE (type); | |
510 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
511 | { | |
512 | type = TYPE_TARGET_TYPE (type); | |
0df8b418 MS |
513 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* If not using |
514 | thunks. */ | |
515 | || TYPE_CODE (type) == TYPE_CODE_PTR) /* If using thunks. */ | |
373a8247 PM |
516 | { |
517 | /* Virtual functions tables are full of pointers | |
0df8b418 | 518 | to virtual functions. */ |
373a8247 PM |
519 | return pascal_object_is_vtbl_ptr_type (type); |
520 | } | |
521 | } | |
522 | } | |
523 | return 0; | |
524 | } | |
525 | ||
a2bd3dcd AC |
526 | /* Mutually recursive subroutines of pascal_object_print_value and |
527 | c_val_print to print out a structure's fields: | |
528 | pascal_object_print_value_fields and pascal_object_print_value. | |
373a8247 | 529 | |
79a45b7d | 530 | TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the |
373a8247 PM |
531 | same meanings as in pascal_object_print_value and c_val_print. |
532 | ||
533 | DONT_PRINT is an array of baseclass types that we | |
534 | should not print, or zero if called from top level. */ | |
535 | ||
536 | void | |
fc1a4b47 | 537 | pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, |
490f124f | 538 | int offset, |
fba45db2 | 539 | CORE_ADDR address, struct ui_file *stream, |
79a45b7d | 540 | int recurse, |
0e03807e | 541 | const struct value *val, |
79a45b7d | 542 | const struct value_print_options *options, |
fba45db2 KB |
543 | struct type **dont_print_vb, |
544 | int dont_print_statmem) | |
373a8247 PM |
545 | { |
546 | int i, len, n_baseclasses; | |
373a8247 PM |
547 | char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack); |
548 | ||
549 | CHECK_TYPEDEF (type); | |
550 | ||
551 | fprintf_filtered (stream, "{"); | |
552 | len = TYPE_NFIELDS (type); | |
553 | n_baseclasses = TYPE_N_BASECLASSES (type); | |
554 | ||
555 | /* Print out baseclasses such that we don't print | |
556 | duplicates of virtual baseclasses. */ | |
557 | if (n_baseclasses > 0) | |
490f124f PA |
558 | pascal_object_print_value (type, valaddr, offset, address, |
559 | stream, recurse + 1, val, | |
560 | options, dont_print_vb); | |
373a8247 PM |
561 | |
562 | if (!len && n_baseclasses == 1) | |
563 | fprintf_filtered (stream, "<No data fields>"); | |
564 | else | |
565 | { | |
c1b6e682 | 566 | struct obstack tmp_obstack = dont_print_statmem_obstack; |
373a8247 PM |
567 | int fields_seen = 0; |
568 | ||
569 | if (dont_print_statmem == 0) | |
570 | { | |
571 | /* If we're at top level, carve out a completely fresh | |
572 | chunk of the obstack and use that until this particular | |
573 | invocation returns. */ | |
373a8247 PM |
574 | obstack_finish (&dont_print_statmem_obstack); |
575 | } | |
576 | ||
577 | for (i = n_baseclasses; i < len; i++) | |
578 | { | |
579 | /* If requested, skip printing of static fields. */ | |
79a45b7d | 580 | if (!options->pascal_static_field_print |
d6a843b5 | 581 | && field_is_static (&TYPE_FIELD (type, i))) |
373a8247 PM |
582 | continue; |
583 | if (fields_seen) | |
584 | fprintf_filtered (stream, ", "); | |
585 | else if (n_baseclasses > 0) | |
586 | { | |
79a45b7d | 587 | if (options->pretty) |
373a8247 PM |
588 | { |
589 | fprintf_filtered (stream, "\n"); | |
590 | print_spaces_filtered (2 + 2 * recurse, stream); | |
591 | fputs_filtered ("members of ", stream); | |
592 | fputs_filtered (type_name_no_tag (type), stream); | |
593 | fputs_filtered (": ", stream); | |
594 | } | |
595 | } | |
596 | fields_seen = 1; | |
597 | ||
79a45b7d | 598 | if (options->pretty) |
373a8247 PM |
599 | { |
600 | fprintf_filtered (stream, "\n"); | |
601 | print_spaces_filtered (2 + 2 * recurse, stream); | |
602 | } | |
603 | else | |
604 | { | |
605 | wrap_here (n_spaces (2 + 2 * recurse)); | |
606 | } | |
79a45b7d | 607 | if (options->inspect_it) |
373a8247 PM |
608 | { |
609 | if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) | |
610 | fputs_filtered ("\"( ptr \"", stream); | |
611 | else | |
612 | fputs_filtered ("\"( nodef \"", stream); | |
d6a843b5 | 613 | if (field_is_static (&TYPE_FIELD (type, i))) |
373a8247 PM |
614 | fputs_filtered ("static ", stream); |
615 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
616 | language_cplus, | |
617 | DMGL_PARAMS | DMGL_ANSI); | |
618 | fputs_filtered ("\" \"", stream); | |
619 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
620 | language_cplus, | |
621 | DMGL_PARAMS | DMGL_ANSI); | |
622 | fputs_filtered ("\") \"", stream); | |
623 | } | |
624 | else | |
625 | { | |
626 | annotate_field_begin (TYPE_FIELD_TYPE (type, i)); | |
627 | ||
d6a843b5 | 628 | if (field_is_static (&TYPE_FIELD (type, i))) |
373a8247 PM |
629 | fputs_filtered ("static ", stream); |
630 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
631 | language_cplus, | |
632 | DMGL_PARAMS | DMGL_ANSI); | |
633 | annotate_field_name_end (); | |
634 | fputs_filtered (" = ", stream); | |
635 | annotate_field_value (); | |
636 | } | |
637 | ||
d6a843b5 JK |
638 | if (!field_is_static (&TYPE_FIELD (type, i)) |
639 | && TYPE_FIELD_PACKED (type, i)) | |
373a8247 | 640 | { |
6943961c | 641 | struct value *v; |
373a8247 PM |
642 | |
643 | /* Bitfields require special handling, especially due to byte | |
644 | order problems. */ | |
645 | if (TYPE_FIELD_IGNORE (type, i)) | |
646 | { | |
647 | fputs_filtered ("<optimized out or zero length>", stream); | |
648 | } | |
8cf6f0b1 TT |
649 | else if (value_bits_synthetic_pointer (val, |
650 | TYPE_FIELD_BITPOS (type, | |
651 | i), | |
652 | TYPE_FIELD_BITSIZE (type, | |
653 | i))) | |
654 | { | |
655 | fputs_filtered (_("<synthetic pointer>"), stream); | |
656 | } | |
0e03807e TT |
657 | else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i), |
658 | TYPE_FIELD_BITSIZE (type, i))) | |
659 | { | |
585fdaa1 | 660 | val_print_optimized_out (stream); |
0e03807e | 661 | } |
373a8247 PM |
662 | else |
663 | { | |
79a45b7d | 664 | struct value_print_options opts = *options; |
ad3bbd48 | 665 | |
5467c6c8 | 666 | v = value_field_bitfield (type, i, valaddr, offset, val); |
373a8247 | 667 | |
79a45b7d TT |
668 | opts.deref_ref = 0; |
669 | common_val_print (v, stream, recurse + 1, &opts, | |
670 | current_language); | |
373a8247 PM |
671 | } |
672 | } | |
673 | else | |
674 | { | |
675 | if (TYPE_FIELD_IGNORE (type, i)) | |
676 | { | |
677 | fputs_filtered ("<optimized out or zero length>", stream); | |
678 | } | |
d6a843b5 | 679 | else if (field_is_static (&TYPE_FIELD (type, i))) |
373a8247 | 680 | { |
3e43a32a | 681 | /* struct value *v = value_static_field (type, i); |
0df8b418 | 682 | v4.17 specific. */ |
6943961c | 683 | struct value *v; |
ad3bbd48 | 684 | |
5467c6c8 | 685 | v = value_field_bitfield (type, i, valaddr, offset, val); |
373a8247 PM |
686 | |
687 | if (v == NULL) | |
585fdaa1 | 688 | val_print_optimized_out (stream); |
373a8247 | 689 | else |
79a45b7d TT |
690 | pascal_object_print_static_field (v, stream, recurse + 1, |
691 | options); | |
373a8247 PM |
692 | } |
693 | else | |
694 | { | |
79a45b7d | 695 | struct value_print_options opts = *options; |
ad3bbd48 | 696 | |
79a45b7d | 697 | opts.deref_ref = 0; |
373a8247 PM |
698 | /* val_print (TYPE_FIELD_TYPE (type, i), |
699 | valaddr + TYPE_FIELD_BITPOS (type, i) / 8, | |
700 | address + TYPE_FIELD_BITPOS (type, i) / 8, 0, | |
701 | stream, format, 0, recurse + 1, pretty); */ | |
702 | val_print (TYPE_FIELD_TYPE (type, i), | |
490f124f PA |
703 | valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8, |
704 | address, stream, recurse + 1, val, &opts, | |
d8ca156b | 705 | current_language); |
373a8247 PM |
706 | } |
707 | } | |
708 | annotate_field_end (); | |
709 | } | |
710 | ||
711 | if (dont_print_statmem == 0) | |
712 | { | |
713 | /* Free the space used to deal with the printing | |
714 | of the members from top level. */ | |
715 | obstack_free (&dont_print_statmem_obstack, last_dont_print); | |
716 | dont_print_statmem_obstack = tmp_obstack; | |
717 | } | |
718 | ||
79a45b7d | 719 | if (options->pretty) |
373a8247 PM |
720 | { |
721 | fprintf_filtered (stream, "\n"); | |
722 | print_spaces_filtered (2 * recurse, stream); | |
723 | } | |
724 | } | |
725 | fprintf_filtered (stream, "}"); | |
726 | } | |
727 | ||
728 | /* Special val_print routine to avoid printing multiple copies of virtual | |
729 | baseclasses. */ | |
730 | ||
7080f20f | 731 | static void |
fc1a4b47 | 732 | pascal_object_print_value (struct type *type, const gdb_byte *valaddr, |
490f124f | 733 | int offset, |
a2bd3dcd | 734 | CORE_ADDR address, struct ui_file *stream, |
79a45b7d | 735 | int recurse, |
0e03807e | 736 | const struct value *val, |
79a45b7d | 737 | const struct value_print_options *options, |
fba45db2 | 738 | struct type **dont_print_vb) |
373a8247 | 739 | { |
373a8247 | 740 | struct type **last_dont_print |
ad3bbd48 | 741 | = (struct type **) obstack_next_free (&dont_print_vb_obstack); |
c1b6e682 | 742 | struct obstack tmp_obstack = dont_print_vb_obstack; |
373a8247 PM |
743 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); |
744 | ||
745 | if (dont_print_vb == 0) | |
746 | { | |
747 | /* If we're at top level, carve out a completely fresh | |
748 | chunk of the obstack and use that until this particular | |
749 | invocation returns. */ | |
373a8247 PM |
750 | /* Bump up the high-water mark. Now alpha is omega. */ |
751 | obstack_finish (&dont_print_vb_obstack); | |
752 | } | |
753 | ||
754 | for (i = 0; i < n_baseclasses; i++) | |
755 | { | |
8af8e3bc | 756 | int boffset = 0; |
373a8247 | 757 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); |
0d5cff50 | 758 | const char *basename = type_name_no_tag (baseclass); |
8af8e3bc | 759 | const gdb_byte *base_valaddr = NULL; |
490f124f | 760 | int thisoffset; |
8af8e3bc PA |
761 | volatile struct gdb_exception ex; |
762 | int skip = 0; | |
373a8247 PM |
763 | |
764 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
765 | { | |
766 | struct type **first_dont_print | |
ad3bbd48 | 767 | = (struct type **) obstack_base (&dont_print_vb_obstack); |
373a8247 PM |
768 | |
769 | int j = (struct type **) obstack_next_free (&dont_print_vb_obstack) | |
ad3bbd48 | 770 | - first_dont_print; |
373a8247 PM |
771 | |
772 | while (--j >= 0) | |
773 | if (baseclass == first_dont_print[j]) | |
774 | goto flush_it; | |
775 | ||
776 | obstack_ptr_grow (&dont_print_vb_obstack, baseclass); | |
777 | } | |
778 | ||
490f124f PA |
779 | thisoffset = offset; |
780 | ||
8af8e3bc PA |
781 | TRY_CATCH (ex, RETURN_MASK_ERROR) |
782 | { | |
783 | boffset = baseclass_offset (type, i, valaddr, offset, address, val); | |
784 | } | |
785 | if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR) | |
786 | skip = -1; | |
787 | else if (ex.reason < 0) | |
788 | skip = 1; | |
789 | else | |
790 | { | |
791 | skip = 0; | |
792 | ||
793 | /* The virtual base class pointer might have been clobbered by the | |
794 | user program. Make sure that it still points to a valid memory | |
795 | location. */ | |
796 | ||
797 | if (boffset < 0 || boffset >= TYPE_LENGTH (type)) | |
798 | { | |
799 | /* FIXME (alloc): not safe is baseclass is really really big. */ | |
800 | gdb_byte *buf = alloca (TYPE_LENGTH (baseclass)); | |
801 | ||
802 | base_valaddr = buf; | |
803 | if (target_read_memory (address + boffset, buf, | |
804 | TYPE_LENGTH (baseclass)) != 0) | |
805 | skip = 1; | |
806 | address = address + boffset; | |
807 | thisoffset = 0; | |
808 | boffset = 0; | |
809 | } | |
810 | else | |
811 | base_valaddr = valaddr; | |
812 | } | |
373a8247 | 813 | |
79a45b7d | 814 | if (options->pretty) |
373a8247 PM |
815 | { |
816 | fprintf_filtered (stream, "\n"); | |
817 | print_spaces_filtered (2 * recurse, stream); | |
818 | } | |
819 | fputs_filtered ("<", stream); | |
820 | /* Not sure what the best notation is in the case where there is no | |
821 | baseclass name. */ | |
822 | ||
823 | fputs_filtered (basename ? basename : "", stream); | |
824 | fputs_filtered ("> = ", stream); | |
825 | ||
8af8e3bc PA |
826 | if (skip < 0) |
827 | val_print_unavailable (stream); | |
828 | else if (skip > 0) | |
829 | val_print_invalid_address (stream); | |
373a8247 | 830 | else |
3e43a32a | 831 | pascal_object_print_value_fields (baseclass, base_valaddr, |
490f124f PA |
832 | thisoffset + boffset, address, |
833 | stream, recurse, val, options, | |
373a8247 PM |
834 | (struct type **) obstack_base (&dont_print_vb_obstack), |
835 | 0); | |
836 | fputs_filtered (", ", stream); | |
837 | ||
838 | flush_it: | |
839 | ; | |
840 | } | |
841 | ||
842 | if (dont_print_vb == 0) | |
843 | { | |
844 | /* Free the space used to deal with the printing | |
845 | of this type from top level. */ | |
846 | obstack_free (&dont_print_vb_obstack, last_dont_print); | |
847 | /* Reset watermark so that we can continue protecting | |
848 | ourselves from whatever we were protecting ourselves. */ | |
849 | dont_print_vb_obstack = tmp_obstack; | |
850 | } | |
851 | } | |
852 | ||
853 | /* Print value of a static member. | |
854 | To avoid infinite recursion when printing a class that contains | |
855 | a static instance of the class, we keep the addresses of all printed | |
856 | static member classes in an obstack and refuse to print them more | |
857 | than once. | |
858 | ||
79a45b7d | 859 | VAL contains the value to print, STREAM, RECURSE, and OPTIONS |
373a8247 PM |
860 | have the same meanings as in c_val_print. */ |
861 | ||
862 | static void | |
806048c6 | 863 | pascal_object_print_static_field (struct value *val, |
79a45b7d TT |
864 | struct ui_file *stream, |
865 | int recurse, | |
866 | const struct value_print_options *options) | |
373a8247 | 867 | { |
806048c6 | 868 | struct type *type = value_type (val); |
79a45b7d | 869 | struct value_print_options opts; |
806048c6 | 870 | |
373a8247 PM |
871 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
872 | { | |
42ae5230 | 873 | CORE_ADDR *first_dont_print, addr; |
373a8247 PM |
874 | int i; |
875 | ||
876 | first_dont_print | |
877 | = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack); | |
878 | i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack) | |
879 | - first_dont_print; | |
880 | ||
881 | while (--i >= 0) | |
882 | { | |
42ae5230 | 883 | if (value_address (val) == first_dont_print[i]) |
373a8247 | 884 | { |
3e43a32a MS |
885 | fputs_filtered ("\ |
886 | <same as static member of an already seen type>", | |
373a8247 PM |
887 | stream); |
888 | return; | |
889 | } | |
890 | } | |
891 | ||
42ae5230 TT |
892 | addr = value_address (val); |
893 | obstack_grow (&dont_print_statmem_obstack, (char *) &addr, | |
373a8247 PM |
894 | sizeof (CORE_ADDR)); |
895 | ||
896 | CHECK_TYPEDEF (type); | |
490f124f PA |
897 | pascal_object_print_value_fields (type, |
898 | value_contents_for_printing (val), | |
899 | value_embedded_offset (val), | |
900 | addr, | |
901 | stream, recurse, | |
902 | val, options, NULL, 1); | |
373a8247 PM |
903 | return; |
904 | } | |
79a45b7d TT |
905 | |
906 | opts = *options; | |
907 | opts.deref_ref = 0; | |
908 | common_val_print (val, stream, recurse, &opts, current_language); | |
373a8247 PM |
909 | } |
910 | ||
3e43a32a MS |
911 | /* -Wmissing-prototypes */ |
912 | extern initialize_file_ftype _initialize_pascal_valprint; | |
373a8247 PM |
913 | |
914 | void | |
fba45db2 | 915 | _initialize_pascal_valprint (void) |
373a8247 | 916 | { |
5bf193a2 | 917 | add_setshow_boolean_cmd ("pascal_static-members", class_support, |
79a45b7d | 918 | &user_print_options.pascal_static_field_print, _("\ |
5bf193a2 AC |
919 | Set printing of pascal static members."), _("\ |
920 | Show printing of pascal static members."), NULL, | |
921 | NULL, | |
920d2a44 | 922 | show_pascal_static_field_print, |
5bf193a2 | 923 | &setprintlist, &showprintlist); |
373a8247 | 924 | } |