Commit | Line | Data |
---|---|---|
a8a69e63 | 1 | /* Support for printing Chill values for GDB, the GNU debugger. |
67e9b3b3 PS |
2 | Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994 |
3 | Free Software Foundation, Inc. | |
a8a69e63 FF |
4 | |
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. */ | |
20 | ||
21 | #include "defs.h" | |
22 | #include "obstack.h" | |
23 | #include "symtab.h" | |
24 | #include "gdbtypes.h" | |
25 | #include "valprint.h" | |
26 | #include "expression.h" | |
8fbdca53 | 27 | #include "value.h" |
a8a69e63 | 28 | #include "language.h" |
5e81259d | 29 | #include "demangle.h" |
100f92e2 | 30 | #include "c-lang.h" /* For c_val_print */ |
a8a69e63 | 31 | |
8fbdca53 | 32 | static void |
199b2450 | 33 | chill_print_value_fields PARAMS ((struct type *, char *, GDB_FILE *, int, int, |
8fbdca53 FF |
34 | enum val_prettyprint, struct type **)); |
35 | ||
a8a69e63 FF |
36 | \f |
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 | |
40 | target byte order. | |
41 | ||
42 | If the data are a string pointer, returns the number of string characters | |
43 | printed. | |
44 | ||
45 | If DEREF_REF is nonzero, then dereference references, otherwise just print | |
46 | them like pointers. | |
47 | ||
48 | The PRETTY parameter controls prettyprinting. */ | |
49 | ||
50 | int | |
51 | chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse, | |
52 | pretty) | |
53 | struct type *type; | |
54 | char *valaddr; | |
55 | CORE_ADDR address; | |
199b2450 | 56 | GDB_FILE *stream; |
a8a69e63 FF |
57 | int format; |
58 | int deref_ref; | |
59 | int recurse; | |
60 | enum val_prettyprint pretty; | |
61 | { | |
a8a69e63 | 62 | LONGEST val; |
ec16f701 | 63 | unsigned int i = 0; /* Number of characters printed. */ |
c7da3ed3 | 64 | struct type *elttype; |
c7da3ed3 | 65 | CORE_ADDR addr; |
a8a69e63 FF |
66 | |
67 | switch (TYPE_CODE (type)) | |
68 | { | |
69 | case TYPE_CODE_ARRAY: | |
70 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
71 | { | |
a8a69e63 FF |
72 | if (prettyprint_arrays) |
73 | { | |
74 | print_spaces_filtered (2 + 2 * recurse, stream); | |
75 | } | |
76 | fprintf_filtered (stream, "["); | |
a9b37611 FF |
77 | val_print_array_elements (type, valaddr, address, stream, format, |
78 | deref_ref, recurse, pretty, 0); | |
a8a69e63 FF |
79 | fprintf_filtered (stream, "]"); |
80 | } | |
81 | else | |
82 | { | |
83 | error ("unimplemented in chill_val_print; unspecified array length"); | |
84 | } | |
85 | break; | |
86 | ||
87 | case TYPE_CODE_INT: | |
88 | format = format ? format : output_format; | |
89 | if (format) | |
90 | { | |
91 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
92 | } | |
93 | else | |
94 | { | |
95 | val_print_type_code_int (type, valaddr, stream); | |
96 | } | |
97 | break; | |
98 | ||
99 | case TYPE_CODE_CHAR: | |
100 | format = format ? format : output_format; | |
101 | if (format) | |
102 | { | |
103 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
104 | } | |
105 | else | |
106 | { | |
107 | LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr), | |
108 | stream); | |
109 | } | |
110 | break; | |
111 | ||
112 | case TYPE_CODE_FLT: | |
113 | if (format) | |
114 | { | |
115 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
116 | } | |
117 | else | |
118 | { | |
119 | print_floating (valaddr, type, stream); | |
120 | } | |
121 | break; | |
122 | ||
123 | case TYPE_CODE_BOOL: | |
124 | format = format ? format : output_format; | |
125 | if (format) | |
126 | { | |
127 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
128 | } | |
129 | else | |
130 | { | |
61932a8e | 131 | /* FIXME: Why is this using builtin_type_chill_bool not type? */ |
a8a69e63 FF |
132 | val = unpack_long (builtin_type_chill_bool, valaddr); |
133 | fprintf_filtered (stream, val ? "TRUE" : "FALSE"); | |
134 | } | |
135 | break; | |
136 | ||
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>"); | |
142 | break; | |
143 | ||
144 | case TYPE_CODE_PTR: | |
c7da3ed3 FF |
145 | if (format && format != 's') |
146 | { | |
147 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
148 | break; | |
149 | } | |
150 | addr = unpack_pointer (type, valaddr); | |
151 | elttype = TYPE_TARGET_TYPE (type); | |
152 | ||
153 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
154 | { | |
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. */ | |
158 | return (0); | |
159 | } | |
160 | if (addressprint && format != 's') | |
161 | { | |
d24c0599 | 162 | print_address_numeric (addr, 1, stream); |
c7da3ed3 FF |
163 | } |
164 | ||
165 | /* For a pointer to char or unsigned char, also print the string | |
166 | pointed to, unless pointer is null. */ | |
c7da3ed3 FF |
167 | if (TYPE_LENGTH (elttype) == 1 |
168 | && TYPE_CODE (elttype) == TYPE_CODE_CHAR | |
169 | && (format == 0 || format == 's') | |
170 | && addr != 0 | |
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) | |
174 | { | |
8fbdca53 | 175 | i = val_print_string (addr, 0, stream); |
c7da3ed3 FF |
176 | } |
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)); | |
180 | break; | |
181 | ||
c4413e2c FF |
182 | case TYPE_CODE_STRING: |
183 | if (format && format != 's') | |
184 | { | |
185 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
186 | break; | |
187 | } | |
ec16f701 FF |
188 | i = TYPE_LENGTH (type); |
189 | LA_PRINT_STRING (stream, valaddr, i, 0); | |
c4413e2c FF |
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)); | |
193 | break; | |
194 | ||
cba00921 | 195 | case TYPE_CODE_BITSTRING: |
e909f287 PB |
196 | case TYPE_CODE_SET: |
197 | { | |
198 | struct type *range = TYPE_FIELD_TYPE (type, 0); | |
cba00921 PB |
199 | int low_bound = TYPE_LOW_BOUND (range); |
200 | int high_bound = TYPE_HIGH_BOUND (range); | |
e909f287 | 201 | int i; |
cba00921 | 202 | int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING; |
e909f287 PB |
203 | int need_comma = 0; |
204 | int in_range = 0; | |
205 | ||
206 | if (is_bitstring) | |
207 | fputs_filtered ("B'", stream); | |
208 | else | |
209 | fputs_filtered ("[", stream); | |
210 | for (i = low_bound; i <= high_bound; i++) | |
211 | { | |
212 | int element = value_bit_index (type, valaddr, i); | |
213 | if (is_bitstring) | |
214 | fprintf_filtered (stream, "%d", element); | |
215 | else if (element) | |
216 | { | |
217 | if (need_comma) | |
218 | fputs_filtered (", ", stream); | |
219 | print_type_scalar (TYPE_TARGET_TYPE (range), i, stream); | |
220 | need_comma = 1; | |
221 | ||
222 | /* Look for a continuous range of true elements. */ | |
223 | if (i+1 <= high_bound && value_bit_index (type, valaddr, ++i)) | |
224 | { | |
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)) | |
229 | j = i; | |
230 | print_type_scalar (TYPE_TARGET_TYPE (range), j, stream); | |
231 | } | |
232 | } | |
233 | } | |
234 | if (is_bitstring) | |
235 | fputs_filtered ("'", stream); | |
236 | else | |
237 | fputs_filtered ("]", stream); | |
238 | } | |
239 | break; | |
240 | ||
8fbdca53 | 241 | case TYPE_CODE_STRUCT: |
cba00921 PB |
242 | if (chill_is_varying_struct (type)) |
243 | { | |
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; | |
247 | ||
248 | switch (TYPE_CODE (inner)) | |
249 | { | |
250 | case TYPE_CODE_STRING: | |
251 | if (length > TYPE_LENGTH (type)) | |
252 | { | |
253 | fprintf_filtered (stream, | |
254 | "<dynamic length %d > static length %d>", | |
255 | length, TYPE_LENGTH (type)); | |
256 | length > TYPE_LENGTH (type); | |
257 | } | |
258 | LA_PRINT_STRING (stream, data_addr, length, 0); | |
259 | return length; | |
260 | } | |
261 | } | |
8fbdca53 FF |
262 | chill_print_value_fields (type, valaddr, stream, format, recurse, pretty, |
263 | 0); | |
264 | break; | |
265 | ||
a8a69e63 | 266 | case TYPE_CODE_REF: |
8a177da6 PB |
267 | if (addressprint) |
268 | { | |
833e0d94 JK |
269 | fprintf_filtered (stream, "LOC("); |
270 | print_address_numeric | |
271 | (extract_address (valaddr, TARGET_PTR_BIT / HOST_CHAR_BIT), | |
d24c0599 | 272 | 1, |
833e0d94 JK |
273 | stream); |
274 | fprintf_filtered (stream, ")"); | |
8a177da6 PB |
275 | if (deref_ref) |
276 | fputs_filtered (": ", stream); | |
277 | } | |
278 | /* De-reference the reference. */ | |
279 | if (deref_ref) | |
280 | { | |
281 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF) | |
282 | { | |
82a2edfb | 283 | value_ptr deref_val = |
8a177da6 PB |
284 | value_at |
285 | (TYPE_TARGET_TYPE (type), | |
286 | unpack_pointer (lookup_pointer_type (builtin_type_void), | |
287 | valaddr)); | |
288 | val_print (VALUE_TYPE (deref_val), | |
289 | VALUE_CONTENTS (deref_val), | |
290 | VALUE_ADDRESS (deref_val), stream, format, | |
291 | deref_ref, recurse + 1, pretty); | |
292 | } | |
293 | else | |
294 | fputs_filtered ("???", stream); | |
295 | } | |
296 | break; | |
297 | ||
a8a69e63 | 298 | case TYPE_CODE_ENUM: |
8a177da6 PB |
299 | c_val_print (type, valaddr, address, stream, format, |
300 | deref_ref, recurse, pretty); | |
301 | break; | |
302 | ||
11b959da FF |
303 | case TYPE_CODE_RANGE: |
304 | if (TYPE_TARGET_TYPE (type)) | |
305 | chill_val_print (TYPE_TARGET_TYPE (type), valaddr, address, stream, | |
306 | format, deref_ref, recurse, pretty); | |
307 | break; | |
308 | ||
8a177da6 PB |
309 | case TYPE_CODE_MEMBER: |
310 | case TYPE_CODE_UNION: | |
a8a69e63 FF |
311 | case TYPE_CODE_FUNC: |
312 | case TYPE_CODE_VOID: | |
313 | case TYPE_CODE_ERROR: | |
a8a69e63 | 314 | default: |
11b959da | 315 | /* Let's defer printing to the C printer, rather than |
8a177da6 PB |
316 | print an error message. FIXME! */ |
317 | c_val_print (type, valaddr, address, stream, format, | |
318 | deref_ref, recurse, pretty); | |
a8a69e63 | 319 | } |
199b2450 | 320 | gdb_flush (stream); |
a8a69e63 FF |
321 | return (0); |
322 | } | |
8fbdca53 FF |
323 | |
324 | /* Mutually recursive subroutines of cplus_print_value and c_val_print to | |
325 | print out a structure's fields: cp_print_value_fields and cplus_print_value. | |
326 | ||
327 | TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the | |
328 | same meanings as in cplus_print_value and c_val_print. | |
329 | ||
330 | DONT_PRINT is an array of baseclass types that we | |
331 | should not print, or zero if called from top level. */ | |
332 | ||
333 | static void | |
334 | chill_print_value_fields (type, valaddr, stream, format, recurse, pretty, | |
335 | dont_print) | |
336 | struct type *type; | |
337 | char *valaddr; | |
199b2450 | 338 | GDB_FILE *stream; |
8fbdca53 FF |
339 | int format; |
340 | int recurse; | |
341 | enum val_prettyprint pretty; | |
342 | struct type **dont_print; | |
343 | { | |
344 | int i, len; | |
345 | int fields_seen = 0; | |
346 | ||
347 | check_stub_type (type); | |
348 | ||
8a177da6 | 349 | fprintf_filtered (stream, "["); |
8fbdca53 FF |
350 | len = TYPE_NFIELDS (type); |
351 | if (len == 0) | |
352 | { | |
353 | fprintf_filtered (stream, "<No data fields>"); | |
354 | } | |
355 | else | |
356 | { | |
357 | for (i = 0; i < len; i++) | |
358 | { | |
359 | if (fields_seen) | |
360 | { | |
361 | fprintf_filtered (stream, ", "); | |
362 | } | |
363 | fields_seen = 1; | |
364 | if (pretty) | |
365 | { | |
366 | fprintf_filtered (stream, "\n"); | |
367 | print_spaces_filtered (2 + 2 * recurse, stream); | |
368 | } | |
369 | else | |
370 | { | |
371 | wrap_here (n_spaces (2 + 2 * recurse)); | |
372 | } | |
8a177da6 | 373 | fputs_filtered (".", stream); |
5e81259d FF |
374 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), |
375 | language_chill, DMGL_NO_OPTS); | |
8a177da6 | 376 | fputs_filtered (": ", stream); |
8fbdca53 FF |
377 | if (TYPE_FIELD_PACKED (type, i)) |
378 | { | |
82a2edfb | 379 | value_ptr v; |
8fbdca53 FF |
380 | |
381 | /* Bitfields require special handling, especially due to byte | |
382 | order problems. */ | |
383 | v = value_from_longest (TYPE_FIELD_TYPE (type, i), | |
384 | unpack_field_as_long (type, valaddr, i)); | |
385 | ||
386 | chill_val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, | |
387 | stream, format, 0, recurse + 1, pretty); | |
388 | } | |
389 | else | |
390 | { | |
391 | chill_val_print (TYPE_FIELD_TYPE (type, i), | |
392 | valaddr + TYPE_FIELD_BITPOS (type, i) / 8, | |
393 | 0, stream, format, 0, recurse + 1, pretty); | |
394 | } | |
395 | } | |
396 | if (pretty) | |
397 | { | |
398 | fprintf_filtered (stream, "\n"); | |
399 | print_spaces_filtered (2 * recurse, stream); | |
400 | } | |
401 | } | |
8a177da6 | 402 | fprintf_filtered (stream, "]"); |
8fbdca53 | 403 | } |