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