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 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
);
38 /* Print function pointer with inferior address ADDRESS onto stdio
42 print_function_pointer_address (CORE_ADDR address
, struct ui_file
*stream
)
44 CORE_ADDR func_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
48 /* If the function pointer is represented by a description, print the
49 address of the description. */
50 if (addressprint
&& func_addr
!= address
)
52 fputs_filtered ("@", stream
);
53 fputs_filtered (paddress (address
), stream
);
54 fputs_filtered (": ", stream
);
56 print_address_demangle (func_addr
, stream
, demangle
);
60 * get_long_set_bounds - assigns the bounds of the long set to low and high.
64 get_long_set_bounds (struct type
*type
, LONGEST
*low
, LONGEST
*high
)
68 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
70 len
= TYPE_NFIELDS (type
);
71 i
= TYPE_N_BASECLASSES (type
);
74 *low
= TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, i
)));
75 *high
= TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
,
79 error (_("expecting long_set"));
84 m2_print_long_set (struct type
*type
, const gdb_byte
*valaddr
,
85 int embedded_offset
, CORE_ADDR address
,
86 struct ui_file
*stream
, int format
,
87 enum val_prettyprint pretty
)
91 LONGEST previous_low
= 0;
92 LONGEST previous_high
= 0;
93 LONGEST i
, low_bound
, high_bound
;
94 LONGEST field_low
, field_high
;
100 CHECK_TYPEDEF (type
);
102 fprintf_filtered (stream
, "{");
103 len
= TYPE_NFIELDS (type
);
104 if (get_long_set_bounds (type
, &low_bound
, &high_bound
))
106 field
= TYPE_N_BASECLASSES (type
);
107 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
111 fprintf_filtered (stream
, " %s }", _("<unknown bounds of set>"));
115 target
= TYPE_TARGET_TYPE (range
);
117 target
= builtin_type_int
;
119 if (get_discrete_bounds (range
, &field_low
, &field_high
) >= 0)
121 for (i
= low_bound
; i
<= high_bound
; i
++)
123 bitval
= value_bit_index (TYPE_FIELD_TYPE (type
, field
),
124 (TYPE_FIELD_BITPOS (type
, field
) / 8) +
125 valaddr
+ embedded_offset
, i
);
127 error (_("bit test is out of range"));
134 fprintf_filtered (stream
, ", ");
135 print_type_scalar (target
, i
, stream
);
146 if (previous_low
+1 < previous_high
)
147 fprintf_filtered (stream
, "..");
148 if (previous_low
+1 < previous_high
)
149 print_type_scalar (target
, previous_high
, stream
);
158 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
159 if (get_discrete_bounds (range
, &field_low
, &field_high
) < 0)
161 target
= TYPE_TARGET_TYPE (range
);
163 target
= builtin_type_int
;
168 if (previous_low
+1 < previous_high
)
170 fprintf_filtered (stream
, "..");
171 print_type_scalar (target
, previous_high
, stream
);
175 fprintf_filtered (stream
, "}");
180 print_unpacked_pointer (struct type
*type
,
181 CORE_ADDR address
, CORE_ADDR addr
,
182 int format
, struct ui_file
*stream
)
184 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
186 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
188 /* Try to print what function it points to. */
189 print_function_pointer_address (addr
, stream
);
190 /* Return value is irrelevant except for string pointers. */
194 if (addressprint
&& format
!= 's')
195 fputs_filtered (paddress (address
), stream
);
197 /* For a pointer to char or unsigned char, also print the string
198 pointed to, unless pointer is null. */
200 if (TYPE_LENGTH (elttype
) == 1
201 && TYPE_CODE (elttype
) == TYPE_CODE_INT
202 && (format
== 0 || format
== 's')
204 return val_print_string (addr
, -1, TYPE_LENGTH (elttype
), stream
);
210 print_variable_at_address (struct type
*type
, const gdb_byte
*valaddr
,
211 struct ui_file
*stream
, int format
,
212 int deref_ref
, int recurse
,
213 enum val_prettyprint pretty
)
215 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
216 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
218 fprintf_filtered (stream
, "[");
219 fputs_filtered (paddress (addr
), stream
);
220 fprintf_filtered (stream
, "] : ");
222 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
224 struct value
*deref_val
=
226 (TYPE_TARGET_TYPE (type
),
227 unpack_pointer (lookup_pointer_type (builtin_type_void
),
229 common_val_print (deref_val
, stream
, format
, deref_ref
,
233 fputs_filtered ("???", stream
);
236 /* Print data of type TYPE located at VALADDR (within GDB), which came from
237 the inferior at address ADDRESS, onto stdio stream STREAM according to
238 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
241 If the data are a string pointer, returns the number of string characters
244 If DEREF_REF is nonzero, then dereference references, otherwise just print
247 The PRETTY parameter controls prettyprinting. */
250 m2_val_print (struct type
*type
, const gdb_byte
*valaddr
, int embedded_offset
,
251 CORE_ADDR address
, struct ui_file
*stream
, int format
,
252 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
254 unsigned int i
= 0; /* Number of characters printed */
256 struct type
*elttype
;
258 int length_pos
, length_size
, string_pos
;
263 CHECK_TYPEDEF (type
);
264 switch (TYPE_CODE (type
))
266 case TYPE_CODE_ARRAY
:
267 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
269 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
270 eltlen
= TYPE_LENGTH (elttype
);
271 len
= TYPE_LENGTH (type
) / eltlen
;
272 if (prettyprint_arrays
)
273 print_spaces_filtered (2 + 2 * recurse
, stream
);
274 /* For an array of chars, print with string syntax. */
276 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
277 || ((current_language
->la_language
== language_m2
)
278 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
279 && (format
== 0 || format
== 's'))
281 /* If requested, look for the first null char and only print
282 elements up to it. */
283 if (stop_print_at_null
)
285 unsigned int temp_len
;
287 /* Look for a NULL char. */
289 (valaddr
+ embedded_offset
)[temp_len
]
290 && temp_len
< len
&& temp_len
< print_max
;
295 LA_PRINT_STRING (stream
, valaddr
+ embedded_offset
, len
, 1, 0);
300 fprintf_filtered (stream
, "{");
301 val_print_array_elements (type
, valaddr
+ embedded_offset
,
302 address
, stream
, format
, deref_ref
,
304 fprintf_filtered (stream
, "}");
308 /* Array of unspecified length: treat like pointer to first elt. */
309 print_unpacked_pointer (type
, address
, address
, format
, stream
);
313 if (TYPE_CONST (type
))
314 print_variable_at_address (type
, valaddr
+ embedded_offset
,
315 stream
, format
, deref_ref
, recurse
,
317 else if (format
&& format
!= 's')
318 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
,
322 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
323 print_unpacked_pointer (type
, addr
, address
, format
, stream
);
328 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
332 = extract_typed_address (valaddr
+ embedded_offset
, type
);
333 fprintf_filtered (stream
, "@");
334 fputs_filtered (paddress (addr
), stream
);
336 fputs_filtered (": ", stream
);
338 /* De-reference the reference. */
341 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
343 struct value
*deref_val
=
345 (TYPE_TARGET_TYPE (type
),
346 unpack_pointer (lookup_pointer_type (builtin_type_void
),
347 valaddr
+ embedded_offset
));
348 common_val_print (deref_val
, stream
, format
, deref_ref
,
352 fputs_filtered ("???", stream
);
356 case TYPE_CODE_UNION
:
357 if (recurse
&& !unionprint
)
359 fprintf_filtered (stream
, "{...}");
363 case TYPE_CODE_STRUCT
:
364 if (m2_is_long_set (type
))
365 m2_print_long_set (type
, valaddr
, embedded_offset
, address
,
366 stream
, format
, pretty
);
368 cp_print_value_fields (type
, type
, valaddr
, embedded_offset
,
369 address
, stream
, format
,
370 recurse
, pretty
, NULL
, 0);
376 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
380 len
= TYPE_NFIELDS (type
);
381 val
= unpack_long (type
, valaddr
+ embedded_offset
);
382 for (i
= 0; i
< len
; i
++)
385 if (val
== TYPE_FIELD_BITPOS (type
, i
))
392 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
396 print_longest (stream
, 'd', 0, val
);
403 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
407 /* FIXME, we should consider, at least for ANSI C language, eliminating
408 the distinction made between FUNCs and POINTERs to FUNCs. */
409 fprintf_filtered (stream
, "{");
410 type_print (type
, "", stream
, -1);
411 fprintf_filtered (stream
, "} ");
412 /* Try to print what function it points to, and its address. */
413 print_address_demangle (address
, stream
, demangle
);
417 format
= format
? format
: output_format
;
419 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
423 val
= unpack_long (type
, valaddr
+ embedded_offset
);
425 fputs_filtered ("FALSE", stream
);
427 fputs_filtered ("TRUE", stream
);
429 fprintf_filtered (stream
, "%ld)", (long int) val
);
433 case TYPE_CODE_RANGE
:
434 if (TYPE_LENGTH (type
) == TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
436 m2_val_print (TYPE_TARGET_TYPE (type
), valaddr
, embedded_offset
,
437 address
, stream
, format
, deref_ref
, recurse
, pretty
);
440 /* FIXME: create_range_type does not set the unsigned bit in a
441 range type (I think it probably should copy it from the target
442 type), so we won't print values which are too large to
443 fit in a signed integer correctly. */
444 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
445 print with the target type, though, because the size of our type
446 and the target type might differ). */
450 format
= format
? format
: output_format
;
452 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
,
455 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
459 format
= format
? format
: output_format
;
461 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
465 val
= unpack_long (type
, valaddr
+ embedded_offset
);
466 if (TYPE_UNSIGNED (type
))
467 fprintf_filtered (stream
, "%u", (unsigned int) val
);
469 fprintf_filtered (stream
, "%d", (int) val
);
470 fputs_filtered (" ", stream
);
471 LA_PRINT_CHAR ((unsigned char) val
, stream
);
477 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
480 print_floating (valaddr
+ embedded_offset
, type
, stream
);
483 case TYPE_CODE_METHOD
:
486 case TYPE_CODE_BITSTRING
:
488 elttype
= TYPE_INDEX_TYPE (type
);
489 CHECK_TYPEDEF (elttype
);
490 if (TYPE_STUB (elttype
))
492 fprintf_filtered (stream
, _("<incomplete type>"));
498 struct type
*range
= elttype
;
499 LONGEST low_bound
, high_bound
;
501 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
505 fputs_filtered ("B'", stream
);
507 fputs_filtered ("{", stream
);
509 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
513 fputs_filtered (_("<error value>"), stream
);
517 for (i
= low_bound
; i
<= high_bound
; i
++)
519 int element
= value_bit_index (type
, valaddr
+ embedded_offset
,
524 goto maybe_bad_bstring
;
527 fprintf_filtered (stream
, "%d", element
);
531 fputs_filtered (", ", stream
);
532 print_type_scalar (range
, i
, stream
);
535 if (i
+ 1 <= high_bound
536 && value_bit_index (type
, valaddr
+ embedded_offset
,
540 fputs_filtered ("..", stream
);
541 while (i
+ 1 <= high_bound
542 && value_bit_index (type
,
543 valaddr
+ embedded_offset
,
546 print_type_scalar (range
, j
, stream
);
552 fputs_filtered ("'", stream
);
554 fputs_filtered ("}", stream
);
559 fprintf_filtered (stream
, "void");
562 case TYPE_CODE_ERROR
:
563 fprintf_filtered (stream
, _("<error type>"));
566 case TYPE_CODE_UNDEF
:
567 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
568 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
569 and no complete type for struct foo in that file. */
570 fprintf_filtered (stream
, _("<incomplete type>"));
574 error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type
));
This page took 0.043497 seconds and 4 git commands to generate.