Change extension language pretty-printers to use value API
[deliverable/binutils-gdb.git] / gdb / p-valprint.c
CommitLineData
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
1e592a8a
TT
45static void pascal_object_print_value_fields (struct type *, const gdb_byte *,
46 LONGEST,
47 CORE_ADDR, struct ui_file *,
48 int,
49 struct value *,
50 const struct value_print_options *,
51 struct type **, int);
52
07a32858
TT
53static void pascal_object_print_value_fields (struct value *, struct ui_file *,
54 int,
55 const struct value_print_options *,
56 struct type **, int);
57
e88acd96
TT
58/* Decorations for Pascal. */
59
60static const struct generic_val_print_decorations p_decorations =
61{
62 "",
63 " + ",
64 " * I",
65 "true",
66 "false",
00272ec4
TT
67 "void",
68 "{",
69 "}"
e88acd96
TT
70};
71
32b72a42 72/* See val_print for a description of the various parameters of this
d3eab38a 73 function; they are identical. */
373a8247 74
d3eab38a 75void
e8b24d9f 76pascal_val_print (struct type *type,
a2bd3dcd 77 int embedded_offset, CORE_ADDR address,
79a45b7d 78 struct ui_file *stream, int recurse,
e8b24d9f 79 struct value *original_value,
79a45b7d 80 const struct value_print_options *options)
373a8247 81{
5af949e3 82 struct gdbarch *gdbarch = get_type_arch (type);
34877895 83 enum bfd_endian byte_order = type_byte_order (type);
52f0bd74 84 unsigned int i = 0; /* Number of characters printed */
373a8247
PM
85 unsigned len;
86 struct type *elttype;
87 unsigned eltlen;
5598ce11 88 int length_pos, length_size, string_pos;
6c7a06a3 89 struct type *char_type;
373a8247 90 CORE_ADDR addr;
b012acdd 91 int want_space = 0;
e8b24d9f 92 const gdb_byte *valaddr = value_contents_for_printing (original_value);
373a8247 93
f168693b 94 type = check_typedef (type);
373a8247
PM
95 switch (TYPE_CODE (type))
96 {
97 case TYPE_CODE_ARRAY:
b926417a
TT
98 {
99 LONGEST low_bound, high_bound;
373a8247 100
b926417a
TT
101 if (get_array_bounds (type, &low_bound, &high_bound))
102 {
103 len = high_bound - low_bound + 1;
104 elttype = check_typedef (TYPE_TARGET_TYPE (type));
105 eltlen = TYPE_LENGTH (elttype);
106 if (options->prettyformat_arrays)
107 {
108 print_spaces_filtered (2 + 2 * recurse, stream);
109 }
110 /* If 's' format is used, try to print out as string.
111 If no format is given, print as string if element type
112 is of TYPE_CODE_CHAR and element size is 1,2 or 4. */
113 if (options->format == 's'
114 || ((eltlen == 1 || eltlen == 2 || eltlen == 4)
115 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
116 && options->format == 0))
117 {
118 /* If requested, look for the first null char and only print
119 elements up to it. */
120 if (options->stop_print_at_null)
121 {
122 unsigned int temp_len;
123
124 /* Look for a NULL char. */
125 for (temp_len = 0;
126 extract_unsigned_integer (valaddr + embedded_offset +
127 temp_len * eltlen, eltlen,
128 byte_order)
129 && temp_len < len && temp_len < options->print_max;
130 temp_len++);
131 len = temp_len;
132 }
133
134 LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
135 valaddr + embedded_offset, len, NULL, 0,
136 options);
137 i = len;
138 }
139 else
140 {
141 fprintf_filtered (stream, "{");
142 /* If this is a virtual function table, print the 0th
143 entry specially, and the rest of the members normally. */
144 if (pascal_object_is_vtbl_ptr_type (elttype))
145 {
146 i = 1;
147 fprintf_filtered (stream, "%d vtable entries", len - 1);
148 }
149 else
150 {
151 i = 0;
152 }
153 val_print_array_elements (type, embedded_offset,
154 address, stream, recurse,
155 original_value, options, i);
156 fprintf_filtered (stream, "}");
157 }
158 break;
159 }
160 /* Array of unspecified length: treat like pointer to first elt. */
161 addr = address + embedded_offset;
162 }
373a8247
PM
163 goto print_unpacked_pointer;
164
165 case TYPE_CODE_PTR:
79a45b7d 166 if (options->format && options->format != 's')
373a8247 167 {
e8b24d9f 168 val_print_scalar_formatted (type, embedded_offset,
ab2188aa 169 original_value, options, 0, stream);
373a8247
PM
170 break;
171 }
79a45b7d 172 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
373a8247
PM
173 {
174 /* Print the unmangled name if desired. */
175 /* Print vtable entry - we only get here if we ARE using
0df8b418 176 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
b276f1bb 177 /* Extract the address, assume that it is unsigned. */
e17a4113
UW
178 addr = extract_unsigned_integer (valaddr + embedded_offset,
179 TYPE_LENGTH (type), byte_order);
edf0c1b7 180 print_address_demangle (options, gdbarch, addr, stream, demangle);
373a8247
PM
181 break;
182 }
91e8df85 183 check_typedef (TYPE_TARGET_TYPE (type));
e13eedd5
PM
184
185 addr = unpack_pointer (type, valaddr + embedded_offset);
186 print_unpacked_pointer:
187 elttype = check_typedef (TYPE_TARGET_TYPE (type));
188
189 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
373a8247 190 {
e13eedd5 191 /* Try to print what function it points to. */
edf0c1b7 192 print_address_demangle (options, gdbarch, addr, stream, demangle);
d3eab38a 193 return;
e13eedd5 194 }
373a8247 195
e13eedd5
PM
196 if (options->addressprint && options->format != 's')
197 {
198 fputs_filtered (paddress (gdbarch, addr), stream);
b012acdd 199 want_space = 1;
e13eedd5 200 }
373a8247 201
e13eedd5
PM
202 /* For a pointer to char or unsigned char, also print the string
203 pointed to, unless pointer is null. */
204 if (((TYPE_LENGTH (elttype) == 1
205 && (TYPE_CODE (elttype) == TYPE_CODE_INT
206 || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
207 || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
208 && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
209 && (options->format == 0 || options->format == 's')
210 && addr != 0)
211 {
b012acdd
TT
212 if (want_space)
213 fputs_filtered (" ", stream);
0df8b418 214 /* No wide string yet. */
09ca9e2e 215 i = val_print_string (elttype, NULL, addr, -1, stream, options);
e13eedd5 216 }
0df8b418 217 /* Also for pointers to pascal strings. */
e13eedd5
PM
218 /* Note: this is Free Pascal specific:
219 as GDB does not recognize stabs pascal strings
220 Pascal strings are mapped to records
0df8b418 221 with lowercase names PM. */
e13eedd5
PM
222 if (is_pascal_string_type (elttype, &length_pos, &length_size,
223 &string_pos, &char_type, NULL)
224 && addr != 0)
225 {
226 ULONGEST string_length;
7c543f7b 227 gdb_byte *buffer;
ad3bbd48 228
b012acdd
TT
229 if (want_space)
230 fputs_filtered (" ", stream);
7c543f7b 231 buffer = (gdb_byte *) xmalloc (length_size);
e13eedd5
PM
232 read_memory (addr + length_pos, buffer, length_size);
233 string_length = extract_unsigned_integer (buffer, length_size,
234 byte_order);
235 xfree (buffer);
09ca9e2e
TT
236 i = val_print_string (char_type, NULL,
237 addr + string_pos, string_length,
238 stream, options);
e13eedd5
PM
239 }
240 else if (pascal_object_is_vtbl_member (type))
241 {
0df8b418 242 /* Print vtbl's nicely. */
3e43a32a
MS
243 CORE_ADDR vt_address = unpack_pointer (type,
244 valaddr + embedded_offset);
7cbd4a93 245 struct bound_minimal_symbol msymbol =
ad3bbd48
MS
246 lookup_minimal_symbol_by_pc (vt_address);
247
9cb709b6
TT
248 /* If 'symbol_print' is set, we did the work above. */
249 if (!options->symbol_print
7cbd4a93 250 && (msymbol.minsym != NULL)
77e371c0 251 && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
373a8247 252 {
b012acdd
TT
253 if (want_space)
254 fputs_filtered (" ", stream);
255 fputs_filtered ("<", stream);
c9d95fa3 256 fputs_filtered (msymbol.minsym->print_name (), stream);
e13eedd5 257 fputs_filtered (">", stream);
b012acdd 258 want_space = 1;
373a8247 259 }
e13eedd5 260 if (vt_address && options->vtblprint)
373a8247 261 {
e13eedd5 262 struct value *vt_val;
be903358 263 struct symbol *wsym = NULL;
e13eedd5 264 struct type *wtype;
373a8247 265
b012acdd
TT
266 if (want_space)
267 fputs_filtered (" ", stream);
268
7cbd4a93 269 if (msymbol.minsym != NULL)
de63c46b 270 {
c9d95fa3 271 const char *search_name = msymbol.minsym->search_name ();
582942f4 272 wsym = lookup_symbol_search_name (search_name, NULL,
de63c46b
PA
273 VAR_DOMAIN).symbol;
274 }
e13eedd5
PM
275
276 if (wsym)
373a8247 277 {
e13eedd5 278 wtype = SYMBOL_TYPE (wsym);
373a8247 279 }
e13eedd5 280 else
373a8247 281 {
e13eedd5
PM
282 wtype = TYPE_TARGET_TYPE (type);
283 }
284 vt_val = value_at (wtype, vt_address);
285 common_val_print (vt_val, stream, recurse + 1, options,
286 current_language);
2a998fc0 287 if (options->prettyformat)
e13eedd5
PM
288 {
289 fprintf_filtered (stream, "\n");
290 print_spaces_filtered (2 + 2 * recurse, stream);
373a8247
PM
291 }
292 }
373a8247 293 }
e13eedd5 294
d3eab38a 295 return;
373a8247 296
373a8247 297 case TYPE_CODE_REF:
e88acd96
TT
298 case TYPE_CODE_ENUM:
299 case TYPE_CODE_FLAGS:
300 case TYPE_CODE_FUNC:
301 case TYPE_CODE_RANGE:
302 case TYPE_CODE_INT:
303 case TYPE_CODE_FLT:
304 case TYPE_CODE_VOID:
305 case TYPE_CODE_ERROR:
306 case TYPE_CODE_UNDEF:
307 case TYPE_CODE_BOOL:
308 case TYPE_CODE_CHAR:
e8b24d9f 309 generic_val_print (type, embedded_offset, address,
e88acd96
TT
310 stream, recurse, original_value, options,
311 &p_decorations);
373a8247
PM
312 break;
313
314 case TYPE_CODE_UNION:
79a45b7d 315 if (recurse && !options->unionprint)
373a8247
PM
316 {
317 fprintf_filtered (stream, "{...}");
318 break;
319 }
320 /* Fall through. */
321 case TYPE_CODE_STRUCT:
79a45b7d 322 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
373a8247
PM
323 {
324 /* Print the unmangled name if desired. */
325 /* Print vtable entry - we only get here if NOT using
0df8b418 326 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
b276f1bb
AC
327 /* Extract the address, assume that it is unsigned. */
328 print_address_demangle
edf0c1b7 329 (options, gdbarch,
3e43a32a
MS
330 extract_unsigned_integer (valaddr + embedded_offset
331 + TYPE_FIELD_BITPOS (type,
332 VTBL_FNADDR_OFFSET) / 8,
333 TYPE_LENGTH (TYPE_FIELD_TYPE (type,
334 VTBL_FNADDR_OFFSET)),
335 byte_order),
b276f1bb 336 stream, demangle);
373a8247
PM
337 }
338 else
339 {
5598ce11 340 if (is_pascal_string_type (type, &length_pos, &length_size,
6c7a06a3 341 &string_pos, &char_type, NULL))
373a8247 342 {
3e43a32a
MS
343 len = extract_unsigned_integer (valaddr + embedded_offset
344 + length_pos, length_size,
345 byte_order);
6ced1581 346 LA_PRINT_STRING (stream, char_type,
be759fcf
PM
347 valaddr + embedded_offset + string_pos,
348 len, NULL, 0, options);
373a8247
PM
349 }
350 else
490f124f 351 pascal_object_print_value_fields (type, valaddr, embedded_offset,
3e43a32a
MS
352 address, stream, recurse,
353 original_value, options,
354 NULL, 0);
373a8247
PM
355 }
356 break;
357
373a8247
PM
358 case TYPE_CODE_SET:
359 elttype = TYPE_INDEX_TYPE (type);
f168693b 360 elttype = check_typedef (elttype);
74a9bb82 361 if (TYPE_STUB (elttype))
373a8247 362 {
7f6aba03 363 fprintf_styled (stream, metadata_style.style (), "<incomplete type>");
373a8247
PM
364 break;
365 }
366 else
367 {
368 struct type *range = elttype;
369 LONGEST low_bound, high_bound;
373a8247
PM
370 int need_comma = 0;
371
6b1755ce 372 fputs_filtered ("[", stream);
373a8247 373
b926417a 374 int bound_info = get_discrete_bounds (range, &low_bound, &high_bound);
7a081a30
PM
375 if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
376 {
377 /* If we know the size of the set type, we can figure out the
378 maximum value. */
b926417a 379 bound_info = 0;
7a081a30
PM
380 high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
381 TYPE_HIGH_BOUND (range) = high_bound;
382 }
373a8247 383 maybe_bad_bstring:
b926417a 384 if (bound_info < 0)
373a8247 385 {
7f6aba03 386 fputs_styled ("<error value>", metadata_style.style (), stream);
373a8247
PM
387 goto done;
388 }
389
390 for (i = low_bound; i <= high_bound; i++)
391 {
3e43a32a
MS
392 int element = value_bit_index (type,
393 valaddr + embedded_offset, i);
ad3bbd48 394
373a8247
PM
395 if (element < 0)
396 {
397 i = element;
398 goto maybe_bad_bstring;
399 }
6b1755ce 400 if (element)
373a8247
PM
401 {
402 if (need_comma)
403 fputs_filtered (", ", stream);
404 print_type_scalar (range, i, stream);
405 need_comma = 1;
406
3e43a32a
MS
407 if (i + 1 <= high_bound
408 && value_bit_index (type,
409 valaddr + embedded_offset, ++i))
373a8247
PM
410 {
411 int j = i;
ad3bbd48 412
373a8247
PM
413 fputs_filtered ("..", stream);
414 while (i + 1 <= high_bound
3e43a32a
MS
415 && value_bit_index (type,
416 valaddr + embedded_offset,
417 ++i))
373a8247
PM
418 j = i;
419 print_type_scalar (range, j, stream);
420 }
421 }
422 }
423 done:
6b1755ce 424 fputs_filtered ("]", stream);
373a8247
PM
425 }
426 break;
427
373a8247 428 default:
3e43a32a
MS
429 error (_("Invalid pascal type code %d in symbol table."),
430 TYPE_CODE (type));
373a8247 431 }
373a8247 432}
c0941be6
TT
433
434/* See p-lang.h. */
435
436void
437pascal_value_print_inner (struct value *val, struct ui_file *stream,
438 int recurse,
439 const struct value_print_options *options)
440
441{
64d64d3a
TT
442 struct type *type = check_typedef (value_type (val));
443 struct gdbarch *gdbarch = get_type_arch (type);
444 enum bfd_endian byte_order = type_byte_order (type);
445 unsigned int i = 0; /* Number of characters printed */
446 unsigned len;
447 struct type *elttype;
448 unsigned eltlen;
449 int length_pos, length_size, string_pos;
450 struct type *char_type;
451 CORE_ADDR addr;
452 int want_space = 0;
453 const gdb_byte *valaddr = value_contents_for_printing (val);
454
455 switch (TYPE_CODE (type))
456 {
457 case TYPE_CODE_ARRAY:
458 {
459 LONGEST low_bound, high_bound;
460
461 if (get_array_bounds (type, &low_bound, &high_bound))
462 {
463 len = high_bound - low_bound + 1;
464 elttype = check_typedef (TYPE_TARGET_TYPE (type));
465 eltlen = TYPE_LENGTH (elttype);
466 if (options->prettyformat_arrays)
467 {
468 print_spaces_filtered (2 + 2 * recurse, stream);
469 }
470 /* If 's' format is used, try to print out as string.
471 If no format is given, print as string if element type
472 is of TYPE_CODE_CHAR and element size is 1,2 or 4. */
473 if (options->format == 's'
474 || ((eltlen == 1 || eltlen == 2 || eltlen == 4)
475 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
476 && options->format == 0))
477 {
478 /* If requested, look for the first null char and only print
479 elements up to it. */
480 if (options->stop_print_at_null)
481 {
482 unsigned int temp_len;
483
484 /* Look for a NULL char. */
485 for (temp_len = 0;
486 extract_unsigned_integer (valaddr + temp_len * eltlen,
487 eltlen, byte_order)
488 && temp_len < len && temp_len < options->print_max;
489 temp_len++);
490 len = temp_len;
491 }
492
493 LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
494 valaddr, len, NULL, 0, options);
495 i = len;
496 }
497 else
498 {
499 fprintf_filtered (stream, "{");
500 /* If this is a virtual function table, print the 0th
501 entry specially, and the rest of the members normally. */
502 if (pascal_object_is_vtbl_ptr_type (elttype))
503 {
504 i = 1;
505 fprintf_filtered (stream, "%d vtable entries", len - 1);
506 }
507 else
508 {
509 i = 0;
510 }
511 value_print_array_elements (val, stream, recurse, options, i);
512 fprintf_filtered (stream, "}");
513 }
514 break;
515 }
516 /* Array of unspecified length: treat like pointer to first elt. */
517 addr = value_address (val);
518 }
519 goto print_unpacked_pointer;
520
521 case TYPE_CODE_PTR:
522 if (options->format && options->format != 's')
523 {
524 value_print_scalar_formatted (val, options, 0, stream);
525 break;
526 }
527 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
528 {
529 /* Print the unmangled name if desired. */
530 /* Print vtable entry - we only get here if we ARE using
531 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
532 /* Extract the address, assume that it is unsigned. */
533 addr = extract_unsigned_integer (valaddr,
534 TYPE_LENGTH (type), byte_order);
535 print_address_demangle (options, gdbarch, addr, stream, demangle);
536 break;
537 }
538 check_typedef (TYPE_TARGET_TYPE (type));
539
540 addr = unpack_pointer (type, valaddr);
541 print_unpacked_pointer:
542 elttype = check_typedef (TYPE_TARGET_TYPE (type));
543
544 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
545 {
546 /* Try to print what function it points to. */
547 print_address_demangle (options, gdbarch, addr, stream, demangle);
548 return;
549 }
550
551 if (options->addressprint && options->format != 's')
552 {
553 fputs_filtered (paddress (gdbarch, addr), stream);
554 want_space = 1;
555 }
556
557 /* For a pointer to char or unsigned char, also print the string
558 pointed to, unless pointer is null. */
559 if (((TYPE_LENGTH (elttype) == 1
560 && (TYPE_CODE (elttype) == TYPE_CODE_INT
561 || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
562 || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
563 && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
564 && (options->format == 0 || options->format == 's')
565 && addr != 0)
566 {
567 if (want_space)
568 fputs_filtered (" ", stream);
569 /* No wide string yet. */
570 i = val_print_string (elttype, NULL, addr, -1, stream, options);
571 }
572 /* Also for pointers to pascal strings. */
573 /* Note: this is Free Pascal specific:
574 as GDB does not recognize stabs pascal strings
575 Pascal strings are mapped to records
576 with lowercase names PM. */
577 if (is_pascal_string_type (elttype, &length_pos, &length_size,
578 &string_pos, &char_type, NULL)
579 && addr != 0)
580 {
581 ULONGEST string_length;
582 gdb_byte *buffer;
583
584 if (want_space)
585 fputs_filtered (" ", stream);
586 buffer = (gdb_byte *) xmalloc (length_size);
587 read_memory (addr + length_pos, buffer, length_size);
588 string_length = extract_unsigned_integer (buffer, length_size,
589 byte_order);
590 xfree (buffer);
591 i = val_print_string (char_type, NULL,
592 addr + string_pos, string_length,
593 stream, options);
594 }
595 else if (pascal_object_is_vtbl_member (type))
596 {
597 /* Print vtbl's nicely. */
598 CORE_ADDR vt_address = unpack_pointer (type, valaddr);
599 struct bound_minimal_symbol msymbol =
600 lookup_minimal_symbol_by_pc (vt_address);
601
602 /* If 'symbol_print' is set, we did the work above. */
603 if (!options->symbol_print
604 && (msymbol.minsym != NULL)
605 && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
606 {
607 if (want_space)
608 fputs_filtered (" ", stream);
609 fputs_filtered ("<", stream);
610 fputs_filtered (msymbol.minsym->print_name (), stream);
611 fputs_filtered (">", stream);
612 want_space = 1;
613 }
614 if (vt_address && options->vtblprint)
615 {
616 struct value *vt_val;
617 struct symbol *wsym = NULL;
618 struct type *wtype;
619
620 if (want_space)
621 fputs_filtered (" ", stream);
622
623 if (msymbol.minsym != NULL)
624 {
625 const char *search_name = msymbol.minsym->search_name ();
626 wsym = lookup_symbol_search_name (search_name, NULL,
627 VAR_DOMAIN).symbol;
628 }
629
630 if (wsym)
631 {
632 wtype = SYMBOL_TYPE (wsym);
633 }
634 else
635 {
636 wtype = TYPE_TARGET_TYPE (type);
637 }
638 vt_val = value_at (wtype, vt_address);
639 common_val_print (vt_val, stream, recurse + 1, options,
640 current_language);
641 if (options->prettyformat)
642 {
643 fprintf_filtered (stream, "\n");
644 print_spaces_filtered (2 + 2 * recurse, stream);
645 }
646 }
647 }
648
649 return;
650
651 case TYPE_CODE_REF:
652 case TYPE_CODE_ENUM:
653 case TYPE_CODE_FLAGS:
654 case TYPE_CODE_FUNC:
655 case TYPE_CODE_RANGE:
656 case TYPE_CODE_INT:
657 case TYPE_CODE_FLT:
658 case TYPE_CODE_VOID:
659 case TYPE_CODE_ERROR:
660 case TYPE_CODE_UNDEF:
661 case TYPE_CODE_BOOL:
662 case TYPE_CODE_CHAR:
663 generic_value_print (val, stream, recurse, options, &p_decorations);
664 break;
665
666 case TYPE_CODE_UNION:
667 if (recurse && !options->unionprint)
668 {
669 fprintf_filtered (stream, "{...}");
670 break;
671 }
672 /* Fall through. */
673 case TYPE_CODE_STRUCT:
674 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
675 {
676 /* Print the unmangled name if desired. */
677 /* Print vtable entry - we only get here if NOT using
678 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
679 /* Extract the address, assume that it is unsigned. */
680 print_address_demangle
681 (options, gdbarch,
682 extract_unsigned_integer (valaddr
683 + TYPE_FIELD_BITPOS (type,
684 VTBL_FNADDR_OFFSET) / 8,
685 TYPE_LENGTH (TYPE_FIELD_TYPE (type,
686 VTBL_FNADDR_OFFSET)),
687 byte_order),
688 stream, demangle);
689 }
690 else
691 {
692 if (is_pascal_string_type (type, &length_pos, &length_size,
693 &string_pos, &char_type, NULL))
694 {
695 len = extract_unsigned_integer (valaddr + length_pos,
696 length_size, byte_order);
697 LA_PRINT_STRING (stream, char_type, valaddr + string_pos,
698 len, NULL, 0, options);
699 }
700 else
701 pascal_object_print_value_fields (type, valaddr, 0,
702 value_address (val), stream,
703 recurse, val, options,
704 NULL, 0);
705 }
706 break;
707
708 case TYPE_CODE_SET:
709 elttype = TYPE_INDEX_TYPE (type);
710 elttype = check_typedef (elttype);
711 if (TYPE_STUB (elttype))
712 {
713 fprintf_styled (stream, metadata_style.style (), "<incomplete type>");
714 break;
715 }
716 else
717 {
718 struct type *range = elttype;
719 LONGEST low_bound, high_bound;
720 int need_comma = 0;
721
722 fputs_filtered ("[", stream);
723
724 int bound_info = get_discrete_bounds (range, &low_bound, &high_bound);
725 if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
726 {
727 /* If we know the size of the set type, we can figure out the
728 maximum value. */
729 bound_info = 0;
730 high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
731 TYPE_HIGH_BOUND (range) = high_bound;
732 }
733 maybe_bad_bstring:
734 if (bound_info < 0)
735 {
736 fputs_styled ("<error value>", metadata_style.style (), stream);
737 goto done;
738 }
739
740 for (i = low_bound; i <= high_bound; i++)
741 {
742 int element = value_bit_index (type, valaddr, i);
743
744 if (element < 0)
745 {
746 i = element;
747 goto maybe_bad_bstring;
748 }
749 if (element)
750 {
751 if (need_comma)
752 fputs_filtered (", ", stream);
753 print_type_scalar (range, i, stream);
754 need_comma = 1;
755
756 if (i + 1 <= high_bound
757 && value_bit_index (type, valaddr, ++i))
758 {
759 int j = i;
760
761 fputs_filtered ("..", stream);
762 while (i + 1 <= high_bound
763 && value_bit_index (type, valaddr, ++i))
764 j = i;
765 print_type_scalar (range, j, stream);
766 }
767 }
768 }
769 done:
770 fputs_filtered ("]", stream);
771 }
772 break;
773
774 default:
775 error (_("Invalid pascal type code %d in symbol table."),
776 TYPE_CODE (type));
777 }
c0941be6
TT
778}
779
373a8247 780\f
8e069a98 781void
79a45b7d
TT
782pascal_value_print (struct value *val, struct ui_file *stream,
783 const struct value_print_options *options)
373a8247 784{
df407dfe 785 struct type *type = value_type (val);
278582cb
PM
786 struct value_print_options opts = *options;
787
788 opts.deref_ref = 1;
373a8247
PM
789
790 /* If it is a pointer, indicate what it points to.
791
792 Print type also if it is a reference.
793
794 Object pascal: if it is a member pointer, we will take care
795 of that when we print it. */
b20a3440
PM
796 if (TYPE_CODE (type) == TYPE_CODE_PTR
797 || TYPE_CODE (type) == TYPE_CODE_REF)
373a8247
PM
798 {
799 /* Hack: remove (char *) for char strings. Their
0df8b418 800 type is indicated by the quoted string anyway. */
6ced1581 801 if (TYPE_CODE (type) == TYPE_CODE_PTR
b20a3440
PM
802 && TYPE_NAME (type) == NULL
803 && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
6314a349 804 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
373a8247 805 {
0df8b418 806 /* Print nothing. */
373a8247
PM
807 }
808 else
809 {
810 fprintf_filtered (stream, "(");
811 type_print (type, "", stream, -1);
812 fprintf_filtered (stream, ") ");
813 }
814 }
8e069a98 815 common_val_print (val, stream, 0, &opts, current_language);
373a8247
PM
816}
817
818
920d2a44
AC
819static void
820show_pascal_static_field_print (struct ui_file *file, int from_tty,
821 struct cmd_list_element *c, const char *value)
822{
823 fprintf_filtered (file, _("Printing of pascal static members is %s.\n"),
824 value);
825}
373a8247
PM
826
827static struct obstack dont_print_vb_obstack;
828static struct obstack dont_print_statmem_obstack;
829
806048c6 830static void pascal_object_print_static_field (struct value *,
79a45b7d
TT
831 struct ui_file *, int,
832 const struct value_print_options *);
373a8247 833
fc1a4b47 834static void pascal_object_print_value (struct type *, const gdb_byte *,
6b850546 835 LONGEST,
79a45b7d 836 CORE_ADDR, struct ui_file *, int,
e8b24d9f 837 struct value *,
79a45b7d 838 const struct value_print_options *,
a2bd3dcd 839 struct type **);
373a8247 840
07a32858
TT
841static void pascal_object_print_value (struct value *, struct ui_file *, int,
842 const struct value_print_options *,
843 struct type **);
844
373a8247
PM
845/* It was changed to this after 2.4.5. */
846const char pascal_vtbl_ptr_name[] =
847{'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
848
849/* Return truth value for assertion that TYPE is of the type
850 "pointer to virtual function". */
851
852int
fba45db2 853pascal_object_is_vtbl_ptr_type (struct type *type)
373a8247 854{
a737d952 855 const char *type_name = TYPE_NAME (type);
373a8247 856
fe978cb0
PA
857 return (type_name != NULL
858 && strcmp (type_name, pascal_vtbl_ptr_name) == 0);
373a8247
PM
859}
860
861/* Return truth value for the assertion that TYPE is of the type
862 "pointer to virtual function table". */
863
864int
fba45db2 865pascal_object_is_vtbl_member (struct type *type)
373a8247
PM
866{
867 if (TYPE_CODE (type) == TYPE_CODE_PTR)
868 {
869 type = TYPE_TARGET_TYPE (type);
870 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
871 {
872 type = TYPE_TARGET_TYPE (type);
0df8b418
MS
873 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* If not using
874 thunks. */
875 || TYPE_CODE (type) == TYPE_CODE_PTR) /* If using thunks. */
373a8247
PM
876 {
877 /* Virtual functions tables are full of pointers
0df8b418 878 to virtual functions. */
373a8247
PM
879 return pascal_object_is_vtbl_ptr_type (type);
880 }
881 }
882 }
883 return 0;
884}
885
a2bd3dcd
AC
886/* Mutually recursive subroutines of pascal_object_print_value and
887 c_val_print to print out a structure's fields:
888 pascal_object_print_value_fields and pascal_object_print_value.
373a8247 889
79a45b7d 890 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
373a8247
PM
891 same meanings as in pascal_object_print_value and c_val_print.
892
893 DONT_PRINT is an array of baseclass types that we
894 should not print, or zero if called from top level. */
895
1e592a8a 896static void
fc1a4b47 897pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
6b850546 898 LONGEST offset,
fba45db2 899 CORE_ADDR address, struct ui_file *stream,
79a45b7d 900 int recurse,
e8b24d9f 901 struct value *val,
79a45b7d 902 const struct value_print_options *options,
fba45db2
KB
903 struct type **dont_print_vb,
904 int dont_print_statmem)
373a8247
PM
905{
906 int i, len, n_baseclasses;
79f33898
SM
907 char *last_dont_print
908 = (char *) obstack_next_free (&dont_print_statmem_obstack);
373a8247 909
f168693b 910 type = check_typedef (type);
373a8247
PM
911
912 fprintf_filtered (stream, "{");
913 len = TYPE_NFIELDS (type);
914 n_baseclasses = TYPE_N_BASECLASSES (type);
915
916 /* Print out baseclasses such that we don't print
917 duplicates of virtual baseclasses. */
918 if (n_baseclasses > 0)
490f124f
PA
919 pascal_object_print_value (type, valaddr, offset, address,
920 stream, recurse + 1, val,
921 options, dont_print_vb);
373a8247
PM
922
923 if (!len && n_baseclasses == 1)
7f6aba03 924 fprintf_styled (stream, metadata_style.style (), "<No data fields>");
373a8247
PM
925 else
926 {
c1b6e682 927 struct obstack tmp_obstack = dont_print_statmem_obstack;
373a8247
PM
928 int fields_seen = 0;
929
930 if (dont_print_statmem == 0)
931 {
932 /* If we're at top level, carve out a completely fresh
933 chunk of the obstack and use that until this particular
934 invocation returns. */
373a8247
PM
935 obstack_finish (&dont_print_statmem_obstack);
936 }
937
938 for (i = n_baseclasses; i < len; i++)
939 {
940 /* If requested, skip printing of static fields. */
79a45b7d 941 if (!options->pascal_static_field_print
d6a843b5 942 && field_is_static (&TYPE_FIELD (type, i)))
373a8247
PM
943 continue;
944 if (fields_seen)
945 fprintf_filtered (stream, ", ");
946 else if (n_baseclasses > 0)
947 {
2a998fc0 948 if (options->prettyformat)
373a8247
PM
949 {
950 fprintf_filtered (stream, "\n");
951 print_spaces_filtered (2 + 2 * recurse, stream);
952 fputs_filtered ("members of ", stream);
a737d952 953 fputs_filtered (TYPE_NAME (type), stream);
373a8247
PM
954 fputs_filtered (": ", stream);
955 }
956 }
957 fields_seen = 1;
958
2a998fc0 959 if (options->prettyformat)
373a8247
PM
960 {
961 fprintf_filtered (stream, "\n");
962 print_spaces_filtered (2 + 2 * recurse, stream);
963 }
964 else
965 {
966 wrap_here (n_spaces (2 + 2 * recurse));
967 }
e93a8774
TT
968
969 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
970
971 if (field_is_static (&TYPE_FIELD (type, i)))
3f0cbb04
TT
972 {
973 fputs_filtered ("static ", stream);
974 fprintf_symbol_filtered (stream,
975 TYPE_FIELD_NAME (type, i),
976 current_language->la_language,
977 DMGL_PARAMS | DMGL_ANSI);
978 }
979 else
980 fputs_styled (TYPE_FIELD_NAME (type, i),
981 variable_name_style.style (), stream);
e93a8774
TT
982 annotate_field_name_end ();
983 fputs_filtered (" = ", stream);
984 annotate_field_value ();
373a8247 985
d6a843b5
JK
986 if (!field_is_static (&TYPE_FIELD (type, i))
987 && TYPE_FIELD_PACKED (type, i))
373a8247 988 {
6943961c 989 struct value *v;
373a8247
PM
990
991 /* Bitfields require special handling, especially due to byte
992 order problems. */
993 if (TYPE_FIELD_IGNORE (type, i))
994 {
7f6aba03
TT
995 fputs_styled ("<optimized out or zero length>",
996 metadata_style.style (), stream);
373a8247 997 }
8cf6f0b1
TT
998 else if (value_bits_synthetic_pointer (val,
999 TYPE_FIELD_BITPOS (type,
1000 i),
1001 TYPE_FIELD_BITSIZE (type,
1002 i)))
1003 {
7f6aba03
TT
1004 fputs_styled (_("<synthetic pointer>"),
1005 metadata_style.style (), stream);
8cf6f0b1 1006 }
373a8247
PM
1007 else
1008 {
79a45b7d 1009 struct value_print_options opts = *options;
ad3bbd48 1010
5467c6c8 1011 v = value_field_bitfield (type, i, valaddr, offset, val);
373a8247 1012
79a45b7d
TT
1013 opts.deref_ref = 0;
1014 common_val_print (v, stream, recurse + 1, &opts,
1015 current_language);
373a8247
PM
1016 }
1017 }
1018 else
1019 {
1020 if (TYPE_FIELD_IGNORE (type, i))
1021 {
7f6aba03
TT
1022 fputs_styled ("<optimized out or zero length>",
1023 metadata_style.style (), stream);
373a8247 1024 }
d6a843b5 1025 else if (field_is_static (&TYPE_FIELD (type, i)))
373a8247 1026 {
3e43a32a 1027 /* struct value *v = value_static_field (type, i);
0df8b418 1028 v4.17 specific. */
6943961c 1029 struct value *v;
ad3bbd48 1030
5467c6c8 1031 v = value_field_bitfield (type, i, valaddr, offset, val);
373a8247
PM
1032
1033 if (v == NULL)
901461f8 1034 val_print_optimized_out (NULL, stream);
373a8247 1035 else
79a45b7d
TT
1036 pascal_object_print_static_field (v, stream, recurse + 1,
1037 options);
373a8247
PM
1038 }
1039 else
1040 {
79a45b7d 1041 struct value_print_options opts = *options;
ad3bbd48 1042
79a45b7d 1043 opts.deref_ref = 0;
373a8247
PM
1044 /* val_print (TYPE_FIELD_TYPE (type, i),
1045 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
1046 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
1047 stream, format, 0, recurse + 1, pretty); */
1048 val_print (TYPE_FIELD_TYPE (type, i),
e8b24d9f 1049 offset + TYPE_FIELD_BITPOS (type, i) / 8,
490f124f 1050 address, stream, recurse + 1, val, &opts,
d8ca156b 1051 current_language);
373a8247
PM
1052 }
1053 }
1054 annotate_field_end ();
1055 }
1056
1057 if (dont_print_statmem == 0)
1058 {
1059 /* Free the space used to deal with the printing
1060 of the members from top level. */
1061 obstack_free (&dont_print_statmem_obstack, last_dont_print);
1062 dont_print_statmem_obstack = tmp_obstack;
1063 }
1064
2a998fc0 1065 if (options->prettyformat)
373a8247
PM
1066 {
1067 fprintf_filtered (stream, "\n");
1068 print_spaces_filtered (2 * recurse, stream);
1069 }
1070 }
1071 fprintf_filtered (stream, "}");
1072}
1073
07a32858
TT
1074/* Mutually recursive subroutines of pascal_object_print_value and
1075 pascal_value_print to print out a structure's fields:
1076 pascal_object_print_value_fields and pascal_object_print_value.
1077
1078 VAL, STREAM, RECURSE, and OPTIONS have the same meanings as in
1079 pascal_object_print_value and c_value_print.
1080
1081 DONT_PRINT is an array of baseclass types that we
1082 should not print, or zero if called from top level. */
1083
1084static void
1085pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
1086 int recurse,
1087 const struct value_print_options *options,
1088 struct type **dont_print_vb,
1089 int dont_print_statmem)
1090{
1091 int i, len, n_baseclasses;
1092 char *last_dont_print
1093 = (char *) obstack_next_free (&dont_print_statmem_obstack);
1094
1095 struct type *type = check_typedef (value_type (val));
1096
1097 fprintf_filtered (stream, "{");
1098 len = TYPE_NFIELDS (type);
1099 n_baseclasses = TYPE_N_BASECLASSES (type);
1100
1101 /* Print out baseclasses such that we don't print
1102 duplicates of virtual baseclasses. */
1103 if (n_baseclasses > 0)
1104 pascal_object_print_value (val, stream, recurse + 1,
1105 options, dont_print_vb);
1106
1107 if (!len && n_baseclasses == 1)
1108 fprintf_styled (stream, metadata_style.style (), "<No data fields>");
1109 else
1110 {
1111 struct obstack tmp_obstack = dont_print_statmem_obstack;
1112 int fields_seen = 0;
1113 const gdb_byte *valaddr = value_contents_for_printing (val);
1114
1115 if (dont_print_statmem == 0)
1116 {
1117 /* If we're at top level, carve out a completely fresh
1118 chunk of the obstack and use that until this particular
1119 invocation returns. */
1120 obstack_finish (&dont_print_statmem_obstack);
1121 }
1122
1123 for (i = n_baseclasses; i < len; i++)
1124 {
1125 /* If requested, skip printing of static fields. */
1126 if (!options->pascal_static_field_print
1127 && field_is_static (&TYPE_FIELD (type, i)))
1128 continue;
1129 if (fields_seen)
1130 fprintf_filtered (stream, ", ");
1131 else if (n_baseclasses > 0)
1132 {
1133 if (options->prettyformat)
1134 {
1135 fprintf_filtered (stream, "\n");
1136 print_spaces_filtered (2 + 2 * recurse, stream);
1137 fputs_filtered ("members of ", stream);
1138 fputs_filtered (TYPE_NAME (type), stream);
1139 fputs_filtered (": ", stream);
1140 }
1141 }
1142 fields_seen = 1;
1143
1144 if (options->prettyformat)
1145 {
1146 fprintf_filtered (stream, "\n");
1147 print_spaces_filtered (2 + 2 * recurse, stream);
1148 }
1149 else
1150 {
1151 wrap_here (n_spaces (2 + 2 * recurse));
1152 }
1153
1154 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
1155
1156 if (field_is_static (&TYPE_FIELD (type, i)))
1157 {
1158 fputs_filtered ("static ", stream);
1159 fprintf_symbol_filtered (stream,
1160 TYPE_FIELD_NAME (type, i),
1161 current_language->la_language,
1162 DMGL_PARAMS | DMGL_ANSI);
1163 }
1164 else
1165 fputs_styled (TYPE_FIELD_NAME (type, i),
1166 variable_name_style.style (), stream);
1167 annotate_field_name_end ();
1168 fputs_filtered (" = ", stream);
1169 annotate_field_value ();
1170
1171 if (!field_is_static (&TYPE_FIELD (type, i))
1172 && TYPE_FIELD_PACKED (type, i))
1173 {
1174 struct value *v;
1175
1176 /* Bitfields require special handling, especially due to byte
1177 order problems. */
1178 if (TYPE_FIELD_IGNORE (type, i))
1179 {
1180 fputs_styled ("<optimized out or zero length>",
1181 metadata_style.style (), stream);
1182 }
1183 else if (value_bits_synthetic_pointer (val,
1184 TYPE_FIELD_BITPOS (type,
1185 i),
1186 TYPE_FIELD_BITSIZE (type,
1187 i)))
1188 {
1189 fputs_styled (_("<synthetic pointer>"),
1190 metadata_style.style (), stream);
1191 }
1192 else
1193 {
1194 struct value_print_options opts = *options;
1195
1196 v = value_field_bitfield (type, i, valaddr, 0, val);
1197
1198 opts.deref_ref = 0;
1199 common_val_print (v, stream, recurse + 1, &opts,
1200 current_language);
1201 }
1202 }
1203 else
1204 {
1205 if (TYPE_FIELD_IGNORE (type, i))
1206 {
1207 fputs_styled ("<optimized out or zero length>",
1208 metadata_style.style (), stream);
1209 }
1210 else if (field_is_static (&TYPE_FIELD (type, i)))
1211 {
1212 /* struct value *v = value_static_field (type, i);
1213 v4.17 specific. */
1214 struct value *v;
1215
1216 v = value_field_bitfield (type, i, valaddr, 0, val);
1217
1218 if (v == NULL)
1219 val_print_optimized_out (NULL, stream);
1220 else
1221 pascal_object_print_static_field (v, stream, recurse + 1,
1222 options);
1223 }
1224 else
1225 {
1226 struct value_print_options opts = *options;
1227
1228 opts.deref_ref = 0;
1229
1230 struct value *v = value_primitive_field (val, 0, i,
1231 value_type (val));
1232 common_val_print (v, stream, recurse + 1, &opts,
1233 current_language);
1234 }
1235 }
1236 annotate_field_end ();
1237 }
1238
1239 if (dont_print_statmem == 0)
1240 {
1241 /* Free the space used to deal with the printing
1242 of the members from top level. */
1243 obstack_free (&dont_print_statmem_obstack, last_dont_print);
1244 dont_print_statmem_obstack = tmp_obstack;
1245 }
1246
1247 if (options->prettyformat)
1248 {
1249 fprintf_filtered (stream, "\n");
1250 print_spaces_filtered (2 * recurse, stream);
1251 }
1252 }
1253 fprintf_filtered (stream, "}");
1254}
1255
373a8247
PM
1256/* Special val_print routine to avoid printing multiple copies of virtual
1257 baseclasses. */
1258
7080f20f 1259static void
fc1a4b47 1260pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
6b850546 1261 LONGEST offset,
a2bd3dcd 1262 CORE_ADDR address, struct ui_file *stream,
79a45b7d 1263 int recurse,
e8b24d9f 1264 struct value *val,
79a45b7d 1265 const struct value_print_options *options,
fba45db2 1266 struct type **dont_print_vb)
373a8247 1267{
373a8247 1268 struct type **last_dont_print
ad3bbd48 1269 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
c1b6e682 1270 struct obstack tmp_obstack = dont_print_vb_obstack;
373a8247
PM
1271 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
1272
1273 if (dont_print_vb == 0)
1274 {
1275 /* If we're at top level, carve out a completely fresh
1276 chunk of the obstack and use that until this particular
1277 invocation returns. */
373a8247
PM
1278 /* Bump up the high-water mark. Now alpha is omega. */
1279 obstack_finish (&dont_print_vb_obstack);
1280 }
1281
1282 for (i = 0; i < n_baseclasses; i++)
1283 {
6b850546 1284 LONGEST boffset = 0;
373a8247 1285 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
a737d952 1286 const char *basename = TYPE_NAME (baseclass);
8af8e3bc 1287 const gdb_byte *base_valaddr = NULL;
6b850546 1288 LONGEST thisoffset;
8af8e3bc 1289 int skip = 0;
49663d05 1290 gdb::byte_vector buf;
373a8247
PM
1291
1292 if (BASETYPE_VIA_VIRTUAL (type, i))
1293 {
1294 struct type **first_dont_print
ad3bbd48 1295 = (struct type **) obstack_base (&dont_print_vb_obstack);
373a8247
PM
1296
1297 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
ad3bbd48 1298 - first_dont_print;
373a8247
PM
1299
1300 while (--j >= 0)
1301 if (baseclass == first_dont_print[j])
1302 goto flush_it;
1303
1304 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
1305 }
1306
490f124f
PA
1307 thisoffset = offset;
1308
a70b8144 1309 try
8af8e3bc
PA
1310 {
1311 boffset = baseclass_offset (type, i, valaddr, offset, address, val);
1312 }
230d2906 1313 catch (const gdb_exception_error &ex)
8af8e3bc 1314 {
7556d4a4
PA
1315 if (ex.error == NOT_AVAILABLE_ERROR)
1316 skip = -1;
1317 else
1318 skip = 1;
1319 }
8af8e3bc 1320
7556d4a4
PA
1321 if (skip == 0)
1322 {
8af8e3bc
PA
1323 /* The virtual base class pointer might have been clobbered by the
1324 user program. Make sure that it still points to a valid memory
1325 location. */
1326
1327 if (boffset < 0 || boffset >= TYPE_LENGTH (type))
1328 {
49663d05 1329 buf.resize (TYPE_LENGTH (baseclass));
6c18f3e0 1330
49663d05
TT
1331 base_valaddr = buf.data ();
1332 if (target_read_memory (address + boffset, buf.data (),
8af8e3bc
PA
1333 TYPE_LENGTH (baseclass)) != 0)
1334 skip = 1;
1335 address = address + boffset;
1336 thisoffset = 0;
1337 boffset = 0;
1338 }
1339 else
1340 base_valaddr = valaddr;
1341 }
373a8247 1342
2a998fc0 1343 if (options->prettyformat)
373a8247
PM
1344 {
1345 fprintf_filtered (stream, "\n");
1346 print_spaces_filtered (2 * recurse, stream);
1347 }
1348 fputs_filtered ("<", stream);
1349 /* Not sure what the best notation is in the case where there is no
1350 baseclass name. */
1351
1352 fputs_filtered (basename ? basename : "", stream);
1353 fputs_filtered ("> = ", stream);
1354
8af8e3bc
PA
1355 if (skip < 0)
1356 val_print_unavailable (stream);
1357 else if (skip > 0)
1358 val_print_invalid_address (stream);
373a8247 1359 else
3e43a32a 1360 pascal_object_print_value_fields (baseclass, base_valaddr,
490f124f
PA
1361 thisoffset + boffset, address,
1362 stream, recurse, val, options,
373a8247
PM
1363 (struct type **) obstack_base (&dont_print_vb_obstack),
1364 0);
1365 fputs_filtered (", ", stream);
1366
1367 flush_it:
1368 ;
1369 }
1370
1371 if (dont_print_vb == 0)
1372 {
1373 /* Free the space used to deal with the printing
1374 of this type from top level. */
1375 obstack_free (&dont_print_vb_obstack, last_dont_print);
1376 /* Reset watermark so that we can continue protecting
1377 ourselves from whatever we were protecting ourselves. */
1378 dont_print_vb_obstack = tmp_obstack;
1379 }
1380}
1381
07a32858
TT
1382/* Special val_print routine to avoid printing multiple copies of virtual
1383 baseclasses. */
1384
1385static void
1386pascal_object_print_value (struct value *val, struct ui_file *stream,
1387 int recurse,
1388 const struct value_print_options *options,
1389 struct type **dont_print_vb)
1390{
1391 struct type **last_dont_print
1392 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
1393 struct obstack tmp_obstack = dont_print_vb_obstack;
1394 struct type *type = check_typedef (value_type (val));
1395 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
1396
1397 if (dont_print_vb == 0)
1398 {
1399 /* If we're at top level, carve out a completely fresh
1400 chunk of the obstack and use that until this particular
1401 invocation returns. */
1402 /* Bump up the high-water mark. Now alpha is omega. */
1403 obstack_finish (&dont_print_vb_obstack);
1404 }
1405
1406 for (i = 0; i < n_baseclasses; i++)
1407 {
1408 LONGEST boffset = 0;
1409 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1410 const char *basename = TYPE_NAME (baseclass);
1411 int skip = 0;
1412
1413 if (BASETYPE_VIA_VIRTUAL (type, i))
1414 {
1415 struct type **first_dont_print
1416 = (struct type **) obstack_base (&dont_print_vb_obstack);
1417
1418 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
1419 - first_dont_print;
1420
1421 while (--j >= 0)
1422 if (baseclass == first_dont_print[j])
1423 goto flush_it;
1424
1425 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
1426 }
1427
1428 struct value *base_value;
1429 try
1430 {
1431 base_value = value_primitive_field (val, 0, i, type);
1432 }
1433 catch (const gdb_exception_error &ex)
1434 {
1435 if (ex.error == NOT_AVAILABLE_ERROR)
1436 skip = -1;
1437 else
1438 skip = 1;
1439 }
1440
1441 if (skip == 0)
1442 {
1443 /* The virtual base class pointer might have been clobbered by the
1444 user program. Make sure that it still points to a valid memory
1445 location. */
1446
1447 if (boffset < 0 || boffset >= TYPE_LENGTH (type))
1448 {
1449 CORE_ADDR address= value_address (val);
1450 gdb::byte_vector buf (TYPE_LENGTH (baseclass));
1451
1452 if (target_read_memory (address + boffset, buf.data (),
1453 TYPE_LENGTH (baseclass)) != 0)
1454 skip = 1;
1455 base_value = value_from_contents_and_address (baseclass,
1456 buf.data (),
1457 address + boffset);
1458 baseclass = value_type (base_value);
1459 boffset = 0;
1460 }
1461 }
1462
1463 if (options->prettyformat)
1464 {
1465 fprintf_filtered (stream, "\n");
1466 print_spaces_filtered (2 * recurse, stream);
1467 }
1468 fputs_filtered ("<", stream);
1469 /* Not sure what the best notation is in the case where there is no
1470 baseclass name. */
1471
1472 fputs_filtered (basename ? basename : "", stream);
1473 fputs_filtered ("> = ", stream);
1474
1475 if (skip < 0)
1476 val_print_unavailable (stream);
1477 else if (skip > 0)
1478 val_print_invalid_address (stream);
1479 else
1480 pascal_object_print_value_fields
1481 (base_value, stream, recurse, options,
1482 (struct type **) obstack_base (&dont_print_vb_obstack),
1483 0);
1484 fputs_filtered (", ", stream);
1485
1486 flush_it:
1487 ;
1488 }
1489
1490 if (dont_print_vb == 0)
1491 {
1492 /* Free the space used to deal with the printing
1493 of this type from top level. */
1494 obstack_free (&dont_print_vb_obstack, last_dont_print);
1495 /* Reset watermark so that we can continue protecting
1496 ourselves from whatever we were protecting ourselves. */
1497 dont_print_vb_obstack = tmp_obstack;
1498 }
1499}
1500
373a8247
PM
1501/* Print value of a static member.
1502 To avoid infinite recursion when printing a class that contains
1503 a static instance of the class, we keep the addresses of all printed
1504 static member classes in an obstack and refuse to print them more
1505 than once.
1506
79a45b7d 1507 VAL contains the value to print, STREAM, RECURSE, and OPTIONS
373a8247
PM
1508 have the same meanings as in c_val_print. */
1509
1510static void
806048c6 1511pascal_object_print_static_field (struct value *val,
79a45b7d
TT
1512 struct ui_file *stream,
1513 int recurse,
1514 const struct value_print_options *options)
373a8247 1515{
806048c6 1516 struct type *type = value_type (val);
79a45b7d 1517 struct value_print_options opts;
806048c6 1518
686d4def
PA
1519 if (value_entirely_optimized_out (val))
1520 {
1521 val_print_optimized_out (val, stream);
1522 return;
1523 }
1524
373a8247
PM
1525 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1526 {
42ae5230 1527 CORE_ADDR *first_dont_print, addr;
373a8247
PM
1528 int i;
1529
1530 first_dont_print
1531 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
1532 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
1533 - first_dont_print;
1534
1535 while (--i >= 0)
1536 {
42ae5230 1537 if (value_address (val) == first_dont_print[i])
373a8247 1538 {
2dbc041e
TT
1539 fputs_styled (_("\
1540<same as static member of an already seen type>"),
1541 metadata_style.style (), stream);
373a8247
PM
1542 return;
1543 }
1544 }
1545
42ae5230
TT
1546 addr = value_address (val);
1547 obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
373a8247
PM
1548 sizeof (CORE_ADDR));
1549
f168693b 1550 type = check_typedef (type);
490f124f
PA
1551 pascal_object_print_value_fields (type,
1552 value_contents_for_printing (val),
1553 value_embedded_offset (val),
1554 addr,
1555 stream, recurse,
1556 val, options, NULL, 1);
373a8247
PM
1557 return;
1558 }
79a45b7d
TT
1559
1560 opts = *options;
1561 opts.deref_ref = 0;
1562 common_val_print (val, stream, recurse, &opts, current_language);
373a8247
PM
1563}
1564
6c265988 1565void _initialize_pascal_valprint ();
373a8247 1566void
6c265988 1567_initialize_pascal_valprint ()
373a8247 1568{
5bf193a2 1569 add_setshow_boolean_cmd ("pascal_static-members", class_support,
79a45b7d 1570 &user_print_options.pascal_static_field_print, _("\
5bf193a2
AC
1571Set printing of pascal static members."), _("\
1572Show printing of pascal static members."), NULL,
1573 NULL,
920d2a44 1574 show_pascal_static_field_print,
5bf193a2 1575 &setprintlist, &showprintlist);
373a8247 1576}
This page took 1.870286 seconds and 4 git commands to generate.