Keep Lynx files
[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"
100f92e2 29#include "c-lang.h" /* For c_val_print */
a8a69e63 30
8fbdca53
FF
31static void
32chill_print_value_fields PARAMS ((struct type *, char *, FILE *, int, int,
33 enum val_prettyprint, struct type **));
34
a8a69e63
FF
35\f
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
39 target byte order.
40
41 If the data are a string pointer, returns the number of string characters
42 printed.
43
44 If DEREF_REF is nonzero, then dereference references, otherwise just print
45 them like pointers.
46
47 The PRETTY parameter controls prettyprinting. */
48
49int
50chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
51 pretty)
52 struct type *type;
53 char *valaddr;
54 CORE_ADDR address;
55 FILE *stream;
56 int format;
57 int deref_ref;
58 int recurse;
59 enum val_prettyprint pretty;
60{
a8a69e63 61 LONGEST val;
ec16f701 62 unsigned int i = 0; /* Number of characters printed. */
c7da3ed3 63 struct type *elttype;
c7da3ed3 64 CORE_ADDR addr;
a8a69e63
FF
65
66 switch (TYPE_CODE (type))
67 {
68 case TYPE_CODE_ARRAY:
69 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
70 {
a8a69e63
FF
71 if (prettyprint_arrays)
72 {
73 print_spaces_filtered (2 + 2 * recurse, stream);
74 }
75 fprintf_filtered (stream, "[");
a9b37611
FF
76 val_print_array_elements (type, valaddr, address, stream, format,
77 deref_ref, recurse, pretty, 0);
a8a69e63
FF
78 fprintf_filtered (stream, "]");
79 }
80 else
81 {
82 error ("unimplemented in chill_val_print; unspecified array length");
83 }
84 break;
85
86 case TYPE_CODE_INT:
87 format = format ? format : output_format;
88 if (format)
89 {
90 print_scalar_formatted (valaddr, type, format, 0, stream);
91 }
92 else
93 {
94 val_print_type_code_int (type, valaddr, stream);
95 }
96 break;
97
98 case TYPE_CODE_CHAR:
99 format = format ? format : output_format;
100 if (format)
101 {
102 print_scalar_formatted (valaddr, type, format, 0, stream);
103 }
104 else
105 {
106 LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr),
107 stream);
108 }
109 break;
110
111 case TYPE_CODE_FLT:
112 if (format)
113 {
114 print_scalar_formatted (valaddr, type, format, 0, stream);
115 }
116 else
117 {
118 print_floating (valaddr, type, stream);
119 }
120 break;
121
122 case TYPE_CODE_BOOL:
123 format = format ? format : output_format;
124 if (format)
125 {
126 print_scalar_formatted (valaddr, type, format, 0, stream);
127 }
128 else
129 {
130 val = unpack_long (builtin_type_chill_bool, valaddr);
131 fprintf_filtered (stream, val ? "TRUE" : "FALSE");
132 }
133 break;
134
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>");
140 break;
141
142 case TYPE_CODE_PTR:
c7da3ed3
FF
143 if (format && format != 's')
144 {
145 print_scalar_formatted (valaddr, type, format, 0, stream);
146 break;
147 }
148 addr = unpack_pointer (type, valaddr);
149 elttype = TYPE_TARGET_TYPE (type);
150
151 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
152 {
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. */
156 return (0);
157 }
158 if (addressprint && format != 's')
159 {
5573d7d4 160 fprintf_filtered (stream, "H'%lx", (unsigned long) addr);
c7da3ed3
FF
161 }
162
163 /* For a pointer to char or unsigned char, also print the string
164 pointed to, unless pointer is null. */
c7da3ed3
FF
165 if (TYPE_LENGTH (elttype) == 1
166 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
167 && (format == 0 || format == 's')
168 && addr != 0
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)
172 {
8fbdca53 173 i = val_print_string (addr, 0, stream);
c7da3ed3
FF
174 }
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));
178 break;
179
c4413e2c
FF
180 case TYPE_CODE_STRING:
181 if (format && format != 's')
182 {
183 print_scalar_formatted (valaddr, type, format, 0, stream);
184 break;
185 }
c4413e2c
FF
186 if (addressprint && format != 's')
187 {
bf5b632d
JK
188 /* This used to say `addr', which is unset at this point.
189 Is `address' what is meant? */
5573d7d4 190 fprintf_filtered (stream, "H'%lx ", (unsigned long) address);
c4413e2c 191 }
ec16f701
FF
192 i = TYPE_LENGTH (type);
193 LA_PRINT_STRING (stream, valaddr, i, 0);
c4413e2c
FF
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));
197 break;
198
8fbdca53
FF
199 case TYPE_CODE_STRUCT:
200 chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
201 0);
202 break;
203
a8a69e63 204 case TYPE_CODE_REF:
8a177da6
PB
205 if (addressprint)
206 {
207 fprintf_filtered (stream, "LOC(H'%lx)",
208 unpack_long (builtin_type_int, valaddr));
209 if (deref_ref)
210 fputs_filtered (": ", stream);
211 }
212 /* De-reference the reference. */
213 if (deref_ref)
214 {
215 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
216 {
217 value deref_val =
218 value_at
219 (TYPE_TARGET_TYPE (type),
220 unpack_pointer (lookup_pointer_type (builtin_type_void),
221 valaddr));
222 val_print (VALUE_TYPE (deref_val),
223 VALUE_CONTENTS (deref_val),
224 VALUE_ADDRESS (deref_val), stream, format,
225 deref_ref, recurse + 1, pretty);
226 }
227 else
228 fputs_filtered ("???", stream);
229 }
230 break;
231
a8a69e63 232 case TYPE_CODE_ENUM:
8a177da6
PB
233 c_val_print (type, valaddr, address, stream, format,
234 deref_ref, recurse, pretty);
235 break;
236
237 case TYPE_CODE_MEMBER:
238 case TYPE_CODE_UNION:
a8a69e63
FF
239 case TYPE_CODE_FUNC:
240 case TYPE_CODE_VOID:
241 case TYPE_CODE_ERROR:
242 case TYPE_CODE_RANGE:
a8a69e63 243 default:
8a177da6
PB
244 /* Let's derfer printing to the C printer, rather than
245 print an error message. FIXME! */
246 c_val_print (type, valaddr, address, stream, format,
247 deref_ref, recurse, pretty);
a8a69e63
FF
248 }
249 fflush (stream);
250 return (0);
251}
8fbdca53
FF
252
253/* Mutually recursive subroutines of cplus_print_value and c_val_print to
254 print out a structure's fields: cp_print_value_fields and cplus_print_value.
255
256 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
257 same meanings as in cplus_print_value and c_val_print.
258
259 DONT_PRINT is an array of baseclass types that we
260 should not print, or zero if called from top level. */
261
262static void
263chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
264 dont_print)
265 struct type *type;
266 char *valaddr;
267 FILE *stream;
268 int format;
269 int recurse;
270 enum val_prettyprint pretty;
271 struct type **dont_print;
272{
273 int i, len;
274 int fields_seen = 0;
275
276 check_stub_type (type);
277
8a177da6 278 fprintf_filtered (stream, "[");
8fbdca53
FF
279 len = TYPE_NFIELDS (type);
280 if (len == 0)
281 {
282 fprintf_filtered (stream, "<No data fields>");
283 }
284 else
285 {
286 for (i = 0; i < len; i++)
287 {
288 if (fields_seen)
289 {
290 fprintf_filtered (stream, ", ");
291 }
292 fields_seen = 1;
293 if (pretty)
294 {
295 fprintf_filtered (stream, "\n");
296 print_spaces_filtered (2 + 2 * recurse, stream);
297 }
298 else
299 {
300 wrap_here (n_spaces (2 + 2 * recurse));
301 }
8a177da6 302 fputs_filtered (".", stream);
5e81259d
FF
303 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
304 language_chill, DMGL_NO_OPTS);
8a177da6 305 fputs_filtered (": ", stream);
8fbdca53
FF
306 if (TYPE_FIELD_PACKED (type, i))
307 {
308 value v;
309
310 /* Bitfields require special handling, especially due to byte
311 order problems. */
312 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
313 unpack_field_as_long (type, valaddr, i));
314
315 chill_val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
316 stream, format, 0, recurse + 1, pretty);
317 }
318 else
319 {
320 chill_val_print (TYPE_FIELD_TYPE (type, i),
321 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
322 0, stream, format, 0, recurse + 1, pretty);
323 }
324 }
325 if (pretty)
326 {
327 fprintf_filtered (stream, "\n");
328 print_spaces_filtered (2 * recurse, stream);
329 }
330 }
8a177da6 331 fprintf_filtered (stream, "]");
8fbdca53
FF
332}
333
This page took 0.080679 seconds and 4 git commands to generate.