Commit | Line | Data |
---|---|---|
373a8247 | 1 | /* Support for printing Pascal values for GDB, the GNU debugger. |
5bcca90b | 2 | |
4c38e0a4 | 3 | Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010 |
4f2aea11 | 4 | Free Software Foundation, Inc. |
373a8247 PM |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
373a8247 PM |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
373a8247 PM |
20 | |
21 | /* This file is derived from c-valprint.c */ | |
22 | ||
23 | #include "defs.h" | |
04ea0df1 | 24 | #include "gdb_obstack.h" |
373a8247 PM |
25 | #include "symtab.h" |
26 | #include "gdbtypes.h" | |
27 | #include "expression.h" | |
28 | #include "value.h" | |
29 | #include "command.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "gdbcore.h" | |
32 | #include "demangle.h" | |
33 | #include "valprint.h" | |
3172dc30 | 34 | #include "typeprint.h" |
373a8247 PM |
35 | #include "language.h" |
36 | #include "target.h" | |
37 | #include "annotate.h" | |
38 | #include "p-lang.h" | |
eb43544b | 39 | #include "cp-abi.h" |
d3cbe7ef | 40 | #include "cp-support.h" |
373a8247 PM |
41 | \f |
42 | ||
43 | ||
44 | ||
45 | /* Print data of type TYPE located at VALADDR (within GDB), which came from | |
46 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
79a45b7d | 47 | OPTIONS. The data at VALADDR is in target byte order. |
373a8247 PM |
48 | |
49 | If the data are a string pointer, returns the number of string characters | |
79a45b7d | 50 | printed. */ |
373a8247 PM |
51 | |
52 | ||
53 | int | |
fc1a4b47 | 54 | pascal_val_print (struct type *type, const gdb_byte *valaddr, |
a2bd3dcd | 55 | int embedded_offset, CORE_ADDR address, |
79a45b7d | 56 | struct ui_file *stream, int recurse, |
0e03807e | 57 | const struct value *original_value, |
79a45b7d | 58 | const struct value_print_options *options) |
373a8247 | 59 | { |
5af949e3 | 60 | struct gdbarch *gdbarch = get_type_arch (type); |
e17a4113 | 61 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
52f0bd74 | 62 | unsigned int i = 0; /* Number of characters printed */ |
373a8247 | 63 | unsigned len; |
df178451 | 64 | LONGEST low_bound, high_bound; |
373a8247 PM |
65 | struct type *elttype; |
66 | unsigned eltlen; | |
5598ce11 | 67 | int length_pos, length_size, string_pos; |
6c7a06a3 | 68 | struct type *char_type; |
373a8247 PM |
69 | LONGEST val; |
70 | CORE_ADDR addr; | |
71 | ||
72 | CHECK_TYPEDEF (type); | |
73 | switch (TYPE_CODE (type)) | |
74 | { | |
75 | case TYPE_CODE_ARRAY: | |
8148cf8d | 76 | if (get_array_bounds (type, &low_bound, &high_bound)) |
373a8247 | 77 | { |
8148cf8d | 78 | len = high_bound - low_bound + 1; |
373a8247 PM |
79 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); |
80 | eltlen = TYPE_LENGTH (elttype); | |
79a45b7d | 81 | if (options->prettyprint_arrays) |
373a8247 PM |
82 | { |
83 | print_spaces_filtered (2 + 2 * recurse, stream); | |
84 | } | |
6e354e5e PM |
85 | /* If 's' format is used, try to print out as string. |
86 | If no format is given, print as string if element type | |
87 | is of TYPE_CODE_CHAR and element size is 1,2 or 4. */ | |
88 | if (options->format == 's' | |
89 | || ((eltlen == 1 || eltlen == 2 || eltlen == 4) | |
90 | && TYPE_CODE (elttype) == TYPE_CODE_CHAR | |
91 | && options->format == 0)) | |
373a8247 PM |
92 | { |
93 | /* If requested, look for the first null char and only print | |
94 | elements up to it. */ | |
79a45b7d | 95 | if (options->stop_print_at_null) |
373a8247 PM |
96 | { |
97 | unsigned int temp_len; | |
98 | ||
99 | /* Look for a NULL char. */ | |
100 | for (temp_len = 0; | |
58159490 | 101 | extract_unsigned_integer (valaddr + embedded_offset + |
e17a4113 UW |
102 | temp_len * eltlen, eltlen, |
103 | byte_order) | |
79a45b7d | 104 | && temp_len < len && temp_len < options->print_max; |
373a8247 PM |
105 | temp_len++); |
106 | len = temp_len; | |
107 | } | |
108 | ||
6c7a06a3 | 109 | LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), |
be759fcf | 110 | valaddr + embedded_offset, len, NULL, 0, |
6c7a06a3 | 111 | options); |
373a8247 PM |
112 | i = len; |
113 | } | |
114 | else | |
115 | { | |
116 | fprintf_filtered (stream, "{"); | |
117 | /* If this is a virtual function table, print the 0th | |
118 | entry specially, and the rest of the members normally. */ | |
119 | if (pascal_object_is_vtbl_ptr_type (elttype)) | |
120 | { | |
121 | i = 1; | |
122 | fprintf_filtered (stream, "%d vtable entries", len - 1); | |
123 | } | |
124 | else | |
125 | { | |
126 | i = 0; | |
127 | } | |
128 | val_print_array_elements (type, valaddr + embedded_offset, address, stream, | |
0e03807e | 129 | recurse, original_value, options, i); |
373a8247 PM |
130 | fprintf_filtered (stream, "}"); |
131 | } | |
132 | break; | |
133 | } | |
134 | /* Array of unspecified length: treat like pointer to first elt. */ | |
135 | addr = address; | |
136 | goto print_unpacked_pointer; | |
137 | ||
138 | case TYPE_CODE_PTR: | |
79a45b7d | 139 | if (options->format && options->format != 's') |
373a8247 | 140 | { |
79a45b7d TT |
141 | print_scalar_formatted (valaddr + embedded_offset, type, |
142 | options, 0, stream); | |
373a8247 PM |
143 | break; |
144 | } | |
79a45b7d | 145 | if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) |
373a8247 PM |
146 | { |
147 | /* Print the unmangled name if desired. */ | |
148 | /* Print vtable entry - we only get here if we ARE using | |
149 | -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ | |
b276f1bb | 150 | /* Extract the address, assume that it is unsigned. */ |
e17a4113 UW |
151 | addr = extract_unsigned_integer (valaddr + embedded_offset, |
152 | TYPE_LENGTH (type), byte_order); | |
153 | print_address_demangle (gdbarch, addr, stream, demangle); | |
373a8247 PM |
154 | break; |
155 | } | |
156 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
e13eedd5 PM |
157 | |
158 | addr = unpack_pointer (type, valaddr + embedded_offset); | |
159 | print_unpacked_pointer: | |
160 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
161 | ||
162 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
373a8247 | 163 | { |
e13eedd5 PM |
164 | /* Try to print what function it points to. */ |
165 | print_address_demangle (gdbarch, addr, stream, demangle); | |
166 | /* Return value is irrelevant except for string pointers. */ | |
167 | return (0); | |
168 | } | |
373a8247 | 169 | |
e13eedd5 PM |
170 | if (options->addressprint && options->format != 's') |
171 | { | |
172 | fputs_filtered (paddress (gdbarch, addr), stream); | |
173 | } | |
373a8247 | 174 | |
e13eedd5 PM |
175 | /* For a pointer to char or unsigned char, also print the string |
176 | pointed to, unless pointer is null. */ | |
177 | if (((TYPE_LENGTH (elttype) == 1 | |
178 | && (TYPE_CODE (elttype) == TYPE_CODE_INT | |
179 | || TYPE_CODE (elttype) == TYPE_CODE_CHAR)) | |
180 | || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4) | |
181 | && TYPE_CODE (elttype) == TYPE_CODE_CHAR)) | |
182 | && (options->format == 0 || options->format == 's') | |
183 | && addr != 0) | |
184 | { | |
185 | /* no wide string yet */ | |
09ca9e2e | 186 | i = val_print_string (elttype, NULL, addr, -1, stream, options); |
e13eedd5 PM |
187 | } |
188 | /* also for pointers to pascal strings */ | |
189 | /* Note: this is Free Pascal specific: | |
190 | as GDB does not recognize stabs pascal strings | |
191 | Pascal strings are mapped to records | |
192 | with lowercase names PM */ | |
193 | if (is_pascal_string_type (elttype, &length_pos, &length_size, | |
194 | &string_pos, &char_type, NULL) | |
195 | && addr != 0) | |
196 | { | |
197 | ULONGEST string_length; | |
198 | void *buffer; | |
ad3bbd48 | 199 | |
e13eedd5 PM |
200 | buffer = xmalloc (length_size); |
201 | read_memory (addr + length_pos, buffer, length_size); | |
202 | string_length = extract_unsigned_integer (buffer, length_size, | |
203 | byte_order); | |
204 | xfree (buffer); | |
09ca9e2e TT |
205 | i = val_print_string (char_type, NULL, |
206 | addr + string_pos, string_length, | |
207 | stream, options); | |
e13eedd5 PM |
208 | } |
209 | else if (pascal_object_is_vtbl_member (type)) | |
210 | { | |
211 | /* print vtbl's nicely */ | |
212 | CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); | |
e13eedd5 | 213 | struct minimal_symbol *msymbol = |
ad3bbd48 MS |
214 | lookup_minimal_symbol_by_pc (vt_address); |
215 | ||
e13eedd5 PM |
216 | if ((msymbol != NULL) |
217 | && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol))) | |
373a8247 | 218 | { |
e13eedd5 PM |
219 | fputs_filtered (" <", stream); |
220 | fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); | |
221 | fputs_filtered (">", stream); | |
373a8247 | 222 | } |
e13eedd5 | 223 | if (vt_address && options->vtblprint) |
373a8247 | 224 | { |
e13eedd5 PM |
225 | struct value *vt_val; |
226 | struct symbol *wsym = (struct symbol *) NULL; | |
227 | struct type *wtype; | |
228 | struct block *block = (struct block *) NULL; | |
229 | int is_this_fld; | |
373a8247 | 230 | |
e13eedd5 PM |
231 | if (msymbol != NULL) |
232 | wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block, | |
233 | VAR_DOMAIN, &is_this_fld); | |
234 | ||
235 | if (wsym) | |
373a8247 | 236 | { |
e13eedd5 | 237 | wtype = SYMBOL_TYPE (wsym); |
373a8247 | 238 | } |
e13eedd5 | 239 | else |
373a8247 | 240 | { |
e13eedd5 PM |
241 | wtype = TYPE_TARGET_TYPE (type); |
242 | } | |
243 | vt_val = value_at (wtype, vt_address); | |
244 | common_val_print (vt_val, stream, recurse + 1, options, | |
245 | current_language); | |
246 | if (options->pretty) | |
247 | { | |
248 | fprintf_filtered (stream, "\n"); | |
249 | print_spaces_filtered (2 + 2 * recurse, stream); | |
373a8247 PM |
250 | } |
251 | } | |
373a8247 | 252 | } |
e13eedd5 PM |
253 | |
254 | /* Return number of characters printed, including the terminating | |
255 | '\0' if we reached the end. val_print_string takes care including | |
256 | the terminating '\0' if necessary. */ | |
257 | return i; | |
258 | ||
373a8247 PM |
259 | break; |
260 | ||
373a8247 PM |
261 | case TYPE_CODE_REF: |
262 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
79a45b7d | 263 | if (options->addressprint) |
373a8247 | 264 | { |
830bb937 UW |
265 | CORE_ADDR addr |
266 | = extract_typed_address (valaddr + embedded_offset, type); | |
ad3bbd48 | 267 | |
373a8247 | 268 | fprintf_filtered (stream, "@"); |
5af949e3 | 269 | fputs_filtered (paddress (gdbarch, addr), stream); |
79a45b7d | 270 | if (options->deref_ref) |
373a8247 PM |
271 | fputs_filtered (": ", stream); |
272 | } | |
273 | /* De-reference the reference. */ | |
79a45b7d | 274 | if (options->deref_ref) |
373a8247 PM |
275 | { |
276 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
277 | { | |
6943961c | 278 | struct value *deref_val = |
ad3bbd48 MS |
279 | value_at |
280 | (TYPE_TARGET_TYPE (type), | |
281 | unpack_pointer (type, valaddr + embedded_offset)); | |
282 | ||
79a45b7d TT |
283 | common_val_print (deref_val, stream, recurse + 1, options, |
284 | current_language); | |
373a8247 PM |
285 | } |
286 | else | |
287 | fputs_filtered ("???", stream); | |
288 | } | |
289 | break; | |
290 | ||
291 | case TYPE_CODE_UNION: | |
79a45b7d | 292 | if (recurse && !options->unionprint) |
373a8247 PM |
293 | { |
294 | fprintf_filtered (stream, "{...}"); | |
295 | break; | |
296 | } | |
297 | /* Fall through. */ | |
298 | case TYPE_CODE_STRUCT: | |
79a45b7d | 299 | if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) |
373a8247 PM |
300 | { |
301 | /* Print the unmangled name if desired. */ | |
302 | /* Print vtable entry - we only get here if NOT using | |
303 | -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */ | |
b276f1bb AC |
304 | /* Extract the address, assume that it is unsigned. */ |
305 | print_address_demangle | |
5af949e3 UW |
306 | (gdbarch, |
307 | extract_unsigned_integer (valaddr + embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8, | |
e17a4113 | 308 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET)), byte_order), |
b276f1bb | 309 | stream, demangle); |
373a8247 PM |
310 | } |
311 | else | |
312 | { | |
5598ce11 | 313 | if (is_pascal_string_type (type, &length_pos, &length_size, |
6c7a06a3 | 314 | &string_pos, &char_type, NULL)) |
373a8247 | 315 | { |
e17a4113 | 316 | len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size, byte_order); |
be759fcf PM |
317 | LA_PRINT_STRING (stream, char_type, |
318 | valaddr + embedded_offset + string_pos, | |
319 | len, NULL, 0, options); | |
373a8247 PM |
320 | } |
321 | else | |
79a45b7d | 322 | pascal_object_print_value_fields (type, valaddr + embedded_offset, address, stream, |
0e03807e | 323 | recurse, original_value, options, NULL, 0); |
373a8247 PM |
324 | } |
325 | break; | |
326 | ||
327 | case TYPE_CODE_ENUM: | |
79a45b7d | 328 | if (options->format) |
373a8247 | 329 | { |
79a45b7d TT |
330 | print_scalar_formatted (valaddr + embedded_offset, type, |
331 | options, 0, stream); | |
373a8247 PM |
332 | break; |
333 | } | |
334 | len = TYPE_NFIELDS (type); | |
335 | val = unpack_long (type, valaddr + embedded_offset); | |
336 | for (i = 0; i < len; i++) | |
337 | { | |
338 | QUIT; | |
339 | if (val == TYPE_FIELD_BITPOS (type, i)) | |
340 | { | |
341 | break; | |
342 | } | |
343 | } | |
344 | if (i < len) | |
345 | { | |
346 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
347 | } | |
348 | else | |
349 | { | |
350 | print_longest (stream, 'd', 0, val); | |
351 | } | |
352 | break; | |
353 | ||
4f2aea11 | 354 | case TYPE_CODE_FLAGS: |
79a45b7d TT |
355 | if (options->format) |
356 | print_scalar_formatted (valaddr + embedded_offset, type, | |
357 | options, 0, stream); | |
4f2aea11 MK |
358 | else |
359 | val_print_type_code_flags (type, valaddr + embedded_offset, stream); | |
360 | break; | |
361 | ||
373a8247 | 362 | case TYPE_CODE_FUNC: |
79a45b7d | 363 | if (options->format) |
373a8247 | 364 | { |
79a45b7d TT |
365 | print_scalar_formatted (valaddr + embedded_offset, type, |
366 | options, 0, stream); | |
373a8247 PM |
367 | break; |
368 | } | |
369 | /* FIXME, we should consider, at least for ANSI C language, eliminating | |
370 | the distinction made between FUNCs and POINTERs to FUNCs. */ | |
371 | fprintf_filtered (stream, "{"); | |
372 | type_print (type, "", stream, -1); | |
373 | fprintf_filtered (stream, "} "); | |
374 | /* Try to print what function it points to, and its address. */ | |
5af949e3 | 375 | print_address_demangle (gdbarch, address, stream, demangle); |
373a8247 PM |
376 | break; |
377 | ||
378 | case TYPE_CODE_BOOL: | |
79a45b7d TT |
379 | if (options->format || options->output_format) |
380 | { | |
381 | struct value_print_options opts = *options; | |
ad3bbd48 | 382 | |
79a45b7d TT |
383 | opts.format = (options->format ? options->format |
384 | : options->output_format); | |
385 | print_scalar_formatted (valaddr + embedded_offset, type, | |
386 | &opts, 0, stream); | |
387 | } | |
373a8247 PM |
388 | else |
389 | { | |
390 | val = unpack_long (type, valaddr + embedded_offset); | |
391 | if (val == 0) | |
392 | fputs_filtered ("false", stream); | |
393 | else if (val == 1) | |
394 | fputs_filtered ("true", stream); | |
395 | else | |
396 | { | |
397 | fputs_filtered ("true (", stream); | |
398 | fprintf_filtered (stream, "%ld)", (long int) val); | |
399 | } | |
400 | } | |
401 | break; | |
402 | ||
403 | case TYPE_CODE_RANGE: | |
404 | /* FIXME: create_range_type does not set the unsigned bit in a | |
405 | range type (I think it probably should copy it from the target | |
406 | type), so we won't print values which are too large to | |
407 | fit in a signed integer correctly. */ | |
408 | /* FIXME: Doesn't handle ranges of enums correctly. (Can't just | |
409 | print with the target type, though, because the size of our type | |
410 | and the target type might differ). */ | |
411 | /* FALLTHROUGH */ | |
412 | ||
413 | case TYPE_CODE_INT: | |
79a45b7d | 414 | if (options->format || options->output_format) |
373a8247 | 415 | { |
79a45b7d | 416 | struct value_print_options opts = *options; |
ad3bbd48 | 417 | |
79a45b7d TT |
418 | opts.format = (options->format ? options->format |
419 | : options->output_format); | |
420 | print_scalar_formatted (valaddr + embedded_offset, type, | |
421 | &opts, 0, stream); | |
373a8247 PM |
422 | } |
423 | else | |
424 | { | |
425 | val_print_type_code_int (type, valaddr + embedded_offset, stream); | |
426 | } | |
427 | break; | |
428 | ||
429 | case TYPE_CODE_CHAR: | |
79a45b7d | 430 | if (options->format || options->output_format) |
373a8247 | 431 | { |
79a45b7d | 432 | struct value_print_options opts = *options; |
ad3bbd48 | 433 | |
79a45b7d TT |
434 | opts.format = (options->format ? options->format |
435 | : options->output_format); | |
436 | print_scalar_formatted (valaddr + embedded_offset, type, | |
437 | &opts, 0, stream); | |
373a8247 PM |
438 | } |
439 | else | |
440 | { | |
441 | val = unpack_long (type, valaddr + embedded_offset); | |
442 | if (TYPE_UNSIGNED (type)) | |
443 | fprintf_filtered (stream, "%u", (unsigned int) val); | |
444 | else | |
445 | fprintf_filtered (stream, "%d", (int) val); | |
446 | fputs_filtered (" ", stream); | |
6c7a06a3 | 447 | LA_PRINT_CHAR ((unsigned char) val, type, stream); |
373a8247 PM |
448 | } |
449 | break; | |
450 | ||
451 | case TYPE_CODE_FLT: | |
79a45b7d | 452 | if (options->format) |
373a8247 | 453 | { |
79a45b7d TT |
454 | print_scalar_formatted (valaddr + embedded_offset, type, |
455 | options, 0, stream); | |
373a8247 PM |
456 | } |
457 | else | |
458 | { | |
459 | print_floating (valaddr + embedded_offset, type, stream); | |
460 | } | |
461 | break; | |
462 | ||
463 | case TYPE_CODE_BITSTRING: | |
464 | case TYPE_CODE_SET: | |
465 | elttype = TYPE_INDEX_TYPE (type); | |
466 | CHECK_TYPEDEF (elttype); | |
74a9bb82 | 467 | if (TYPE_STUB (elttype)) |
373a8247 PM |
468 | { |
469 | fprintf_filtered (stream, "<incomplete type>"); | |
470 | gdb_flush (stream); | |
471 | break; | |
472 | } | |
473 | else | |
474 | { | |
475 | struct type *range = elttype; | |
476 | LONGEST low_bound, high_bound; | |
477 | int i; | |
478 | int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING; | |
479 | int need_comma = 0; | |
480 | ||
481 | if (is_bitstring) | |
482 | fputs_filtered ("B'", stream); | |
483 | else | |
484 | fputs_filtered ("[", stream); | |
485 | ||
486 | i = get_discrete_bounds (range, &low_bound, &high_bound); | |
7a081a30 PM |
487 | if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0) |
488 | { | |
489 | /* If we know the size of the set type, we can figure out the | |
490 | maximum value. */ | |
491 | i = 0; | |
492 | high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1; | |
493 | TYPE_HIGH_BOUND (range) = high_bound; | |
494 | } | |
373a8247 PM |
495 | maybe_bad_bstring: |
496 | if (i < 0) | |
497 | { | |
498 | fputs_filtered ("<error value>", stream); | |
499 | goto done; | |
500 | } | |
501 | ||
502 | for (i = low_bound; i <= high_bound; i++) | |
503 | { | |
504 | int element = value_bit_index (type, valaddr + embedded_offset, i); | |
ad3bbd48 | 505 | |
373a8247 PM |
506 | if (element < 0) |
507 | { | |
508 | i = element; | |
509 | goto maybe_bad_bstring; | |
510 | } | |
511 | if (is_bitstring) | |
512 | fprintf_filtered (stream, "%d", element); | |
513 | else if (element) | |
514 | { | |
515 | if (need_comma) | |
516 | fputs_filtered (", ", stream); | |
517 | print_type_scalar (range, i, stream); | |
518 | need_comma = 1; | |
519 | ||
520 | if (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, ++i)) | |
521 | { | |
522 | int j = i; | |
ad3bbd48 | 523 | |
373a8247 PM |
524 | fputs_filtered ("..", stream); |
525 | while (i + 1 <= high_bound | |
526 | && value_bit_index (type, valaddr + embedded_offset, ++i)) | |
527 | j = i; | |
528 | print_type_scalar (range, j, stream); | |
529 | } | |
530 | } | |
531 | } | |
532 | done: | |
533 | if (is_bitstring) | |
534 | fputs_filtered ("'", stream); | |
535 | else | |
536 | fputs_filtered ("]", stream); | |
537 | } | |
538 | break; | |
539 | ||
540 | case TYPE_CODE_VOID: | |
541 | fprintf_filtered (stream, "void"); | |
542 | break; | |
543 | ||
544 | case TYPE_CODE_ERROR: | |
b00fdb78 | 545 | fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type)); |
373a8247 PM |
546 | break; |
547 | ||
548 | case TYPE_CODE_UNDEF: | |
549 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
550 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" | |
551 | and no complete type for struct foo in that file. */ | |
552 | fprintf_filtered (stream, "<incomplete type>"); | |
553 | break; | |
554 | ||
555 | default: | |
8a3fe4f8 | 556 | error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type)); |
373a8247 PM |
557 | } |
558 | gdb_flush (stream); | |
559 | return (0); | |
560 | } | |
561 | \f | |
562 | int | |
79a45b7d TT |
563 | pascal_value_print (struct value *val, struct ui_file *stream, |
564 | const struct value_print_options *options) | |
373a8247 | 565 | { |
df407dfe | 566 | struct type *type = value_type (val); |
278582cb PM |
567 | struct value_print_options opts = *options; |
568 | ||
569 | opts.deref_ref = 1; | |
373a8247 PM |
570 | |
571 | /* If it is a pointer, indicate what it points to. | |
572 | ||
573 | Print type also if it is a reference. | |
574 | ||
575 | Object pascal: if it is a member pointer, we will take care | |
576 | of that when we print it. */ | |
b20a3440 PM |
577 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
578 | || TYPE_CODE (type) == TYPE_CODE_REF) | |
373a8247 PM |
579 | { |
580 | /* Hack: remove (char *) for char strings. Their | |
581 | type is indicated by the quoted string anyway. */ | |
b20a3440 PM |
582 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
583 | && TYPE_NAME (type) == NULL | |
584 | && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL | |
6314a349 | 585 | && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0) |
373a8247 PM |
586 | { |
587 | /* Print nothing */ | |
588 | } | |
589 | else | |
590 | { | |
591 | fprintf_filtered (stream, "("); | |
592 | type_print (type, "", stream, -1); | |
593 | fprintf_filtered (stream, ") "); | |
594 | } | |
595 | } | |
278582cb | 596 | return common_val_print (val, stream, 0, &opts, current_language); |
373a8247 PM |
597 | } |
598 | ||
599 | ||
920d2a44 AC |
600 | static void |
601 | show_pascal_static_field_print (struct ui_file *file, int from_tty, | |
602 | struct cmd_list_element *c, const char *value) | |
603 | { | |
604 | fprintf_filtered (file, _("Printing of pascal static members is %s.\n"), | |
605 | value); | |
606 | } | |
373a8247 PM |
607 | |
608 | static struct obstack dont_print_vb_obstack; | |
609 | static struct obstack dont_print_statmem_obstack; | |
610 | ||
806048c6 | 611 | static void pascal_object_print_static_field (struct value *, |
79a45b7d TT |
612 | struct ui_file *, int, |
613 | const struct value_print_options *); | |
373a8247 | 614 | |
fc1a4b47 | 615 | static void pascal_object_print_value (struct type *, const gdb_byte *, |
79a45b7d | 616 | CORE_ADDR, struct ui_file *, int, |
0e03807e | 617 | const struct value *, |
79a45b7d | 618 | const struct value_print_options *, |
a2bd3dcd | 619 | struct type **); |
373a8247 | 620 | |
373a8247 PM |
621 | /* It was changed to this after 2.4.5. */ |
622 | const char pascal_vtbl_ptr_name[] = | |
623 | {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0}; | |
624 | ||
625 | /* Return truth value for assertion that TYPE is of the type | |
626 | "pointer to virtual function". */ | |
627 | ||
628 | int | |
fba45db2 | 629 | pascal_object_is_vtbl_ptr_type (struct type *type) |
373a8247 PM |
630 | { |
631 | char *typename = type_name_no_tag (type); | |
632 | ||
633 | return (typename != NULL | |
6314a349 | 634 | && strcmp (typename, pascal_vtbl_ptr_name) == 0); |
373a8247 PM |
635 | } |
636 | ||
637 | /* Return truth value for the assertion that TYPE is of the type | |
638 | "pointer to virtual function table". */ | |
639 | ||
640 | int | |
fba45db2 | 641 | pascal_object_is_vtbl_member (struct type *type) |
373a8247 PM |
642 | { |
643 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
644 | { | |
645 | type = TYPE_TARGET_TYPE (type); | |
646 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
647 | { | |
648 | type = TYPE_TARGET_TYPE (type); | |
649 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* if not using thunks */ | |
650 | || TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */ | |
651 | { | |
652 | /* Virtual functions tables are full of pointers | |
653 | to virtual functions. */ | |
654 | return pascal_object_is_vtbl_ptr_type (type); | |
655 | } | |
656 | } | |
657 | } | |
658 | return 0; | |
659 | } | |
660 | ||
a2bd3dcd AC |
661 | /* Mutually recursive subroutines of pascal_object_print_value and |
662 | c_val_print to print out a structure's fields: | |
663 | pascal_object_print_value_fields and pascal_object_print_value. | |
373a8247 | 664 | |
79a45b7d | 665 | TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the |
373a8247 PM |
666 | same meanings as in pascal_object_print_value and c_val_print. |
667 | ||
668 | DONT_PRINT is an array of baseclass types that we | |
669 | should not print, or zero if called from top level. */ | |
670 | ||
671 | void | |
fc1a4b47 | 672 | pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, |
fba45db2 | 673 | CORE_ADDR address, struct ui_file *stream, |
79a45b7d | 674 | int recurse, |
0e03807e | 675 | const struct value *val, |
79a45b7d | 676 | const struct value_print_options *options, |
fba45db2 KB |
677 | struct type **dont_print_vb, |
678 | int dont_print_statmem) | |
373a8247 PM |
679 | { |
680 | int i, len, n_baseclasses; | |
373a8247 PM |
681 | char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack); |
682 | ||
683 | CHECK_TYPEDEF (type); | |
684 | ||
685 | fprintf_filtered (stream, "{"); | |
686 | len = TYPE_NFIELDS (type); | |
687 | n_baseclasses = TYPE_N_BASECLASSES (type); | |
688 | ||
689 | /* Print out baseclasses such that we don't print | |
690 | duplicates of virtual baseclasses. */ | |
691 | if (n_baseclasses > 0) | |
692 | pascal_object_print_value (type, valaddr, address, stream, | |
0e03807e | 693 | recurse + 1, val, options, dont_print_vb); |
373a8247 PM |
694 | |
695 | if (!len && n_baseclasses == 1) | |
696 | fprintf_filtered (stream, "<No data fields>"); | |
697 | else | |
698 | { | |
c1b6e682 | 699 | struct obstack tmp_obstack = dont_print_statmem_obstack; |
373a8247 PM |
700 | int fields_seen = 0; |
701 | ||
702 | if (dont_print_statmem == 0) | |
703 | { | |
704 | /* If we're at top level, carve out a completely fresh | |
705 | chunk of the obstack and use that until this particular | |
706 | invocation returns. */ | |
373a8247 PM |
707 | obstack_finish (&dont_print_statmem_obstack); |
708 | } | |
709 | ||
710 | for (i = n_baseclasses; i < len; i++) | |
711 | { | |
712 | /* If requested, skip printing of static fields. */ | |
79a45b7d | 713 | if (!options->pascal_static_field_print |
d6a843b5 | 714 | && field_is_static (&TYPE_FIELD (type, i))) |
373a8247 PM |
715 | continue; |
716 | if (fields_seen) | |
717 | fprintf_filtered (stream, ", "); | |
718 | else if (n_baseclasses > 0) | |
719 | { | |
79a45b7d | 720 | if (options->pretty) |
373a8247 PM |
721 | { |
722 | fprintf_filtered (stream, "\n"); | |
723 | print_spaces_filtered (2 + 2 * recurse, stream); | |
724 | fputs_filtered ("members of ", stream); | |
725 | fputs_filtered (type_name_no_tag (type), stream); | |
726 | fputs_filtered (": ", stream); | |
727 | } | |
728 | } | |
729 | fields_seen = 1; | |
730 | ||
79a45b7d | 731 | if (options->pretty) |
373a8247 PM |
732 | { |
733 | fprintf_filtered (stream, "\n"); | |
734 | print_spaces_filtered (2 + 2 * recurse, stream); | |
735 | } | |
736 | else | |
737 | { | |
738 | wrap_here (n_spaces (2 + 2 * recurse)); | |
739 | } | |
79a45b7d | 740 | if (options->inspect_it) |
373a8247 PM |
741 | { |
742 | if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) | |
743 | fputs_filtered ("\"( ptr \"", stream); | |
744 | else | |
745 | fputs_filtered ("\"( nodef \"", stream); | |
d6a843b5 | 746 | if (field_is_static (&TYPE_FIELD (type, i))) |
373a8247 PM |
747 | fputs_filtered ("static ", stream); |
748 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
749 | language_cplus, | |
750 | DMGL_PARAMS | DMGL_ANSI); | |
751 | fputs_filtered ("\" \"", stream); | |
752 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
753 | language_cplus, | |
754 | DMGL_PARAMS | DMGL_ANSI); | |
755 | fputs_filtered ("\") \"", stream); | |
756 | } | |
757 | else | |
758 | { | |
759 | annotate_field_begin (TYPE_FIELD_TYPE (type, i)); | |
760 | ||
d6a843b5 | 761 | if (field_is_static (&TYPE_FIELD (type, i))) |
373a8247 PM |
762 | fputs_filtered ("static ", stream); |
763 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
764 | language_cplus, | |
765 | DMGL_PARAMS | DMGL_ANSI); | |
766 | annotate_field_name_end (); | |
767 | fputs_filtered (" = ", stream); | |
768 | annotate_field_value (); | |
769 | } | |
770 | ||
d6a843b5 JK |
771 | if (!field_is_static (&TYPE_FIELD (type, i)) |
772 | && TYPE_FIELD_PACKED (type, i)) | |
373a8247 | 773 | { |
6943961c | 774 | struct value *v; |
373a8247 PM |
775 | |
776 | /* Bitfields require special handling, especially due to byte | |
777 | order problems. */ | |
778 | if (TYPE_FIELD_IGNORE (type, i)) | |
779 | { | |
780 | fputs_filtered ("<optimized out or zero length>", stream); | |
781 | } | |
8cf6f0b1 TT |
782 | else if (value_bits_synthetic_pointer (val, |
783 | TYPE_FIELD_BITPOS (type, | |
784 | i), | |
785 | TYPE_FIELD_BITSIZE (type, | |
786 | i))) | |
787 | { | |
788 | fputs_filtered (_("<synthetic pointer>"), stream); | |
789 | } | |
0e03807e TT |
790 | else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i), |
791 | TYPE_FIELD_BITSIZE (type, i))) | |
792 | { | |
793 | fputs_filtered (_("<value optimized out>"), stream); | |
794 | } | |
373a8247 PM |
795 | else |
796 | { | |
79a45b7d | 797 | struct value_print_options opts = *options; |
ad3bbd48 | 798 | |
373a8247 PM |
799 | v = value_from_longest (TYPE_FIELD_TYPE (type, i), |
800 | unpack_field_as_long (type, valaddr, i)); | |
801 | ||
79a45b7d TT |
802 | opts.deref_ref = 0; |
803 | common_val_print (v, stream, recurse + 1, &opts, | |
804 | current_language); | |
373a8247 PM |
805 | } |
806 | } | |
807 | else | |
808 | { | |
809 | if (TYPE_FIELD_IGNORE (type, i)) | |
810 | { | |
811 | fputs_filtered ("<optimized out or zero length>", stream); | |
812 | } | |
d6a843b5 | 813 | else if (field_is_static (&TYPE_FIELD (type, i))) |
373a8247 | 814 | { |
6943961c AC |
815 | /* struct value *v = value_static_field (type, i); v4.17 specific */ |
816 | struct value *v; | |
ad3bbd48 | 817 | |
373a8247 PM |
818 | v = value_from_longest (TYPE_FIELD_TYPE (type, i), |
819 | unpack_field_as_long (type, valaddr, i)); | |
820 | ||
821 | if (v == NULL) | |
822 | fputs_filtered ("<optimized out>", stream); | |
823 | else | |
79a45b7d TT |
824 | pascal_object_print_static_field (v, stream, recurse + 1, |
825 | options); | |
373a8247 PM |
826 | } |
827 | else | |
828 | { | |
79a45b7d | 829 | struct value_print_options opts = *options; |
ad3bbd48 | 830 | |
79a45b7d | 831 | opts.deref_ref = 0; |
373a8247 PM |
832 | /* val_print (TYPE_FIELD_TYPE (type, i), |
833 | valaddr + TYPE_FIELD_BITPOS (type, i) / 8, | |
834 | address + TYPE_FIELD_BITPOS (type, i) / 8, 0, | |
835 | stream, format, 0, recurse + 1, pretty); */ | |
836 | val_print (TYPE_FIELD_TYPE (type, i), | |
837 | valaddr, TYPE_FIELD_BITPOS (type, i) / 8, | |
838 | address + TYPE_FIELD_BITPOS (type, i) / 8, | |
0e03807e | 839 | stream, recurse + 1, val, &opts, |
d8ca156b | 840 | current_language); |
373a8247 PM |
841 | } |
842 | } | |
843 | annotate_field_end (); | |
844 | } | |
845 | ||
846 | if (dont_print_statmem == 0) | |
847 | { | |
848 | /* Free the space used to deal with the printing | |
849 | of the members from top level. */ | |
850 | obstack_free (&dont_print_statmem_obstack, last_dont_print); | |
851 | dont_print_statmem_obstack = tmp_obstack; | |
852 | } | |
853 | ||
79a45b7d | 854 | if (options->pretty) |
373a8247 PM |
855 | { |
856 | fprintf_filtered (stream, "\n"); | |
857 | print_spaces_filtered (2 * recurse, stream); | |
858 | } | |
859 | } | |
860 | fprintf_filtered (stream, "}"); | |
861 | } | |
862 | ||
863 | /* Special val_print routine to avoid printing multiple copies of virtual | |
864 | baseclasses. */ | |
865 | ||
7080f20f | 866 | static void |
fc1a4b47 | 867 | pascal_object_print_value (struct type *type, const gdb_byte *valaddr, |
a2bd3dcd | 868 | CORE_ADDR address, struct ui_file *stream, |
79a45b7d | 869 | int recurse, |
0e03807e | 870 | const struct value *val, |
79a45b7d | 871 | const struct value_print_options *options, |
fba45db2 | 872 | struct type **dont_print_vb) |
373a8247 | 873 | { |
373a8247 | 874 | struct type **last_dont_print |
ad3bbd48 | 875 | = (struct type **) obstack_next_free (&dont_print_vb_obstack); |
c1b6e682 | 876 | struct obstack tmp_obstack = dont_print_vb_obstack; |
373a8247 PM |
877 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); |
878 | ||
879 | if (dont_print_vb == 0) | |
880 | { | |
881 | /* If we're at top level, carve out a completely fresh | |
882 | chunk of the obstack and use that until this particular | |
883 | invocation returns. */ | |
373a8247 PM |
884 | /* Bump up the high-water mark. Now alpha is omega. */ |
885 | obstack_finish (&dont_print_vb_obstack); | |
886 | } | |
887 | ||
888 | for (i = 0; i < n_baseclasses; i++) | |
889 | { | |
890 | int boffset; | |
891 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); | |
4a52dc15 | 892 | char *basename = type_name_no_tag (baseclass); |
fc1a4b47 | 893 | const gdb_byte *base_valaddr; |
373a8247 PM |
894 | |
895 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
896 | { | |
897 | struct type **first_dont_print | |
ad3bbd48 | 898 | = (struct type **) obstack_base (&dont_print_vb_obstack); |
373a8247 PM |
899 | |
900 | int j = (struct type **) obstack_next_free (&dont_print_vb_obstack) | |
ad3bbd48 | 901 | - first_dont_print; |
373a8247 PM |
902 | |
903 | while (--j >= 0) | |
904 | if (baseclass == first_dont_print[j]) | |
905 | goto flush_it; | |
906 | ||
907 | obstack_ptr_grow (&dont_print_vb_obstack, baseclass); | |
908 | } | |
909 | ||
910 | boffset = baseclass_offset (type, i, valaddr, address); | |
911 | ||
79a45b7d | 912 | if (options->pretty) |
373a8247 PM |
913 | { |
914 | fprintf_filtered (stream, "\n"); | |
915 | print_spaces_filtered (2 * recurse, stream); | |
916 | } | |
917 | fputs_filtered ("<", stream); | |
918 | /* Not sure what the best notation is in the case where there is no | |
919 | baseclass name. */ | |
920 | ||
921 | fputs_filtered (basename ? basename : "", stream); | |
922 | fputs_filtered ("> = ", stream); | |
923 | ||
924 | /* The virtual base class pointer might have been clobbered by the | |
925 | user program. Make sure that it still points to a valid memory | |
926 | location. */ | |
927 | ||
928 | if (boffset != -1 && (boffset < 0 || boffset >= TYPE_LENGTH (type))) | |
929 | { | |
34c0bd93 | 930 | /* FIXME (alloc): not safe is baseclass is really really big. */ |
fc1a4b47 | 931 | gdb_byte *buf = alloca (TYPE_LENGTH (baseclass)); |
ad3bbd48 | 932 | |
a2bd3dcd AC |
933 | base_valaddr = buf; |
934 | if (target_read_memory (address + boffset, buf, | |
373a8247 PM |
935 | TYPE_LENGTH (baseclass)) != 0) |
936 | boffset = -1; | |
937 | } | |
938 | else | |
939 | base_valaddr = valaddr + boffset; | |
940 | ||
941 | if (boffset == -1) | |
942 | fprintf_filtered (stream, "<invalid address>"); | |
943 | else | |
944 | pascal_object_print_value_fields (baseclass, base_valaddr, address + boffset, | |
0e03807e | 945 | stream, recurse, val, options, |
373a8247 PM |
946 | (struct type **) obstack_base (&dont_print_vb_obstack), |
947 | 0); | |
948 | fputs_filtered (", ", stream); | |
949 | ||
950 | flush_it: | |
951 | ; | |
952 | } | |
953 | ||
954 | if (dont_print_vb == 0) | |
955 | { | |
956 | /* Free the space used to deal with the printing | |
957 | of this type from top level. */ | |
958 | obstack_free (&dont_print_vb_obstack, last_dont_print); | |
959 | /* Reset watermark so that we can continue protecting | |
960 | ourselves from whatever we were protecting ourselves. */ | |
961 | dont_print_vb_obstack = tmp_obstack; | |
962 | } | |
963 | } | |
964 | ||
965 | /* Print value of a static member. | |
966 | To avoid infinite recursion when printing a class that contains | |
967 | a static instance of the class, we keep the addresses of all printed | |
968 | static member classes in an obstack and refuse to print them more | |
969 | than once. | |
970 | ||
79a45b7d | 971 | VAL contains the value to print, STREAM, RECURSE, and OPTIONS |
373a8247 PM |
972 | have the same meanings as in c_val_print. */ |
973 | ||
974 | static void | |
806048c6 | 975 | pascal_object_print_static_field (struct value *val, |
79a45b7d TT |
976 | struct ui_file *stream, |
977 | int recurse, | |
978 | const struct value_print_options *options) | |
373a8247 | 979 | { |
806048c6 | 980 | struct type *type = value_type (val); |
79a45b7d | 981 | struct value_print_options opts; |
806048c6 | 982 | |
373a8247 PM |
983 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
984 | { | |
42ae5230 | 985 | CORE_ADDR *first_dont_print, addr; |
373a8247 PM |
986 | int i; |
987 | ||
988 | first_dont_print | |
989 | = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack); | |
990 | i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack) | |
991 | - first_dont_print; | |
992 | ||
993 | while (--i >= 0) | |
994 | { | |
42ae5230 | 995 | if (value_address (val) == first_dont_print[i]) |
373a8247 PM |
996 | { |
997 | fputs_filtered ("<same as static member of an already seen type>", | |
998 | stream); | |
999 | return; | |
1000 | } | |
1001 | } | |
1002 | ||
42ae5230 TT |
1003 | addr = value_address (val); |
1004 | obstack_grow (&dont_print_statmem_obstack, (char *) &addr, | |
373a8247 PM |
1005 | sizeof (CORE_ADDR)); |
1006 | ||
1007 | CHECK_TYPEDEF (type); | |
42ae5230 | 1008 | pascal_object_print_value_fields (type, value_contents (val), addr, |
0e03807e TT |
1009 | stream, recurse, NULL, options, |
1010 | NULL, 1); | |
373a8247 PM |
1011 | return; |
1012 | } | |
79a45b7d TT |
1013 | |
1014 | opts = *options; | |
1015 | opts.deref_ref = 0; | |
1016 | common_val_print (val, stream, recurse, &opts, current_language); | |
373a8247 PM |
1017 | } |
1018 | ||
b9362cc7 | 1019 | extern initialize_file_ftype _initialize_pascal_valprint; /* -Wmissing-prototypes */ |
373a8247 PM |
1020 | |
1021 | void | |
fba45db2 | 1022 | _initialize_pascal_valprint (void) |
373a8247 | 1023 | { |
5bf193a2 | 1024 | add_setshow_boolean_cmd ("pascal_static-members", class_support, |
79a45b7d | 1025 | &user_print_options.pascal_static_field_print, _("\ |
5bf193a2 AC |
1026 | Set printing of pascal static members."), _("\ |
1027 | Show printing of pascal static members."), NULL, | |
1028 | NULL, | |
920d2a44 | 1029 | show_pascal_static_field_print, |
5bf193a2 | 1030 | &setprintlist, &showprintlist); |
373a8247 | 1031 | } |