1 /* Support for printing Chill values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "expression.h"
29 #include "c-lang.h" /* For c_val_print */
32 chill_print_value_fields
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int,
33 enum val_prettyprint
, struct type
**));
36 /* Print data of type TYPE located at VALADDR (within GDB), which came from
37 the inferior at address ADDRESS, onto stdio stream STREAM according to
38 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
41 If the data are a string pointer, returns the number of string characters
44 If DEREF_REF is nonzero, then dereference references, otherwise just print
47 The PRETTY parameter controls prettyprinting. */
50 chill_val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
,
59 enum val_prettyprint pretty
;
62 unsigned int i
= 0; /* Number of characters printed. */
66 switch (TYPE_CODE (type
))
69 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
71 if (prettyprint_arrays
)
73 print_spaces_filtered (2 + 2 * recurse
, stream
);
75 fprintf_filtered (stream
, "[");
76 val_print_array_elements (type
, valaddr
, address
, stream
, format
,
77 deref_ref
, recurse
, pretty
, 0);
78 fprintf_filtered (stream
, "]");
82 error ("unimplemented in chill_val_print; unspecified array length");
87 format
= format
? format
: output_format
;
90 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
94 val_print_type_code_int (type
, valaddr
, stream
);
99 format
= format
? format
: output_format
;
102 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
106 LA_PRINT_CHAR ((unsigned char) unpack_long (type
, valaddr
),
114 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
118 print_floating (valaddr
, type
, stream
);
123 format
= format
? format
: output_format
;
126 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
130 val
= unpack_long (builtin_type_chill_bool
, valaddr
);
131 fprintf_filtered (stream
, val
? "TRUE" : "FALSE");
135 case TYPE_CODE_UNDEF
:
136 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
137 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
138 and no complete type for struct foo in that file. */
139 fprintf_filtered (stream
, "<incomplete type>");
143 if (format
&& format
!= 's')
145 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
148 addr
= unpack_pointer (type
, valaddr
);
149 elttype
= TYPE_TARGET_TYPE (type
);
151 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
153 /* Try to print what function it points to. */
154 print_address_demangle (addr
, stream
, demangle
);
155 /* Return value is irrelevant except for string pointers. */
158 if (addressprint
&& format
!= 's')
160 fprintf_filtered (stream
, "H'%lx", (unsigned long) addr
);
163 /* For a pointer to char or unsigned char, also print the string
164 pointed to, unless pointer is null. */
165 if (TYPE_LENGTH (elttype
) == 1
166 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
167 && (format
== 0 || format
== 's')
169 && /* If print_max is UINT_MAX, the alloca below will fail.
170 In that case don't try to print the string. */
171 print_max
< UINT_MAX
)
173 i
= val_print_string (addr
, 0, stream
);
175 /* Return number of characters printed, plus one for the
176 terminating null if we have "reached the end". */
177 return (i
+ (print_max
&& i
!= print_max
));
180 case TYPE_CODE_STRING
:
181 if (format
&& format
!= 's')
183 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
186 if (addressprint
&& format
!= 's')
188 /* This used to say `addr', which is unset at this point.
189 Is `address' what is meant? */
190 fprintf_filtered (stream
, "H'%lx ", (unsigned long) address
);
192 i
= TYPE_LENGTH (type
);
193 LA_PRINT_STRING (stream
, valaddr
, i
, 0);
194 /* Return number of characters printed, plus one for the terminating
195 null if we have "reached the end". */
196 return (i
+ (print_max
&& i
!= print_max
));
201 struct type
*range
= TYPE_FIELD_TYPE (type
, 0);
202 int low_bound
= TYPE_FIELD_BITPOS (range
, 0);
203 int high_bound
= TYPE_FIELD_BITPOS (range
, 1);
205 int is_bitstring
= 0;
210 fputs_filtered ("B'", stream
);
212 fputs_filtered ("[", stream
);
213 for (i
= low_bound
; i
<= high_bound
; i
++)
215 int element
= value_bit_index (type
, valaddr
, i
);
217 fprintf_filtered (stream
, "%d", element
);
221 fputs_filtered (", ", stream
);
222 print_type_scalar (TYPE_TARGET_TYPE (range
), i
, stream
);
225 /* Look for a continuous range of true elements. */
226 if (i
+1 <= high_bound
&& value_bit_index (type
, valaddr
, ++i
))
228 int j
= i
; /* j is the upper bound so far of the range */
229 fputs_filtered (":", stream
);
230 while (i
+1 <= high_bound
231 && value_bit_index (type
, valaddr
, ++i
))
233 print_type_scalar (TYPE_TARGET_TYPE (range
), j
, stream
);
238 fputs_filtered ("'", stream
);
240 fputs_filtered ("]", stream
);
244 case TYPE_CODE_STRUCT
:
245 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
252 fprintf_filtered (stream
, "LOC(H'%lx)",
253 unpack_long (builtin_type_int
, valaddr
));
255 fputs_filtered (": ", stream
);
257 /* De-reference the reference. */
260 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
264 (TYPE_TARGET_TYPE (type
),
265 unpack_pointer (lookup_pointer_type (builtin_type_void
),
267 val_print (VALUE_TYPE (deref_val
),
268 VALUE_CONTENTS (deref_val
),
269 VALUE_ADDRESS (deref_val
), stream
, format
,
270 deref_ref
, recurse
+ 1, pretty
);
273 fputs_filtered ("???", stream
);
278 c_val_print (type
, valaddr
, address
, stream
, format
,
279 deref_ref
, recurse
, pretty
);
282 case TYPE_CODE_RANGE
:
283 if (TYPE_TARGET_TYPE (type
))
284 chill_val_print (TYPE_TARGET_TYPE (type
), valaddr
, address
, stream
,
285 format
, deref_ref
, recurse
, pretty
);
288 case TYPE_CODE_MEMBER
:
289 case TYPE_CODE_UNION
:
292 case TYPE_CODE_ERROR
:
294 /* Let's defer printing to the C printer, rather than
295 print an error message. FIXME! */
296 c_val_print (type
, valaddr
, address
, stream
, format
,
297 deref_ref
, recurse
, pretty
);
303 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
304 print out a structure's fields: cp_print_value_fields and cplus_print_value.
306 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
307 same meanings as in cplus_print_value and c_val_print.
309 DONT_PRINT is an array of baseclass types that we
310 should not print, or zero if called from top level. */
313 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
320 enum val_prettyprint pretty
;
321 struct type
**dont_print
;
326 check_stub_type (type
);
328 fprintf_filtered (stream
, "[");
329 len
= TYPE_NFIELDS (type
);
332 fprintf_filtered (stream
, "<No data fields>");
336 for (i
= 0; i
< len
; i
++)
340 fprintf_filtered (stream
, ", ");
345 fprintf_filtered (stream
, "\n");
346 print_spaces_filtered (2 + 2 * recurse
, stream
);
350 wrap_here (n_spaces (2 + 2 * recurse
));
352 fputs_filtered (".", stream
);
353 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
354 language_chill
, DMGL_NO_OPTS
);
355 fputs_filtered (": ", stream
);
356 if (TYPE_FIELD_PACKED (type
, i
))
360 /* Bitfields require special handling, especially due to byte
362 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
363 unpack_field_as_long (type
, valaddr
, i
));
365 chill_val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
366 stream
, format
, 0, recurse
+ 1, pretty
);
370 chill_val_print (TYPE_FIELD_TYPE (type
, i
),
371 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
372 0, stream
, format
, 0, recurse
+ 1, pretty
);
377 fprintf_filtered (stream
, "\n");
378 print_spaces_filtered (2 * recurse
, stream
);
381 fprintf_filtered (stream
, "]");
This page took 0.068702 seconds and 4 git commands to generate.