1 /* Support for printing Chill values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "expression.h"
30 #include "c-lang.h" /* For c_val_print */
33 chill_print_value_fields
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int,
34 enum val_prettyprint
, struct type
**));
37 /* Print data of type TYPE located at VALADDR (within GDB), which came from
38 the inferior at address ADDRESS, onto stdio stream STREAM according to
39 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
42 If the data are a string pointer, returns the number of string characters
45 If DEREF_REF is nonzero, then dereference references, otherwise just print
48 The PRETTY parameter controls prettyprinting. */
51 chill_val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
,
60 enum val_prettyprint pretty
;
63 unsigned int i
= 0; /* Number of characters printed. */
67 switch (TYPE_CODE (type
))
70 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
72 if (prettyprint_arrays
)
74 print_spaces_filtered (2 + 2 * recurse
, stream
);
76 fprintf_filtered (stream
, "[");
77 val_print_array_elements (type
, valaddr
, address
, stream
, format
,
78 deref_ref
, recurse
, pretty
, 0);
79 fprintf_filtered (stream
, "]");
83 error ("unimplemented in chill_val_print; unspecified array length");
88 format
= format
? format
: output_format
;
91 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
95 val_print_type_code_int (type
, valaddr
, stream
);
100 format
= format
? format
: output_format
;
103 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
107 LA_PRINT_CHAR ((unsigned char) unpack_long (type
, valaddr
),
115 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
119 print_floating (valaddr
, type
, stream
);
124 format
= format
? format
: output_format
;
127 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
131 /* FIXME: Why is this using builtin_type_chill_bool not type? */
132 val
= unpack_long (builtin_type_chill_bool
, valaddr
);
133 fprintf_filtered (stream
, val
? "TRUE" : "FALSE");
137 case TYPE_CODE_UNDEF
:
138 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
139 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
140 and no complete type for struct foo in that file. */
141 fprintf_filtered (stream
, "<incomplete type>");
145 if (format
&& format
!= 's')
147 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
150 addr
= unpack_pointer (type
, valaddr
);
151 elttype
= TYPE_TARGET_TYPE (type
);
153 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
155 /* Try to print what function it points to. */
156 print_address_demangle (addr
, stream
, demangle
);
157 /* Return value is irrelevant except for string pointers. */
160 if (addressprint
&& format
!= 's')
162 print_address_numeric (addr
, stream
);
165 /* For a pointer to char or unsigned char, also print the string
166 pointed to, unless pointer is null. */
167 if (TYPE_LENGTH (elttype
) == 1
168 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
169 && (format
== 0 || format
== 's')
171 && /* If print_max is UINT_MAX, the alloca below will fail.
172 In that case don't try to print the string. */
173 print_max
< UINT_MAX
)
175 i
= val_print_string (addr
, 0, stream
);
177 /* Return number of characters printed, plus one for the
178 terminating null if we have "reached the end". */
179 return (i
+ (print_max
&& i
!= print_max
));
182 case TYPE_CODE_STRING
:
183 if (format
&& format
!= 's')
185 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
188 i
= TYPE_LENGTH (type
);
189 LA_PRINT_STRING (stream
, valaddr
, i
, 0);
190 /* Return number of characters printed, plus one for the terminating
191 null if we have "reached the end". */
192 return (i
+ (print_max
&& i
!= print_max
));
195 case TYPE_CODE_BITSTRING
:
198 struct type
*range
= TYPE_FIELD_TYPE (type
, 0);
199 int low_bound
= TYPE_LOW_BOUND (range
);
200 int high_bound
= TYPE_HIGH_BOUND (range
);
202 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
207 fputs_filtered ("B'", stream
);
209 fputs_filtered ("[", stream
);
210 for (i
= low_bound
; i
<= high_bound
; i
++)
212 int element
= value_bit_index (type
, valaddr
, i
);
214 fprintf_filtered (stream
, "%d", element
);
218 fputs_filtered (", ", stream
);
219 print_type_scalar (TYPE_TARGET_TYPE (range
), i
, stream
);
222 /* Look for a continuous range of true elements. */
223 if (i
+1 <= high_bound
&& value_bit_index (type
, valaddr
, ++i
))
225 int j
= i
; /* j is the upper bound so far of the range */
226 fputs_filtered (":", stream
);
227 while (i
+1 <= high_bound
228 && value_bit_index (type
, valaddr
, ++i
))
230 print_type_scalar (TYPE_TARGET_TYPE (range
), j
, stream
);
235 fputs_filtered ("'", stream
);
237 fputs_filtered ("]", stream
);
241 case TYPE_CODE_STRUCT
:
242 if (chill_is_varying_struct (type
))
244 struct type
*inner
= TYPE_FIELD_TYPE (type
, 1);
245 long length
= unpack_long (TYPE_FIELD_TYPE (type
, 0), valaddr
);
246 char *data_addr
= valaddr
+ TYPE_FIELD_BITPOS (type
, 1) / 8;
248 switch (TYPE_CODE (inner
))
250 case TYPE_CODE_STRING
:
251 if (length
> TYPE_LENGTH (type
))
253 fprintf_filtered (stream
,
254 "<dynamic length %d > static length %d>",
255 length
, TYPE_LENGTH (type
));
256 length
> TYPE_LENGTH (type
);
258 LA_PRINT_STRING (stream
, data_addr
, length
, 0);
262 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
269 fprintf_filtered (stream
, "LOC(");
270 print_address_numeric
271 (extract_address (valaddr
, TARGET_PTR_BIT
/ HOST_CHAR_BIT
),
273 fprintf_filtered (stream
, ")");
275 fputs_filtered (": ", stream
);
277 /* De-reference the reference. */
280 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
282 value_ptr deref_val
=
284 (TYPE_TARGET_TYPE (type
),
285 unpack_pointer (lookup_pointer_type (builtin_type_void
),
287 val_print (VALUE_TYPE (deref_val
),
288 VALUE_CONTENTS (deref_val
),
289 VALUE_ADDRESS (deref_val
), stream
, format
,
290 deref_ref
, recurse
+ 1, pretty
);
293 fputs_filtered ("???", stream
);
298 c_val_print (type
, valaddr
, address
, stream
, format
,
299 deref_ref
, recurse
, pretty
);
302 case TYPE_CODE_RANGE
:
303 if (TYPE_TARGET_TYPE (type
))
304 chill_val_print (TYPE_TARGET_TYPE (type
), valaddr
, address
, stream
,
305 format
, deref_ref
, recurse
, pretty
);
308 case TYPE_CODE_MEMBER
:
309 case TYPE_CODE_UNION
:
312 case TYPE_CODE_ERROR
:
314 /* Let's defer printing to the C printer, rather than
315 print an error message. FIXME! */
316 c_val_print (type
, valaddr
, address
, stream
, format
,
317 deref_ref
, recurse
, pretty
);
323 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
324 print out a structure's fields: cp_print_value_fields and cplus_print_value.
326 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
327 same meanings as in cplus_print_value and c_val_print.
329 DONT_PRINT is an array of baseclass types that we
330 should not print, or zero if called from top level. */
333 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
340 enum val_prettyprint pretty
;
341 struct type
**dont_print
;
346 check_stub_type (type
);
348 fprintf_filtered (stream
, "[");
349 len
= TYPE_NFIELDS (type
);
352 fprintf_filtered (stream
, "<No data fields>");
356 for (i
= 0; i
< len
; i
++)
360 fprintf_filtered (stream
, ", ");
365 fprintf_filtered (stream
, "\n");
366 print_spaces_filtered (2 + 2 * recurse
, stream
);
370 wrap_here (n_spaces (2 + 2 * recurse
));
372 fputs_filtered (".", stream
);
373 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
374 language_chill
, DMGL_NO_OPTS
);
375 fputs_filtered (": ", stream
);
376 if (TYPE_FIELD_PACKED (type
, i
))
380 /* Bitfields require special handling, especially due to byte
382 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
383 unpack_field_as_long (type
, valaddr
, i
));
385 chill_val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
386 stream
, format
, 0, recurse
+ 1, pretty
);
390 chill_val_print (TYPE_FIELD_TYPE (type
, i
),
391 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
392 0, stream
, format
, 0, recurse
+ 1, pretty
);
397 fprintf_filtered (stream
, "\n");
398 print_spaces_filtered (2 * recurse
, stream
);
401 fprintf_filtered (stream
, "]");
This page took 0.036571 seconds and 4 git commands to generate.