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