1 /* Support for printing Modula 2 values for GDB, the GNU debugger.
3 Copyright (C) 1986, 1988-1989, 1991-1992, 1996, 1998, 2000, 2005-2012
4 Free Software Foundation, Inc.
6 This file is part of GDB.
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
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "expression.h"
28 #include "typeprint.h"
33 static int print_unpacked_pointer (struct type
*type
,
34 CORE_ADDR address
, CORE_ADDR addr
,
35 const struct value_print_options
*options
,
36 struct ui_file
*stream
);
38 m2_print_array_contents (struct type
*type
, const gdb_byte
*valaddr
,
39 int embedded_offset
, CORE_ADDR address
,
40 struct ui_file
*stream
, int recurse
,
41 const struct value
*val
,
42 const struct value_print_options
*options
,
46 /* get_long_set_bounds - assigns the bounds of the long set to low and
50 get_long_set_bounds (struct type
*type
, LONGEST
*low
, LONGEST
*high
)
54 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
56 len
= TYPE_NFIELDS (type
);
57 i
= TYPE_N_BASECLASSES (type
);
60 *low
= TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, i
)));
61 *high
= TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
,
65 error (_("expecting long_set"));
70 m2_print_long_set (struct type
*type
, const gdb_byte
*valaddr
,
71 int embedded_offset
, CORE_ADDR address
,
72 struct ui_file
*stream
)
76 LONGEST previous_low
= 0;
77 LONGEST previous_high
= 0;
78 LONGEST i
, low_bound
, high_bound
;
79 LONGEST field_low
, field_high
;
87 fprintf_filtered (stream
, "{");
88 len
= TYPE_NFIELDS (type
);
89 if (get_long_set_bounds (type
, &low_bound
, &high_bound
))
91 field
= TYPE_N_BASECLASSES (type
);
92 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
96 fprintf_filtered (stream
, " %s }", _("<unknown bounds of set>"));
100 target
= TYPE_TARGET_TYPE (range
);
102 if (get_discrete_bounds (range
, &field_low
, &field_high
) >= 0)
104 for (i
= low_bound
; i
<= high_bound
; i
++)
106 bitval
= value_bit_index (TYPE_FIELD_TYPE (type
, field
),
107 (TYPE_FIELD_BITPOS (type
, field
) / 8) +
108 valaddr
+ embedded_offset
, i
);
110 error (_("bit test is out of range"));
117 fprintf_filtered (stream
, ", ");
118 print_type_scalar (target
, i
, stream
);
129 if (previous_low
+1 < previous_high
)
130 fprintf_filtered (stream
, "..");
131 if (previous_low
+1 < previous_high
)
132 print_type_scalar (target
, previous_high
, stream
);
141 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
142 if (get_discrete_bounds (range
, &field_low
, &field_high
) < 0)
144 target
= TYPE_TARGET_TYPE (range
);
149 if (previous_low
+1 < previous_high
)
151 fprintf_filtered (stream
, "..");
152 print_type_scalar (target
, previous_high
, stream
);
156 fprintf_filtered (stream
, "}");
161 m2_print_unbounded_array (struct type
*type
, const gdb_byte
*valaddr
,
162 int embedded_offset
, CORE_ADDR address
,
163 struct ui_file
*stream
, int recurse
,
164 const struct value_print_options
*options
)
166 struct type
*content_type
;
171 CHECK_TYPEDEF (type
);
172 content_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0));
174 addr
= unpack_pointer (TYPE_FIELD_TYPE (type
, 0),
175 (TYPE_FIELD_BITPOS (type
, 0) / 8) +
176 valaddr
+ embedded_offset
);
178 val
= value_at_lazy (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0)),
180 len
= unpack_field_as_long (type
, valaddr
+ embedded_offset
, 1);
182 fprintf_filtered (stream
, "{");
183 m2_print_array_contents (value_type (val
),
184 value_contents_for_printing (val
),
185 value_embedded_offset (val
), addr
, stream
,
186 recurse
, val
, options
, len
);
187 fprintf_filtered (stream
, ", HIGH = %d}", (int) len
);
191 print_unpacked_pointer (struct type
*type
,
192 CORE_ADDR address
, CORE_ADDR addr
,
193 const struct value_print_options
*options
,
194 struct ui_file
*stream
)
196 struct gdbarch
*gdbarch
= get_type_arch (type
);
197 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
199 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
201 /* Try to print what function it points to. */
202 print_function_pointer_address (gdbarch
, addr
, stream
,
203 options
->addressprint
);
204 /* Return value is irrelevant except for string pointers. */
208 if (options
->addressprint
&& options
->format
!= 's')
209 fputs_filtered (paddress (gdbarch
, address
), stream
);
211 /* For a pointer to char or unsigned char, also print the string
212 pointed to, unless pointer is null. */
214 if (TYPE_LENGTH (elttype
) == 1
215 && TYPE_CODE (elttype
) == TYPE_CODE_INT
216 && (options
->format
== 0 || options
->format
== 's')
218 return val_print_string (TYPE_TARGET_TYPE (type
), NULL
, addr
, -1,
225 print_variable_at_address (struct type
*type
,
226 const gdb_byte
*valaddr
,
227 struct ui_file
*stream
,
229 const struct value_print_options
*options
)
231 struct gdbarch
*gdbarch
= get_type_arch (type
);
232 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
233 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
235 fprintf_filtered (stream
, "[");
236 fputs_filtered (paddress (gdbarch
, addr
), stream
);
237 fprintf_filtered (stream
, "] : ");
239 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
241 struct value
*deref_val
=
242 value_at (TYPE_TARGET_TYPE (type
), unpack_pointer (type
, valaddr
));
244 common_val_print (deref_val
, stream
, recurse
, options
, current_language
);
247 fputs_filtered ("???", stream
);
251 /* m2_print_array_contents - prints out the contents of an
252 array up to a max_print values.
253 It prints arrays of char as a string
254 and all other data types as comma
258 m2_print_array_contents (struct type
*type
, const gdb_byte
*valaddr
,
259 int embedded_offset
, CORE_ADDR address
,
260 struct ui_file
*stream
, int recurse
,
261 const struct value
*val
,
262 const struct value_print_options
*options
,
266 CHECK_TYPEDEF (type
);
268 if (TYPE_LENGTH (type
) > 0)
270 eltlen
= TYPE_LENGTH (type
);
271 if (options
->prettyprint_arrays
)
272 print_spaces_filtered (2 + 2 * recurse
, stream
);
273 /* For an array of chars, print with string syntax. */
275 ((TYPE_CODE (type
) == TYPE_CODE_INT
)
276 || ((current_language
->la_language
== language_m2
)
277 && (TYPE_CODE (type
) == TYPE_CODE_CHAR
)))
278 && (options
->format
== 0 || options
->format
== 's'))
279 val_print_string (type
, NULL
, address
, len
+1, stream
, options
);
282 fprintf_filtered (stream
, "{");
283 val_print_array_elements (type
, valaddr
, embedded_offset
,
284 address
, stream
, recurse
, val
,
286 fprintf_filtered (stream
, "}");
292 /* See val_print for a description of the various parameters of this
293 function; they are identical. The semantics of the return value is
294 also identical to val_print. */
297 m2_val_print (struct type
*type
, const gdb_byte
*valaddr
, int embedded_offset
,
298 CORE_ADDR address
, struct ui_file
*stream
, int recurse
,
299 const struct value
*original_value
,
300 const struct value_print_options
*options
)
302 struct gdbarch
*gdbarch
= get_type_arch (type
);
303 unsigned int i
= 0; /* Number of characters printed. */
305 struct type
*elttype
;
310 CHECK_TYPEDEF (type
);
311 switch (TYPE_CODE (type
))
313 case TYPE_CODE_ARRAY
:
314 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
316 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
317 eltlen
= TYPE_LENGTH (elttype
);
318 len
= TYPE_LENGTH (type
) / eltlen
;
319 if (options
->prettyprint_arrays
)
320 print_spaces_filtered (2 + 2 * recurse
, stream
);
321 /* For an array of chars, print with string syntax. */
323 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
324 || ((current_language
->la_language
== language_m2
)
325 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
326 && (options
->format
== 0 || options
->format
== 's'))
328 /* If requested, look for the first null char and only print
329 elements up to it. */
330 if (options
->stop_print_at_null
)
332 unsigned int temp_len
;
334 /* Look for a NULL char. */
336 (valaddr
+ embedded_offset
)[temp_len
]
337 && temp_len
< len
&& temp_len
< options
->print_max
;
342 LA_PRINT_STRING (stream
, TYPE_TARGET_TYPE (type
),
343 valaddr
+ embedded_offset
, len
, NULL
,
349 fprintf_filtered (stream
, "{");
350 val_print_array_elements (type
, valaddr
, embedded_offset
,
352 recurse
, original_value
,
354 fprintf_filtered (stream
, "}");
358 /* Array of unspecified length: treat like pointer to first elt. */
359 print_unpacked_pointer (type
, address
, address
, options
, stream
);
363 if (TYPE_CONST (type
))
364 print_variable_at_address (type
, valaddr
+ embedded_offset
,
365 stream
, recurse
, options
);
366 else if (options
->format
&& options
->format
!= 's')
367 val_print_scalar_formatted (type
, valaddr
, embedded_offset
,
368 original_value
, options
, 0, stream
);
371 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
372 print_unpacked_pointer (type
, addr
, address
, options
, stream
);
377 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
378 if (options
->addressprint
)
381 = extract_typed_address (valaddr
+ embedded_offset
, type
);
383 fprintf_filtered (stream
, "@");
384 fputs_filtered (paddress (gdbarch
, addr
), stream
);
385 if (options
->deref_ref
)
386 fputs_filtered (": ", stream
);
388 /* De-reference the reference. */
389 if (options
->deref_ref
)
391 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
393 struct value
*deref_val
=
395 (TYPE_TARGET_TYPE (type
),
396 unpack_pointer (type
, valaddr
+ embedded_offset
));
398 common_val_print (deref_val
, stream
, recurse
, options
,
402 fputs_filtered ("???", stream
);
406 case TYPE_CODE_UNION
:
407 if (recurse
&& !options
->unionprint
)
409 fprintf_filtered (stream
, "{...}");
413 case TYPE_CODE_STRUCT
:
414 if (m2_is_long_set (type
))
415 m2_print_long_set (type
, valaddr
, embedded_offset
, address
,
417 else if (m2_is_unbounded_array (type
))
418 m2_print_unbounded_array (type
, valaddr
, embedded_offset
,
419 address
, stream
, recurse
, options
);
421 cp_print_value_fields (type
, type
, valaddr
, embedded_offset
,
422 address
, stream
, recurse
, original_value
,
429 val_print_scalar_formatted (type
, valaddr
, embedded_offset
,
430 original_value
, options
, 0, stream
);
433 len
= TYPE_NFIELDS (type
);
434 val
= unpack_long (type
, valaddr
+ embedded_offset
);
435 for (i
= 0; i
< len
; i
++)
438 if (val
== TYPE_FIELD_BITPOS (type
, i
))
445 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
449 print_longest (stream
, 'd', 0, val
);
456 val_print_scalar_formatted (type
, valaddr
, embedded_offset
,
457 original_value
, options
, 0, stream
);
460 /* FIXME, we should consider, at least for ANSI C language, eliminating
461 the distinction made between FUNCs and POINTERs to FUNCs. */
462 fprintf_filtered (stream
, "{");
463 type_print (type
, "", stream
, -1);
464 fprintf_filtered (stream
, "} ");
465 /* Try to print what function it points to, and its address. */
466 print_address_demangle (gdbarch
, address
, stream
, demangle
);
470 if (options
->format
|| options
->output_format
)
472 struct value_print_options opts
= *options
;
474 opts
.format
= (options
->format
? options
->format
475 : options
->output_format
);
476 val_print_scalar_formatted (type
, valaddr
, embedded_offset
,
477 original_value
, &opts
, 0, stream
);
481 val
= unpack_long (type
, valaddr
+ embedded_offset
);
483 fputs_filtered ("FALSE", stream
);
485 fputs_filtered ("TRUE", stream
);
487 fprintf_filtered (stream
, "%ld)", (long int) val
);
491 case TYPE_CODE_RANGE
:
492 if (TYPE_LENGTH (type
) == TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
494 m2_val_print (TYPE_TARGET_TYPE (type
), valaddr
, embedded_offset
,
495 address
, stream
, recurse
, original_value
, options
);
498 /* FIXME: create_range_type does not set the unsigned bit in a
499 range type (I think it probably should copy it from the target
500 type), so we won't print values which are too large to
501 fit in a signed integer correctly. */
502 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
503 print with the target type, though, because the size of our type
504 and the target type might differ). */
508 if (options
->format
|| options
->output_format
)
510 struct value_print_options opts
= *options
;
512 opts
.format
= (options
->format
? options
->format
513 : options
->output_format
);
514 val_print_scalar_formatted (type
, valaddr
, embedded_offset
,
515 original_value
, &opts
, 0, stream
);
518 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
522 if (options
->format
|| options
->output_format
)
524 struct value_print_options opts
= *options
;
526 opts
.format
= (options
->format
? options
->format
527 : options
->output_format
);
528 val_print_scalar_formatted (type
, valaddr
, embedded_offset
,
529 original_value
, &opts
, 0, stream
);
533 val
= unpack_long (type
, valaddr
+ embedded_offset
);
534 if (TYPE_UNSIGNED (type
))
535 fprintf_filtered (stream
, "%u", (unsigned int) val
);
537 fprintf_filtered (stream
, "%d", (int) val
);
538 fputs_filtered (" ", stream
);
539 LA_PRINT_CHAR ((unsigned char) val
, type
, stream
);
545 val_print_scalar_formatted (type
, valaddr
, embedded_offset
,
546 original_value
, options
, 0, stream
);
548 print_floating (valaddr
+ embedded_offset
, type
, stream
);
551 case TYPE_CODE_METHOD
:
554 case TYPE_CODE_BITSTRING
:
556 elttype
= TYPE_INDEX_TYPE (type
);
557 CHECK_TYPEDEF (elttype
);
558 if (TYPE_STUB (elttype
))
560 fprintf_filtered (stream
, _("<incomplete type>"));
566 struct type
*range
= elttype
;
567 LONGEST low_bound
, high_bound
;
569 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
573 fputs_filtered ("B'", stream
);
575 fputs_filtered ("{", stream
);
577 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
581 fputs_filtered (_("<error value>"), stream
);
585 for (i
= low_bound
; i
<= high_bound
; i
++)
587 int element
= value_bit_index (type
, valaddr
+ embedded_offset
,
593 goto maybe_bad_bstring
;
596 fprintf_filtered (stream
, "%d", element
);
600 fputs_filtered (", ", stream
);
601 print_type_scalar (range
, i
, stream
);
604 if (i
+ 1 <= high_bound
605 && value_bit_index (type
, valaddr
+ embedded_offset
,
610 fputs_filtered ("..", stream
);
611 while (i
+ 1 <= high_bound
612 && value_bit_index (type
,
613 valaddr
+ embedded_offset
,
616 print_type_scalar (range
, j
, stream
);
622 fputs_filtered ("'", stream
);
624 fputs_filtered ("}", stream
);
629 fprintf_filtered (stream
, "void");
632 case TYPE_CODE_ERROR
:
633 fprintf_filtered (stream
, "%s", TYPE_ERROR_NAME (type
));
636 case TYPE_CODE_UNDEF
:
637 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
638 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
639 and no complete type for struct foo in that file. */
640 fprintf_filtered (stream
, _("<incomplete type>"));
644 error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type
));
This page took 0.07812 seconds and 4 git commands to generate.