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 2 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, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
26 #include "expression.h"
30 #include "typeprint.h"
35 int print_unpacked_pointer (struct type
*type
,
36 CORE_ADDR address
, CORE_ADDR addr
,
37 int format
, struct ui_file
*stream
);
40 /* Print function pointer with inferior address ADDRESS onto stdio
44 print_function_pointer_address (CORE_ADDR address
, struct ui_file
*stream
)
46 CORE_ADDR func_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
50 /* If the function pointer is represented by a description, print the
51 address of the description. */
52 if (addressprint
&& func_addr
!= address
)
54 fputs_filtered ("@", stream
);
55 fputs_filtered (paddress (address
), stream
);
56 fputs_filtered (": ", stream
);
58 print_address_demangle (func_addr
, stream
, demangle
);
62 * get_long_set_bounds - assigns the bounds of the long set to low and high.
66 get_long_set_bounds (struct type
*type
, LONGEST
*low
, LONGEST
*high
)
70 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
72 len
= TYPE_NFIELDS (type
);
73 i
= TYPE_N_BASECLASSES (type
);
76 *low
= TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, i
)));
77 *high
= TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
,
81 error (_("expecting long_set"));
86 m2_print_long_set (struct type
*type
, const gdb_byte
*valaddr
,
87 int embedded_offset
, CORE_ADDR address
,
88 struct ui_file
*stream
, int format
,
89 enum val_prettyprint pretty
)
93 LONGEST previous_low
= 0;
94 LONGEST previous_high
= 0;
95 LONGEST i
, low_bound
, high_bound
;
96 LONGEST field_low
, field_high
;
102 CHECK_TYPEDEF (type
);
104 fprintf_filtered (stream
, "{");
105 len
= TYPE_NFIELDS (type
);
106 if (get_long_set_bounds (type
, &low_bound
, &high_bound
))
108 field
= TYPE_N_BASECLASSES (type
);
109 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
113 fprintf_filtered (stream
, " %s }", _("<unknown bounds of set>"));
117 target
= TYPE_TARGET_TYPE (range
);
119 target
= builtin_type_int
;
121 if (get_discrete_bounds (range
, &field_low
, &field_high
) >= 0)
123 for (i
= low_bound
; i
<= high_bound
; i
++)
125 bitval
= value_bit_index (TYPE_FIELD_TYPE (type
, field
),
126 (TYPE_FIELD_BITPOS (type
, field
) / 8) +
127 valaddr
+ embedded_offset
, i
);
129 error (_("bit test is out of range"));
136 fprintf_filtered (stream
, ", ");
137 print_type_scalar (target
, i
, stream
);
148 if (previous_low
+1 < previous_high
)
149 fprintf_filtered (stream
, "..");
150 if (previous_low
+1 < previous_high
)
151 print_type_scalar (target
, previous_high
, stream
);
160 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
161 if (get_discrete_bounds (range
, &field_low
, &field_high
) < 0)
163 target
= TYPE_TARGET_TYPE (range
);
165 target
= builtin_type_int
;
170 if (previous_low
+1 < previous_high
)
172 fprintf_filtered (stream
, "..");
173 print_type_scalar (target
, previous_high
, stream
);
177 fprintf_filtered (stream
, "}");
182 print_unpacked_pointer (struct type
*type
,
183 CORE_ADDR address
, CORE_ADDR addr
,
184 int format
, struct ui_file
*stream
)
186 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
188 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
190 /* Try to print what function it points to. */
191 print_function_pointer_address (addr
, stream
);
192 /* Return value is irrelevant except for string pointers. */
196 if (addressprint
&& format
!= 's')
197 fputs_filtered (paddress (address
), stream
);
199 /* For a pointer to char or unsigned char, also print the string
200 pointed to, unless pointer is null. */
202 if (TYPE_LENGTH (elttype
) == 1
203 && TYPE_CODE (elttype
) == TYPE_CODE_INT
204 && (format
== 0 || format
== 's')
206 return val_print_string (addr
, -1, TYPE_LENGTH (elttype
), stream
);
212 print_variable_at_address (struct type
*type
, const gdb_byte
*valaddr
,
213 struct ui_file
*stream
, int format
,
214 int deref_ref
, int recurse
,
215 enum val_prettyprint pretty
)
217 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
218 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
220 fprintf_filtered (stream
, "[");
221 fputs_filtered (paddress (addr
), stream
);
222 fprintf_filtered (stream
, "] : ");
224 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
226 struct value
*deref_val
=
228 (TYPE_TARGET_TYPE (type
),
229 unpack_pointer (lookup_pointer_type (builtin_type_void
),
231 common_val_print (deref_val
, stream
, format
, deref_ref
,
235 fputs_filtered ("???", stream
);
238 /* Print data of type TYPE located at VALADDR (within GDB), which came from
239 the inferior at address ADDRESS, onto stdio stream STREAM according to
240 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
243 If the data are a string pointer, returns the number of string characters
246 If DEREF_REF is nonzero, then dereference references, otherwise just print
249 The PRETTY parameter controls prettyprinting. */
252 m2_val_print (struct type
*type
, const gdb_byte
*valaddr
, int embedded_offset
,
253 CORE_ADDR address
, struct ui_file
*stream
, int format
,
254 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
256 unsigned int i
= 0; /* Number of characters printed */
258 struct type
*elttype
;
260 int length_pos
, length_size
, string_pos
;
265 CHECK_TYPEDEF (type
);
266 switch (TYPE_CODE (type
))
268 case TYPE_CODE_ARRAY
:
269 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
271 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
272 eltlen
= TYPE_LENGTH (elttype
);
273 len
= TYPE_LENGTH (type
) / eltlen
;
274 if (prettyprint_arrays
)
275 print_spaces_filtered (2 + 2 * recurse
, stream
);
276 /* For an array of chars, print with string syntax. */
278 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
279 || ((current_language
->la_language
== language_m2
)
280 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
281 && (format
== 0 || format
== 's'))
283 /* If requested, look for the first null char and only print
284 elements up to it. */
285 if (stop_print_at_null
)
287 unsigned int temp_len
;
289 /* Look for a NULL char. */
291 (valaddr
+ embedded_offset
)[temp_len
]
292 && temp_len
< len
&& temp_len
< print_max
;
297 LA_PRINT_STRING (stream
, valaddr
+ embedded_offset
, len
, 1, 0);
302 fprintf_filtered (stream
, "{");
303 val_print_array_elements (type
, valaddr
+ embedded_offset
,
304 address
, stream
, format
, deref_ref
,
306 fprintf_filtered (stream
, "}");
310 /* Array of unspecified length: treat like pointer to first elt. */
311 print_unpacked_pointer (type
, address
, address
, format
, stream
);
315 if (TYPE_CONST (type
))
316 print_variable_at_address (type
, valaddr
+ embedded_offset
,
317 stream
, format
, deref_ref
, recurse
,
319 else if (format
&& format
!= 's')
320 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
,
324 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
325 print_unpacked_pointer (type
, addr
, address
, format
, stream
);
330 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
334 = extract_typed_address (valaddr
+ embedded_offset
, type
);
335 fprintf_filtered (stream
, "@");
336 fputs_filtered (paddress (addr
), stream
);
338 fputs_filtered (": ", stream
);
340 /* De-reference the reference. */
343 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
345 struct value
*deref_val
=
347 (TYPE_TARGET_TYPE (type
),
348 unpack_pointer (lookup_pointer_type (builtin_type_void
),
349 valaddr
+ embedded_offset
));
350 common_val_print (deref_val
, stream
, format
, deref_ref
,
354 fputs_filtered ("???", stream
);
358 case TYPE_CODE_UNION
:
359 if (recurse
&& !unionprint
)
361 fprintf_filtered (stream
, "{...}");
365 case TYPE_CODE_STRUCT
:
366 if (m2_is_long_set (type
))
367 m2_print_long_set (type
, valaddr
, embedded_offset
, address
,
368 stream
, format
, pretty
);
370 cp_print_value_fields (type
, type
, valaddr
, embedded_offset
,
371 address
, stream
, format
,
372 recurse
, pretty
, NULL
, 0);
378 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
382 len
= TYPE_NFIELDS (type
);
383 val
= unpack_long (type
, valaddr
+ embedded_offset
);
384 for (i
= 0; i
< len
; i
++)
387 if (val
== TYPE_FIELD_BITPOS (type
, i
))
394 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
398 print_longest (stream
, 'd', 0, val
);
405 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
409 /* FIXME, we should consider, at least for ANSI C language, eliminating
410 the distinction made between FUNCs and POINTERs to FUNCs. */
411 fprintf_filtered (stream
, "{");
412 type_print (type
, "", stream
, -1);
413 fprintf_filtered (stream
, "} ");
414 /* Try to print what function it points to, and its address. */
415 print_address_demangle (address
, stream
, demangle
);
419 format
= format
? format
: output_format
;
421 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
425 val
= unpack_long (type
, valaddr
+ embedded_offset
);
427 fputs_filtered ("FALSE", stream
);
429 fputs_filtered ("TRUE", stream
);
431 fprintf_filtered (stream
, "%ld)", (long int) val
);
435 case TYPE_CODE_RANGE
:
436 if (TYPE_LENGTH (type
) == TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
438 m2_val_print (TYPE_TARGET_TYPE (type
), valaddr
, embedded_offset
,
439 address
, stream
, format
, deref_ref
, recurse
, pretty
);
442 /* FIXME: create_range_type does not set the unsigned bit in a
443 range type (I think it probably should copy it from the target
444 type), so we won't print values which are too large to
445 fit in a signed integer correctly. */
446 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
447 print with the target type, though, because the size of our type
448 and the target type might differ). */
452 format
= format
? format
: output_format
;
454 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
,
457 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
461 format
= format
? format
: output_format
;
463 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
467 val
= unpack_long (type
, valaddr
+ embedded_offset
);
468 if (TYPE_UNSIGNED (type
))
469 fprintf_filtered (stream
, "%u", (unsigned int) val
);
471 fprintf_filtered (stream
, "%d", (int) val
);
472 fputs_filtered (" ", stream
);
473 LA_PRINT_CHAR ((unsigned char) val
, stream
);
479 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
482 print_floating (valaddr
+ embedded_offset
, type
, stream
);
485 case TYPE_CODE_METHOD
:
488 case TYPE_CODE_BITSTRING
:
490 elttype
= TYPE_INDEX_TYPE (type
);
491 CHECK_TYPEDEF (elttype
);
492 if (TYPE_STUB (elttype
))
494 fprintf_filtered (stream
, _("<incomplete type>"));
500 struct type
*range
= elttype
;
501 LONGEST low_bound
, high_bound
;
503 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
507 fputs_filtered ("B'", stream
);
509 fputs_filtered ("{", stream
);
511 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
515 fputs_filtered (_("<error value>"), stream
);
519 for (i
= low_bound
; i
<= high_bound
; i
++)
521 int element
= value_bit_index (type
, valaddr
+ embedded_offset
,
526 goto maybe_bad_bstring
;
529 fprintf_filtered (stream
, "%d", element
);
533 fputs_filtered (", ", stream
);
534 print_type_scalar (range
, i
, stream
);
537 if (i
+ 1 <= high_bound
538 && value_bit_index (type
, valaddr
+ embedded_offset
,
542 fputs_filtered ("..", stream
);
543 while (i
+ 1 <= high_bound
544 && value_bit_index (type
,
545 valaddr
+ embedded_offset
,
548 print_type_scalar (range
, j
, stream
);
554 fputs_filtered ("'", stream
);
556 fputs_filtered ("}", stream
);
561 fprintf_filtered (stream
, "void");
564 case TYPE_CODE_ERROR
:
565 fprintf_filtered (stream
, _("<error type>"));
568 case TYPE_CODE_UNDEF
:
569 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
570 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
571 and no complete type for struct foo in that file. */
572 fprintf_filtered (stream
, _("<incomplete type>"));
576 error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type
));
This page took 0.049429 seconds and 4 git commands to generate.