Commit | Line | Data |
---|---|---|
373a8247 | 1 | /* Support for printing Pascal values for GDB, the GNU debugger. |
5bcca90b | 2 | |
b811d2c2 | 3 | Copyright (C) 2000-2020 Free Software Foundation, Inc. |
373a8247 PM |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
373a8247 PM |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
373a8247 PM |
19 | |
20 | /* This file is derived from c-valprint.c */ | |
21 | ||
22 | #include "defs.h" | |
04ea0df1 | 23 | #include "gdb_obstack.h" |
373a8247 PM |
24 | #include "symtab.h" |
25 | #include "gdbtypes.h" | |
26 | #include "expression.h" | |
27 | #include "value.h" | |
28 | #include "command.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "gdbcore.h" | |
31 | #include "demangle.h" | |
32 | #include "valprint.h" | |
3172dc30 | 33 | #include "typeprint.h" |
373a8247 PM |
34 | #include "language.h" |
35 | #include "target.h" | |
36 | #include "annotate.h" | |
37 | #include "p-lang.h" | |
eb43544b | 38 | #include "cp-abi.h" |
d3cbe7ef | 39 | #include "cp-support.h" |
77e371c0 | 40 | #include "objfiles.h" |
268a13a5 | 41 | #include "gdbsupport/byte-vector.h" |
7f6aba03 | 42 | #include "cli/cli-style.h" |
373a8247 PM |
43 | \f |
44 | ||
07a32858 TT |
45 | static void pascal_object_print_value_fields (struct value *, struct ui_file *, |
46 | int, | |
47 | const struct value_print_options *, | |
48 | struct type **, int); | |
49 | ||
e88acd96 TT |
50 | /* Decorations for Pascal. */ |
51 | ||
52 | static const struct generic_val_print_decorations p_decorations = | |
53 | { | |
54 | "", | |
55 | " + ", | |
56 | " * I", | |
57 | "true", | |
58 | "false", | |
00272ec4 TT |
59 | "void", |
60 | "{", | |
61 | "}" | |
e88acd96 TT |
62 | }; |
63 | ||
426a9c18 | 64 | /* See p-lang.h. */ |
373a8247 | 65 | |
d3eab38a | 66 | void |
426a9c18 TT |
67 | pascal_value_print_inner (struct value *val, struct ui_file *stream, |
68 | int recurse, | |
69 | const struct value_print_options *options) | |
70 | ||
373a8247 | 71 | { |
426a9c18 | 72 | struct type *type = check_typedef (value_type (val)); |
5af949e3 | 73 | struct gdbarch *gdbarch = get_type_arch (type); |
34877895 | 74 | enum bfd_endian byte_order = type_byte_order (type); |
52f0bd74 | 75 | unsigned int i = 0; /* Number of characters printed */ |
373a8247 PM |
76 | unsigned len; |
77 | struct type *elttype; | |
78 | unsigned eltlen; | |
5598ce11 | 79 | int length_pos, length_size, string_pos; |
6c7a06a3 | 80 | struct type *char_type; |
373a8247 | 81 | CORE_ADDR addr; |
b012acdd | 82 | int want_space = 0; |
426a9c18 | 83 | const gdb_byte *valaddr = value_contents_for_printing (val); |
373a8247 | 84 | |
78134374 | 85 | switch (type->code ()) |
373a8247 PM |
86 | { |
87 | case TYPE_CODE_ARRAY: | |
b926417a TT |
88 | { |
89 | LONGEST low_bound, high_bound; | |
373a8247 | 90 | |
b926417a TT |
91 | if (get_array_bounds (type, &low_bound, &high_bound)) |
92 | { | |
93 | len = high_bound - low_bound + 1; | |
94 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
95 | eltlen = TYPE_LENGTH (elttype); | |
b926417a TT |
96 | /* If 's' format is used, try to print out as string. |
97 | If no format is given, print as string if element type | |
98 | is of TYPE_CODE_CHAR and element size is 1,2 or 4. */ | |
99 | if (options->format == 's' | |
100 | || ((eltlen == 1 || eltlen == 2 || eltlen == 4) | |
78134374 | 101 | && elttype->code () == TYPE_CODE_CHAR |
b926417a TT |
102 | && options->format == 0)) |
103 | { | |
104 | /* If requested, look for the first null char and only print | |
105 | elements up to it. */ | |
106 | if (options->stop_print_at_null) | |
107 | { | |
108 | unsigned int temp_len; | |
109 | ||
110 | /* Look for a NULL char. */ | |
111 | for (temp_len = 0; | |
426a9c18 TT |
112 | extract_unsigned_integer (valaddr + temp_len * eltlen, |
113 | eltlen, byte_order) | |
b926417a TT |
114 | && temp_len < len && temp_len < options->print_max; |
115 | temp_len++); | |
116 | len = temp_len; | |
117 | } | |
118 | ||
119 | LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), | |
426a9c18 | 120 | valaddr, len, NULL, 0, options); |
b926417a TT |
121 | i = len; |
122 | } | |
123 | else | |
124 | { | |
125 | fprintf_filtered (stream, "{"); | |
126 | /* If this is a virtual function table, print the 0th | |
127 | entry specially, and the rest of the members normally. */ | |
128 | if (pascal_object_is_vtbl_ptr_type (elttype)) | |
129 | { | |
130 | i = 1; | |
131 | fprintf_filtered (stream, "%d vtable entries", len - 1); | |
132 | } | |
133 | else | |
134 | { | |
135 | i = 0; | |
136 | } | |
426a9c18 | 137 | value_print_array_elements (val, stream, recurse, options, i); |
b926417a TT |
138 | fprintf_filtered (stream, "}"); |
139 | } | |
140 | break; | |
141 | } | |
142 | /* Array of unspecified length: treat like pointer to first elt. */ | |
426a9c18 | 143 | addr = value_address (val); |
b926417a | 144 | } |
373a8247 PM |
145 | goto print_unpacked_pointer; |
146 | ||
147 | case TYPE_CODE_PTR: | |
79a45b7d | 148 | if (options->format && options->format != 's') |
373a8247 | 149 | { |
426a9c18 | 150 | value_print_scalar_formatted (val, 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. */ |
426a9c18 | 159 | addr = extract_unsigned_integer (valaddr, |
e17a4113 | 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 | 165 | |
426a9c18 | 166 | addr = unpack_pointer (type, valaddr); |
e13eedd5 PM |
167 | print_unpacked_pointer: |
168 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
169 | ||
78134374 | 170 | if (elttype->code () == 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 | |
78134374 SM |
186 | && (elttype->code () == TYPE_CODE_INT |
187 | || elttype->code () == TYPE_CODE_CHAR)) | |
188 | || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4) | |
189 | && elttype->code () == TYPE_CODE_CHAR)) | |
e13eedd5 PM |
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; | |
7c543f7b | 208 | gdb_byte *buffer; |
ad3bbd48 | 209 | |
b012acdd TT |
210 | if (want_space) |
211 | fputs_filtered (" ", stream); | |
7c543f7b | 212 | buffer = (gdb_byte *) xmalloc (length_size); |
e13eedd5 PM |
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. */ |
426a9c18 | 224 | CORE_ADDR vt_address = unpack_pointer (type, valaddr); |
7cbd4a93 | 225 | struct bound_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 | |
7cbd4a93 | 230 | && (msymbol.minsym != NULL) |
77e371c0 | 231 | && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol))) |
373a8247 | 232 | { |
b012acdd TT |
233 | if (want_space) |
234 | fputs_filtered (" ", stream); | |
235 | fputs_filtered ("<", stream); | |
c9d95fa3 | 236 | fputs_filtered (msymbol.minsym->print_name (), stream); |
e13eedd5 | 237 | fputs_filtered (">", stream); |
b012acdd | 238 | want_space = 1; |
373a8247 | 239 | } |
e13eedd5 | 240 | if (vt_address && options->vtblprint) |
373a8247 | 241 | { |
e13eedd5 | 242 | struct value *vt_val; |
be903358 | 243 | struct symbol *wsym = NULL; |
e13eedd5 | 244 | struct type *wtype; |
373a8247 | 245 | |
b012acdd TT |
246 | if (want_space) |
247 | fputs_filtered (" ", stream); | |
248 | ||
7cbd4a93 | 249 | if (msymbol.minsym != NULL) |
de63c46b | 250 | { |
c9d95fa3 | 251 | const char *search_name = msymbol.minsym->search_name (); |
582942f4 | 252 | wsym = lookup_symbol_search_name (search_name, NULL, |
de63c46b PA |
253 | VAR_DOMAIN).symbol; |
254 | } | |
e13eedd5 PM |
255 | |
256 | if (wsym) | |
373a8247 | 257 | { |
e13eedd5 | 258 | wtype = SYMBOL_TYPE (wsym); |
373a8247 | 259 | } |
e13eedd5 | 260 | else |
373a8247 | 261 | { |
e13eedd5 PM |
262 | wtype = TYPE_TARGET_TYPE (type); |
263 | } | |
264 | vt_val = value_at (wtype, vt_address); | |
265 | common_val_print (vt_val, stream, recurse + 1, options, | |
266 | current_language); | |
2a998fc0 | 267 | if (options->prettyformat) |
e13eedd5 PM |
268 | { |
269 | fprintf_filtered (stream, "\n"); | |
270 | print_spaces_filtered (2 + 2 * recurse, stream); | |
373a8247 PM |
271 | } |
272 | } | |
373a8247 | 273 | } |
e13eedd5 | 274 | |
d3eab38a | 275 | return; |
373a8247 | 276 | |
373a8247 | 277 | case TYPE_CODE_REF: |
e88acd96 TT |
278 | case TYPE_CODE_ENUM: |
279 | case TYPE_CODE_FLAGS: | |
280 | case TYPE_CODE_FUNC: | |
281 | case TYPE_CODE_RANGE: | |
282 | case TYPE_CODE_INT: | |
283 | case TYPE_CODE_FLT: | |
284 | case TYPE_CODE_VOID: | |
285 | case TYPE_CODE_ERROR: | |
286 | case TYPE_CODE_UNDEF: | |
287 | case TYPE_CODE_BOOL: | |
288 | case TYPE_CODE_CHAR: | |
426a9c18 | 289 | generic_value_print (val, stream, recurse, options, &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, |
940da03e SM |
308 | extract_unsigned_integer |
309 | (valaddr + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8, | |
310 | TYPE_LENGTH (type->field (VTBL_FNADDR_OFFSET).type ()), | |
311 | byte_order), | |
b276f1bb | 312 | stream, demangle); |
373a8247 PM |
313 | } |
314 | else | |
315 | { | |
5598ce11 | 316 | if (is_pascal_string_type (type, &length_pos, &length_size, |
6c7a06a3 | 317 | &string_pos, &char_type, NULL)) |
373a8247 | 318 | { |
426a9c18 TT |
319 | len = extract_unsigned_integer (valaddr + length_pos, |
320 | length_size, byte_order); | |
321 | LA_PRINT_STRING (stream, char_type, valaddr + string_pos, | |
be759fcf | 322 | len, NULL, 0, options); |
373a8247 PM |
323 | } |
324 | else | |
426a9c18 TT |
325 | pascal_object_print_value_fields (val, stream, recurse, |
326 | options, NULL, 0); | |
373a8247 PM |
327 | } |
328 | break; | |
329 | ||
373a8247 | 330 | case TYPE_CODE_SET: |
3d967001 | 331 | elttype = type->index_type (); |
f168693b | 332 | elttype = check_typedef (elttype); |
e46d3488 | 333 | if (elttype->is_stub ()) |
373a8247 | 334 | { |
7f6aba03 | 335 | fprintf_styled (stream, metadata_style.style (), "<incomplete type>"); |
373a8247 PM |
336 | break; |
337 | } | |
338 | else | |
339 | { | |
340 | struct type *range = elttype; | |
341 | LONGEST low_bound, high_bound; | |
373a8247 PM |
342 | int need_comma = 0; |
343 | ||
6b1755ce | 344 | fputs_filtered ("[", stream); |
373a8247 | 345 | |
b926417a | 346 | int bound_info = get_discrete_bounds (range, &low_bound, &high_bound); |
7a081a30 PM |
347 | if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0) |
348 | { | |
349 | /* If we know the size of the set type, we can figure out the | |
350 | maximum value. */ | |
b926417a | 351 | bound_info = 0; |
7a081a30 | 352 | high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1; |
8c2e4e06 | 353 | range->bounds ()->high.set_const_val (high_bound); |
7a081a30 | 354 | } |
373a8247 | 355 | maybe_bad_bstring: |
b926417a | 356 | if (bound_info < 0) |
373a8247 | 357 | { |
7f6aba03 | 358 | fputs_styled ("<error value>", metadata_style.style (), stream); |
373a8247 PM |
359 | goto done; |
360 | } | |
361 | ||
362 | for (i = low_bound; i <= high_bound; i++) | |
363 | { | |
426a9c18 | 364 | int element = value_bit_index (type, valaddr, i); |
ad3bbd48 | 365 | |
373a8247 PM |
366 | if (element < 0) |
367 | { | |
368 | i = element; | |
369 | goto maybe_bad_bstring; | |
370 | } | |
6b1755ce | 371 | if (element) |
373a8247 PM |
372 | { |
373 | if (need_comma) | |
374 | fputs_filtered (", ", stream); | |
375 | print_type_scalar (range, i, stream); | |
376 | need_comma = 1; | |
377 | ||
3e43a32a | 378 | if (i + 1 <= high_bound |
426a9c18 | 379 | && value_bit_index (type, valaddr, ++i)) |
373a8247 PM |
380 | { |
381 | int j = i; | |
ad3bbd48 | 382 | |
373a8247 PM |
383 | fputs_filtered ("..", stream); |
384 | while (i + 1 <= high_bound | |
426a9c18 | 385 | && value_bit_index (type, valaddr, ++i)) |
373a8247 PM |
386 | j = i; |
387 | print_type_scalar (range, j, stream); | |
388 | } | |
389 | } | |
390 | } | |
391 | done: | |
6b1755ce | 392 | fputs_filtered ("]", stream); |
373a8247 PM |
393 | } |
394 | break; | |
395 | ||
373a8247 | 396 | default: |
3e43a32a | 397 | error (_("Invalid pascal type code %d in symbol table."), |
78134374 | 398 | type->code ()); |
373a8247 | 399 | } |
373a8247 | 400 | } |
c0941be6 | 401 | |
426a9c18 | 402 | \f |
c0941be6 | 403 | void |
426a9c18 TT |
404 | pascal_value_print (struct value *val, struct ui_file *stream, |
405 | const struct value_print_options *options) | |
c0941be6 | 406 | { |
426a9c18 TT |
407 | struct type *type = value_type (val); |
408 | struct value_print_options opts = *options; | |
64d64d3a | 409 | |
426a9c18 | 410 | opts.deref_ref = 1; |
64d64d3a | 411 | |
426a9c18 | 412 | /* If it is a pointer, indicate what it points to. |
64d64d3a | 413 | |
426a9c18 | 414 | Print type also if it is a reference. |
64d64d3a | 415 | |
426a9c18 TT |
416 | Object pascal: if it is a member pointer, we will take care |
417 | of that when we print it. */ | |
78134374 SM |
418 | if (type->code () == TYPE_CODE_PTR |
419 | || type->code () == TYPE_CODE_REF) | |
426a9c18 TT |
420 | { |
421 | /* Hack: remove (char *) for char strings. Their | |
422 | type is indicated by the quoted string anyway. */ | |
78134374 | 423 | if (type->code () == TYPE_CODE_PTR |
7d93a1e0 SM |
424 | && type->name () == NULL |
425 | && TYPE_TARGET_TYPE (type)->name () != NULL | |
426 | && strcmp (TYPE_TARGET_TYPE (type)->name (), "char") == 0) | |
64d64d3a | 427 | { |
426a9c18 | 428 | /* Print nothing. */ |
64d64d3a | 429 | } |
426a9c18 | 430 | else |
64d64d3a | 431 | { |
426a9c18 TT |
432 | fprintf_filtered (stream, "("); |
433 | type_print (type, "", stream, -1); | |
434 | fprintf_filtered (stream, ") "); | |
64d64d3a | 435 | } |
426a9c18 TT |
436 | } |
437 | common_val_print (val, stream, 0, &opts, current_language); | |
438 | } | |
64d64d3a | 439 | |
64d64d3a | 440 | |
426a9c18 TT |
441 | static void |
442 | show_pascal_static_field_print (struct ui_file *file, int from_tty, | |
443 | struct cmd_list_element *c, const char *value) | |
444 | { | |
445 | fprintf_filtered (file, _("Printing of pascal static members is %s.\n"), | |
446 | value); | |
447 | } | |
64d64d3a | 448 | |
426a9c18 TT |
449 | static struct obstack dont_print_vb_obstack; |
450 | static struct obstack dont_print_statmem_obstack; | |
64d64d3a | 451 | |
426a9c18 TT |
452 | static void pascal_object_print_static_field (struct value *, |
453 | struct ui_file *, int, | |
454 | const struct value_print_options *); | |
64d64d3a | 455 | |
426a9c18 TT |
456 | static void pascal_object_print_value (struct value *, struct ui_file *, int, |
457 | const struct value_print_options *, | |
458 | struct type **); | |
64d64d3a | 459 | |
426a9c18 TT |
460 | /* It was changed to this after 2.4.5. */ |
461 | const char pascal_vtbl_ptr_name[] = | |
462 | {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0}; | |
64d64d3a | 463 | |
426a9c18 TT |
464 | /* Return truth value for assertion that TYPE is of the type |
465 | "pointer to virtual function". */ | |
64d64d3a | 466 | |
426a9c18 TT |
467 | int |
468 | pascal_object_is_vtbl_ptr_type (struct type *type) | |
469 | { | |
7d93a1e0 | 470 | const char *type_name = type->name (); |
373a8247 | 471 | |
fe978cb0 PA |
472 | return (type_name != NULL |
473 | && strcmp (type_name, pascal_vtbl_ptr_name) == 0); | |
373a8247 PM |
474 | } |
475 | ||
476 | /* Return truth value for the assertion that TYPE is of the type | |
477 | "pointer to virtual function table". */ | |
478 | ||
479 | int | |
fba45db2 | 480 | pascal_object_is_vtbl_member (struct type *type) |
373a8247 | 481 | { |
78134374 | 482 | if (type->code () == TYPE_CODE_PTR) |
373a8247 PM |
483 | { |
484 | type = TYPE_TARGET_TYPE (type); | |
78134374 | 485 | if (type->code () == TYPE_CODE_ARRAY) |
373a8247 PM |
486 | { |
487 | type = TYPE_TARGET_TYPE (type); | |
78134374 | 488 | if (type->code () == TYPE_CODE_STRUCT /* If not using |
0df8b418 | 489 | thunks. */ |
78134374 | 490 | || type->code () == TYPE_CODE_PTR) /* If using thunks. */ |
373a8247 PM |
491 | { |
492 | /* Virtual functions tables are full of pointers | |
0df8b418 | 493 | to virtual functions. */ |
373a8247 PM |
494 | return pascal_object_is_vtbl_ptr_type (type); |
495 | } | |
496 | } | |
497 | } | |
498 | return 0; | |
499 | } | |
500 | ||
07a32858 TT |
501 | /* Mutually recursive subroutines of pascal_object_print_value and |
502 | pascal_value_print to print out a structure's fields: | |
503 | pascal_object_print_value_fields and pascal_object_print_value. | |
504 | ||
505 | VAL, STREAM, RECURSE, and OPTIONS have the same meanings as in | |
506 | pascal_object_print_value and c_value_print. | |
507 | ||
508 | DONT_PRINT is an array of baseclass types that we | |
509 | should not print, or zero if called from top level. */ | |
510 | ||
511 | static void | |
512 | pascal_object_print_value_fields (struct value *val, struct ui_file *stream, | |
513 | int recurse, | |
514 | const struct value_print_options *options, | |
515 | struct type **dont_print_vb, | |
516 | int dont_print_statmem) | |
517 | { | |
518 | int i, len, n_baseclasses; | |
519 | char *last_dont_print | |
520 | = (char *) obstack_next_free (&dont_print_statmem_obstack); | |
521 | ||
522 | struct type *type = check_typedef (value_type (val)); | |
523 | ||
524 | fprintf_filtered (stream, "{"); | |
1f704f76 | 525 | len = type->num_fields (); |
07a32858 TT |
526 | n_baseclasses = TYPE_N_BASECLASSES (type); |
527 | ||
528 | /* Print out baseclasses such that we don't print | |
529 | duplicates of virtual baseclasses. */ | |
530 | if (n_baseclasses > 0) | |
531 | pascal_object_print_value (val, stream, recurse + 1, | |
532 | options, dont_print_vb); | |
533 | ||
534 | if (!len && n_baseclasses == 1) | |
535 | fprintf_styled (stream, metadata_style.style (), "<No data fields>"); | |
536 | else | |
537 | { | |
538 | struct obstack tmp_obstack = dont_print_statmem_obstack; | |
539 | int fields_seen = 0; | |
540 | const gdb_byte *valaddr = value_contents_for_printing (val); | |
541 | ||
542 | if (dont_print_statmem == 0) | |
543 | { | |
544 | /* If we're at top level, carve out a completely fresh | |
545 | chunk of the obstack and use that until this particular | |
546 | invocation returns. */ | |
547 | obstack_finish (&dont_print_statmem_obstack); | |
548 | } | |
549 | ||
550 | for (i = n_baseclasses; i < len; i++) | |
551 | { | |
552 | /* If requested, skip printing of static fields. */ | |
553 | if (!options->pascal_static_field_print | |
ceacbf6e | 554 | && field_is_static (&type->field (i))) |
07a32858 TT |
555 | continue; |
556 | if (fields_seen) | |
557 | fprintf_filtered (stream, ", "); | |
558 | else if (n_baseclasses > 0) | |
559 | { | |
560 | if (options->prettyformat) | |
561 | { | |
562 | fprintf_filtered (stream, "\n"); | |
563 | print_spaces_filtered (2 + 2 * recurse, stream); | |
564 | fputs_filtered ("members of ", stream); | |
7d93a1e0 | 565 | fputs_filtered (type->name (), stream); |
07a32858 TT |
566 | fputs_filtered (": ", stream); |
567 | } | |
568 | } | |
569 | fields_seen = 1; | |
570 | ||
571 | if (options->prettyformat) | |
572 | { | |
573 | fprintf_filtered (stream, "\n"); | |
574 | print_spaces_filtered (2 + 2 * recurse, stream); | |
575 | } | |
576 | else | |
577 | { | |
578 | wrap_here (n_spaces (2 + 2 * recurse)); | |
579 | } | |
580 | ||
940da03e | 581 | annotate_field_begin (type->field (i).type ()); |
07a32858 | 582 | |
ceacbf6e | 583 | if (field_is_static (&type->field (i))) |
07a32858 TT |
584 | { |
585 | fputs_filtered ("static ", stream); | |
586 | fprintf_symbol_filtered (stream, | |
587 | TYPE_FIELD_NAME (type, i), | |
588 | current_language->la_language, | |
589 | DMGL_PARAMS | DMGL_ANSI); | |
590 | } | |
591 | else | |
592 | fputs_styled (TYPE_FIELD_NAME (type, i), | |
593 | variable_name_style.style (), stream); | |
594 | annotate_field_name_end (); | |
595 | fputs_filtered (" = ", stream); | |
596 | annotate_field_value (); | |
597 | ||
ceacbf6e | 598 | if (!field_is_static (&type->field (i)) |
07a32858 TT |
599 | && TYPE_FIELD_PACKED (type, i)) |
600 | { | |
601 | struct value *v; | |
602 | ||
603 | /* Bitfields require special handling, especially due to byte | |
604 | order problems. */ | |
605 | if (TYPE_FIELD_IGNORE (type, i)) | |
606 | { | |
607 | fputs_styled ("<optimized out or zero length>", | |
608 | metadata_style.style (), stream); | |
609 | } | |
610 | else if (value_bits_synthetic_pointer (val, | |
611 | TYPE_FIELD_BITPOS (type, | |
612 | i), | |
613 | TYPE_FIELD_BITSIZE (type, | |
614 | i))) | |
615 | { | |
616 | fputs_styled (_("<synthetic pointer>"), | |
617 | metadata_style.style (), stream); | |
618 | } | |
619 | else | |
620 | { | |
621 | struct value_print_options opts = *options; | |
622 | ||
623 | v = value_field_bitfield (type, i, valaddr, 0, val); | |
624 | ||
625 | opts.deref_ref = 0; | |
626 | common_val_print (v, stream, recurse + 1, &opts, | |
627 | current_language); | |
628 | } | |
629 | } | |
630 | else | |
631 | { | |
632 | if (TYPE_FIELD_IGNORE (type, i)) | |
633 | { | |
634 | fputs_styled ("<optimized out or zero length>", | |
635 | metadata_style.style (), stream); | |
636 | } | |
ceacbf6e | 637 | else if (field_is_static (&type->field (i))) |
07a32858 TT |
638 | { |
639 | /* struct value *v = value_static_field (type, i); | |
640 | v4.17 specific. */ | |
641 | struct value *v; | |
642 | ||
643 | v = value_field_bitfield (type, i, valaddr, 0, val); | |
644 | ||
645 | if (v == NULL) | |
646 | val_print_optimized_out (NULL, stream); | |
647 | else | |
648 | pascal_object_print_static_field (v, stream, recurse + 1, | |
649 | options); | |
650 | } | |
651 | else | |
652 | { | |
653 | struct value_print_options opts = *options; | |
654 | ||
655 | opts.deref_ref = 0; | |
656 | ||
657 | struct value *v = value_primitive_field (val, 0, i, | |
658 | value_type (val)); | |
659 | common_val_print (v, stream, recurse + 1, &opts, | |
660 | current_language); | |
661 | } | |
662 | } | |
663 | annotate_field_end (); | |
664 | } | |
665 | ||
666 | if (dont_print_statmem == 0) | |
667 | { | |
668 | /* Free the space used to deal with the printing | |
669 | of the members from top level. */ | |
670 | obstack_free (&dont_print_statmem_obstack, last_dont_print); | |
671 | dont_print_statmem_obstack = tmp_obstack; | |
672 | } | |
673 | ||
674 | if (options->prettyformat) | |
675 | { | |
676 | fprintf_filtered (stream, "\n"); | |
677 | print_spaces_filtered (2 * recurse, stream); | |
678 | } | |
679 | } | |
680 | fprintf_filtered (stream, "}"); | |
681 | } | |
682 | ||
07a32858 TT |
683 | /* Special val_print routine to avoid printing multiple copies of virtual |
684 | baseclasses. */ | |
685 | ||
686 | static void | |
687 | pascal_object_print_value (struct value *val, struct ui_file *stream, | |
688 | int recurse, | |
689 | const struct value_print_options *options, | |
690 | struct type **dont_print_vb) | |
691 | { | |
692 | struct type **last_dont_print | |
693 | = (struct type **) obstack_next_free (&dont_print_vb_obstack); | |
694 | struct obstack tmp_obstack = dont_print_vb_obstack; | |
695 | struct type *type = check_typedef (value_type (val)); | |
696 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); | |
697 | ||
698 | if (dont_print_vb == 0) | |
699 | { | |
700 | /* If we're at top level, carve out a completely fresh | |
701 | chunk of the obstack and use that until this particular | |
702 | invocation returns. */ | |
703 | /* Bump up the high-water mark. Now alpha is omega. */ | |
704 | obstack_finish (&dont_print_vb_obstack); | |
705 | } | |
706 | ||
707 | for (i = 0; i < n_baseclasses; i++) | |
708 | { | |
709 | LONGEST boffset = 0; | |
710 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); | |
7d93a1e0 | 711 | const char *basename = baseclass->name (); |
07a32858 TT |
712 | int skip = 0; |
713 | ||
714 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
715 | { | |
716 | struct type **first_dont_print | |
717 | = (struct type **) obstack_base (&dont_print_vb_obstack); | |
718 | ||
719 | int j = (struct type **) obstack_next_free (&dont_print_vb_obstack) | |
720 | - first_dont_print; | |
721 | ||
722 | while (--j >= 0) | |
723 | if (baseclass == first_dont_print[j]) | |
724 | goto flush_it; | |
725 | ||
726 | obstack_ptr_grow (&dont_print_vb_obstack, baseclass); | |
727 | } | |
728 | ||
729 | struct value *base_value; | |
730 | try | |
731 | { | |
732 | base_value = value_primitive_field (val, 0, i, type); | |
733 | } | |
734 | catch (const gdb_exception_error &ex) | |
735 | { | |
771dd3a8 | 736 | base_value = nullptr; |
07a32858 TT |
737 | if (ex.error == NOT_AVAILABLE_ERROR) |
738 | skip = -1; | |
739 | else | |
740 | skip = 1; | |
741 | } | |
742 | ||
743 | if (skip == 0) | |
744 | { | |
745 | /* The virtual base class pointer might have been clobbered by the | |
746 | user program. Make sure that it still points to a valid memory | |
747 | location. */ | |
748 | ||
749 | if (boffset < 0 || boffset >= TYPE_LENGTH (type)) | |
750 | { | |
751 | CORE_ADDR address= value_address (val); | |
752 | gdb::byte_vector buf (TYPE_LENGTH (baseclass)); | |
753 | ||
754 | if (target_read_memory (address + boffset, buf.data (), | |
755 | TYPE_LENGTH (baseclass)) != 0) | |
756 | skip = 1; | |
757 | base_value = value_from_contents_and_address (baseclass, | |
758 | buf.data (), | |
759 | address + boffset); | |
760 | baseclass = value_type (base_value); | |
761 | boffset = 0; | |
762 | } | |
763 | } | |
764 | ||
765 | if (options->prettyformat) | |
766 | { | |
767 | fprintf_filtered (stream, "\n"); | |
768 | print_spaces_filtered (2 * recurse, stream); | |
769 | } | |
770 | fputs_filtered ("<", stream); | |
771 | /* Not sure what the best notation is in the case where there is no | |
772 | baseclass name. */ | |
773 | ||
774 | fputs_filtered (basename ? basename : "", stream); | |
775 | fputs_filtered ("> = ", stream); | |
776 | ||
777 | if (skip < 0) | |
778 | val_print_unavailable (stream); | |
779 | else if (skip > 0) | |
780 | val_print_invalid_address (stream); | |
781 | else | |
782 | pascal_object_print_value_fields | |
783 | (base_value, stream, recurse, options, | |
784 | (struct type **) obstack_base (&dont_print_vb_obstack), | |
785 | 0); | |
786 | fputs_filtered (", ", stream); | |
787 | ||
788 | flush_it: | |
789 | ; | |
790 | } | |
791 | ||
792 | if (dont_print_vb == 0) | |
793 | { | |
794 | /* Free the space used to deal with the printing | |
795 | of this type from top level. */ | |
796 | obstack_free (&dont_print_vb_obstack, last_dont_print); | |
797 | /* Reset watermark so that we can continue protecting | |
798 | ourselves from whatever we were protecting ourselves. */ | |
799 | dont_print_vb_obstack = tmp_obstack; | |
800 | } | |
801 | } | |
802 | ||
373a8247 PM |
803 | /* Print value of a static member. |
804 | To avoid infinite recursion when printing a class that contains | |
805 | a static instance of the class, we keep the addresses of all printed | |
806 | static member classes in an obstack and refuse to print them more | |
807 | than once. | |
808 | ||
79a45b7d | 809 | VAL contains the value to print, STREAM, RECURSE, and OPTIONS |
373a8247 PM |
810 | have the same meanings as in c_val_print. */ |
811 | ||
812 | static void | |
806048c6 | 813 | pascal_object_print_static_field (struct value *val, |
79a45b7d TT |
814 | struct ui_file *stream, |
815 | int recurse, | |
816 | const struct value_print_options *options) | |
373a8247 | 817 | { |
806048c6 | 818 | struct type *type = value_type (val); |
79a45b7d | 819 | struct value_print_options opts; |
806048c6 | 820 | |
686d4def PA |
821 | if (value_entirely_optimized_out (val)) |
822 | { | |
823 | val_print_optimized_out (val, stream); | |
824 | return; | |
825 | } | |
826 | ||
78134374 | 827 | if (type->code () == TYPE_CODE_STRUCT) |
373a8247 | 828 | { |
42ae5230 | 829 | CORE_ADDR *first_dont_print, addr; |
373a8247 PM |
830 | int i; |
831 | ||
832 | first_dont_print | |
833 | = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack); | |
834 | i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack) | |
835 | - first_dont_print; | |
836 | ||
837 | while (--i >= 0) | |
838 | { | |
42ae5230 | 839 | if (value_address (val) == first_dont_print[i]) |
373a8247 | 840 | { |
2dbc041e TT |
841 | fputs_styled (_("\ |
842 | <same as static member of an already seen type>"), | |
843 | metadata_style.style (), stream); | |
373a8247 PM |
844 | return; |
845 | } | |
846 | } | |
847 | ||
42ae5230 TT |
848 | addr = value_address (val); |
849 | obstack_grow (&dont_print_statmem_obstack, (char *) &addr, | |
373a8247 PM |
850 | sizeof (CORE_ADDR)); |
851 | ||
f168693b | 852 | type = check_typedef (type); |
426a9c18 TT |
853 | pascal_object_print_value_fields (val, stream, recurse, |
854 | options, NULL, 1); | |
373a8247 PM |
855 | return; |
856 | } | |
79a45b7d TT |
857 | |
858 | opts = *options; | |
859 | opts.deref_ref = 0; | |
860 | common_val_print (val, stream, recurse, &opts, current_language); | |
373a8247 PM |
861 | } |
862 | ||
6c265988 | 863 | void _initialize_pascal_valprint (); |
373a8247 | 864 | void |
6c265988 | 865 | _initialize_pascal_valprint () |
373a8247 | 866 | { |
5bf193a2 | 867 | add_setshow_boolean_cmd ("pascal_static-members", class_support, |
79a45b7d | 868 | &user_print_options.pascal_static_field_print, _("\ |
5bf193a2 AC |
869 | Set printing of pascal static members."), _("\ |
870 | Show printing of pascal static members."), NULL, | |
871 | NULL, | |
920d2a44 | 872 | show_pascal_static_field_print, |
5bf193a2 | 873 | &setprintlist, &showprintlist); |
373a8247 | 874 | } |