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