7b4ac7e1 |
1 | /* Print values for GNU debugger gdb. |
4187119d |
2 | Copyright (C) 1986, 1988, 1989 Free Software Foundation, Inc. |
7b4ac7e1 |
3 | |
4187119d |
4 | This file is part of GDB. |
7b4ac7e1 |
5 | |
4187119d |
6 | GDB is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 1, or (at your option) |
9 | any later version. |
7b4ac7e1 |
10 | |
4187119d |
11 | GDB is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with GDB; see the file COPYING. If not, write to |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
7b4ac7e1 |
19 | |
20 | #include <stdio.h> |
21 | #include "defs.h" |
3bf57d21 |
22 | #include "param.h" |
7b4ac7e1 |
23 | #include "symtab.h" |
24 | #include "value.h" |
25 | |
7a67dd45 |
26 | /* GNU software is only expected to run on systems with 32-bit integers. */ |
27 | #define UINT_MAX 0xffffffff |
28 | |
7b4ac7e1 |
29 | /* Maximum number of chars to print for a string pointer value |
7a67dd45 |
30 | or vector contents, or UINT_MAX for no limit. */ |
7b4ac7e1 |
31 | |
7a67dd45 |
32 | static unsigned int print_max; |
7b4ac7e1 |
33 | |
34 | static void type_print_varspec_suffix (); |
35 | static void type_print_varspec_prefix (); |
36 | static void type_print_base (); |
bb7592f0 |
37 | static void type_print_method_args (); |
7b4ac7e1 |
38 | |
7b4ac7e1 |
39 | |
40 | char **unsigned_type_table; |
41 | char **signed_type_table; |
42 | char **float_type_table; |
4187119d |
43 | |
44 | |
45 | /* Print repeat counts if there are more than this |
46 | many repetitions of an element in an array. */ |
47 | #define REPEAT_COUNT_THRESHOLD 10 |
48 | \f |
49 | /* Print the character string STRING, printing at most LENGTH characters. |
50 | Printing stops early if the number hits print_max; repeat counts |
7a67dd45 |
51 | are printed as appropriate. Print ellipses at the end if we |
52 | had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */ |
4187119d |
53 | |
54 | void |
7a67dd45 |
55 | print_string (stream, string, length, force_ellipses) |
4187119d |
56 | FILE *stream; |
57 | char *string; |
58 | unsigned int length; |
7a67dd45 |
59 | int force_ellipses; |
4187119d |
60 | { |
61 | register unsigned int i; |
62 | unsigned int things_printed = 0; |
63 | int in_quotes = 0; |
64 | int need_comma = 0; |
65 | |
66 | if (length == 0) |
67 | { |
68 | fputs_filtered ("\"\"", stdout); |
69 | return; |
70 | } |
71 | |
72 | for (i = 0; i < length && things_printed < print_max; ++i) |
73 | { |
74 | /* Position of the character we are examining |
75 | to see whether it is repeated. */ |
76 | unsigned int rep1; |
77 | /* Number of repititions we have detected so far. */ |
78 | unsigned int reps; |
79 | |
80 | QUIT; |
81 | |
82 | if (need_comma) |
83 | { |
84 | fputs_filtered (", ", stream); |
85 | need_comma = 0; |
86 | } |
87 | |
88 | rep1 = i + 1; |
89 | reps = 1; |
90 | while (rep1 < length && string[rep1] == string[i]) |
91 | { |
92 | ++rep1; |
93 | ++reps; |
94 | } |
95 | |
96 | if (reps > REPEAT_COUNT_THRESHOLD) |
97 | { |
98 | if (in_quotes) |
99 | { |
100 | fputs_filtered ("\", ", stream); |
101 | in_quotes = 0; |
102 | } |
103 | fputs_filtered ("'", stream); |
104 | printchar (string[i], stream, '\''); |
105 | fprintf_filtered (stream, "' <repeats %u times>", reps); |
106 | i = rep1 - 1; |
107 | things_printed += REPEAT_COUNT_THRESHOLD; |
108 | need_comma = 1; |
109 | } |
110 | else |
111 | { |
112 | if (!in_quotes) |
113 | { |
114 | fputs_filtered ("\"", stream); |
115 | in_quotes = 1; |
116 | } |
117 | printchar (string[i], stream, '"'); |
118 | ++things_printed; |
119 | } |
120 | } |
121 | |
122 | /* Terminate the quotes if necessary. */ |
123 | if (in_quotes) |
124 | fputs_filtered ("\"", stream); |
125 | |
7a67dd45 |
126 | if (force_ellipses || i < length) |
4187119d |
127 | fputs_filtered ("...", stream); |
128 | } |
7b4ac7e1 |
129 | \f |
130 | /* Print the value VAL in C-ish syntax on stream STREAM. |
3bf57d21 |
131 | FORMAT is a format-letter, or 0 for print in natural format of data type. |
7b4ac7e1 |
132 | If the object printed is a string pointer, returns |
133 | the number of string bytes printed. */ |
134 | |
e91b87a3 |
135 | int |
4187119d |
136 | value_print (val, stream, format, pretty) |
7b4ac7e1 |
137 | value val; |
138 | FILE *stream; |
3bf57d21 |
139 | char format; |
4187119d |
140 | enum val_prettyprint pretty; |
7b4ac7e1 |
141 | { |
4187119d |
142 | register unsigned int i, n, typelen; |
7b4ac7e1 |
143 | |
144 | /* A "repeated" value really contains several values in a row. |
145 | They are made by the @ operator. |
146 | Print such values as if they were arrays. */ |
147 | |
148 | if (VALUE_REPEATED (val)) |
149 | { |
150 | n = VALUE_REPETITIONS (val); |
151 | typelen = TYPE_LENGTH (VALUE_TYPE (val)); |
4187119d |
152 | fprintf_filtered (stream, "{"); |
7b4ac7e1 |
153 | /* Print arrays of characters using string syntax. */ |
3bf57d21 |
154 | if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT |
155 | && format == 0) |
7a67dd45 |
156 | print_string (stream, VALUE_CONTENTS (val), n, 0); |
7b4ac7e1 |
157 | else |
158 | { |
4187119d |
159 | unsigned int things_printed = 0; |
160 | |
161 | for (i = 0; i < n && things_printed < print_max; i++) |
7b4ac7e1 |
162 | { |
4187119d |
163 | /* Position of the array element we are examining to see |
164 | whether it is repeated. */ |
165 | unsigned int rep1; |
166 | /* Number of repititions we have detected so far. */ |
167 | unsigned int reps; |
168 | |
169 | if (i != 0) |
170 | fprintf_filtered (stream, ", "); |
171 | |
172 | rep1 = i + 1; |
173 | reps = 1; |
174 | while (rep1 < n |
175 | && !bcmp (VALUE_CONTENTS (val) + typelen * i, |
176 | VALUE_CONTENTS (val) + typelen * rep1, typelen)) |
177 | { |
178 | ++reps; |
179 | ++rep1; |
180 | } |
181 | |
182 | if (reps > REPEAT_COUNT_THRESHOLD) |
183 | { |
184 | val_print (VALUE_TYPE (val), |
185 | VALUE_CONTENTS (val) + typelen * i, |
186 | VALUE_ADDRESS (val) + typelen * i, |
187 | stream, format, 1, 0, pretty); |
188 | fprintf (stream, " <repeats %u times>", reps); |
189 | i = rep1 - 1; |
190 | things_printed += REPEAT_COUNT_THRESHOLD; |
191 | } |
192 | else |
193 | { |
194 | val_print (VALUE_TYPE (val), |
195 | VALUE_CONTENTS (val) + typelen * i, |
196 | VALUE_ADDRESS (val) + typelen * i, |
197 | stream, format, 1, 0, pretty); |
198 | things_printed++; |
199 | } |
7b4ac7e1 |
200 | } |
201 | if (i < n) |
4187119d |
202 | fprintf_filtered (stream, "..."); |
7b4ac7e1 |
203 | } |
4187119d |
204 | fprintf_filtered (stream, "}"); |
e91b87a3 |
205 | return n * typelen; |
7b4ac7e1 |
206 | } |
207 | else |
208 | { |
bb7592f0 |
209 | /* If it is a pointer, indicate what it points to. |
210 | |
e91b87a3 |
211 | Print type also if it is a reference. |
bb7592f0 |
212 | |
e91b87a3 |
213 | C++: if it is a member pointer, we will take care |
bb7592f0 |
214 | of that when we print it. */ |
215 | if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR |
216 | || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF) |
7b4ac7e1 |
217 | { |
4187119d |
218 | fprintf_filtered (stream, "("); |
7b4ac7e1 |
219 | type_print (VALUE_TYPE (val), "", stream, -1); |
4187119d |
220 | fprintf_filtered (stream, ") "); |
221 | |
222 | /* If this is a function pointer, try to print what |
223 | function it is pointing to by name. */ |
224 | if (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (val))) |
225 | == TYPE_CODE_FUNC) |
226 | { |
227 | print_address (((int *) VALUE_CONTENTS (val))[0], stream); |
228 | /* Return value is irrelevant except for string pointers. */ |
229 | return 0; |
230 | } |
7b4ac7e1 |
231 | } |
232 | return val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), |
4187119d |
233 | VALUE_ADDRESS (val), stream, format, 1, 0, pretty); |
7b4ac7e1 |
234 | } |
235 | } |
236 | \f |
4187119d |
237 | static int prettyprint; /* Controls prettyprinting of structures. */ |
238 | int unionprint; /* Controls printing of nested unions. */ |
239 | |
3bf57d21 |
240 | /* Print data of type TYPE located at VALADDR (within GDB), |
241 | which came from the inferior at address ADDRESS, |
242 | onto stdio stream STREAM according to FORMAT |
243 | (a letter or 0 for natural format). |
7b4ac7e1 |
244 | |
245 | If the data are a string pointer, returns the number of |
bb7592f0 |
246 | sting characters printed. |
247 | |
e91b87a3 |
248 | if DEREF_REF is nonzero, then dereference references, |
4187119d |
249 | otherwise just print them like pointers. |
250 | |
251 | The PRETTY parameter controls prettyprinting. */ |
7b4ac7e1 |
252 | |
253 | int |
4187119d |
254 | val_print (type, valaddr, address, stream, format, |
255 | deref_ref, recurse, pretty) |
7b4ac7e1 |
256 | struct type *type; |
257 | char *valaddr; |
258 | CORE_ADDR address; |
259 | FILE *stream; |
3bf57d21 |
260 | char format; |
bb7592f0 |
261 | int deref_ref; |
4187119d |
262 | int recurse; |
263 | enum val_prettyprint pretty; |
7b4ac7e1 |
264 | { |
4187119d |
265 | register unsigned int i; |
bb7592f0 |
266 | int len, n_baseclasses; |
7b4ac7e1 |
267 | struct type *elttype; |
268 | int eltlen; |
e91b87a3 |
269 | LONGEST val; |
7b4ac7e1 |
270 | unsigned char c; |
271 | |
4187119d |
272 | if (pretty == Val_pretty_default) |
273 | { |
274 | pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint; |
275 | } |
276 | |
7b4ac7e1 |
277 | QUIT; |
278 | |
4187119d |
279 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) |
280 | { |
281 | fprintf_filtered (stream, "<Type not defined in this context>"); |
282 | fflush (stream); |
283 | return 0; |
284 | } |
285 | |
7b4ac7e1 |
286 | switch (TYPE_CODE (type)) |
287 | { |
288 | case TYPE_CODE_ARRAY: |
4187119d |
289 | if (TYPE_LENGTH (type) >= 0 |
290 | && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) |
7b4ac7e1 |
291 | { |
292 | elttype = TYPE_TARGET_TYPE (type); |
293 | eltlen = TYPE_LENGTH (elttype); |
294 | len = TYPE_LENGTH (type) / eltlen; |
4187119d |
295 | fprintf_filtered (stream, "{"); |
7b4ac7e1 |
296 | /* For an array of chars, print with string syntax. */ |
3bf57d21 |
297 | if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT |
298 | && format == 0) |
7a67dd45 |
299 | print_string (stream, valaddr, len, 0); |
7b4ac7e1 |
300 | else |
301 | { |
4187119d |
302 | unsigned int things_printed = 0; |
303 | |
304 | for (i = 0; i < len && things_printed < print_max; i++) |
7b4ac7e1 |
305 | { |
4187119d |
306 | /* Position of the array element we are examining to see |
307 | whether it is repeated. */ |
308 | unsigned int rep1; |
309 | /* Number of repititions we have detected so far. */ |
310 | unsigned int reps; |
311 | |
312 | if (i > 0) |
313 | fprintf_filtered (stream, ", "); |
314 | |
315 | rep1 = i + 1; |
316 | reps = 1; |
317 | while (rep1 < len |
318 | && !bcmp (valaddr + i * eltlen, |
319 | valaddr + rep1 * eltlen, eltlen)) |
320 | { |
321 | ++reps; |
322 | ++rep1; |
323 | } |
324 | |
325 | if (reps > REPEAT_COUNT_THRESHOLD) |
326 | { |
327 | val_print (elttype, valaddr + i * eltlen, |
328 | 0, stream, format, deref_ref, |
329 | recurse + 1, pretty); |
330 | fprintf_filtered (stream, " <repeats %u times>", reps); |
331 | i = rep1 - 1; |
332 | things_printed += REPEAT_COUNT_THRESHOLD; |
333 | } |
334 | else |
335 | { |
336 | val_print (elttype, valaddr + i * eltlen, |
337 | 0, stream, format, deref_ref, |
338 | recurse + 1, pretty); |
339 | things_printed++; |
340 | } |
7b4ac7e1 |
341 | } |
342 | if (i < len) |
4187119d |
343 | fprintf_filtered (stream, "..."); |
7b4ac7e1 |
344 | } |
4187119d |
345 | fprintf_filtered (stream, "}"); |
7b4ac7e1 |
346 | break; |
347 | } |
4187119d |
348 | /* Array of unspecified length: treat like pointer to first elt. */ |
349 | valaddr = (char *) &address; |
7b4ac7e1 |
350 | |
351 | case TYPE_CODE_PTR: |
3bf57d21 |
352 | if (format) |
7b4ac7e1 |
353 | { |
3bf57d21 |
354 | print_scalar_formatted (valaddr, type, format, 0, stream); |
355 | break; |
6368691e |
356 | } |
4187119d |
357 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD) |
6368691e |
358 | { |
bb7592f0 |
359 | struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)); |
360 | struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)); |
361 | struct fn_field *f; |
362 | int j, len2; |
363 | char *kind = ""; |
364 | |
365 | val = unpack_long (builtin_type_int, valaddr); |
4187119d |
366 | if (val < 128) |
6368691e |
367 | { |
4187119d |
368 | len = TYPE_NFN_FIELDS (domain); |
369 | for (i = 0; i < len; i++) |
bb7592f0 |
370 | { |
4187119d |
371 | f = TYPE_FN_FIELDLIST1 (domain, i); |
372 | len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); |
bb7592f0 |
373 | |
4187119d |
374 | for (j = 0; j < len2; j++) |
bb7592f0 |
375 | { |
4187119d |
376 | QUIT; |
377 | if (TYPE_FN_FIELD_VOFFSET (f, j) == val) |
bb7592f0 |
378 | { |
4187119d |
379 | kind = "virtual"; |
380 | goto common; |
bb7592f0 |
381 | } |
382 | } |
383 | } |
bb7592f0 |
384 | } |
385 | else |
386 | { |
4187119d |
387 | struct symbol *sym = find_pc_function ((CORE_ADDR) val); |
388 | if (sym == 0) |
389 | error ("invalid pointer to member function"); |
390 | len = TYPE_NFN_FIELDS (domain); |
bb7592f0 |
391 | for (i = 0; i < len; i++) |
392 | { |
4187119d |
393 | f = TYPE_FN_FIELDLIST1 (domain, i); |
394 | len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); |
395 | |
396 | for (j = 0; j < len2; j++) |
bb7592f0 |
397 | { |
4187119d |
398 | QUIT; |
399 | if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j))) |
400 | goto common; |
bb7592f0 |
401 | } |
402 | } |
4187119d |
403 | } |
404 | common: |
405 | if (i < len) |
406 | { |
407 | fprintf_filtered (stream, "&"); |
408 | type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0); |
409 | fprintf (stream, kind); |
410 | if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' |
411 | && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$') |
412 | type_print_method_args |
413 | (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", |
414 | TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream); |
415 | else |
416 | type_print_method_args |
417 | (TYPE_FN_FIELD_ARGS (f, j), "", |
418 | TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream); |
419 | break; |
420 | } |
421 | fprintf_filtered (stream, "("); |
422 | type_print (type, "", stream, -1); |
423 | fprintf_filtered (stream, ") %d", (int) val >> 3); |
424 | } |
425 | else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER) |
426 | { |
427 | struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)); |
428 | struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)); |
429 | char *kind = ""; |
430 | |
431 | /* VAL is a byte offset into the structure type DOMAIN. |
432 | Find the name of the field for that offset and |
433 | print it. */ |
434 | int extra = 0; |
435 | int bits = 0; |
436 | len = TYPE_NFIELDS (domain); |
437 | /* @@ Make VAL into bit offset */ |
438 | val = unpack_long (builtin_type_int, valaddr) << 3; |
439 | for (i = 0; i < len; i++) |
440 | { |
441 | int bitpos = TYPE_FIELD_BITPOS (domain, i); |
442 | QUIT; |
443 | if (val == bitpos) |
444 | break; |
445 | if (val < bitpos && i > 0) |
bb7592f0 |
446 | { |
4187119d |
447 | int ptrsize = (TYPE_LENGTH (builtin_type_char) * TYPE_LENGTH (target)); |
448 | /* Somehow pointing into a field. */ |
449 | i -= 1; |
450 | extra = (val - TYPE_FIELD_BITPOS (domain, i)); |
451 | if (extra & 0x3) |
452 | bits = 1; |
453 | else |
454 | extra >>= 3; |
bb7592f0 |
455 | break; |
456 | } |
457 | } |
4187119d |
458 | if (i < len) |
459 | { |
460 | fprintf_filtered (stream, "&"); |
461 | type_print_base (domain, stream, 0, 0); |
462 | fprintf_filtered (stream, "::"); |
463 | fputs_filtered (TYPE_FIELD_NAME (domain, i), stream); |
464 | if (extra) |
465 | fprintf_filtered (stream, " + %d bytes", extra); |
466 | if (bits) |
467 | fprintf_filtered (stream, " (offset in bits)"); |
468 | break; |
469 | } |
470 | fprintf_filtered (stream, "%d", val >> 3); |
bb7592f0 |
471 | } |
472 | else |
473 | { |
4187119d |
474 | fprintf_filtered (stream, "0x%x", * (int *) valaddr); |
bb7592f0 |
475 | /* For a pointer to char or unsigned char, |
476 | also print the string pointed to, unless pointer is null. */ |
e91b87a3 |
477 | |
bb7592f0 |
478 | /* For an array of chars, print with string syntax. */ |
479 | elttype = TYPE_TARGET_TYPE (type); |
e91b87a3 |
480 | i = 0; /* Number of characters printed. */ |
481 | if (TYPE_LENGTH (elttype) == 1 |
482 | && TYPE_CODE (elttype) == TYPE_CODE_INT |
bb7592f0 |
483 | && format == 0 |
4187119d |
484 | && unpack_long (type, valaddr) != 0 |
7a67dd45 |
485 | /* If print_max is UINT_MAX, the alloca below will fail. |
486 | In that case don't try to print the string. */ |
487 | && print_max < UINT_MAX) |
bb7592f0 |
488 | { |
4187119d |
489 | fprintf_filtered (stream, " "); |
e91b87a3 |
490 | |
491 | /* Get first character. */ |
492 | if (read_memory ( (CORE_ADDR) unpack_long (type, valaddr), |
493 | &c, 1)) |
bb7592f0 |
494 | { |
e91b87a3 |
495 | /* First address out of bounds. */ |
4187119d |
496 | fprintf_filtered (stream, "<Address 0x%x out of bounds>", |
e91b87a3 |
497 | (* (int *) valaddr)); |
498 | break; |
499 | } |
500 | else |
501 | { |
502 | /* A real string. */ |
503 | int out_of_bounds = 0; |
4187119d |
504 | char *string = (char *) alloca (print_max); |
505 | |
7a67dd45 |
506 | /* If the loop ends by us hitting print_max characters, |
507 | we need to have elipses at the end. */ |
508 | int force_ellipses = 1; |
509 | |
510 | /* This loop only fetches print_max characters, even |
511 | though print_string might want to print more |
512 | (with repeated characters). This is so that |
513 | we don't spend forever fetching if we print |
514 | a long string consisting of the same character |
515 | repeated. */ |
4187119d |
516 | while (i < print_max) |
e91b87a3 |
517 | { |
518 | QUIT; |
e91b87a3 |
519 | if (read_memory ((CORE_ADDR) unpack_long (type, valaddr) |
520 | + i, &c, 1)) |
521 | { |
e91b87a3 |
522 | out_of_bounds = 1; |
7a67dd45 |
523 | force_ellipses = 0; |
e91b87a3 |
524 | break; |
525 | } |
4187119d |
526 | else if (c == '\0') |
7a67dd45 |
527 | { |
528 | force_ellipses = 0; |
529 | break; |
530 | } |
4187119d |
531 | else |
532 | string[i++] = c; |
e91b87a3 |
533 | } |
4187119d |
534 | |
535 | if (i != 0) |
7a67dd45 |
536 | print_string (stream, string, i, force_ellipses); |
4187119d |
537 | if (out_of_bounds) |
538 | fprintf_filtered (stream, |
7a67dd45 |
539 | " <Address 0x%x out of bounds>", |
4187119d |
540 | (*(int *) valaddr) + i); |
bb7592f0 |
541 | } |
4187119d |
542 | |
bb7592f0 |
543 | fflush (stream); |
7b4ac7e1 |
544 | } |
e91b87a3 |
545 | /* Return number of characters printed, plus one for the |
546 | terminating null if we have "reached the end". */ |
547 | return i + (print_max && i != print_max); |
7b4ac7e1 |
548 | } |
549 | break; |
550 | |
bb7592f0 |
551 | case TYPE_CODE_MEMBER: |
552 | error ("not implemented: member type in val_print"); |
553 | break; |
554 | |
555 | case TYPE_CODE_REF: |
4187119d |
556 | fprintf_filtered (stream, "(0x%x &) = ", * (int *) valaddr); |
bb7592f0 |
557 | /* De-reference the reference. */ |
558 | if (deref_ref) |
e91b87a3 |
559 | { |
560 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF) |
561 | { |
562 | value val = value_at (TYPE_TARGET_TYPE (type), * (int *) valaddr); |
563 | val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), |
4187119d |
564 | VALUE_ADDRESS (val), stream, format, |
565 | deref_ref, recurse + 1, pretty); |
e91b87a3 |
566 | } |
567 | else |
4187119d |
568 | fprintf_filtered (stream, "???"); |
e91b87a3 |
569 | } |
bb7592f0 |
570 | break; |
571 | |
7b4ac7e1 |
572 | case TYPE_CODE_UNION: |
4187119d |
573 | if (recurse && !unionprint) |
574 | { |
575 | fprintf_filtered (stream, "{...}"); |
576 | break; |
577 | } |
578 | /* Fall through. */ |
579 | case TYPE_CODE_STRUCT: |
580 | fprintf_filtered (stream, "{"); |
7b4ac7e1 |
581 | len = TYPE_NFIELDS (type); |
bb7592f0 |
582 | n_baseclasses = TYPE_N_BASECLASSES (type); |
583 | for (i = 1; i <= n_baseclasses; i++) |
7b4ac7e1 |
584 | { |
4187119d |
585 | fprintf_filtered (stream, "\n"); |
586 | if (pretty) |
587 | print_spaces_filtered (2 + 2 * recurse, stream); |
588 | fputs_filtered ("<", stream); |
589 | fputs_filtered (TYPE_NAME (TYPE_BASECLASS (type, i)), stream); |
590 | fputs_filtered ("> = ", stream); |
bb7592f0 |
591 | val_print (TYPE_FIELD_TYPE (type, 0), |
592 | valaddr + TYPE_FIELD_BITPOS (type, i-1) / 8, |
4187119d |
593 | 0, stream, 0, 0, recurse + 1, pretty); |
bb7592f0 |
594 | } |
4187119d |
595 | if (i > 1) { |
596 | fprintf_filtered (stream, "\n"); |
597 | print_spaces_filtered (2 + 2 * recurse, stream); |
598 | fputs_filtered ("members of ", stream); |
599 | fputs_filtered (TYPE_NAME (type), stream); |
600 | fputs_filtered (": ", stream); |
601 | } |
602 | if (!len && i == 1) |
603 | fprintf_filtered (stream, "<No data fields>"); |
604 | else |
bb7592f0 |
605 | { |
4187119d |
606 | for (i -= 1; i < len; i++) |
7b4ac7e1 |
607 | { |
4187119d |
608 | if (i > n_baseclasses) fprintf_filtered (stream, ", "); |
609 | if (pretty) |
610 | { |
611 | fprintf_filtered (stream, "\n"); |
612 | print_spaces_filtered (2 + 2 * recurse, stream); |
613 | } |
614 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); |
615 | fputs_filtered (" = ", stream); |
616 | /* check if static field */ |
617 | if (TYPE_FIELD_STATIC (type, i)) |
618 | { |
619 | value v; |
620 | |
621 | v = value_static_field (type, TYPE_FIELD_NAME (type, i), i); |
622 | val_print (TYPE_FIELD_TYPE (type, i), |
623 | VALUE_CONTENTS (v), 0, stream, format, |
624 | deref_ref, recurse + 1, pretty); |
625 | } |
626 | else if (TYPE_FIELD_PACKED (type, i)) |
627 | { |
628 | char *valp = (char *) & val; |
629 | union {int i; char c;} test; |
630 | test.i = 1; |
631 | if (test.c != 1) |
632 | valp += sizeof val - TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)); |
633 | val = unpack_field_as_long (type, valaddr, i); |
634 | val_print (TYPE_FIELD_TYPE (type, i), valp, 0, |
635 | stream, format, deref_ref, recurse + 1, pretty); |
636 | } |
637 | else |
638 | { |
639 | val_print (TYPE_FIELD_TYPE (type, i), |
640 | valaddr + TYPE_FIELD_BITPOS (type, i) / 8, |
641 | 0, stream, format, deref_ref, |
642 | recurse + 1, pretty); |
643 | } |
7b4ac7e1 |
644 | } |
4187119d |
645 | if (pretty) |
e91b87a3 |
646 | { |
4187119d |
647 | fprintf_filtered (stream, "\n"); |
648 | print_spaces_filtered (2 * recurse, stream); |
e91b87a3 |
649 | } |
7b4ac7e1 |
650 | } |
4187119d |
651 | fprintf_filtered (stream, "}"); |
7b4ac7e1 |
652 | break; |
653 | |
654 | case TYPE_CODE_ENUM: |
3bf57d21 |
655 | if (format) |
656 | { |
657 | print_scalar_formatted (valaddr, type, format, 0, stream); |
658 | break; |
659 | } |
7b4ac7e1 |
660 | len = TYPE_NFIELDS (type); |
4187119d |
661 | val = unpack_long (builtin_type_int, valaddr); |
7b4ac7e1 |
662 | for (i = 0; i < len; i++) |
663 | { |
664 | QUIT; |
e91b87a3 |
665 | if (val == TYPE_FIELD_BITPOS (type, i)) |
7b4ac7e1 |
666 | break; |
667 | } |
668 | if (i < len) |
4187119d |
669 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); |
7b4ac7e1 |
670 | else |
4187119d |
671 | fprintf_filtered (stream, "%d", (int) val); |
7b4ac7e1 |
672 | break; |
673 | |
674 | case TYPE_CODE_FUNC: |
3bf57d21 |
675 | if (format) |
676 | { |
677 | print_scalar_formatted (valaddr, type, format, 0, stream); |
678 | break; |
679 | } |
4187119d |
680 | fprintf_filtered (stream, "{"); |
7b4ac7e1 |
681 | type_print (type, "", stream, -1); |
4187119d |
682 | fprintf_filtered (stream, "} "); |
683 | fprintf_filtered (stream, "0x%x", address); |
7b4ac7e1 |
684 | break; |
685 | |
686 | case TYPE_CODE_INT: |
3bf57d21 |
687 | if (format) |
688 | { |
689 | print_scalar_formatted (valaddr, type, format, 0, stream); |
690 | break; |
691 | } |
4187119d |
692 | #ifdef PRINT_TYPELESS_INTEGER |
693 | PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr)); |
694 | #else |
695 | #ifndef LONG_LONG |
696 | fprintf_filtered (stream, |
697 | TYPE_UNSIGNED (type) ? "%u" : "%d", |
698 | unpack_long (type, valaddr)); |
699 | #else |
700 | fprintf_filtered (stream, |
701 | TYPE_UNSIGNED (type) ? "%llu" : "%lld", |
702 | unpack_long (type, valaddr)); |
703 | #endif |
704 | #endif |
705 | |
3bf57d21 |
706 | if (TYPE_LENGTH (type) == 1) |
7b4ac7e1 |
707 | { |
4187119d |
708 | fprintf_filtered (stream, " '"); |
e91b87a3 |
709 | printchar ((unsigned char) unpack_long (type, valaddr), |
710 | stream, '\''); |
4187119d |
711 | fprintf_filtered (stream, "'"); |
7b4ac7e1 |
712 | } |
713 | break; |
714 | |
715 | case TYPE_CODE_FLT: |
3bf57d21 |
716 | if (format) |
717 | { |
718 | print_scalar_formatted (valaddr, type, format, 0, stream); |
719 | break; |
720 | } |
7b4ac7e1 |
721 | #ifdef IEEE_FLOAT |
7a67dd45 |
722 | if (is_nan ((char *) valaddr, TYPE_LENGTH (type))) |
7b4ac7e1 |
723 | { |
4187119d |
724 | fprintf_filtered (stream, "NaN"); |
7b4ac7e1 |
725 | break; |
726 | } |
727 | #endif |
e91b87a3 |
728 | { |
729 | double doub; |
730 | int inv; |
731 | |
732 | doub = unpack_double (type, valaddr, &inv); |
733 | if (inv) |
4187119d |
734 | fprintf_filtered (stream, "Invalid float value"); |
e91b87a3 |
735 | else |
4187119d |
736 | fprintf_filtered (stream, |
737 | TYPE_LENGTH (type) <= 4? "%.6g": "%.16g", doub); |
e91b87a3 |
738 | } |
7b4ac7e1 |
739 | break; |
740 | |
741 | case TYPE_CODE_VOID: |
4187119d |
742 | fprintf_filtered (stream, "void"); |
7b4ac7e1 |
743 | break; |
744 | |
745 | default: |
746 | error ("Invalid type code in symbol table."); |
747 | } |
748 | fflush (stream); |
4187119d |
749 | return 0; |
7b4ac7e1 |
750 | } |
751 | \f |
752 | #ifdef IEEE_FLOAT |
753 | |
7b4ac7e1 |
754 | /* Nonzero if ARG (a double) is a NAN. */ |
755 | |
756 | int |
e91b87a3 |
757 | is_nan (fp, len) |
7a67dd45 |
758 | char *fp; |
4187119d |
759 | int len; |
7b4ac7e1 |
760 | { |
761 | int lowhalf, highhalf; |
4187119d |
762 | union ieee |
763 | { |
764 | long i[2]; /* ASSUMED 32 BITS */ |
765 | float f; /* ASSUMED 32 BITS */ |
766 | double d; /* ASSUMED 64 BITS */ |
767 | } *arg; |
e91b87a3 |
768 | |
769 | arg = (union ieee *)fp; |
770 | |
771 | /* |
772 | * Single precision float. |
773 | */ |
4187119d |
774 | if (len == sizeof(long)) |
775 | { |
776 | highhalf = arg->i[0]; |
777 | return ((((highhalf >> 23) & 0xFF) == 0xFF) |
778 | && 0 != (highhalf & 0x7FFFFF)); |
779 | } |
780 | |
7b4ac7e1 |
781 | /* Separate the high and low words of the double. |
782 | Distinguish big and little-endian machines. */ |
e91b87a3 |
783 | #ifdef WORDS_BIG_ENDIAN |
784 | lowhalf = arg->i[1], highhalf = arg->i[0]; |
785 | #else |
786 | lowhalf = arg->i[0], highhalf = arg->i[1]; |
787 | #endif |
4187119d |
788 | |
7b4ac7e1 |
789 | /* Nan: exponent is the maximum possible, and fraction is nonzero. */ |
790 | return (((highhalf>>20) & 0x7ff) == 0x7ff |
4187119d |
791 | && ! ((highhalf & 0xfffff == 0) && (lowhalf == 0))); |
7b4ac7e1 |
792 | } |
793 | #endif |
794 | \f |
795 | /* Print a description of a type TYPE |
796 | in the form of a declaration of a variable named VARSTRING. |
797 | Output goes to STREAM (via stdio). |
798 | If SHOW is positive, we show the contents of the outermost level |
799 | of structure even if there is a type name that could be used instead. |
800 | If SHOW is negative, we never show the details of elements' types. */ |
801 | |
e91b87a3 |
802 | void |
7b4ac7e1 |
803 | type_print (type, varstring, stream, show) |
804 | struct type *type; |
805 | char *varstring; |
806 | FILE *stream; |
807 | int show; |
808 | { |
809 | type_print_1 (type, varstring, stream, show, 0); |
810 | } |
811 | |
812 | /* LEVEL is the depth to indent lines by. */ |
813 | |
e91b87a3 |
814 | void |
7b4ac7e1 |
815 | type_print_1 (type, varstring, stream, show, level) |
816 | struct type *type; |
817 | char *varstring; |
818 | FILE *stream; |
819 | int show; |
820 | int level; |
821 | { |
822 | register enum type_code code; |
823 | type_print_base (type, stream, show, level); |
824 | code = TYPE_CODE (type); |
825 | if ((varstring && *varstring) |
826 | || |
827 | /* Need a space if going to print stars or brackets; |
828 | but not if we will print just a type name. */ |
829 | ((show > 0 || TYPE_NAME (type) == 0) |
830 | && |
831 | (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC |
4187119d |
832 | || code == TYPE_CODE_METHOD |
bb7592f0 |
833 | || code == TYPE_CODE_ARRAY |
834 | || code == TYPE_CODE_MEMBER |
835 | || code == TYPE_CODE_REF))) |
4187119d |
836 | fprintf_filtered (stream, " "); |
7b4ac7e1 |
837 | type_print_varspec_prefix (type, stream, show, 0); |
4187119d |
838 | fputs_filtered (varstring, stream); |
7b4ac7e1 |
839 | type_print_varspec_suffix (type, stream, show, 0); |
840 | } |
841 | |
bb7592f0 |
842 | /* Print the method arguments ARGS to the file STREAM. */ |
843 | static void |
4187119d |
844 | type_print_method_args (args, prefix, varstring, staticp, stream) |
bb7592f0 |
845 | struct type **args; |
846 | char *prefix, *varstring; |
4187119d |
847 | int staticp; |
bb7592f0 |
848 | FILE *stream; |
849 | { |
850 | int i; |
851 | |
4187119d |
852 | fputs_filtered (" ", stream); |
853 | fputs_filtered (prefix, stream); |
854 | fputs_filtered (varstring, stream); |
855 | fputs_filtered (" (", stream); |
856 | if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID) |
bb7592f0 |
857 | { |
4187119d |
858 | i = !staticp; /* skip the class variable */ |
bb7592f0 |
859 | while (1) |
860 | { |
861 | type_print (args[i++], "", stream, 0); |
862 | if (!args[i]) |
863 | { |
4187119d |
864 | fprintf_filtered (stream, " ..."); |
bb7592f0 |
865 | break; |
866 | } |
867 | else if (args[i]->code != TYPE_CODE_VOID) |
868 | { |
4187119d |
869 | fprintf_filtered (stream, ", "); |
bb7592f0 |
870 | } |
871 | else break; |
872 | } |
873 | } |
4187119d |
874 | fprintf_filtered (stream, ")"); |
bb7592f0 |
875 | } |
e91b87a3 |
876 | |
bb7592f0 |
877 | /* If TYPE is a derived type, then print out derivation |
878 | information. Print out all layers of the type heirarchy |
879 | until we encounter one with multiple inheritance. |
880 | At that point, print out that ply, and return. */ |
881 | static void |
882 | type_print_derivation_info (stream, type) |
883 | FILE *stream; |
884 | struct type *type; |
885 | { |
886 | char *name; |
887 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); |
888 | struct type *basetype = 0; |
889 | |
890 | while (type && n_baseclasses == 1) |
891 | { |
892 | basetype = TYPE_BASECLASS (type, 1); |
893 | if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype))) |
894 | { |
895 | while (*name != ' ') name++; |
4187119d |
896 | fprintf_filtered (stream, ": %s%s ", |
bb7592f0 |
897 | TYPE_VIA_PUBLIC (basetype) ? "public" : "private", |
4187119d |
898 | TYPE_VIA_VIRTUAL (basetype) ? " virtual" : ""); |
899 | fputs_filtered (name + 1, stream); |
900 | fputs_filtered (" ", stream); |
bb7592f0 |
901 | } |
902 | n_baseclasses = TYPE_N_BASECLASSES (basetype); |
903 | type = basetype; |
904 | } |
905 | |
906 | if (type) |
907 | { |
908 | if (n_baseclasses != 0) |
4187119d |
909 | fprintf_filtered (stream, ": "); |
bb7592f0 |
910 | for (i = 1; i <= n_baseclasses; i++) |
911 | { |
912 | basetype = TYPE_BASECLASS (type, i); |
913 | if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype))) |
914 | { |
915 | while (*name != ' ') name++; |
4187119d |
916 | fprintf_filtered (stream, "%s%s ", |
bb7592f0 |
917 | TYPE_VIA_PUBLIC (basetype) ? "public" : "private", |
4187119d |
918 | TYPE_VIA_VIRTUAL (basetype) ? " virtual" : ""); |
919 | fputs_filtered (name + 1, stream); |
bb7592f0 |
920 | } |
921 | if (i < n_baseclasses) |
4187119d |
922 | fprintf_filtered (stream, ", "); |
bb7592f0 |
923 | } |
4187119d |
924 | fprintf_filtered (stream, " "); |
bb7592f0 |
925 | } |
926 | } |
927 | |
7b4ac7e1 |
928 | /* Print any asterisks or open-parentheses needed before the |
929 | variable name (to describe its type). |
930 | |
931 | On outermost call, pass 0 for PASSED_A_PTR. |
932 | On outermost call, SHOW > 0 means should ignore |
933 | any typename for TYPE and show its details. |
934 | SHOW is always zero on recursive calls. */ |
935 | |
936 | static void |
937 | type_print_varspec_prefix (type, stream, show, passed_a_ptr) |
938 | struct type *type; |
939 | FILE *stream; |
940 | int show; |
941 | int passed_a_ptr; |
942 | { |
3bf57d21 |
943 | if (type == 0) |
944 | return; |
945 | |
7b4ac7e1 |
946 | if (TYPE_NAME (type) && show <= 0) |
947 | return; |
948 | |
949 | QUIT; |
950 | |
951 | switch (TYPE_CODE (type)) |
952 | { |
953 | case TYPE_CODE_PTR: |
954 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); |
4187119d |
955 | fprintf_filtered (stream, "*"); |
7b4ac7e1 |
956 | break; |
957 | |
bb7592f0 |
958 | case TYPE_CODE_MEMBER: |
4187119d |
959 | if (passed_a_ptr) |
960 | fprintf_filtered (stream, "("); |
bb7592f0 |
961 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, |
4187119d |
962 | 0); |
963 | fprintf_filtered (stream, " "); |
964 | type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, |
965 | passed_a_ptr); |
966 | fprintf_filtered (stream, "::"); |
967 | break; |
968 | |
969 | case TYPE_CODE_METHOD: |
970 | if (passed_a_ptr) |
971 | fprintf (stream, "("); |
972 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, |
973 | 0); |
974 | fprintf_filtered (stream, " "); |
bb7592f0 |
975 | type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, |
976 | passed_a_ptr); |
4187119d |
977 | fprintf_filtered (stream, "::"); |
bb7592f0 |
978 | break; |
979 | |
980 | case TYPE_CODE_REF: |
981 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); |
4187119d |
982 | fprintf_filtered (stream, "&"); |
bb7592f0 |
983 | break; |
984 | |
7b4ac7e1 |
985 | case TYPE_CODE_FUNC: |
e91b87a3 |
986 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, |
4187119d |
987 | 0); |
7b4ac7e1 |
988 | if (passed_a_ptr) |
4187119d |
989 | fprintf_filtered (stream, "("); |
7b4ac7e1 |
990 | break; |
e91b87a3 |
991 | |
992 | case TYPE_CODE_ARRAY: |
993 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, |
4187119d |
994 | 0); |
995 | if (passed_a_ptr) |
996 | fprintf_filtered (stream, "("); |
7b4ac7e1 |
997 | } |
998 | } |
999 | |
1000 | /* Print any array sizes, function arguments or close parentheses |
1001 | needed after the variable name (to describe its type). |
1002 | Args work like type_print_varspec_prefix. */ |
1003 | |
1004 | static void |
1005 | type_print_varspec_suffix (type, stream, show, passed_a_ptr) |
1006 | struct type *type; |
1007 | FILE *stream; |
1008 | int show; |
1009 | int passed_a_ptr; |
1010 | { |
3bf57d21 |
1011 | if (type == 0) |
1012 | return; |
1013 | |
7b4ac7e1 |
1014 | if (TYPE_NAME (type) && show <= 0) |
1015 | return; |
1016 | |
1017 | QUIT; |
1018 | |
1019 | switch (TYPE_CODE (type)) |
1020 | { |
1021 | case TYPE_CODE_ARRAY: |
4187119d |
1022 | if (passed_a_ptr) |
1023 | fprintf_filtered (stream, ")"); |
1024 | |
1025 | fprintf_filtered (stream, "["); |
e91b87a3 |
1026 | if (TYPE_LENGTH (type) >= 0 |
1027 | && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) |
4187119d |
1028 | fprintf_filtered (stream, "%d", |
1029 | (TYPE_LENGTH (type) |
1030 | / TYPE_LENGTH (TYPE_TARGET_TYPE (type)))); |
1031 | fprintf_filtered (stream, "]"); |
1032 | |
1033 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, |
1034 | 0); |
7b4ac7e1 |
1035 | break; |
1036 | |
bb7592f0 |
1037 | case TYPE_CODE_MEMBER: |
1038 | if (passed_a_ptr) |
4187119d |
1039 | fprintf_filtered (stream, ")"); |
bb7592f0 |
1040 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0); |
1041 | break; |
1042 | |
4187119d |
1043 | case TYPE_CODE_METHOD: |
1044 | if (passed_a_ptr) |
1045 | fprintf_filtered (stream, ")"); |
1046 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0); |
1047 | if (passed_a_ptr) |
1048 | { |
1049 | int i; |
1050 | struct type **args = TYPE_ARG_TYPES (type); |
1051 | |
1052 | fprintf_filtered (stream, "("); |
1053 | if (args[1] == 0) |
1054 | fprintf_filtered (stream, "..."); |
1055 | else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++) |
1056 | { |
1057 | type_print_1 (args[i], "", stream, -1, 0); |
1058 | if (args[i+1] == 0) |
1059 | fprintf_filtered (stream, "..."); |
1060 | else if (args[i+1]->code != TYPE_CODE_VOID) |
1061 | fprintf_filtered (stream, ","); |
1062 | } |
1063 | fprintf_filtered (stream, ")"); |
1064 | } |
1065 | break; |
1066 | |
7b4ac7e1 |
1067 | case TYPE_CODE_PTR: |
bb7592f0 |
1068 | case TYPE_CODE_REF: |
7b4ac7e1 |
1069 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1); |
1070 | break; |
1071 | |
1072 | case TYPE_CODE_FUNC: |
e91b87a3 |
1073 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, |
1074 | passed_a_ptr); |
7b4ac7e1 |
1075 | if (passed_a_ptr) |
4187119d |
1076 | fprintf_filtered (stream, ")"); |
1077 | fprintf_filtered (stream, "()"); |
7b4ac7e1 |
1078 | break; |
1079 | } |
1080 | } |
1081 | |
1082 | /* Print the name of the type (or the ultimate pointer target, |
1083 | function value or array element), or the description of a |
1084 | structure or union. |
1085 | |
1086 | SHOW nonzero means don't print this type as just its name; |
1087 | show its real definition even if it has a name. |
1088 | SHOW zero means print just typename or struct tag if there is one |
1089 | SHOW negative means abbreviate structure elements. |
1090 | SHOW is decremented for printing of structure elements. |
1091 | |
1092 | LEVEL is the depth to indent by. |
1093 | We increase it for some recursive calls. */ |
1094 | |
1095 | static void |
1096 | type_print_base (type, stream, show, level) |
1097 | struct type *type; |
1098 | FILE *stream; |
1099 | int show; |
1100 | int level; |
1101 | { |
1102 | char *name; |
1103 | register int i; |
1104 | register int len; |
1105 | register int lastval; |
1106 | |
1107 | QUIT; |
1108 | |
3bf57d21 |
1109 | if (type == 0) |
1110 | { |
4187119d |
1111 | fprintf_filtered (stream, "type unknown"); |
3bf57d21 |
1112 | return; |
1113 | } |
1114 | |
7b4ac7e1 |
1115 | if (TYPE_NAME (type) && show <= 0) |
1116 | { |
4187119d |
1117 | fputs_filtered (TYPE_NAME (type), stream); |
7b4ac7e1 |
1118 | return; |
1119 | } |
1120 | |
1121 | switch (TYPE_CODE (type)) |
1122 | { |
1123 | case TYPE_CODE_ARRAY: |
1124 | case TYPE_CODE_PTR: |
bb7592f0 |
1125 | case TYPE_CODE_MEMBER: |
1126 | case TYPE_CODE_REF: |
7b4ac7e1 |
1127 | case TYPE_CODE_FUNC: |
4187119d |
1128 | case TYPE_CODE_METHOD: |
7b4ac7e1 |
1129 | type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); |
1130 | break; |
1131 | |
1132 | case TYPE_CODE_STRUCT: |
4187119d |
1133 | fprintf_filtered (stream, "struct "); |
7b4ac7e1 |
1134 | goto struct_union; |
1135 | |
1136 | case TYPE_CODE_UNION: |
4187119d |
1137 | fprintf_filtered (stream, "union "); |
7b4ac7e1 |
1138 | struct_union: |
1139 | if (TYPE_NAME (type) && (name = TYPE_NAME (type))) |
1140 | { |
1141 | while (*name != ' ') name++; |
4187119d |
1142 | fputs_filtered (name + 1, stream); |
1143 | fputs_filtered (" ", stream); |
7b4ac7e1 |
1144 | } |
1145 | if (show < 0) |
4187119d |
1146 | fprintf_filtered (stream, "{...}"); |
7b4ac7e1 |
1147 | else |
1148 | { |
bb7592f0 |
1149 | int i; |
1150 | |
1151 | type_print_derivation_info (stream, type); |
e91b87a3 |
1152 | |
4187119d |
1153 | fprintf_filtered (stream, "{"); |
7b4ac7e1 |
1154 | len = TYPE_NFIELDS (type); |
4187119d |
1155 | if (len) |
1156 | fprintf_filtered (stream, "\n"); |
1157 | else |
1158 | { |
1159 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) |
1160 | fprintf_filtered (stream, "<incomplete type>\n"); |
1161 | else |
1162 | fprintf_filtered (stream, "<no data fields>\n"); |
1163 | } |
bb7592f0 |
1164 | |
e91b87a3 |
1165 | /* If there is a base class for this type, |
1166 | do not print the field that it occupies. */ |
bb7592f0 |
1167 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) |
7b4ac7e1 |
1168 | { |
1169 | QUIT; |
bb7592f0 |
1170 | /* Don't print out virtual function table. */ |
1171 | if (! strncmp (TYPE_FIELD_NAME (type, i), |
1172 | "_vptr$", 6)) |
1173 | continue; |
1174 | |
4187119d |
1175 | print_spaces_filtered (level + 4, stream); |
bb7592f0 |
1176 | if (TYPE_FIELD_STATIC (type, i)) |
1177 | { |
4187119d |
1178 | fprintf_filtered (stream, "static "); |
bb7592f0 |
1179 | } |
7b4ac7e1 |
1180 | type_print_1 (TYPE_FIELD_TYPE (type, i), |
1181 | TYPE_FIELD_NAME (type, i), |
1182 | stream, show - 1, level + 4); |
e91b87a3 |
1183 | if (!TYPE_FIELD_STATIC (type, i) |
1184 | && TYPE_FIELD_PACKED (type, i)) |
1185 | { |
4187119d |
1186 | /* It is a bitfield. This code does not attempt |
1187 | to look at the bitpos and reconstruct filler, |
1188 | unnamed fields. This would lead to misleading |
1189 | results if the compiler does not put out fields |
1190 | for such things (I don't know what it does). */ |
1191 | fprintf_filtered (stream, " : %d", |
1192 | TYPE_FIELD_BITSIZE (type, i)); |
e91b87a3 |
1193 | } |
4187119d |
1194 | fprintf_filtered (stream, ";\n"); |
3bf57d21 |
1195 | } |
bb7592f0 |
1196 | |
1197 | /* C++: print out the methods */ |
1198 | len = TYPE_NFN_FIELDS (type); |
4187119d |
1199 | if (len) fprintf_filtered (stream, "\n"); |
bb7592f0 |
1200 | for (i = 0; i < len; i++) |
1201 | { |
1202 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); |
1203 | int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); |
1204 | |
1205 | for (j = 0; j < len2; j++) |
1206 | { |
1207 | QUIT; |
4187119d |
1208 | print_spaces_filtered (level + 4, stream); |
bb7592f0 |
1209 | if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) |
4187119d |
1210 | fprintf_filtered (stream, "virtual "); |
1211 | else if (TYPE_FN_FIELD_STATIC_P (f, j)) |
1212 | fprintf_filtered (stream, "static "); |
1213 | type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, 0); |
bb7592f0 |
1214 | if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' |
1215 | && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$') |
1216 | type_print_method_args |
1217 | (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", |
4187119d |
1218 | TYPE_FN_FIELDLIST_NAME (type, i), 0, stream); |
bb7592f0 |
1219 | else |
1220 | type_print_method_args |
1221 | (TYPE_FN_FIELD_ARGS (f, j), "", |
4187119d |
1222 | TYPE_FN_FIELDLIST_NAME (type, i), |
1223 | TYPE_FN_FIELD_STATIC_P (f, j), stream); |
bb7592f0 |
1224 | |
4187119d |
1225 | fprintf_filtered (stream, ";\n"); |
bb7592f0 |
1226 | } |
4187119d |
1227 | if (len2) fprintf_filtered (stream, "\n"); |
bb7592f0 |
1228 | } |
1229 | |
4187119d |
1230 | print_spaces_filtered (level, stream); |
1231 | fprintf_filtered (stream, "}"); |
7b4ac7e1 |
1232 | } |
1233 | break; |
1234 | |
1235 | case TYPE_CODE_ENUM: |
4187119d |
1236 | fprintf_filtered (stream, "enum "); |
7b4ac7e1 |
1237 | if (TYPE_NAME (type)) |
1238 | { |
1239 | name = TYPE_NAME (type); |
1240 | while (*name != ' ') name++; |
4187119d |
1241 | fputs_filtered (name + 1, stream); |
1242 | fputs_filtered (" ", stream); |
7b4ac7e1 |
1243 | } |
1244 | if (show < 0) |
4187119d |
1245 | fprintf_filtered (stream, "{...}"); |
7b4ac7e1 |
1246 | else |
1247 | { |
4187119d |
1248 | fprintf_filtered (stream, "{"); |
7b4ac7e1 |
1249 | len = TYPE_NFIELDS (type); |
1250 | lastval = 0; |
1251 | for (i = 0; i < len; i++) |
1252 | { |
1253 | QUIT; |
4187119d |
1254 | if (i) fprintf_filtered (stream, ", "); |
1255 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); |
e91b87a3 |
1256 | if (lastval != TYPE_FIELD_BITPOS (type, i)) |
7b4ac7e1 |
1257 | { |
4187119d |
1258 | fprintf_filtered (stream, " : %d", TYPE_FIELD_BITPOS (type, i)); |
e91b87a3 |
1259 | lastval = TYPE_FIELD_BITPOS (type, i); |
7b4ac7e1 |
1260 | } |
1261 | lastval++; |
1262 | } |
4187119d |
1263 | fprintf_filtered (stream, "}"); |
7b4ac7e1 |
1264 | } |
1265 | break; |
1266 | |
1267 | case TYPE_CODE_INT: |
1268 | if (TYPE_UNSIGNED (type)) |
1269 | name = unsigned_type_table[TYPE_LENGTH (type)]; |
1270 | else |
1271 | name = signed_type_table[TYPE_LENGTH (type)]; |
4187119d |
1272 | fputs_filtered (name, stream); |
7b4ac7e1 |
1273 | break; |
1274 | |
1275 | case TYPE_CODE_FLT: |
1276 | name = float_type_table[TYPE_LENGTH (type)]; |
4187119d |
1277 | fputs_filtered (name, stream); |
7b4ac7e1 |
1278 | break; |
1279 | |
1280 | case TYPE_CODE_VOID: |
4187119d |
1281 | fprintf_filtered (stream, "void"); |
7b4ac7e1 |
1282 | break; |
1283 | |
1284 | case 0: |
4187119d |
1285 | fprintf_filtered (stream, "struct unknown"); |
7b4ac7e1 |
1286 | break; |
1287 | |
1288 | default: |
1289 | error ("Invalid type code in symbol table."); |
1290 | } |
1291 | } |
1292 | \f |
1293 | static void |
1294 | set_maximum_command (arg) |
1295 | char *arg; |
1296 | { |
1297 | if (!arg) error_no_arg ("value for maximum elements to print"); |
4187119d |
1298 | print_max = parse_and_eval_address (arg); |
7a67dd45 |
1299 | if (print_max == 0) |
1300 | print_max = UINT_MAX; |
4187119d |
1301 | } |
1302 | |
1303 | static void |
1304 | set_prettyprint_command (arg, from_tty) |
1305 | char *arg; |
1306 | int from_tty; |
1307 | { |
1308 | prettyprint = parse_binary_operation ("set prettyprint", arg); |
1309 | } |
1310 | |
1311 | static void |
1312 | set_unionprint_command (arg, from_tty) |
1313 | char *arg; |
1314 | int from_tty; |
1315 | { |
1316 | unionprint = parse_binary_operation ("set unionprint", arg); |
1317 | } |
1318 | |
1319 | format_info (arg, from_tty) |
1320 | char *arg; |
1321 | int from_tty; |
1322 | { |
1323 | if (arg) |
1324 | error ("\"info format\" does not take any arguments."); |
1325 | printf ("Prettyprinting of structures is %s.\n", |
1326 | prettyprint ? "on" : "off"); |
1327 | printf ("Printing of unions interior to structures is %s.\n", |
1328 | unionprint ? "on" : "off"); |
7a67dd45 |
1329 | if (print_max == UINT_MAX) |
1330 | printf_filtered |
1331 | ("There is no maximum number of array elements printed.\n"); |
1332 | else |
1333 | printf_filtered |
1334 | ("The maximum number of array elements printed is %d.\n", print_max); |
7b4ac7e1 |
1335 | } |
1336 | |
e91b87a3 |
1337 | extern struct cmd_list_element *setlist; |
1338 | |
1339 | void |
1340 | _initialize_valprint () |
7b4ac7e1 |
1341 | { |
e91b87a3 |
1342 | add_cmd ("array-max", class_vars, set_maximum_command, |
7a67dd45 |
1343 | "Set NUMBER as limit on string chars or array elements to print.\n\ |
1344 | \"set array-max 0\" causes there to be no limit.", |
e91b87a3 |
1345 | &setlist); |
7b4ac7e1 |
1346 | |
4187119d |
1347 | add_cmd ("prettyprint", class_support, set_prettyprint_command, |
1348 | "Turn prettyprinting of structures on and off.", |
1349 | &setlist); |
1350 | add_alias_cmd ("pp", "prettyprint", class_support, 1, &setlist); |
1351 | |
1352 | add_cmd ("unionprint", class_support, set_unionprint_command, |
1353 | "Turn printing of unions interior to structures on and off.", |
1354 | &setlist); |
1355 | |
1356 | add_info ("format", format_info, |
1357 | "Show current settings of data formatting options."); |
1358 | |
1359 | /* Give people the defaults which they are used to. */ |
1360 | prettyprint = 0; |
1361 | unionprint = 1; |
1362 | |
7b4ac7e1 |
1363 | print_max = 200; |
1364 | |
1365 | unsigned_type_table |
e91b87a3 |
1366 | = (char **) xmalloc ((1 + sizeof (unsigned LONGEST)) * sizeof (char *)); |
1367 | bzero (unsigned_type_table, (1 + sizeof (unsigned LONGEST))); |
7b4ac7e1 |
1368 | unsigned_type_table[sizeof (unsigned char)] = "unsigned char"; |
1369 | unsigned_type_table[sizeof (unsigned short)] = "unsigned short"; |
1370 | unsigned_type_table[sizeof (unsigned long)] = "unsigned long"; |
1371 | unsigned_type_table[sizeof (unsigned int)] = "unsigned int"; |
e91b87a3 |
1372 | #ifdef LONG_LONG |
1373 | unsigned_type_table[sizeof (unsigned long long)] = "unsigned long long"; |
1374 | #endif |
7b4ac7e1 |
1375 | |
1376 | signed_type_table |
e91b87a3 |
1377 | = (char **) xmalloc ((1 + sizeof (LONGEST)) * sizeof (char *)); |
1378 | bzero (signed_type_table, (1 + sizeof (LONGEST))); |
7b4ac7e1 |
1379 | signed_type_table[sizeof (char)] = "char"; |
1380 | signed_type_table[sizeof (short)] = "short"; |
1381 | signed_type_table[sizeof (long)] = "long"; |
1382 | signed_type_table[sizeof (int)] = "int"; |
e91b87a3 |
1383 | #ifdef LONG_LONG |
1384 | signed_type_table[sizeof (long long)] = "long long"; |
1385 | #endif |
7b4ac7e1 |
1386 | |
1387 | float_type_table |
1388 | = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *)); |
1389 | bzero (float_type_table, (1 + sizeof (double))); |
1390 | float_type_table[sizeof (float)] = "float"; |
1391 | float_type_table[sizeof (double)] = "double"; |
1392 | } |
1393 | |