]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/ch-valprint.c
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 */
31 #include "typeprint.h"
35 chill_print_value_fields
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int,
36 enum val_prettyprint
, struct type
**));
39 /* Print data of type TYPE located at VALADDR (within GDB), which came from
40 the inferior at address ADDRESS, onto stdio stream STREAM according to
41 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
44 If the data are a string pointer, returns the number of string characters
47 If DEREF_REF is nonzero, then dereference references, otherwise just print
50 The PRETTY parameter controls prettyprinting. */
53 chill_val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
,
62 enum val_prettyprint pretty
;
65 unsigned int i
= 0; /* Number of characters printed. */
69 switch (TYPE_CODE (type
))
72 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
74 if (prettyprint_arrays
)
76 print_spaces_filtered (2 + 2 * recurse
, stream
);
78 fprintf_filtered (stream
, "[");
79 val_print_array_elements (type
, valaddr
, address
, stream
, format
,
80 deref_ref
, recurse
, pretty
, 0);
81 fprintf_filtered (stream
, "]");
85 error ("unimplemented in chill_val_print; unspecified array length");
90 format
= format
? format
: output_format
;
93 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
97 val_print_type_code_int (type
, valaddr
, stream
);
102 format
= format
? format
: output_format
;
105 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
109 LA_PRINT_CHAR ((unsigned char) unpack_long (type
, valaddr
),
117 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
121 print_floating (valaddr
, type
, stream
);
126 format
= format
? format
: output_format
;
129 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
133 /* FIXME: Why is this using builtin_type_chill_bool not type? */
134 val
= unpack_long (builtin_type_chill_bool
, valaddr
);
135 fprintf_filtered (stream
, val
? "TRUE" : "FALSE");
139 case TYPE_CODE_UNDEF
:
140 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
141 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
142 and no complete type for struct foo in that file. */
143 fprintf_filtered (stream
, "<incomplete type>");
147 if (format
&& format
!= 's')
149 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
152 addr
= unpack_pointer (type
, valaddr
);
153 elttype
= TYPE_TARGET_TYPE (type
);
155 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
157 /* Try to print what function it points to. */
158 print_address_demangle (addr
, stream
, demangle
);
159 /* Return value is irrelevant except for string pointers. */
162 if (addressprint
&& format
!= 's')
164 print_address_numeric (addr
, 1, stream
);
167 /* For a pointer to char or unsigned char, also print the string
168 pointed to, unless pointer is null. */
169 if (TYPE_LENGTH (elttype
) == 1
170 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
171 && (format
== 0 || format
== 's')
173 && /* If print_max is UINT_MAX, the alloca below will fail.
174 In that case don't try to print the string. */
175 print_max
< UINT_MAX
)
177 i
= val_print_string (addr
, 0, stream
);
179 /* Return number of characters printed, plus one for the
180 terminating null if we have "reached the end". */
181 return (i
+ (print_max
&& i
!= print_max
));
184 case TYPE_CODE_STRING
:
185 if (format
&& format
!= 's')
187 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
190 i
= TYPE_LENGTH (type
);
191 LA_PRINT_STRING (stream
, valaddr
, i
, 0);
192 /* Return number of characters printed, plus one for the terminating
193 null if we have "reached the end". */
194 return (i
+ (print_max
&& i
!= print_max
));
197 case TYPE_CODE_BITSTRING
:
200 struct type
*range
= TYPE_FIELD_TYPE (type
, 0);
201 int low_bound
= TYPE_LOW_BOUND (range
);
202 int high_bound
= TYPE_HIGH_BOUND (range
);
204 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
208 fputs_filtered ("B'", stream
);
210 fputs_filtered ("[", stream
);
211 for (i
= low_bound
; i
<= high_bound
; i
++)
213 int element
= value_bit_index (type
, valaddr
, i
);
215 fprintf_filtered (stream
, "%d", element
);
219 fputs_filtered (", ", stream
);
220 print_type_scalar (TYPE_TARGET_TYPE (range
), i
, stream
);
223 /* Look for a continuous range of true elements. */
224 if (i
+1 <= high_bound
&& value_bit_index (type
, valaddr
, ++i
))
226 int j
= i
; /* j is the upper bound so far of the range */
227 fputs_filtered (":", stream
);
228 while (i
+1 <= high_bound
229 && value_bit_index (type
, valaddr
, ++i
))
231 print_type_scalar (TYPE_TARGET_TYPE (range
), j
, stream
);
236 fputs_filtered ("'", stream
);
238 fputs_filtered ("]", stream
);
242 case TYPE_CODE_STRUCT
:
243 if (chill_is_varying_struct (type
))
245 struct type
*inner
= TYPE_FIELD_TYPE (type
, 1);
246 long length
= unpack_long (TYPE_FIELD_TYPE (type
, 0), valaddr
);
247 char *data_addr
= valaddr
+ TYPE_FIELD_BITPOS (type
, 1) / 8;
249 switch (TYPE_CODE (inner
))
251 case TYPE_CODE_STRING
:
252 if (length
> TYPE_LENGTH (type
))
254 fprintf_filtered (stream
,
255 "<dynamic length %d > static length %d>",
256 length
, TYPE_LENGTH (type
));
258 LA_PRINT_STRING (stream
, data_addr
, length
, 0);
264 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
271 fprintf_filtered (stream
, "LOC(");
272 print_address_numeric
273 (extract_address (valaddr
, TARGET_PTR_BIT
/ HOST_CHAR_BIT
),
276 fprintf_filtered (stream
, ")");
278 fputs_filtered (": ", stream
);
280 /* De-reference the reference. */
283 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
285 value_ptr deref_val
=
287 (TYPE_TARGET_TYPE (type
),
288 unpack_pointer (lookup_pointer_type (builtin_type_void
),
290 val_print (VALUE_TYPE (deref_val
),
291 VALUE_CONTENTS (deref_val
),
292 VALUE_ADDRESS (deref_val
), stream
, format
,
293 deref_ref
, recurse
+ 1, pretty
);
296 fputs_filtered ("???", stream
);
301 c_val_print (type
, valaddr
, address
, stream
, format
,
302 deref_ref
, recurse
, pretty
);
305 case TYPE_CODE_RANGE
:
306 if (TYPE_TARGET_TYPE (type
))
307 chill_val_print (TYPE_TARGET_TYPE (type
), valaddr
, address
, stream
,
308 format
, deref_ref
, recurse
, pretty
);
311 case TYPE_CODE_MEMBER
:
312 case TYPE_CODE_UNION
:
315 case TYPE_CODE_ERROR
:
317 /* Let's defer printing to the C printer, rather than
318 print an error message. FIXME! */
319 c_val_print (type
, valaddr
, address
, stream
, format
,
320 deref_ref
, recurse
, pretty
);
326 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
327 print out a structure's fields: cp_print_value_fields and cplus_print_value.
329 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
330 same meanings as in cplus_print_value and c_val_print.
332 DONT_PRINT is an array of baseclass types that we
333 should not print, or zero if called from top level. */
336 chill_print_value_fields (type
, valaddr
, stream
, format
, recurse
, pretty
,
343 enum val_prettyprint pretty
;
344 struct type
**dont_print
;
349 check_stub_type (type
);
351 fprintf_filtered (stream
, "[");
352 len
= TYPE_NFIELDS (type
);
355 fprintf_filtered (stream
, "<No data fields>");
359 for (i
= 0; i
< len
; i
++)
363 fprintf_filtered (stream
, ", ");
368 fprintf_filtered (stream
, "\n");
369 print_spaces_filtered (2 + 2 * recurse
, stream
);
373 wrap_here (n_spaces (2 + 2 * recurse
));
375 fputs_filtered (".", stream
);
376 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
377 language_chill
, DMGL_NO_OPTS
);
378 fputs_filtered (": ", stream
);
379 if (TYPE_FIELD_PACKED (type
, i
))
383 /* Bitfields require special handling, especially due to byte
385 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
386 unpack_field_as_long (type
, valaddr
, i
));
388 chill_val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
389 stream
, format
, 0, recurse
+ 1, pretty
);
393 chill_val_print (TYPE_FIELD_TYPE (type
, i
),
394 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
395 0, stream
, format
, 0, recurse
+ 1, pretty
);
400 fprintf_filtered (stream
, "\n");
401 print_spaces_filtered (2 * recurse
, stream
);
404 fprintf_filtered (stream
, "]");