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 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 int print_unpacked_pointer (struct type
*type
,
34 CORE_ADDR address
, CORE_ADDR addr
,
35 int format
, struct ui_file
*stream
);
37 m2_print_array_contents (struct type
*type
, const gdb_byte
*valaddr
,
38 int embedded_offset
, CORE_ADDR address
,
39 struct ui_file
*stream
, int format
,
40 enum val_prettyprint pretty
,
41 int deref_ref
, int recurse
, int len
);
44 /* Print function pointer with inferior address ADDRESS onto stdio
48 print_function_pointer_address (CORE_ADDR address
, struct ui_file
*stream
)
50 CORE_ADDR func_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
54 /* If the function pointer is represented by a description, print the
55 address of the description. */
56 if (addressprint
&& func_addr
!= address
)
58 fputs_filtered ("@", stream
);
59 fputs_filtered (paddress (address
), stream
);
60 fputs_filtered (": ", stream
);
62 print_address_demangle (func_addr
, stream
, demangle
);
65 /* get_long_set_bounds - assigns the bounds of the long set to low and
69 get_long_set_bounds (struct type
*type
, LONGEST
*low
, LONGEST
*high
)
73 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
75 len
= TYPE_NFIELDS (type
);
76 i
= TYPE_N_BASECLASSES (type
);
79 *low
= TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, i
)));
80 *high
= TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
,
84 error (_("expecting long_set"));
89 m2_print_long_set (struct type
*type
, const gdb_byte
*valaddr
,
90 int embedded_offset
, CORE_ADDR address
,
91 struct ui_file
*stream
, int format
,
92 enum val_prettyprint pretty
)
96 LONGEST previous_low
= 0;
97 LONGEST previous_high
= 0;
98 LONGEST i
, low_bound
, high_bound
;
99 LONGEST field_low
, field_high
;
105 CHECK_TYPEDEF (type
);
107 fprintf_filtered (stream
, "{");
108 len
= TYPE_NFIELDS (type
);
109 if (get_long_set_bounds (type
, &low_bound
, &high_bound
))
111 field
= TYPE_N_BASECLASSES (type
);
112 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
116 fprintf_filtered (stream
, " %s }", _("<unknown bounds of set>"));
120 target
= TYPE_TARGET_TYPE (range
);
122 target
= builtin_type_int
;
124 if (get_discrete_bounds (range
, &field_low
, &field_high
) >= 0)
126 for (i
= low_bound
; i
<= high_bound
; i
++)
128 bitval
= value_bit_index (TYPE_FIELD_TYPE (type
, field
),
129 (TYPE_FIELD_BITPOS (type
, field
) / 8) +
130 valaddr
+ embedded_offset
, i
);
132 error (_("bit test is out of range"));
139 fprintf_filtered (stream
, ", ");
140 print_type_scalar (target
, i
, stream
);
151 if (previous_low
+1 < previous_high
)
152 fprintf_filtered (stream
, "..");
153 if (previous_low
+1 < previous_high
)
154 print_type_scalar (target
, previous_high
, stream
);
163 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
164 if (get_discrete_bounds (range
, &field_low
, &field_high
) < 0)
166 target
= TYPE_TARGET_TYPE (range
);
168 target
= builtin_type_int
;
173 if (previous_low
+1 < previous_high
)
175 fprintf_filtered (stream
, "..");
176 print_type_scalar (target
, previous_high
, stream
);
180 fprintf_filtered (stream
, "}");
185 m2_print_unbounded_array (struct type
*type
, const gdb_byte
*valaddr
,
186 int embedded_offset
, CORE_ADDR address
,
187 struct ui_file
*stream
, int format
,
188 int deref_ref
, enum val_prettyprint pretty
,
191 struct type
*content_type
;
196 CHECK_TYPEDEF (type
);
197 content_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0));
199 addr
= unpack_pointer (TYPE_FIELD_TYPE (type
, 0),
200 (TYPE_FIELD_BITPOS (type
, 0) / 8) +
201 valaddr
+ embedded_offset
);
203 val
= value_at_lazy (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0)),
205 len
= unpack_field_as_long (type
, valaddr
+ embedded_offset
, 1);
207 fprintf_filtered (stream
, "{");
208 m2_print_array_contents (value_type (val
), value_contents(val
),
209 value_embedded_offset (val
), addr
, stream
,
210 format
, deref_ref
, pretty
, recurse
, len
);
211 fprintf_filtered (stream
, ", HIGH = %d}", (int) len
);
215 print_unpacked_pointer (struct type
*type
,
216 CORE_ADDR address
, CORE_ADDR addr
,
217 int format
, struct ui_file
*stream
)
219 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
221 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
223 /* Try to print what function it points to. */
224 print_function_pointer_address (addr
, stream
);
225 /* Return value is irrelevant except for string pointers. */
229 if (addressprint
&& format
!= 's')
230 fputs_filtered (paddress (address
), stream
);
232 /* For a pointer to char or unsigned char, also print the string
233 pointed to, unless pointer is null. */
235 if (TYPE_LENGTH (elttype
) == 1
236 && TYPE_CODE (elttype
) == TYPE_CODE_INT
237 && (format
== 0 || format
== 's')
239 return val_print_string (addr
, -1, TYPE_LENGTH (elttype
), stream
);
245 print_variable_at_address (struct type
*type
,
246 const gdb_byte
*valaddr
,
247 struct ui_file
*stream
, int format
,
248 int deref_ref
, int recurse
,
249 enum val_prettyprint pretty
)
251 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
252 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
254 fprintf_filtered (stream
, "[");
255 fputs_filtered (paddress (addr
), stream
);
256 fprintf_filtered (stream
, "] : ");
258 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
260 struct value
*deref_val
=
262 (TYPE_TARGET_TYPE (type
),
263 unpack_pointer (lookup_pointer_type (builtin_type_void
),
265 common_val_print (deref_val
, stream
, format
, deref_ref
,
269 fputs_filtered ("???", stream
);
273 /* m2_print_array_contents - prints out the contents of an
274 array up to a max_print values.
275 It prints arrays of char as a string
276 and all other data types as comma
280 m2_print_array_contents (struct type
*type
, const gdb_byte
*valaddr
,
281 int embedded_offset
, CORE_ADDR address
,
282 struct ui_file
*stream
, int format
,
283 enum val_prettyprint pretty
,
284 int deref_ref
, int recurse
, int len
)
287 CHECK_TYPEDEF (type
);
289 if (TYPE_LENGTH (type
) > 0)
291 eltlen
= TYPE_LENGTH (type
);
292 if (prettyprint_arrays
)
293 print_spaces_filtered (2 + 2 * recurse
, stream
);
294 /* For an array of chars, print with string syntax. */
296 ((TYPE_CODE (type
) == TYPE_CODE_INT
)
297 || ((current_language
->la_language
== language_m2
)
298 && (TYPE_CODE (type
) == TYPE_CODE_CHAR
)))
299 && (format
== 0 || format
== 's'))
300 val_print_string (address
, len
+1, eltlen
, stream
);
303 fprintf_filtered (stream
, "{");
304 val_print_array_elements (type
, valaddr
+ embedded_offset
,
305 address
, stream
, format
,
306 deref_ref
, recurse
, pretty
, 0);
307 fprintf_filtered (stream
, "}");
313 /* Print data of type TYPE located at VALADDR (within GDB), which came from
314 the inferior at address ADDRESS, onto stdio stream STREAM according to
315 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
318 If the data are a string pointer, returns the number of string characters
321 If DEREF_REF is nonzero, then dereference references, otherwise just print
324 The PRETTY parameter controls prettyprinting. */
327 m2_val_print (struct type
*type
, const gdb_byte
*valaddr
, int embedded_offset
,
328 CORE_ADDR address
, struct ui_file
*stream
, int format
,
329 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
331 unsigned int i
= 0; /* Number of characters printed */
333 struct type
*elttype
;
335 int length_pos
, length_size
, string_pos
;
340 CHECK_TYPEDEF (type
);
341 switch (TYPE_CODE (type
))
343 case TYPE_CODE_ARRAY
:
344 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
346 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
347 eltlen
= TYPE_LENGTH (elttype
);
348 len
= TYPE_LENGTH (type
) / eltlen
;
349 if (prettyprint_arrays
)
350 print_spaces_filtered (2 + 2 * recurse
, stream
);
351 /* For an array of chars, print with string syntax. */
353 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
354 || ((current_language
->la_language
== language_m2
)
355 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
356 && (format
== 0 || format
== 's'))
358 /* If requested, look for the first null char and only print
359 elements up to it. */
360 if (stop_print_at_null
)
362 unsigned int temp_len
;
364 /* Look for a NULL char. */
366 (valaddr
+ embedded_offset
)[temp_len
]
367 && temp_len
< len
&& temp_len
< print_max
;
372 LA_PRINT_STRING (stream
, valaddr
+ embedded_offset
, len
, 1, 0);
377 fprintf_filtered (stream
, "{");
378 val_print_array_elements (type
, valaddr
+ embedded_offset
,
379 address
, stream
, format
, deref_ref
,
381 fprintf_filtered (stream
, "}");
385 /* Array of unspecified length: treat like pointer to first elt. */
386 print_unpacked_pointer (type
, address
, address
, format
, stream
);
390 if (TYPE_CONST (type
))
391 print_variable_at_address (type
, valaddr
+ embedded_offset
,
392 stream
, format
, deref_ref
, recurse
,
394 else if (format
&& format
!= 's')
395 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
,
399 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
400 print_unpacked_pointer (type
, addr
, address
, format
, stream
);
405 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
409 = extract_typed_address (valaddr
+ embedded_offset
, type
);
410 fprintf_filtered (stream
, "@");
411 fputs_filtered (paddress (addr
), stream
);
413 fputs_filtered (": ", stream
);
415 /* De-reference the reference. */
418 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
420 struct value
*deref_val
=
422 (TYPE_TARGET_TYPE (type
),
423 unpack_pointer (lookup_pointer_type (builtin_type_void
),
424 valaddr
+ embedded_offset
));
425 common_val_print (deref_val
, stream
, format
, deref_ref
,
429 fputs_filtered ("???", stream
);
433 case TYPE_CODE_UNION
:
434 if (recurse
&& !unionprint
)
436 fprintf_filtered (stream
, "{...}");
440 case TYPE_CODE_STRUCT
:
441 if (m2_is_long_set (type
))
442 m2_print_long_set (type
, valaddr
, embedded_offset
, address
,
443 stream
, format
, pretty
);
444 else if (m2_is_unbounded_array (type
))
445 m2_print_unbounded_array (type
, valaddr
, embedded_offset
,
446 address
, stream
, format
, deref_ref
,
449 cp_print_value_fields (type
, type
, valaddr
, embedded_offset
,
450 address
, stream
, format
,
451 recurse
, pretty
, NULL
, 0);
457 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
461 len
= TYPE_NFIELDS (type
);
462 val
= unpack_long (type
, valaddr
+ embedded_offset
);
463 for (i
= 0; i
< len
; i
++)
466 if (val
== TYPE_FIELD_BITPOS (type
, i
))
473 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
477 print_longest (stream
, 'd', 0, val
);
484 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
488 /* FIXME, we should consider, at least for ANSI C language, eliminating
489 the distinction made between FUNCs and POINTERs to FUNCs. */
490 fprintf_filtered (stream
, "{");
491 type_print (type
, "", stream
, -1);
492 fprintf_filtered (stream
, "} ");
493 /* Try to print what function it points to, and its address. */
494 print_address_demangle (address
, stream
, demangle
);
498 format
= format
? format
: output_format
;
500 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
504 val
= unpack_long (type
, valaddr
+ embedded_offset
);
506 fputs_filtered ("FALSE", stream
);
508 fputs_filtered ("TRUE", stream
);
510 fprintf_filtered (stream
, "%ld)", (long int) val
);
514 case TYPE_CODE_RANGE
:
515 if (TYPE_LENGTH (type
) == TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
517 m2_val_print (TYPE_TARGET_TYPE (type
), valaddr
, embedded_offset
,
518 address
, stream
, format
, deref_ref
, recurse
, pretty
);
521 /* FIXME: create_range_type does not set the unsigned bit in a
522 range type (I think it probably should copy it from the target
523 type), so we won't print values which are too large to
524 fit in a signed integer correctly. */
525 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
526 print with the target type, though, because the size of our type
527 and the target type might differ). */
531 format
= format
? format
: output_format
;
533 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
,
536 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
540 format
= format
? format
: output_format
;
542 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
546 val
= unpack_long (type
, valaddr
+ embedded_offset
);
547 if (TYPE_UNSIGNED (type
))
548 fprintf_filtered (stream
, "%u", (unsigned int) val
);
550 fprintf_filtered (stream
, "%d", (int) val
);
551 fputs_filtered (" ", stream
);
552 LA_PRINT_CHAR ((unsigned char) val
, stream
);
558 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
561 print_floating (valaddr
+ embedded_offset
, type
, stream
);
564 case TYPE_CODE_METHOD
:
567 case TYPE_CODE_BITSTRING
:
569 elttype
= TYPE_INDEX_TYPE (type
);
570 CHECK_TYPEDEF (elttype
);
571 if (TYPE_STUB (elttype
))
573 fprintf_filtered (stream
, _("<incomplete type>"));
579 struct type
*range
= elttype
;
580 LONGEST low_bound
, high_bound
;
582 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
586 fputs_filtered ("B'", stream
);
588 fputs_filtered ("{", stream
);
590 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
594 fputs_filtered (_("<error value>"), stream
);
598 for (i
= low_bound
; i
<= high_bound
; i
++)
600 int element
= value_bit_index (type
, valaddr
+ embedded_offset
,
605 goto maybe_bad_bstring
;
608 fprintf_filtered (stream
, "%d", element
);
612 fputs_filtered (", ", stream
);
613 print_type_scalar (range
, i
, stream
);
616 if (i
+ 1 <= high_bound
617 && value_bit_index (type
, valaddr
+ embedded_offset
,
621 fputs_filtered ("..", stream
);
622 while (i
+ 1 <= high_bound
623 && value_bit_index (type
,
624 valaddr
+ embedded_offset
,
627 print_type_scalar (range
, j
, stream
);
633 fputs_filtered ("'", stream
);
635 fputs_filtered ("}", stream
);
640 fprintf_filtered (stream
, "void");
643 case TYPE_CODE_ERROR
:
644 fprintf_filtered (stream
, _("<error type>"));
647 case TYPE_CODE_UNDEF
:
648 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
649 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
650 and no complete type for struct foo in that file. */
651 fprintf_filtered (stream
, _("<incomplete type>"));
655 error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type
));
This page took 0.044116 seconds and 4 git commands to generate.