1 /* Support for printing Modula 2 values for GDB, the GNU debugger.
3 Copyright (C) 1986, 1988, 1989, 1991, 1992, 1996, 1998, 2000, 2005, 2006,
4 2007, 2008, 2009, 2010 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 /* Print function pointer with inferior address ADDRESS onto stdio
50 print_function_pointer_address (struct gdbarch
*gdbarch
, CORE_ADDR address
,
51 struct ui_file
*stream
, int addressprint
)
53 CORE_ADDR func_addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, address
,
56 /* If the function pointer is represented by a description, print the
57 address of the description. */
58 if (addressprint
&& func_addr
!= address
)
60 fputs_filtered ("@", stream
);
61 fputs_filtered (paddress (gdbarch
, address
), stream
);
62 fputs_filtered (": ", stream
);
64 print_address_demangle (gdbarch
, func_addr
, stream
, demangle
);
67 /* get_long_set_bounds - assigns the bounds of the long set to low and
71 get_long_set_bounds (struct type
*type
, LONGEST
*low
, LONGEST
*high
)
75 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
77 len
= TYPE_NFIELDS (type
);
78 i
= TYPE_N_BASECLASSES (type
);
81 *low
= TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, i
)));
82 *high
= TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
,
86 error (_("expecting long_set"));
91 m2_print_long_set (struct type
*type
, const gdb_byte
*valaddr
,
92 int embedded_offset
, CORE_ADDR address
,
93 struct ui_file
*stream
)
97 LONGEST previous_low
= 0;
98 LONGEST previous_high
= 0;
99 LONGEST i
, low_bound
, high_bound
;
100 LONGEST field_low
, field_high
;
106 CHECK_TYPEDEF (type
);
108 fprintf_filtered (stream
, "{");
109 len
= TYPE_NFIELDS (type
);
110 if (get_long_set_bounds (type
, &low_bound
, &high_bound
))
112 field
= TYPE_N_BASECLASSES (type
);
113 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
117 fprintf_filtered (stream
, " %s }", _("<unknown bounds of set>"));
121 target
= TYPE_TARGET_TYPE (range
);
123 if (get_discrete_bounds (range
, &field_low
, &field_high
) >= 0)
125 for (i
= low_bound
; i
<= high_bound
; i
++)
127 bitval
= value_bit_index (TYPE_FIELD_TYPE (type
, field
),
128 (TYPE_FIELD_BITPOS (type
, field
) / 8) +
129 valaddr
+ embedded_offset
, i
);
131 error (_("bit test is out of range"));
138 fprintf_filtered (stream
, ", ");
139 print_type_scalar (target
, i
, stream
);
150 if (previous_low
+1 < previous_high
)
151 fprintf_filtered (stream
, "..");
152 if (previous_low
+1 < previous_high
)
153 print_type_scalar (target
, previous_high
, stream
);
162 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
163 if (get_discrete_bounds (range
, &field_low
, &field_high
) < 0)
165 target
= TYPE_TARGET_TYPE (range
);
170 if (previous_low
+1 < previous_high
)
172 fprintf_filtered (stream
, "..");
173 print_type_scalar (target
, previous_high
, stream
);
177 fprintf_filtered (stream
, "}");
182 m2_print_unbounded_array (struct type
*type
, const gdb_byte
*valaddr
,
183 int embedded_offset
, CORE_ADDR address
,
184 struct ui_file
*stream
, int recurse
,
185 const struct value_print_options
*options
)
187 struct type
*content_type
;
192 CHECK_TYPEDEF (type
);
193 content_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0));
195 addr
= unpack_pointer (TYPE_FIELD_TYPE (type
, 0),
196 (TYPE_FIELD_BITPOS (type
, 0) / 8) +
197 valaddr
+ embedded_offset
);
199 val
= value_at_lazy (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0)),
201 len
= unpack_field_as_long (type
, valaddr
+ embedded_offset
, 1);
203 fprintf_filtered (stream
, "{");
204 m2_print_array_contents (value_type (val
), value_contents(val
),
205 value_embedded_offset (val
), addr
, stream
,
206 recurse
, NULL
, options
, len
);
207 fprintf_filtered (stream
, ", HIGH = %d}", (int) len
);
211 print_unpacked_pointer (struct type
*type
,
212 CORE_ADDR address
, CORE_ADDR addr
,
213 const struct value_print_options
*options
,
214 struct ui_file
*stream
)
216 struct gdbarch
*gdbarch
= get_type_arch (type
);
217 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
219 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
221 /* Try to print what function it points to. */
222 print_function_pointer_address (gdbarch
, addr
, stream
,
223 options
->addressprint
);
224 /* Return value is irrelevant except for string pointers. */
228 if (options
->addressprint
&& options
->format
!= 's')
229 fputs_filtered (paddress (gdbarch
, address
), stream
);
231 /* For a pointer to char or unsigned char, also print the string
232 pointed to, unless pointer is null. */
234 if (TYPE_LENGTH (elttype
) == 1
235 && TYPE_CODE (elttype
) == TYPE_CODE_INT
236 && (options
->format
== 0 || options
->format
== 's')
238 return val_print_string (TYPE_TARGET_TYPE (type
), addr
, -1,
245 print_variable_at_address (struct type
*type
,
246 const gdb_byte
*valaddr
,
247 struct ui_file
*stream
,
249 const struct value_print_options
*options
)
251 struct gdbarch
*gdbarch
= get_type_arch (type
);
252 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
253 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
255 fprintf_filtered (stream
, "[");
256 fputs_filtered (paddress (gdbarch
, addr
), stream
);
257 fprintf_filtered (stream
, "] : ");
259 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
261 struct value
*deref_val
=
262 value_at (TYPE_TARGET_TYPE (type
), unpack_pointer (type
, valaddr
));
264 common_val_print (deref_val
, stream
, recurse
, options
, current_language
);
267 fputs_filtered ("???", stream
);
271 /* m2_print_array_contents - prints out the contents of an
272 array up to a max_print values.
273 It prints arrays of char as a string
274 and all other data types as comma
278 m2_print_array_contents (struct type
*type
, const gdb_byte
*valaddr
,
279 int embedded_offset
, CORE_ADDR address
,
280 struct ui_file
*stream
, int recurse
,
281 const struct value
*val
,
282 const struct value_print_options
*options
,
286 CHECK_TYPEDEF (type
);
288 if (TYPE_LENGTH (type
) > 0)
290 eltlen
= TYPE_LENGTH (type
);
291 if (options
->prettyprint_arrays
)
292 print_spaces_filtered (2 + 2 * recurse
, stream
);
293 /* For an array of chars, print with string syntax. */
295 ((TYPE_CODE (type
) == TYPE_CODE_INT
)
296 || ((current_language
->la_language
== language_m2
)
297 && (TYPE_CODE (type
) == TYPE_CODE_CHAR
)))
298 && (options
->format
== 0 || options
->format
== 's'))
299 val_print_string (type
, address
, len
+1, stream
, options
);
302 fprintf_filtered (stream
, "{");
303 val_print_array_elements (type
, valaddr
+ embedded_offset
,
304 address
, stream
, recurse
, val
,
306 fprintf_filtered (stream
, "}");
312 /* Print data of type TYPE located at VALADDR (within GDB), which came from
313 the inferior at address ADDRESS, onto stdio stream STREAM according to
314 OPTIONS. The data at VALADDR is in target byte order.
316 If the data are a string pointer, returns the number of string characters
320 m2_val_print (struct type
*type
, const gdb_byte
*valaddr
, int embedded_offset
,
321 CORE_ADDR address
, struct ui_file
*stream
, int recurse
,
322 const struct value
*original_value
,
323 const struct value_print_options
*options
)
325 struct gdbarch
*gdbarch
= get_type_arch (type
);
326 unsigned int i
= 0; /* Number of characters printed */
328 struct type
*elttype
;
333 CHECK_TYPEDEF (type
);
334 switch (TYPE_CODE (type
))
336 case TYPE_CODE_ARRAY
:
337 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
339 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
340 eltlen
= TYPE_LENGTH (elttype
);
341 len
= TYPE_LENGTH (type
) / eltlen
;
342 if (options
->prettyprint_arrays
)
343 print_spaces_filtered (2 + 2 * recurse
, stream
);
344 /* For an array of chars, print with string syntax. */
346 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
347 || ((current_language
->la_language
== language_m2
)
348 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
349 && (options
->format
== 0 || options
->format
== 's'))
351 /* If requested, look for the first null char and only print
352 elements up to it. */
353 if (options
->stop_print_at_null
)
355 unsigned int temp_len
;
357 /* Look for a NULL char. */
359 (valaddr
+ embedded_offset
)[temp_len
]
360 && temp_len
< len
&& temp_len
< options
->print_max
;
365 LA_PRINT_STRING (stream
, TYPE_TARGET_TYPE (type
),
366 valaddr
+ embedded_offset
, len
, NULL
,
372 fprintf_filtered (stream
, "{");
373 val_print_array_elements (type
, valaddr
+ embedded_offset
,
374 address
, stream
, recurse
, original_value
,
376 fprintf_filtered (stream
, "}");
380 /* Array of unspecified length: treat like pointer to first elt. */
381 print_unpacked_pointer (type
, address
, address
, options
, stream
);
385 if (TYPE_CONST (type
))
386 print_variable_at_address (type
, valaddr
+ embedded_offset
,
387 stream
, recurse
, options
);
388 else if (options
->format
&& options
->format
!= 's')
389 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
393 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
394 print_unpacked_pointer (type
, addr
, address
, options
, stream
);
399 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
400 if (options
->addressprint
)
403 = extract_typed_address (valaddr
+ embedded_offset
, type
);
405 fprintf_filtered (stream
, "@");
406 fputs_filtered (paddress (gdbarch
, addr
), stream
);
407 if (options
->deref_ref
)
408 fputs_filtered (": ", stream
);
410 /* De-reference the reference. */
411 if (options
->deref_ref
)
413 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
415 struct value
*deref_val
=
417 (TYPE_TARGET_TYPE (type
),
418 unpack_pointer (type
, valaddr
+ embedded_offset
));
420 common_val_print (deref_val
, stream
, recurse
, options
,
424 fputs_filtered ("???", stream
);
428 case TYPE_CODE_UNION
:
429 if (recurse
&& !options
->unionprint
)
431 fprintf_filtered (stream
, "{...}");
435 case TYPE_CODE_STRUCT
:
436 if (m2_is_long_set (type
))
437 m2_print_long_set (type
, valaddr
, embedded_offset
, address
,
439 else if (m2_is_unbounded_array (type
))
440 m2_print_unbounded_array (type
, valaddr
, embedded_offset
,
441 address
, stream
, recurse
, options
);
443 cp_print_value_fields (type
, type
, valaddr
, embedded_offset
,
444 address
, stream
, recurse
, original_value
,
451 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
455 len
= TYPE_NFIELDS (type
);
456 val
= unpack_long (type
, valaddr
+ embedded_offset
);
457 for (i
= 0; i
< len
; i
++)
460 if (val
== TYPE_FIELD_BITPOS (type
, i
))
467 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
471 print_longest (stream
, 'd', 0, val
);
478 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
482 /* FIXME, we should consider, at least for ANSI C language, eliminating
483 the distinction made between FUNCs and POINTERs to FUNCs. */
484 fprintf_filtered (stream
, "{");
485 type_print (type
, "", stream
, -1);
486 fprintf_filtered (stream
, "} ");
487 /* Try to print what function it points to, and its address. */
488 print_address_demangle (gdbarch
, address
, stream
, demangle
);
492 if (options
->format
|| options
->output_format
)
494 struct value_print_options opts
= *options
;
496 opts
.format
= (options
->format
? options
->format
497 : options
->output_format
);
498 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
503 val
= unpack_long (type
, valaddr
+ embedded_offset
);
505 fputs_filtered ("FALSE", stream
);
507 fputs_filtered ("TRUE", stream
);
509 fprintf_filtered (stream
, "%ld)", (long int) val
);
513 case TYPE_CODE_RANGE
:
514 if (TYPE_LENGTH (type
) == TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
516 m2_val_print (TYPE_TARGET_TYPE (type
), valaddr
, embedded_offset
,
517 address
, stream
, recurse
, original_value
, options
);
520 /* FIXME: create_range_type does not set the unsigned bit in a
521 range type (I think it probably should copy it from the target
522 type), so we won't print values which are too large to
523 fit in a signed integer correctly. */
524 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
525 print with the target type, though, because the size of our type
526 and the target type might differ). */
530 if (options
->format
|| options
->output_format
)
532 struct value_print_options opts
= *options
;
534 opts
.format
= (options
->format
? options
->format
535 : options
->output_format
);
536 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
540 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
544 if (options
->format
|| options
->output_format
)
546 struct value_print_options opts
= *options
;
548 opts
.format
= (options
->format
? options
->format
549 : options
->output_format
);
550 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
555 val
= unpack_long (type
, valaddr
+ embedded_offset
);
556 if (TYPE_UNSIGNED (type
))
557 fprintf_filtered (stream
, "%u", (unsigned int) val
);
559 fprintf_filtered (stream
, "%d", (int) val
);
560 fputs_filtered (" ", stream
);
561 LA_PRINT_CHAR ((unsigned char) val
, type
, stream
);
567 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
570 print_floating (valaddr
+ embedded_offset
, type
, stream
);
573 case TYPE_CODE_METHOD
:
576 case TYPE_CODE_BITSTRING
:
578 elttype
= TYPE_INDEX_TYPE (type
);
579 CHECK_TYPEDEF (elttype
);
580 if (TYPE_STUB (elttype
))
582 fprintf_filtered (stream
, _("<incomplete type>"));
588 struct type
*range
= elttype
;
589 LONGEST low_bound
, high_bound
;
591 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
595 fputs_filtered ("B'", stream
);
597 fputs_filtered ("{", stream
);
599 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
603 fputs_filtered (_("<error value>"), stream
);
607 for (i
= low_bound
; i
<= high_bound
; i
++)
609 int element
= value_bit_index (type
, valaddr
+ embedded_offset
,
615 goto maybe_bad_bstring
;
618 fprintf_filtered (stream
, "%d", element
);
622 fputs_filtered (", ", stream
);
623 print_type_scalar (range
, i
, stream
);
626 if (i
+ 1 <= high_bound
627 && value_bit_index (type
, valaddr
+ embedded_offset
,
632 fputs_filtered ("..", stream
);
633 while (i
+ 1 <= high_bound
634 && value_bit_index (type
,
635 valaddr
+ embedded_offset
,
638 print_type_scalar (range
, j
, stream
);
644 fputs_filtered ("'", stream
);
646 fputs_filtered ("}", stream
);
651 fprintf_filtered (stream
, "void");
654 case TYPE_CODE_ERROR
:
655 fprintf_filtered (stream
, "%s", TYPE_ERROR_NAME (type
));
658 case TYPE_CODE_UNDEF
:
659 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
660 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
661 and no complete type for struct foo in that file. */
662 fprintf_filtered (stream
, _("<incomplete type>"));
666 error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type
));
This page took 0.047022 seconds and 4 git commands to generate.