1 /* Support for printing Modula 2 values for GDB, the GNU debugger.
3 Copyright (C) 1986, 1988, 1989, 1991, 1992, 1996, 1998,
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
27 #include "expression.h"
31 #include "typeprint.h"
36 int print_unpacked_pointer (struct type
*type
,
37 CORE_ADDR address
, CORE_ADDR addr
,
38 int format
, struct ui_file
*stream
);
41 /* Print function pointer with inferior address ADDRESS onto stdio
45 print_function_pointer_address (CORE_ADDR address
, struct ui_file
*stream
)
47 CORE_ADDR func_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
51 /* If the function pointer is represented by a description, print the
52 address of the description. */
53 if (addressprint
&& func_addr
!= address
)
55 fputs_filtered ("@", stream
);
56 fputs_filtered (paddress (address
), stream
);
57 fputs_filtered (": ", stream
);
59 print_address_demangle (func_addr
, stream
, demangle
);
63 * get_long_set_bounds - assigns the bounds of the long set to low and high.
67 get_long_set_bounds (struct type
*type
, LONGEST
*low
, LONGEST
*high
)
71 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
73 len
= TYPE_NFIELDS (type
);
74 i
= TYPE_N_BASECLASSES (type
);
77 *low
= TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, i
)));
78 *high
= TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
,
82 error (_("expecting long_set"));
87 m2_print_long_set (struct type
*type
, const gdb_byte
*valaddr
,
88 int embedded_offset
, CORE_ADDR address
,
89 struct ui_file
*stream
, int format
,
90 enum val_prettyprint pretty
)
94 LONGEST previous_low
= 0;
95 LONGEST previous_high
= 0;
96 LONGEST i
, low_bound
, high_bound
;
97 LONGEST field_low
, field_high
;
103 CHECK_TYPEDEF (type
);
105 fprintf_filtered (stream
, "{");
106 len
= TYPE_NFIELDS (type
);
107 if (get_long_set_bounds (type
, &low_bound
, &high_bound
))
109 field
= TYPE_N_BASECLASSES (type
);
110 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
114 fprintf_filtered (stream
, " %s }", _("<unknown bounds of set>"));
118 target
= TYPE_TARGET_TYPE (range
);
120 target
= builtin_type_int
;
122 if (get_discrete_bounds (range
, &field_low
, &field_high
) >= 0)
124 for (i
= low_bound
; i
<= high_bound
; i
++)
126 bitval
= value_bit_index (TYPE_FIELD_TYPE (type
, field
),
127 (TYPE_FIELD_BITPOS (type
, field
) / 8) +
128 valaddr
+ embedded_offset
, i
);
130 error (_("bit test is out of range"));
137 fprintf_filtered (stream
, ", ");
138 print_type_scalar (target
, i
, stream
);
149 if (previous_low
+1 < previous_high
)
150 fprintf_filtered (stream
, "..");
151 if (previous_low
+1 < previous_high
)
152 print_type_scalar (target
, previous_high
, stream
);
161 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
162 if (get_discrete_bounds (range
, &field_low
, &field_high
) < 0)
164 target
= TYPE_TARGET_TYPE (range
);
166 target
= builtin_type_int
;
171 if (previous_low
+1 < previous_high
)
173 fprintf_filtered (stream
, "..");
174 print_type_scalar (target
, previous_high
, stream
);
178 fprintf_filtered (stream
, "}");
183 print_unpacked_pointer (struct type
*type
,
184 CORE_ADDR address
, CORE_ADDR addr
,
185 int format
, struct ui_file
*stream
)
187 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
189 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
191 /* Try to print what function it points to. */
192 print_function_pointer_address (addr
, stream
);
193 /* Return value is irrelevant except for string pointers. */
197 if (addressprint
&& format
!= 's')
198 fputs_filtered (paddress (address
), stream
);
200 /* For a pointer to char or unsigned char, also print the string
201 pointed to, unless pointer is null. */
203 if (TYPE_LENGTH (elttype
) == 1
204 && TYPE_CODE (elttype
) == TYPE_CODE_INT
205 && (format
== 0 || format
== 's')
207 return val_print_string (addr
, -1, TYPE_LENGTH (elttype
), stream
);
213 print_variable_at_address (struct type
*type
, const gdb_byte
*valaddr
,
214 struct ui_file
*stream
, int format
,
215 int deref_ref
, int recurse
,
216 enum val_prettyprint pretty
)
218 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
219 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
221 fprintf_filtered (stream
, "[");
222 fputs_filtered (paddress (addr
), stream
);
223 fprintf_filtered (stream
, "] : ");
225 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
227 struct value
*deref_val
=
229 (TYPE_TARGET_TYPE (type
),
230 unpack_pointer (lookup_pointer_type (builtin_type_void
),
232 common_val_print (deref_val
, stream
, format
, deref_ref
,
236 fputs_filtered ("???", stream
);
239 /* Print data of type TYPE located at VALADDR (within GDB), which came from
240 the inferior at address ADDRESS, onto stdio stream STREAM according to
241 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
244 If the data are a string pointer, returns the number of string characters
247 If DEREF_REF is nonzero, then dereference references, otherwise just print
250 The PRETTY parameter controls prettyprinting. */
253 m2_val_print (struct type
*type
, const gdb_byte
*valaddr
, int embedded_offset
,
254 CORE_ADDR address
, struct ui_file
*stream
, int format
,
255 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
257 unsigned int i
= 0; /* Number of characters printed */
259 struct type
*elttype
;
261 int length_pos
, length_size
, string_pos
;
266 CHECK_TYPEDEF (type
);
267 switch (TYPE_CODE (type
))
269 case TYPE_CODE_ARRAY
:
270 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
272 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
273 eltlen
= TYPE_LENGTH (elttype
);
274 len
= TYPE_LENGTH (type
) / eltlen
;
275 if (prettyprint_arrays
)
276 print_spaces_filtered (2 + 2 * recurse
, stream
);
277 /* For an array of chars, print with string syntax. */
279 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
280 || ((current_language
->la_language
== language_m2
)
281 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
282 && (format
== 0 || format
== 's'))
284 /* If requested, look for the first null char and only print
285 elements up to it. */
286 if (stop_print_at_null
)
288 unsigned int temp_len
;
290 /* Look for a NULL char. */
292 (valaddr
+ embedded_offset
)[temp_len
]
293 && temp_len
< len
&& temp_len
< print_max
;
298 LA_PRINT_STRING (stream
, valaddr
+ embedded_offset
, len
, 1, 0);
303 fprintf_filtered (stream
, "{");
304 val_print_array_elements (type
, valaddr
+ embedded_offset
,
305 address
, stream
, format
, deref_ref
,
307 fprintf_filtered (stream
, "}");
311 /* Array of unspecified length: treat like pointer to first elt. */
312 print_unpacked_pointer (type
, address
, address
, format
, stream
);
316 if (TYPE_CONST (type
))
317 print_variable_at_address (type
, valaddr
+ embedded_offset
,
318 stream
, format
, deref_ref
, recurse
,
320 else if (format
&& format
!= 's')
321 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
,
325 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
326 print_unpacked_pointer (type
, addr
, address
, format
, stream
);
330 case TYPE_CODE_MEMBER
:
331 error (_("not implemented: member type in m2_val_print"));
335 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
339 = extract_typed_address (valaddr
+ embedded_offset
, type
);
340 fprintf_filtered (stream
, "@");
341 fputs_filtered (paddress (addr
), stream
);
343 fputs_filtered (": ", stream
);
345 /* De-reference the reference. */
348 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
350 struct value
*deref_val
=
352 (TYPE_TARGET_TYPE (type
),
353 unpack_pointer (lookup_pointer_type (builtin_type_void
),
354 valaddr
+ embedded_offset
));
355 common_val_print (deref_val
, stream
, format
, deref_ref
,
359 fputs_filtered ("???", stream
);
363 case TYPE_CODE_UNION
:
364 if (recurse
&& !unionprint
)
366 fprintf_filtered (stream
, "{...}");
370 case TYPE_CODE_STRUCT
:
371 if (m2_is_long_set (type
))
372 m2_print_long_set (type
, valaddr
, embedded_offset
, address
,
373 stream
, format
, pretty
);
375 cp_print_value_fields (type
, type
, valaddr
, embedded_offset
,
376 address
, stream
, format
,
377 recurse
, pretty
, NULL
, 0);
383 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
387 len
= TYPE_NFIELDS (type
);
388 val
= unpack_long (type
, valaddr
+ embedded_offset
);
389 for (i
= 0; i
< len
; i
++)
392 if (val
== TYPE_FIELD_BITPOS (type
, i
))
399 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
403 print_longest (stream
, 'd', 0, val
);
410 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
414 /* FIXME, we should consider, at least for ANSI C language, eliminating
415 the distinction made between FUNCs and POINTERs to FUNCs. */
416 fprintf_filtered (stream
, "{");
417 type_print (type
, "", stream
, -1);
418 fprintf_filtered (stream
, "} ");
419 /* Try to print what function it points to, and its address. */
420 print_address_demangle (address
, stream
, demangle
);
424 format
= format
? format
: output_format
;
426 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
430 val
= unpack_long (type
, valaddr
+ embedded_offset
);
432 fputs_filtered ("FALSE", stream
);
434 fputs_filtered ("TRUE", stream
);
436 fprintf_filtered (stream
, "%ld)", (long int) val
);
440 case TYPE_CODE_RANGE
:
441 if (TYPE_LENGTH (type
) == TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
443 m2_val_print (TYPE_TARGET_TYPE (type
), valaddr
, embedded_offset
,
444 address
, stream
, format
, deref_ref
, recurse
, pretty
);
447 /* FIXME: create_range_type does not set the unsigned bit in a
448 range type (I think it probably should copy it from the target
449 type), so we won't print values which are too large to
450 fit in a signed integer correctly. */
451 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
452 print with the target type, though, because the size of our type
453 and the target type might differ). */
457 format
= format
? format
: output_format
;
459 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
,
462 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
466 format
= format
? format
: output_format
;
468 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
472 val
= unpack_long (type
, valaddr
+ embedded_offset
);
473 if (TYPE_UNSIGNED (type
))
474 fprintf_filtered (stream
, "%u", (unsigned int) val
);
476 fprintf_filtered (stream
, "%d", (int) val
);
477 fputs_filtered (" ", stream
);
478 LA_PRINT_CHAR ((unsigned char) val
, stream
);
484 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
487 print_floating (valaddr
+ embedded_offset
, type
, stream
);
490 case TYPE_CODE_METHOD
:
493 case TYPE_CODE_BITSTRING
:
495 elttype
= TYPE_INDEX_TYPE (type
);
496 CHECK_TYPEDEF (elttype
);
497 if (TYPE_STUB (elttype
))
499 fprintf_filtered (stream
, _("<incomplete type>"));
505 struct type
*range
= elttype
;
506 LONGEST low_bound
, high_bound
;
508 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
512 fputs_filtered ("B'", stream
);
514 fputs_filtered ("{", stream
);
516 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
520 fputs_filtered (_("<error value>"), stream
);
524 for (i
= low_bound
; i
<= high_bound
; i
++)
526 int element
= value_bit_index (type
, valaddr
+ embedded_offset
,
531 goto maybe_bad_bstring
;
534 fprintf_filtered (stream
, "%d", element
);
538 fputs_filtered (", ", stream
);
539 print_type_scalar (range
, i
, stream
);
542 if (i
+ 1 <= high_bound
543 && value_bit_index (type
, valaddr
+ embedded_offset
,
547 fputs_filtered ("..", stream
);
548 while (i
+ 1 <= high_bound
549 && value_bit_index (type
,
550 valaddr
+ embedded_offset
,
553 print_type_scalar (range
, j
, stream
);
559 fputs_filtered ("'", stream
);
561 fputs_filtered ("}", stream
);
566 fprintf_filtered (stream
, "void");
569 case TYPE_CODE_ERROR
:
570 fprintf_filtered (stream
, _("<error type>"));
573 case TYPE_CODE_UNDEF
:
574 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
575 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
576 and no complete type for struct foo in that file. */
577 fprintf_filtered (stream
, _("<incomplete type>"));
581 error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type
));
This page took 0.041989 seconds and 4 git commands to generate.