use remote-utils facilities for baud_rate
[deliverable/binutils-gdb.git] / gdb / ch-valprint.c
CommitLineData
a8a69e63
FF
1/* Support for printing Chill values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#include "defs.h"
21#include "obstack.h"
22#include "symtab.h"
23#include "gdbtypes.h"
24#include "valprint.h"
25#include "expression.h"
8fbdca53 26#include "value.h"
a8a69e63 27#include "language.h"
5e81259d 28#include "demangle.h"
a8a69e63 29
8fbdca53
FF
30static void
31chill_print_value_fields PARAMS ((struct type *, char *, FILE *, int, int,
32 enum val_prettyprint, struct type **));
33
a8a69e63
FF
34\f
35/* Print data of type TYPE located at VALADDR (within GDB), which came from
36 the inferior at address ADDRESS, onto stdio stream STREAM according to
37 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
38 target byte order.
39
40 If the data are a string pointer, returns the number of string characters
41 printed.
42
43 If DEREF_REF is nonzero, then dereference references, otherwise just print
44 them like pointers.
45
46 The PRETTY parameter controls prettyprinting. */
47
48int
49chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
50 pretty)
51 struct type *type;
52 char *valaddr;
53 CORE_ADDR address;
54 FILE *stream;
55 int format;
56 int deref_ref;
57 int recurse;
58 enum val_prettyprint pretty;
59{
a8a69e63 60 LONGEST val;
ec16f701 61 unsigned int i = 0; /* Number of characters printed. */
c7da3ed3 62 struct type *elttype;
c7da3ed3 63 CORE_ADDR addr;
a8a69e63
FF
64
65 switch (TYPE_CODE (type))
66 {
67 case TYPE_CODE_ARRAY:
68 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
69 {
a8a69e63
FF
70 if (prettyprint_arrays)
71 {
72 print_spaces_filtered (2 + 2 * recurse, stream);
73 }
74 fprintf_filtered (stream, "[");
a9b37611
FF
75 val_print_array_elements (type, valaddr, address, stream, format,
76 deref_ref, recurse, pretty, 0);
a8a69e63
FF
77 fprintf_filtered (stream, "]");
78 }
79 else
80 {
81 error ("unimplemented in chill_val_print; unspecified array length");
82 }
83 break;
84
85 case TYPE_CODE_INT:
86 format = format ? format : output_format;
87 if (format)
88 {
89 print_scalar_formatted (valaddr, type, format, 0, stream);
90 }
91 else
92 {
93 val_print_type_code_int (type, valaddr, stream);
94 }
95 break;
96
97 case TYPE_CODE_CHAR:
98 format = format ? format : output_format;
99 if (format)
100 {
101 print_scalar_formatted (valaddr, type, format, 0, stream);
102 }
103 else
104 {
105 LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr),
106 stream);
107 }
108 break;
109
110 case TYPE_CODE_FLT:
111 if (format)
112 {
113 print_scalar_formatted (valaddr, type, format, 0, stream);
114 }
115 else
116 {
117 print_floating (valaddr, type, stream);
118 }
119 break;
120
121 case TYPE_CODE_BOOL:
122 format = format ? format : output_format;
123 if (format)
124 {
125 print_scalar_formatted (valaddr, type, format, 0, stream);
126 }
127 else
128 {
129 val = unpack_long (builtin_type_chill_bool, valaddr);
130 fprintf_filtered (stream, val ? "TRUE" : "FALSE");
131 }
132 break;
133
134 case TYPE_CODE_UNDEF:
135 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
136 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
137 and no complete type for struct foo in that file. */
138 fprintf_filtered (stream, "<incomplete type>");
139 break;
140
141 case TYPE_CODE_PTR:
c7da3ed3
FF
142 if (format && format != 's')
143 {
144 print_scalar_formatted (valaddr, type, format, 0, stream);
145 break;
146 }
147 addr = unpack_pointer (type, valaddr);
148 elttype = TYPE_TARGET_TYPE (type);
149
150 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
151 {
152 /* Try to print what function it points to. */
153 print_address_demangle (addr, stream, demangle);
154 /* Return value is irrelevant except for string pointers. */
155 return (0);
156 }
157 if (addressprint && format != 's')
158 {
8a177da6 159 fprintf_filtered (stream, "H'%x", addr);
c7da3ed3
FF
160 }
161
162 /* For a pointer to char or unsigned char, also print the string
163 pointed to, unless pointer is null. */
c7da3ed3
FF
164 if (TYPE_LENGTH (elttype) == 1
165 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
166 && (format == 0 || format == 's')
167 && addr != 0
168 && /* If print_max is UINT_MAX, the alloca below will fail.
169 In that case don't try to print the string. */
170 print_max < UINT_MAX)
171 {
8fbdca53 172 i = val_print_string (addr, 0, stream);
c7da3ed3
FF
173 }
174 /* Return number of characters printed, plus one for the
175 terminating null if we have "reached the end". */
176 return (i + (print_max && i != print_max));
177 break;
178
c4413e2c
FF
179 case TYPE_CODE_STRING:
180 if (format && format != 's')
181 {
182 print_scalar_formatted (valaddr, type, format, 0, stream);
183 break;
184 }
c4413e2c
FF
185 if (addressprint && format != 's')
186 {
bf5b632d
JK
187 /* This used to say `addr', which is unset at this point.
188 Is `address' what is meant? */
189 fprintf_filtered (stream, "H'%x ", address);
c4413e2c 190 }
ec16f701
FF
191 i = TYPE_LENGTH (type);
192 LA_PRINT_STRING (stream, valaddr, i, 0);
c4413e2c
FF
193 /* Return number of characters printed, plus one for the terminating
194 null if we have "reached the end". */
195 return (i + (print_max && i != print_max));
196 break;
197
8fbdca53
FF
198 case TYPE_CODE_STRUCT:
199 chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
200 0);
201 break;
202
a8a69e63 203 case TYPE_CODE_REF:
8a177da6
PB
204 if (addressprint)
205 {
206 fprintf_filtered (stream, "LOC(H'%lx)",
207 unpack_long (builtin_type_int, valaddr));
208 if (deref_ref)
209 fputs_filtered (": ", stream);
210 }
211 /* De-reference the reference. */
212 if (deref_ref)
213 {
214 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
215 {
216 value deref_val =
217 value_at
218 (TYPE_TARGET_TYPE (type),
219 unpack_pointer (lookup_pointer_type (builtin_type_void),
220 valaddr));
221 val_print (VALUE_TYPE (deref_val),
222 VALUE_CONTENTS (deref_val),
223 VALUE_ADDRESS (deref_val), stream, format,
224 deref_ref, recurse + 1, pretty);
225 }
226 else
227 fputs_filtered ("???", stream);
228 }
229 break;
230
a8a69e63 231 case TYPE_CODE_ENUM:
8a177da6
PB
232 c_val_print (type, valaddr, address, stream, format,
233 deref_ref, recurse, pretty);
234 break;
235
236 case TYPE_CODE_MEMBER:
237 case TYPE_CODE_UNION:
a8a69e63
FF
238 case TYPE_CODE_FUNC:
239 case TYPE_CODE_VOID:
240 case TYPE_CODE_ERROR:
241 case TYPE_CODE_RANGE:
a8a69e63 242 default:
8a177da6
PB
243 /* Let's derfer printing to the C printer, rather than
244 print an error message. FIXME! */
245 c_val_print (type, valaddr, address, stream, format,
246 deref_ref, recurse, pretty);
a8a69e63
FF
247 }
248 fflush (stream);
249 return (0);
250}
8fbdca53
FF
251
252/* Mutually recursive subroutines of cplus_print_value and c_val_print to
253 print out a structure's fields: cp_print_value_fields and cplus_print_value.
254
255 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
256 same meanings as in cplus_print_value and c_val_print.
257
258 DONT_PRINT is an array of baseclass types that we
259 should not print, or zero if called from top level. */
260
261static void
262chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
263 dont_print)
264 struct type *type;
265 char *valaddr;
266 FILE *stream;
267 int format;
268 int recurse;
269 enum val_prettyprint pretty;
270 struct type **dont_print;
271{
272 int i, len;
273 int fields_seen = 0;
274
275 check_stub_type (type);
276
8a177da6 277 fprintf_filtered (stream, "[");
8fbdca53
FF
278 len = TYPE_NFIELDS (type);
279 if (len == 0)
280 {
281 fprintf_filtered (stream, "<No data fields>");
282 }
283 else
284 {
285 for (i = 0; i < len; i++)
286 {
287 if (fields_seen)
288 {
289 fprintf_filtered (stream, ", ");
290 }
291 fields_seen = 1;
292 if (pretty)
293 {
294 fprintf_filtered (stream, "\n");
295 print_spaces_filtered (2 + 2 * recurse, stream);
296 }
297 else
298 {
299 wrap_here (n_spaces (2 + 2 * recurse));
300 }
8a177da6 301 fputs_filtered (".", stream);
5e81259d
FF
302 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
303 language_chill, DMGL_NO_OPTS);
8a177da6 304 fputs_filtered (": ", stream);
8fbdca53
FF
305 if (TYPE_FIELD_PACKED (type, i))
306 {
307 value v;
308
309 /* Bitfields require special handling, especially due to byte
310 order problems. */
311 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
312 unpack_field_as_long (type, valaddr, i));
313
314 chill_val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
315 stream, format, 0, recurse + 1, pretty);
316 }
317 else
318 {
319 chill_val_print (TYPE_FIELD_TYPE (type, i),
320 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
321 0, stream, format, 0, recurse + 1, pretty);
322 }
323 }
324 if (pretty)
325 {
326 fprintf_filtered (stream, "\n");
327 print_spaces_filtered (2 * recurse, stream);
328 }
329 }
8a177da6 330 fprintf_filtered (stream, "]");
8fbdca53
FF
331}
332
This page took 0.070218 seconds and 4 git commands to generate.