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