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 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_print_options
*options
,
45 /* Print function pointer with inferior address ADDRESS onto stdio
49 print_function_pointer_address (CORE_ADDR address
, struct ui_file
*stream
,
52 CORE_ADDR func_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
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 (address
), stream
);
62 fputs_filtered (": ", stream
);
64 print_address_demangle (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 target
= builtin_type_int32
;
125 if (get_discrete_bounds (range
, &field_low
, &field_high
) >= 0)
127 for (i
= low_bound
; i
<= high_bound
; i
++)
129 bitval
= value_bit_index (TYPE_FIELD_TYPE (type
, field
),
130 (TYPE_FIELD_BITPOS (type
, field
) / 8) +
131 valaddr
+ embedded_offset
, i
);
133 error (_("bit test is out of range"));
140 fprintf_filtered (stream
, ", ");
141 print_type_scalar (target
, i
, stream
);
152 if (previous_low
+1 < previous_high
)
153 fprintf_filtered (stream
, "..");
154 if (previous_low
+1 < previous_high
)
155 print_type_scalar (target
, previous_high
, stream
);
164 range
= TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type
, field
));
165 if (get_discrete_bounds (range
, &field_low
, &field_high
) < 0)
167 target
= TYPE_TARGET_TYPE (range
);
169 target
= builtin_type_int32
;
174 if (previous_low
+1 < previous_high
)
176 fprintf_filtered (stream
, "..");
177 print_type_scalar (target
, previous_high
, stream
);
181 fprintf_filtered (stream
, "}");
186 m2_print_unbounded_array (struct type
*type
, const gdb_byte
*valaddr
,
187 int embedded_offset
, CORE_ADDR address
,
188 struct ui_file
*stream
, int recurse
,
189 const struct value_print_options
*options
)
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 recurse
, options
, len
);
211 fprintf_filtered (stream
, ", HIGH = %d}", (int) len
);
215 print_unpacked_pointer (struct type
*type
,
216 CORE_ADDR address
, CORE_ADDR addr
,
217 const struct value_print_options
*options
,
218 struct ui_file
*stream
)
220 struct type
*elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
222 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
224 /* Try to print what function it points to. */
225 print_function_pointer_address (addr
, stream
, options
->addressprint
);
226 /* Return value is irrelevant except for string pointers. */
230 if (options
->addressprint
&& options
->format
!= 's')
231 fputs_filtered (paddress (address
), stream
);
233 /* For a pointer to char or unsigned char, also print the string
234 pointed to, unless pointer is null. */
236 if (TYPE_LENGTH (elttype
) == 1
237 && TYPE_CODE (elttype
) == TYPE_CODE_INT
238 && (options
->format
== 0 || options
->format
== 's')
240 return val_print_string (addr
, -1, TYPE_LENGTH (elttype
), stream
, options
);
246 print_variable_at_address (struct type
*type
,
247 const gdb_byte
*valaddr
,
248 struct ui_file
*stream
,
250 const struct value_print_options
*options
)
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 (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
));
263 common_val_print (deref_val
, stream
, recurse
, options
, current_language
);
266 fputs_filtered ("???", stream
);
270 /* m2_print_array_contents - prints out the contents of an
271 array up to a max_print values.
272 It prints arrays of char as a string
273 and all other data types as comma
277 m2_print_array_contents (struct type
*type
, const gdb_byte
*valaddr
,
278 int embedded_offset
, CORE_ADDR address
,
279 struct ui_file
*stream
, int recurse
,
280 const struct value_print_options
*options
,
284 CHECK_TYPEDEF (type
);
286 if (TYPE_LENGTH (type
) > 0)
288 eltlen
= TYPE_LENGTH (type
);
289 if (options
->prettyprint_arrays
)
290 print_spaces_filtered (2 + 2 * recurse
, stream
);
291 /* For an array of chars, print with string syntax. */
293 ((TYPE_CODE (type
) == TYPE_CODE_INT
)
294 || ((current_language
->la_language
== language_m2
)
295 && (TYPE_CODE (type
) == TYPE_CODE_CHAR
)))
296 && (options
->format
== 0 || options
->format
== 's'))
297 val_print_string (address
, len
+1, eltlen
, stream
, options
);
300 fprintf_filtered (stream
, "{");
301 val_print_array_elements (type
, valaddr
+ embedded_offset
,
302 address
, stream
, recurse
, options
, 0);
303 fprintf_filtered (stream
, "}");
309 /* Print data of type TYPE located at VALADDR (within GDB), which came from
310 the inferior at address ADDRESS, onto stdio stream STREAM according to
311 OPTIONS. The data at VALADDR is in target byte order.
313 If the data are a string pointer, returns the number of string characters
317 m2_val_print (struct type
*type
, const gdb_byte
*valaddr
, int embedded_offset
,
318 CORE_ADDR address
, struct ui_file
*stream
, int recurse
,
319 const struct value_print_options
*options
)
321 unsigned int i
= 0; /* Number of characters printed */
323 struct type
*elttype
;
325 int length_pos
, length_size
, string_pos
;
330 CHECK_TYPEDEF (type
);
331 switch (TYPE_CODE (type
))
333 case TYPE_CODE_ARRAY
:
334 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
336 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
337 eltlen
= TYPE_LENGTH (elttype
);
338 len
= TYPE_LENGTH (type
) / eltlen
;
339 if (options
->prettyprint_arrays
)
340 print_spaces_filtered (2 + 2 * recurse
, stream
);
341 /* For an array of chars, print with string syntax. */
343 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
344 || ((current_language
->la_language
== language_m2
)
345 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
346 && (options
->format
== 0 || options
->format
== 's'))
348 /* If requested, look for the first null char and only print
349 elements up to it. */
350 if (options
->stop_print_at_null
)
352 unsigned int temp_len
;
354 /* Look for a NULL char. */
356 (valaddr
+ embedded_offset
)[temp_len
]
357 && temp_len
< len
&& temp_len
< options
->print_max
;
362 LA_PRINT_STRING (stream
, valaddr
+ embedded_offset
, len
, 1, 0,
368 fprintf_filtered (stream
, "{");
369 val_print_array_elements (type
, valaddr
+ embedded_offset
,
370 address
, stream
, recurse
, options
, 0);
371 fprintf_filtered (stream
, "}");
375 /* Array of unspecified length: treat like pointer to first elt. */
376 print_unpacked_pointer (type
, address
, address
, options
, stream
);
380 if (TYPE_CONST (type
))
381 print_variable_at_address (type
, valaddr
+ embedded_offset
,
382 stream
, recurse
, options
);
383 else if (options
->format
&& options
->format
!= 's')
384 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
388 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
389 print_unpacked_pointer (type
, addr
, address
, options
, stream
);
394 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
395 if (options
->addressprint
)
398 = extract_typed_address (valaddr
+ embedded_offset
, type
);
399 fprintf_filtered (stream
, "@");
400 fputs_filtered (paddress (addr
), stream
);
401 if (options
->deref_ref
)
402 fputs_filtered (": ", stream
);
404 /* De-reference the reference. */
405 if (options
->deref_ref
)
407 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
409 struct value
*deref_val
=
411 (TYPE_TARGET_TYPE (type
),
412 unpack_pointer (type
, valaddr
+ embedded_offset
));
413 common_val_print (deref_val
, stream
, recurse
, options
,
417 fputs_filtered ("???", stream
);
421 case TYPE_CODE_UNION
:
422 if (recurse
&& !options
->unionprint
)
424 fprintf_filtered (stream
, "{...}");
428 case TYPE_CODE_STRUCT
:
429 if (m2_is_long_set (type
))
430 m2_print_long_set (type
, valaddr
, embedded_offset
, address
,
432 else if (m2_is_unbounded_array (type
))
433 m2_print_unbounded_array (type
, valaddr
, embedded_offset
,
434 address
, stream
, recurse
, options
);
436 cp_print_value_fields (type
, type
, valaddr
, embedded_offset
,
437 address
, stream
, recurse
, options
, NULL
, 0);
443 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
447 len
= TYPE_NFIELDS (type
);
448 val
= unpack_long (type
, valaddr
+ embedded_offset
);
449 for (i
= 0; i
< len
; i
++)
452 if (val
== TYPE_FIELD_BITPOS (type
, i
))
459 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
463 print_longest (stream
, 'd', 0, val
);
470 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
474 /* FIXME, we should consider, at least for ANSI C language, eliminating
475 the distinction made between FUNCs and POINTERs to FUNCs. */
476 fprintf_filtered (stream
, "{");
477 type_print (type
, "", stream
, -1);
478 fprintf_filtered (stream
, "} ");
479 /* Try to print what function it points to, and its address. */
480 print_address_demangle (address
, stream
, demangle
);
484 if (options
->format
|| options
->output_format
)
486 struct value_print_options opts
= *options
;
487 opts
.format
= (options
->format
? options
->format
488 : options
->output_format
);
489 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
494 val
= unpack_long (type
, valaddr
+ embedded_offset
);
496 fputs_filtered ("FALSE", stream
);
498 fputs_filtered ("TRUE", stream
);
500 fprintf_filtered (stream
, "%ld)", (long int) val
);
504 case TYPE_CODE_RANGE
:
505 if (TYPE_LENGTH (type
) == TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
507 m2_val_print (TYPE_TARGET_TYPE (type
), valaddr
, embedded_offset
,
508 address
, stream
, recurse
, options
);
511 /* FIXME: create_range_type does not set the unsigned bit in a
512 range type (I think it probably should copy it from the target
513 type), so we won't print values which are too large to
514 fit in a signed integer correctly. */
515 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
516 print with the target type, though, because the size of our type
517 and the target type might differ). */
521 if (options
->format
|| options
->output_format
)
523 struct value_print_options opts
= *options
;
524 opts
.format
= (options
->format
? options
->format
525 : options
->output_format
);
526 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
530 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
534 if (options
->format
|| options
->output_format
)
536 struct value_print_options opts
= *options
;
537 opts
.format
= (options
->format
? options
->format
538 : options
->output_format
);
539 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
544 val
= unpack_long (type
, valaddr
+ embedded_offset
);
545 if (TYPE_UNSIGNED (type
))
546 fprintf_filtered (stream
, "%u", (unsigned int) val
);
548 fprintf_filtered (stream
, "%d", (int) val
);
549 fputs_filtered (" ", stream
);
550 LA_PRINT_CHAR ((unsigned char) val
, stream
);
556 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
559 print_floating (valaddr
+ embedded_offset
, type
, stream
);
562 case TYPE_CODE_METHOD
:
565 case TYPE_CODE_BITSTRING
:
567 elttype
= TYPE_INDEX_TYPE (type
);
568 CHECK_TYPEDEF (elttype
);
569 if (TYPE_STUB (elttype
))
571 fprintf_filtered (stream
, _("<incomplete type>"));
577 struct type
*range
= elttype
;
578 LONGEST low_bound
, high_bound
;
580 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
584 fputs_filtered ("B'", stream
);
586 fputs_filtered ("{", stream
);
588 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
592 fputs_filtered (_("<error value>"), stream
);
596 for (i
= low_bound
; i
<= high_bound
; i
++)
598 int element
= value_bit_index (type
, valaddr
+ embedded_offset
,
603 goto maybe_bad_bstring
;
606 fprintf_filtered (stream
, "%d", element
);
610 fputs_filtered (", ", stream
);
611 print_type_scalar (range
, i
, stream
);
614 if (i
+ 1 <= high_bound
615 && value_bit_index (type
, valaddr
+ embedded_offset
,
619 fputs_filtered ("..", stream
);
620 while (i
+ 1 <= high_bound
621 && value_bit_index (type
,
622 valaddr
+ embedded_offset
,
625 print_type_scalar (range
, j
, stream
);
631 fputs_filtered ("'", stream
);
633 fputs_filtered ("}", stream
);
638 fprintf_filtered (stream
, "void");
641 case TYPE_CODE_ERROR
:
642 fprintf_filtered (stream
, _("<error type>"));
645 case TYPE_CODE_UNDEF
:
646 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
647 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
648 and no complete type for struct foo in that file. */
649 fprintf_filtered (stream
, _("<incomplete type>"));
653 error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type
));
This page took 0.061298 seconds and 4 git commands to generate.