]>
Commit | Line | Data |
---|---|---|
bd5635a1 RP |
1 | /* Print values for GNU debugger gdb. |
2 | Copyright (C) 1986, 1988, 1989 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. */ | |
19 | ||
20 | #include <stdio.h> | |
21 | #include <string.h> | |
22 | #include "defs.h" | |
23 | #include "param.h" | |
24 | #include "symtab.h" | |
25 | #include "value.h" | |
26 | #include "gdbcore.h" | |
27 | #include "gdbcmd.h" | |
28 | #include "target.h" | |
29 | #include "obstack.h" | |
30 | ||
31 | #include <errno.h> | |
32 | extern int sys_nerr; | |
33 | extern char *sys_errlist[]; | |
34 | ||
35 | extern void print_scalar_formatted(); /* printcmd.c */ | |
36 | extern void print_address_demangle(); /* printcmd.c */ | |
37 | extern int demangle; /* whether to print C++ syms raw or source-form */ | |
38 | ||
39 | /* Maximum number of chars to print for a string pointer value | |
40 | or vector contents, or UINT_MAX for no limit. */ | |
41 | ||
42 | static unsigned int print_max; | |
43 | ||
44 | static void type_print_varspec_suffix (); | |
45 | static void type_print_varspec_prefix (); | |
46 | static void type_print_base (); | |
47 | static void type_print_method_args (); | |
48 | ||
49 | /* Default input and output radixes, and output format letter. */ | |
50 | ||
51 | unsigned input_radix = 10; | |
52 | unsigned output_radix = 10; | |
53 | int output_format = 0; | |
54 | ||
55 | ||
56 | char **unsigned_type_table; | |
57 | char **signed_type_table; | |
58 | char **float_type_table; | |
59 | ||
60 | ||
61 | /* Print repeat counts if there are more than this | |
62 | many repetitions of an element in an array. */ | |
63 | #define REPEAT_COUNT_THRESHOLD 10 | |
0dce3774 JK |
64 | |
65 | /* Define a mess of print controls. */ | |
66 | ||
67 | int prettyprint; /* Controls pretty printing of structures */ | |
68 | int vtblprint; /* Controls printing of vtbl's */ | |
69 | int unionprint; /* Controls printing of nested unions. */ | |
70 | int arrayprint; /* Controls pretty printing of arrays. */ | |
71 | int addressprint; /* Controls pretty printing of addresses. */ | |
72 | int objectprint; /* Controls looking up an object's derived type | |
73 | using what we find in its vtables. */ | |
74 | ||
75 | struct obstack dont_print_obstack; | |
76 | ||
77 | static void cplus_val_print (); | |
bd5635a1 RP |
78 | \f |
79 | /* Print the character string STRING, printing at most LENGTH characters. | |
80 | Printing stops early if the number hits print_max; repeat counts | |
81 | are printed as appropriate. Print ellipses at the end if we | |
82 | had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */ | |
83 | ||
84 | void | |
85 | print_string (stream, string, length, force_ellipses) | |
86 | FILE *stream; | |
87 | char *string; | |
88 | unsigned int length; | |
89 | int force_ellipses; | |
90 | { | |
91 | register unsigned int i; | |
92 | unsigned int things_printed = 0; | |
93 | int in_quotes = 0; | |
94 | int need_comma = 0; | |
95 | extern int inspect_it; | |
96 | ||
97 | if (length == 0) | |
98 | { | |
99 | fputs_filtered ("\"\"", stdout); | |
100 | return; | |
101 | } | |
102 | ||
103 | for (i = 0; i < length && things_printed < print_max; ++i) | |
104 | { | |
105 | /* Position of the character we are examining | |
106 | to see whether it is repeated. */ | |
107 | unsigned int rep1; | |
108 | /* Number of repetitions we have detected so far. */ | |
109 | unsigned int reps; | |
110 | ||
111 | QUIT; | |
112 | ||
113 | if (need_comma) | |
114 | { | |
115 | fputs_filtered (", ", stream); | |
116 | need_comma = 0; | |
117 | } | |
118 | ||
119 | rep1 = i + 1; | |
120 | reps = 1; | |
121 | while (rep1 < length && string[rep1] == string[i]) | |
122 | { | |
123 | ++rep1; | |
124 | ++reps; | |
125 | } | |
126 | ||
127 | if (reps > REPEAT_COUNT_THRESHOLD) | |
128 | { | |
129 | if (in_quotes) | |
130 | { | |
131 | if (inspect_it) | |
132 | fputs_filtered ("\\\", ", stream); | |
133 | else | |
134 | fputs_filtered ("\", ", stream); | |
135 | in_quotes = 0; | |
136 | } | |
137 | fputs_filtered ("'", stream); | |
138 | printchar (string[i], stream, '\''); | |
139 | fprintf_filtered (stream, "' <repeats %u times>", reps); | |
140 | i = rep1 - 1; | |
141 | things_printed += REPEAT_COUNT_THRESHOLD; | |
142 | need_comma = 1; | |
143 | } | |
144 | else | |
145 | { | |
146 | if (!in_quotes) | |
147 | { | |
148 | if (inspect_it) | |
149 | fputs_filtered ("\\\"", stream); | |
150 | else | |
151 | fputs_filtered ("\"", stream); | |
152 | in_quotes = 1; | |
153 | } | |
154 | printchar (string[i], stream, '"'); | |
155 | ++things_printed; | |
156 | } | |
157 | } | |
158 | ||
159 | /* Terminate the quotes if necessary. */ | |
160 | if (in_quotes) | |
161 | { | |
162 | if (inspect_it) | |
163 | fputs_filtered ("\\\"", stream); | |
164 | else | |
165 | fputs_filtered ("\"", stream); | |
166 | } | |
167 | ||
168 | if (force_ellipses || i < length) | |
169 | fputs_filtered ("...", stream); | |
170 | } | |
171 | ||
172 | /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR, | |
173 | on STREAM. */ | |
174 | ||
175 | void | |
176 | print_floating (valaddr, type, stream) | |
177 | char *valaddr; | |
178 | struct type *type; | |
179 | FILE *stream; | |
180 | { | |
181 | double doub; | |
182 | int inv; | |
183 | unsigned len = TYPE_LENGTH (type); | |
184 | ||
185 | #if defined (IEEE_FLOAT) | |
186 | ||
187 | /* Check for NaN's. Note that this code does not depend on us being | |
188 | on an IEEE conforming system. It only depends on the target | |
189 | machine using IEEE representation. This means (a) | |
190 | cross-debugging works right, and (2) IEEE_FLOAT can (and should) | |
191 | be defined for systems like the 68881, which uses IEEE | |
192 | representation, but is not IEEE conforming. */ | |
193 | ||
194 | { | |
195 | long low, high; | |
196 | /* Is the sign bit 0? */ | |
197 | int nonnegative; | |
198 | /* Is it is a NaN (i.e. the exponent is all ones and | |
199 | the fraction is nonzero)? */ | |
200 | int is_nan; | |
201 | ||
202 | if (len == sizeof (float)) | |
203 | { | |
204 | /* It's single precision. */ | |
205 | bcopy (valaddr, &low, sizeof (low)); | |
206 | /* target -> host. */ | |
207 | SWAP_TARGET_AND_HOST (&low, sizeof (float)); | |
208 | nonnegative = low >= 0; | |
209 | is_nan = ((((low >> 23) & 0xFF) == 0xFF) | |
210 | && 0 != (low & 0x7FFFFF)); | |
211 | low &= 0x7fffff; | |
212 | high = 0; | |
213 | } | |
214 | else | |
215 | { | |
216 | /* It's double precision. Get the high and low words. */ | |
217 | ||
218 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
219 | bcopy (valaddr+4, &low, sizeof (low)); | |
220 | bcopy (valaddr+0, &high, sizeof (high)); | |
221 | #else | |
222 | bcopy (valaddr+0, &low, sizeof (low)); | |
223 | bcopy (valaddr+4, &high, sizeof (high)); | |
224 | #endif | |
225 | SWAP_TARGET_AND_HOST (&low, sizeof (low)); | |
226 | SWAP_TARGET_AND_HOST (&high, sizeof (high)); | |
227 | nonnegative = high >= 0; | |
228 | is_nan = (((high >> 20) & 0x7ff) == 0x7ff | |
229 | && ! ((((high & 0xfffff) == 0)) && (low == 0))); | |
230 | high &= 0xfffff; | |
231 | } | |
232 | ||
233 | if (is_nan) | |
234 | { | |
235 | /* The meaning of the sign and fraction is not defined by IEEE. | |
236 | But the user might know what they mean. For example, they | |
237 | (in an implementation-defined manner) distinguish between | |
238 | signaling and quiet NaN's. */ | |
239 | if (high) | |
240 | fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative, | |
241 | high, low); | |
242 | else | |
243 | fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low); | |
244 | return; | |
245 | } | |
246 | } | |
247 | #endif /* IEEE_FLOAT. */ | |
248 | ||
249 | doub = unpack_double (type, valaddr, &inv); | |
250 | if (inv) | |
251 | fprintf_filtered (stream, "<invalid float value>"); | |
252 | else | |
253 | fprintf_filtered (stream, len <= sizeof(float) ? "%.6g" : "%.17g", doub); | |
254 | } | |
255 | ||
256 | /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */ | |
257 | static void | |
258 | print_hex_chars (stream, valaddr, len) | |
259 | FILE *stream; | |
260 | unsigned char *valaddr; | |
261 | unsigned len; | |
262 | { | |
263 | unsigned char *p; | |
264 | ||
265 | fprintf_filtered (stream, "0x"); | |
266 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
267 | for (p = valaddr; | |
268 | p < valaddr + len; | |
269 | p++) | |
270 | #else /* Little endian. */ | |
271 | for (p = valaddr + len - 1; | |
272 | p >= valaddr; | |
273 | p--) | |
274 | #endif | |
275 | { | |
276 | fprintf_filtered (stream, "%02x", *p); | |
277 | } | |
278 | } | |
279 | \f | |
280 | /* Print the value VAL in C-ish syntax on stream STREAM. | |
281 | FORMAT is a format-letter, or 0 for print in natural format of data type. | |
282 | If the object printed is a string pointer, returns | |
283 | the number of string bytes printed. */ | |
284 | ||
285 | int | |
286 | value_print (val, stream, format, pretty) | |
287 | value val; | |
288 | FILE *stream; | |
289 | char format; | |
290 | enum val_prettyprint pretty; | |
291 | { | |
292 | register unsigned int i, n, typelen; | |
293 | ||
294 | if (val == 0) | |
295 | { | |
296 | printf_filtered ("<address of value unknown>"); | |
297 | return 0; | |
298 | } | |
299 | if (VALUE_OPTIMIZED_OUT (val)) | |
300 | { | |
301 | printf_filtered ("<value optimized out>"); | |
302 | return 0; | |
303 | } | |
aec4cb91 | 304 | |
bd5635a1 RP |
305 | /* A "repeated" value really contains several values in a row. |
306 | They are made by the @ operator. | |
307 | Print such values as if they were arrays. */ | |
308 | ||
309 | else if (VALUE_REPEATED (val)) | |
310 | { | |
311 | n = VALUE_REPETITIONS (val); | |
312 | typelen = TYPE_LENGTH (VALUE_TYPE (val)); | |
313 | fprintf_filtered (stream, "{"); | |
314 | /* Print arrays of characters using string syntax. */ | |
315 | if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT | |
316 | && format == 0) | |
317 | print_string (stream, VALUE_CONTENTS (val), n, 0); | |
318 | else | |
319 | { | |
320 | unsigned int things_printed = 0; | |
321 | ||
322 | for (i = 0; i < n && things_printed < print_max; i++) | |
323 | { | |
324 | /* Position of the array element we are examining to see | |
325 | whether it is repeated. */ | |
326 | unsigned int rep1; | |
327 | /* Number of repetitions we have detected so far. */ | |
328 | unsigned int reps; | |
329 | ||
330 | if (i != 0) | |
331 | fprintf_filtered (stream, ", "); | |
332 | wrap_here (""); | |
333 | ||
334 | rep1 = i + 1; | |
335 | reps = 1; | |
336 | while (rep1 < n | |
337 | && !bcmp (VALUE_CONTENTS (val) + typelen * i, | |
338 | VALUE_CONTENTS (val) + typelen * rep1, typelen)) | |
339 | { | |
340 | ++reps; | |
341 | ++rep1; | |
342 | } | |
343 | ||
344 | if (reps > REPEAT_COUNT_THRESHOLD) | |
345 | { | |
346 | val_print (VALUE_TYPE (val), | |
347 | VALUE_CONTENTS (val) + typelen * i, | |
348 | VALUE_ADDRESS (val) + typelen * i, | |
349 | stream, format, 1, 0, pretty); | |
350 | fprintf (stream, " <repeats %u times>", reps); | |
351 | i = rep1 - 1; | |
352 | things_printed += REPEAT_COUNT_THRESHOLD; | |
353 | } | |
354 | else | |
355 | { | |
356 | val_print (VALUE_TYPE (val), | |
357 | VALUE_CONTENTS (val) + typelen * i, | |
358 | VALUE_ADDRESS (val) + typelen * i, | |
359 | stream, format, 1, 0, pretty); | |
360 | things_printed++; | |
361 | } | |
362 | } | |
363 | if (i < n) | |
364 | fprintf_filtered (stream, "..."); | |
365 | } | |
366 | fprintf_filtered (stream, "}"); | |
367 | return n * typelen; | |
368 | } | |
369 | else | |
370 | { | |
0dce3774 JK |
371 | struct type *type = VALUE_TYPE (val); |
372 | ||
bd5635a1 RP |
373 | /* If it is a pointer, indicate what it points to. |
374 | ||
375 | Print type also if it is a reference. | |
376 | ||
377 | C++: if it is a member pointer, we will take care | |
378 | of that when we print it. */ | |
0dce3774 JK |
379 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
380 | || TYPE_CODE (type) == TYPE_CODE_REF) | |
bd5635a1 RP |
381 | { |
382 | /* Hack: remove (char *) for char strings. Their | |
383 | type is indicated by the quoted string anyway. */ | |
0dce3774 JK |
384 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
385 | && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char) | |
386 | && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT | |
387 | && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type))) | |
bd5635a1 RP |
388 | { |
389 | /* Print nothing */ | |
390 | } | |
391 | else | |
392 | { | |
393 | fprintf_filtered (stream, "("); | |
0dce3774 | 394 | type_print (type, "", stream, -1); |
bd5635a1 RP |
395 | fprintf_filtered (stream, ") "); |
396 | } | |
397 | } | |
0dce3774 | 398 | return val_print (type, VALUE_CONTENTS (val), |
bd5635a1 RP |
399 | VALUE_ADDRESS (val), stream, format, 1, 0, pretty); |
400 | } | |
401 | } | |
402 | ||
403 | /* Return truth value for assertion that TYPE is of the type | |
404 | "pointer to virtual function". */ | |
405 | static int | |
406 | is_vtbl_ptr_type(type) | |
407 | struct type *type; | |
408 | { | |
409 | char *typename = TYPE_NAME(type); | |
410 | static const char vtbl_ptr_name[] = | |
411 | { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e' }; | |
412 | ||
413 | return (typename != NULL && !strcmp(typename, vtbl_ptr_name)); | |
414 | } | |
415 | ||
416 | /* Return truth value for the assertion that TYPE is of the type | |
417 | "pointer to virtual function table". */ | |
418 | static int | |
419 | is_vtbl_member(type) | |
420 | struct type *type; | |
421 | { | |
0dce3774 JK |
422 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
423 | type = TYPE_TARGET_TYPE (type); | |
424 | else | |
425 | return 0; | |
426 | ||
427 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY | |
428 | && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT) | |
bd5635a1 | 429 | /* Virtual functions tables are full of pointers to virtual functions. */ |
0dce3774 | 430 | return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type)); |
bd5635a1 RP |
431 | return 0; |
432 | } | |
433 | \f | |
bd5635a1 RP |
434 | /* Mutually recursive subroutines of cplus_val_print and val_print to print out |
435 | a structure's fields: val_print_fields and cplus_val_print. | |
436 | ||
437 | TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the | |
438 | same meanings as in cplus_val_print and val_print. | |
439 | ||
440 | DONT_PRINT is an array of baseclass types that we | |
441 | should not print, or zero if called from top level. */ | |
442 | static void | |
443 | val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print) | |
444 | struct type *type; | |
445 | char *valaddr; | |
446 | FILE *stream; | |
447 | char format; | |
448 | int recurse; | |
449 | enum val_prettyprint pretty; | |
450 | struct type **dont_print; | |
451 | { | |
452 | int i, len, n_baseclasses; | |
453 | ||
454 | fprintf_filtered (stream, "{"); | |
455 | len = TYPE_NFIELDS (type); | |
456 | n_baseclasses = TYPE_N_BASECLASSES (type); | |
457 | ||
458 | /* Print out baseclasses such that we don't print | |
459 | duplicates of virtual baseclasses. */ | |
460 | if (n_baseclasses > 0) | |
461 | cplus_val_print (type, valaddr, stream, format, recurse+1, pretty, dont_print); | |
462 | ||
463 | if (!len && n_baseclasses == 1) | |
464 | fprintf_filtered (stream, "<No data fields>"); | |
465 | else | |
466 | { | |
467 | extern int inspect_it; | |
468 | int fields_seen = 0; | |
469 | ||
470 | for (i = n_baseclasses; i < len; i++) | |
471 | { | |
472 | /* Check if static field */ | |
473 | if (TYPE_FIELD_STATIC (type, i)) | |
474 | continue; | |
475 | if (fields_seen) | |
476 | fprintf_filtered (stream, ", "); | |
477 | else if (n_baseclasses > 0) | |
478 | { | |
479 | fprintf_filtered (stream, "\n"); | |
480 | print_spaces_filtered (2 + 2 * recurse, stream); | |
481 | fputs_filtered ("members of ", stream); | |
482 | fputs_filtered (type_name_no_tag (type), stream); | |
483 | fputs_filtered (": ", stream); | |
484 | } | |
485 | fields_seen = 1; | |
486 | ||
487 | if (pretty) | |
488 | { | |
489 | fprintf_filtered (stream, "\n"); | |
490 | print_spaces_filtered (2 + 2 * recurse, stream); | |
491 | } | |
492 | else | |
493 | { | |
494 | wrap_here (n_spaces (2 + 2 * recurse)); | |
495 | } | |
496 | if (inspect_it) | |
497 | { | |
498 | if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) | |
499 | fputs_filtered ("\"( ptr \"", stream); | |
500 | else | |
501 | fputs_filtered ("\"( nodef \"", stream); | |
502 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
503 | fputs_filtered ("\" \"", stream); | |
504 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
505 | fputs_filtered ("\") \"", stream); | |
506 | } | |
507 | else | |
508 | { | |
509 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
510 | fputs_filtered (" = ", stream); | |
511 | } | |
512 | if (TYPE_FIELD_PACKED (type, i)) | |
513 | { | |
f266e564 | 514 | value v; |
bd5635a1 | 515 | |
f266e564 JK |
516 | /* Bitfields require special handling, especially due to byte |
517 | order problems. */ | |
518 | v = value_from_long (TYPE_FIELD_TYPE (type, i), | |
519 | unpack_field_as_long (type, valaddr, i)); | |
bd5635a1 | 520 | |
f266e564 | 521 | val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, |
bd5635a1 RP |
522 | stream, format, 0, recurse + 1, pretty); |
523 | } | |
524 | else | |
525 | { | |
526 | val_print (TYPE_FIELD_TYPE (type, i), | |
527 | valaddr + TYPE_FIELD_BITPOS (type, i) / 8, | |
528 | 0, stream, format, 0, recurse + 1, pretty); | |
529 | } | |
530 | } | |
531 | if (pretty) | |
532 | { | |
533 | fprintf_filtered (stream, "\n"); | |
534 | print_spaces_filtered (2 * recurse, stream); | |
535 | } | |
536 | } | |
537 | fprintf_filtered (stream, "}"); | |
538 | } | |
539 | ||
540 | /* Special val_print routine to avoid printing multiple copies of virtual | |
541 | baseclasses. */ | |
542 | ||
543 | static void | |
544 | cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print) | |
545 | struct type *type; | |
546 | char *valaddr; | |
547 | FILE *stream; | |
548 | char format; | |
549 | int recurse; | |
550 | enum val_prettyprint pretty; | |
551 | struct type **dont_print; | |
552 | { | |
553 | struct obstack tmp_obstack; | |
554 | struct type **last_dont_print | |
555 | = (struct type **)obstack_next_free (&dont_print_obstack); | |
556 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); | |
557 | ||
558 | if (dont_print == 0) | |
559 | { | |
560 | /* If we're at top level, carve out a completely fresh | |
561 | chunk of the obstack and use that until this particular | |
562 | invocation returns. */ | |
563 | tmp_obstack = dont_print_obstack; | |
564 | /* Bump up the high-water mark. Now alpha is omega. */ | |
565 | obstack_finish (&dont_print_obstack); | |
566 | } | |
567 | ||
568 | for (i = 0; i < n_baseclasses; i++) | |
569 | { | |
570 | char *baddr; | |
0dce3774 | 571 | int err; |
bd5635a1 RP |
572 | |
573 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
574 | { | |
575 | struct type **first_dont_print | |
576 | = (struct type **)obstack_base (&dont_print_obstack); | |
577 | ||
578 | int j = (struct type **)obstack_next_free (&dont_print_obstack) | |
579 | - first_dont_print; | |
580 | ||
581 | while (--j >= 0) | |
582 | if (TYPE_BASECLASS (type, i) == first_dont_print[j]) | |
583 | goto flush_it; | |
584 | ||
585 | obstack_ptr_grow (&dont_print_obstack, TYPE_BASECLASS (type, i)); | |
586 | } | |
587 | ||
0dce3774 JK |
588 | baddr = baseclass_addr (type, i, valaddr, 0, &err); |
589 | if (err == 0 && baddr == 0) | |
bd5635a1 RP |
590 | error ("could not find virtual baseclass `%s'\n", |
591 | type_name_no_tag (TYPE_BASECLASS (type, i))); | |
592 | ||
593 | fprintf_filtered (stream, "\n"); | |
594 | if (pretty) | |
595 | print_spaces_filtered (2 + 2 * recurse, stream); | |
596 | fputs_filtered ("<", stream); | |
597 | fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream); | |
598 | fputs_filtered ("> = ", stream); | |
0dce3774 JK |
599 | if (err != 0) |
600 | fprintf_filtered (stream, "<invalid address 0x%x>", baddr); | |
601 | else | |
602 | val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format, | |
603 | recurse, pretty, | |
604 | (struct type **)obstack_base (&dont_print_obstack)); | |
bd5635a1 RP |
605 | flush_it: |
606 | ; | |
607 | } | |
608 | ||
609 | if (dont_print == 0) | |
610 | { | |
611 | /* Free the space used to deal with the printing | |
612 | of this type from top level. */ | |
613 | obstack_free (&dont_print_obstack, last_dont_print); | |
614 | /* Reset watermark so that we can continue protecting | |
615 | ourselves from whatever we were protecting ourselves. */ | |
616 | dont_print_obstack = tmp_obstack; | |
617 | } | |
618 | } | |
619 | ||
620 | /* Print data of type TYPE located at VALADDR (within GDB), | |
621 | which came from the inferior at address ADDRESS, | |
622 | onto stdio stream STREAM according to FORMAT | |
623 | (a letter or 0 for natural format). The data at VALADDR | |
624 | is in target byte order. | |
625 | ||
626 | If the data are a string pointer, returns the number of | |
627 | sting characters printed. | |
628 | ||
629 | if DEREF_REF is nonzero, then dereference references, | |
630 | otherwise just print them like pointers. | |
631 | ||
632 | The PRETTY parameter controls prettyprinting. */ | |
633 | ||
634 | int | |
635 | val_print (type, valaddr, address, stream, format, | |
636 | deref_ref, recurse, pretty) | |
637 | struct type *type; | |
638 | char *valaddr; | |
639 | CORE_ADDR address; | |
640 | FILE *stream; | |
641 | char format; | |
642 | int deref_ref; | |
643 | int recurse; | |
644 | enum val_prettyprint pretty; | |
645 | { | |
646 | register unsigned int i; | |
647 | unsigned len; | |
648 | struct type *elttype; | |
649 | unsigned eltlen; | |
650 | LONGEST val; | |
651 | unsigned char c; | |
652 | ||
653 | if (pretty == Val_pretty_default) | |
654 | { | |
655 | pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint; | |
656 | } | |
657 | ||
658 | QUIT; | |
659 | ||
660 | check_stub_type (type); | |
661 | ||
662 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
663 | { | |
664 | fprintf_filtered (stream, "<unknown struct>"); | |
665 | fflush (stream); | |
666 | return 0; | |
667 | } | |
668 | ||
669 | switch (TYPE_CODE (type)) | |
670 | { | |
671 | case TYPE_CODE_ARRAY: | |
e1ce8aa5 JK |
672 | /* FIXME: TYPE_LENGTH (type) is unsigned and therefore always |
673 | 0. Is "> 0" meant? I'm not sure what an "array of | |
674 | unspecified length" (mentioned in the comment for the else-part | |
675 | of this if) is. */ | |
bd5635a1 RP |
676 | if (TYPE_LENGTH (type) >= 0 |
677 | && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
678 | { | |
679 | elttype = TYPE_TARGET_TYPE (type); | |
680 | eltlen = TYPE_LENGTH (elttype); | |
681 | len = TYPE_LENGTH (type) / eltlen; | |
682 | if (arrayprint) | |
683 | print_spaces_filtered (2 + 2 * recurse, stream); | |
684 | fprintf_filtered (stream, "{"); | |
685 | /* For an array of chars, print with string syntax. */ | |
686 | if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT | |
687 | && (format == 0 || format == 's') ) | |
688 | print_string (stream, valaddr, len, 0); | |
689 | else | |
690 | { | |
691 | unsigned int things_printed = 0; | |
692 | ||
0dce3774 JK |
693 | /* If this is a virtual function table, print the 0th |
694 | entry specially, and the rest of the members normally. */ | |
695 | if (is_vtbl_ptr_type (elttype)) | |
696 | { | |
697 | fprintf_filtered (stream, "%d vtable entries", len-1); | |
698 | i = 1; | |
699 | } | |
700 | else | |
701 | i = 0; | |
702 | ||
703 | for (; i < len && things_printed < print_max; i++) | |
bd5635a1 RP |
704 | { |
705 | /* Position of the array element we are examining to see | |
706 | whether it is repeated. */ | |
707 | unsigned int rep1; | |
708 | /* Number of repetitions we have detected so far. */ | |
709 | unsigned int reps; | |
710 | ||
711 | if (i != 0) | |
712 | if (arrayprint) | |
713 | { | |
714 | fprintf_filtered (stream, ",\n"); | |
715 | print_spaces_filtered (2 + 2 * recurse, stream); | |
716 | } | |
717 | else | |
718 | fprintf_filtered (stream, ", "); | |
719 | wrap_here (n_spaces (2 + 2 * recurse)); | |
720 | ||
721 | rep1 = i + 1; | |
722 | reps = 1; | |
723 | while (rep1 < len | |
724 | && !bcmp (valaddr + i * eltlen, | |
725 | valaddr + rep1 * eltlen, eltlen)) | |
726 | { | |
727 | ++reps; | |
728 | ++rep1; | |
729 | } | |
730 | ||
731 | if (reps > REPEAT_COUNT_THRESHOLD) | |
732 | { | |
733 | val_print (elttype, valaddr + i * eltlen, | |
734 | 0, stream, format, deref_ref, | |
735 | recurse + 1, pretty); | |
736 | fprintf_filtered (stream, " <repeats %u times>", reps); | |
737 | i = rep1 - 1; | |
738 | things_printed += REPEAT_COUNT_THRESHOLD; | |
739 | } | |
740 | else | |
741 | { | |
742 | val_print (elttype, valaddr + i * eltlen, | |
743 | 0, stream, format, deref_ref, | |
744 | recurse + 1, pretty); | |
745 | things_printed++; | |
746 | } | |
747 | } | |
748 | if (i < len) | |
749 | fprintf_filtered (stream, "..."); | |
750 | } | |
751 | fprintf_filtered (stream, "}"); | |
752 | break; | |
753 | } | |
754 | /* Array of unspecified length: treat like pointer to first elt. */ | |
755 | valaddr = (char *) &address; | |
756 | ||
757 | case TYPE_CODE_PTR: | |
758 | if (format && format != 's') | |
759 | { | |
760 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
761 | break; | |
762 | } | |
763 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD) | |
764 | { | |
765 | struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)); | |
766 | struct fn_field *f; | |
767 | int j, len2; | |
768 | char *kind = ""; | |
e1ce8aa5 | 769 | CORE_ADDR addr; |
bd5635a1 | 770 | |
e1ce8aa5 JK |
771 | addr = unpack_pointer (lookup_pointer_type (builtin_type_void), |
772 | valaddr); | |
773 | if (addr < 128) | |
bd5635a1 RP |
774 | { |
775 | len = TYPE_NFN_FIELDS (domain); | |
776 | for (i = 0; i < len; i++) | |
777 | { | |
778 | f = TYPE_FN_FIELDLIST1 (domain, i); | |
779 | len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); | |
780 | ||
781 | for (j = 0; j < len2; j++) | |
782 | { | |
783 | QUIT; | |
e1ce8aa5 | 784 | if (TYPE_FN_FIELD_VOFFSET (f, j) == addr) |
bd5635a1 RP |
785 | { |
786 | kind = "virtual"; | |
787 | goto common; | |
788 | } | |
789 | } | |
790 | } | |
791 | } | |
792 | else | |
793 | { | |
e1ce8aa5 | 794 | struct symbol *sym = find_pc_function (addr); |
bd5635a1 RP |
795 | if (sym == 0) |
796 | error ("invalid pointer to member function"); | |
797 | len = TYPE_NFN_FIELDS (domain); | |
798 | for (i = 0; i < len; i++) | |
799 | { | |
800 | f = TYPE_FN_FIELDLIST1 (domain, i); | |
801 | len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); | |
802 | ||
803 | for (j = 0; j < len2; j++) | |
804 | { | |
805 | QUIT; | |
806 | if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j))) | |
807 | goto common; | |
808 | } | |
809 | } | |
810 | } | |
811 | common: | |
812 | if (i < len) | |
813 | { | |
814 | fprintf_filtered (stream, "&"); | |
815 | type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0); | |
816 | fprintf (stream, kind); | |
817 | if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' | |
818 | && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER) | |
819 | type_print_method_args | |
820 | (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", | |
821 | TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream); | |
822 | else | |
823 | type_print_method_args | |
824 | (TYPE_FN_FIELD_ARGS (f, j), "", | |
825 | TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream); | |
826 | break; | |
827 | } | |
828 | fprintf_filtered (stream, "("); | |
829 | type_print (type, "", stream, -1); | |
e1ce8aa5 | 830 | fprintf_filtered (stream, ") %d", (int) addr >> 3); |
bd5635a1 RP |
831 | } |
832 | else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER) | |
833 | { | |
834 | struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)); | |
835 | ||
836 | /* VAL is a byte offset into the structure type DOMAIN. | |
837 | Find the name of the field for that offset and | |
838 | print it. */ | |
839 | int extra = 0; | |
840 | int bits = 0; | |
841 | len = TYPE_NFIELDS (domain); | |
842 | /* @@ Make VAL into bit offset */ | |
843 | val = unpack_long (builtin_type_int, valaddr) << 3; | |
844 | for (i = TYPE_N_BASECLASSES (domain); i < len; i++) | |
845 | { | |
846 | int bitpos = TYPE_FIELD_BITPOS (domain, i); | |
847 | QUIT; | |
848 | if (val == bitpos) | |
849 | break; | |
850 | if (val < bitpos && i != 0) | |
851 | { | |
852 | /* Somehow pointing into a field. */ | |
853 | i -= 1; | |
854 | extra = (val - TYPE_FIELD_BITPOS (domain, i)); | |
855 | if (extra & 0x3) | |
856 | bits = 1; | |
857 | else | |
858 | extra >>= 3; | |
859 | break; | |
860 | } | |
861 | } | |
862 | if (i < len) | |
863 | { | |
864 | fprintf_filtered (stream, "&"); | |
865 | type_print_base (domain, stream, 0, 0); | |
866 | fprintf_filtered (stream, "::"); | |
867 | fputs_filtered (TYPE_FIELD_NAME (domain, i), stream); | |
868 | if (extra) | |
869 | fprintf_filtered (stream, " + %d bytes", extra); | |
870 | if (bits) | |
871 | fprintf_filtered (stream, " (offset in bits)"); | |
872 | break; | |
873 | } | |
874 | fprintf_filtered (stream, "%d", val >> 3); | |
875 | } | |
876 | else | |
877 | { | |
e1ce8aa5 | 878 | CORE_ADDR addr = unpack_pointer (type, valaddr); |
bd5635a1 RP |
879 | elttype = TYPE_TARGET_TYPE (type); |
880 | ||
881 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
882 | { | |
883 | /* Try to print what function it points to. */ | |
884 | print_address_demangle (addr, stream, demangle); | |
885 | /* Return value is irrelevant except for string pointers. */ | |
886 | return 0; | |
887 | } | |
888 | ||
889 | if (addressprint && format != 's') | |
890 | fprintf_filtered (stream, "0x%x", addr); | |
891 | ||
892 | /* For a pointer to char or unsigned char, | |
893 | also print the string pointed to, unless pointer is null. */ | |
894 | i = 0; /* Number of characters printed. */ | |
895 | if (TYPE_LENGTH (elttype) == 1 | |
896 | && TYPE_CODE (elttype) == TYPE_CODE_INT | |
897 | && (format == 0 || format == 's') | |
898 | && addr != 0 | |
899 | /* If print_max is UINT_MAX, the alloca below will fail. | |
900 | In that case don't try to print the string. */ | |
901 | && print_max < UINT_MAX) | |
902 | { | |
903 | int first_addr_err = 0; | |
904 | int errcode = 0; | |
905 | ||
906 | /* Get first character. */ | |
907 | errcode = target_read_memory (addr, (char *)&c, 1); | |
908 | if (errcode != 0) | |
909 | { | |
910 | /* First address out of bounds. */ | |
911 | first_addr_err = 1; | |
912 | } | |
913 | else | |
914 | { | |
915 | /* A real string. */ | |
916 | char *string = (char *) alloca (print_max); | |
917 | ||
918 | /* If the loop ends by us hitting print_max characters, | |
919 | we need to have elipses at the end. */ | |
920 | int force_ellipses = 1; | |
921 | ||
922 | /* This loop always fetches print_max characters, even | |
923 | though print_string might want to print more or fewer | |
924 | (with repeated characters). This is so that | |
925 | we don't spend forever fetching if we print | |
926 | a long string consisting of the same character | |
927 | repeated. Also so we can do it all in one memory | |
928 | operation, which is faster. However, this will be | |
929 | slower if print_max is set high, e.g. if you set | |
930 | print_max to 1000, not only will it take a long | |
931 | time to fetch short strings, but if you are near | |
932 | the end of the address space, it might not work. | |
933 | FIXME. */ | |
934 | QUIT; | |
935 | errcode = target_read_memory (addr, string, print_max); | |
936 | if (errcode != 0) | |
937 | force_ellipses = 0; | |
938 | else | |
939 | for (i = 0; i < print_max; i++) | |
940 | if (string[i] == '\0') | |
941 | { | |
942 | force_ellipses = 0; | |
943 | break; | |
944 | } | |
945 | QUIT; | |
946 | ||
947 | if (addressprint) | |
948 | fputs_filtered (" ", stream); | |
949 | print_string (stream, string, i, force_ellipses); | |
950 | } | |
951 | ||
952 | if (errcode != 0) | |
953 | { | |
954 | if (errcode == EIO) | |
955 | { | |
956 | fprintf_filtered (stream, | |
957 | (" <Address 0x%x out of bounds>" | |
958 | + first_addr_err), | |
959 | addr + i); | |
960 | } | |
961 | else | |
962 | { | |
963 | if (errcode >= sys_nerr || errcode < 0) | |
964 | error ("Error reading memory address 0x%x: unknown error (%d).", | |
965 | addr + i, errcode); | |
966 | else | |
967 | error ("Error reading memory address 0x%x: %s.", | |
968 | addr + i, sys_errlist[errcode]); | |
969 | } | |
970 | } | |
971 | ||
972 | fflush (stream); | |
973 | } | |
974 | else /* print vtbl's nicely */ | |
975 | if (is_vtbl_member(type)) | |
976 | { | |
e1ce8aa5 | 977 | CORE_ADDR vt_address = unpack_pointer (type, valaddr); |
bd5635a1 RP |
978 | |
979 | int vt_index = find_pc_misc_function (vt_address); | |
980 | if (vt_index >= 0 | |
981 | && vt_address == misc_function_vector[vt_index].address) | |
982 | { | |
983 | fputs_filtered (" <", stream); | |
984 | fputs_demangled (misc_function_vector[vt_index].name, | |
985 | stream, 1); | |
986 | fputs_filtered (">", stream); | |
987 | } | |
988 | if (vtblprint) | |
989 | { | |
e1ce8aa5 | 990 | value vt_val; |
bd5635a1 | 991 | |
e1ce8aa5 JK |
992 | vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address); |
993 | val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val), | |
994 | VALUE_ADDRESS (vt_val), stream, format, | |
bd5635a1 RP |
995 | deref_ref, recurse + 1, pretty); |
996 | if (pretty) | |
997 | { | |
998 | fprintf_filtered (stream, "\n"); | |
999 | print_spaces_filtered (2 + 2 * recurse, stream); | |
1000 | } | |
1001 | } | |
1002 | } | |
1003 | ||
1004 | /* Return number of characters printed, plus one for the | |
1005 | terminating null if we have "reached the end". */ | |
1006 | return i + (print_max && i != print_max); | |
1007 | } | |
1008 | break; | |
1009 | ||
1010 | case TYPE_CODE_MEMBER: | |
1011 | error ("not implemented: member type in val_print"); | |
1012 | break; | |
1013 | ||
1014 | case TYPE_CODE_REF: | |
1015 | if (addressprint) | |
1016 | { | |
1017 | fprintf_filtered (stream, "@0x%lx", | |
1018 | unpack_long (builtin_type_int, valaddr)); | |
1019 | if (deref_ref) | |
1020 | fputs_filtered (": ", stream); | |
1021 | } | |
1022 | /* De-reference the reference. */ | |
1023 | if (deref_ref) | |
1024 | { | |
1025 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF) | |
1026 | { | |
e1ce8aa5 JK |
1027 | value deref_val = |
1028 | value_at | |
1029 | (TYPE_TARGET_TYPE (type), | |
1030 | unpack_pointer (lookup_pointer_type (builtin_type_void), | |
1031 | valaddr)); | |
1032 | val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val), | |
1033 | VALUE_ADDRESS (deref_val), stream, format, | |
bd5635a1 RP |
1034 | deref_ref, recurse + 1, pretty); |
1035 | } | |
1036 | else | |
1037 | fputs_filtered ("???", stream); | |
1038 | } | |
1039 | break; | |
1040 | ||
1041 | case TYPE_CODE_UNION: | |
1042 | if (recurse && !unionprint) | |
1043 | { | |
1044 | fprintf_filtered (stream, "{...}"); | |
1045 | break; | |
1046 | } | |
1047 | /* Fall through. */ | |
1048 | case TYPE_CODE_STRUCT: | |
1049 | if (vtblprint && is_vtbl_ptr_type(type)) | |
1050 | { | |
1051 | /* Print the unmangled name if desired. */ | |
1052 | print_address_demangle(*((int *) (valaddr + /* FIXME bytesex */ | |
1053 | TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)), | |
1054 | stream, demangle); | |
1055 | break; | |
1056 | } | |
1057 | val_print_fields (type, valaddr, stream, format, recurse, pretty, 0); | |
1058 | break; | |
1059 | ||
1060 | case TYPE_CODE_ENUM: | |
1061 | if (format) | |
1062 | { | |
1063 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
1064 | break; | |
1065 | } | |
1066 | len = TYPE_NFIELDS (type); | |
1067 | val = unpack_long (builtin_type_int, valaddr); | |
1068 | for (i = 0; i < len; i++) | |
1069 | { | |
1070 | QUIT; | |
1071 | if (val == TYPE_FIELD_BITPOS (type, i)) | |
1072 | break; | |
1073 | } | |
1074 | if (i < len) | |
1075 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
1076 | else | |
e1ce8aa5 JK |
1077 | #ifdef LONG_LONG |
1078 | fprintf_filtered (stream, "%lld", val); | |
1079 | #else | |
1080 | fprintf_filtered (stream, "%ld", val); | |
1081 | #endif | |
bd5635a1 RP |
1082 | break; |
1083 | ||
1084 | case TYPE_CODE_FUNC: | |
1085 | if (format) | |
1086 | { | |
1087 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
1088 | break; | |
1089 | } | |
1090 | fprintf_filtered (stream, "{"); | |
1091 | type_print (type, "", stream, -1); | |
1092 | fprintf_filtered (stream, "} "); | |
1093 | if (addressprint) | |
1094 | fprintf_filtered (stream, "0x%x", address); | |
1095 | break; | |
1096 | ||
1097 | case TYPE_CODE_INT: | |
1098 | if (format || output_format) | |
1099 | { | |
1100 | print_scalar_formatted (valaddr, type, | |
1101 | format? format: output_format, | |
1102 | 0, stream); | |
1103 | break; | |
1104 | } | |
1105 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) | |
1106 | { | |
1107 | if (TYPE_UNSIGNED (type)) | |
1108 | { | |
1109 | /* First figure out whether the number in fact has zeros | |
1110 | in all its bytes more significant than least significant | |
1111 | sizeof (LONGEST) ones. */ | |
1112 | char *p; | |
1113 | /* Pointer to first (i.e. lowest address) nonzero character. */ | |
1114 | char *first_addr; | |
e1ce8aa5 | 1115 | len = TYPE_LENGTH (type); |
bd5635a1 RP |
1116 | |
1117 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
1118 | for (p = valaddr; | |
1119 | len > sizeof (LONGEST) | |
1120 | && p < valaddr + TYPE_LENGTH (type); | |
1121 | p++) | |
1122 | #else /* Little endian. */ | |
1123 | first_addr = valaddr; | |
1124 | for (p = valaddr + TYPE_LENGTH (type); | |
1125 | len > sizeof (LONGEST) && p >= valaddr; | |
1126 | p--) | |
1127 | #endif /* Little endian. */ | |
1128 | { | |
1129 | if (*p == 0) | |
1130 | len--; | |
1131 | else | |
1132 | break; | |
1133 | } | |
1134 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
1135 | first_addr = p; | |
1136 | #endif | |
1137 | ||
1138 | if (len <= sizeof (LONGEST)) | |
1139 | { | |
1140 | /* We can print it in decimal. */ | |
1141 | fprintf_filtered | |
1142 | (stream, | |
1143 | #if defined (LONG_LONG) | |
1144 | "%llu", | |
1145 | #else | |
1146 | "%lu", | |
1147 | #endif | |
1148 | unpack_long (BUILTIN_TYPE_LONGEST, first_addr)); | |
1149 | } | |
1150 | else | |
1151 | { | |
1152 | /* It is big, so print it in hex. */ | |
1153 | print_hex_chars (stream, (unsigned char *)first_addr, len); | |
1154 | } | |
1155 | } | |
1156 | else | |
1157 | { | |
1158 | /* Signed. One could assume two's complement (a reasonable | |
1159 | assumption, I think) and do better than this. */ | |
1160 | print_hex_chars (stream, (unsigned char *)valaddr, | |
1161 | TYPE_LENGTH (type)); | |
1162 | } | |
1163 | break; | |
1164 | } | |
1165 | #ifdef PRINT_TYPELESS_INTEGER | |
1166 | PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr)); | |
1167 | #else | |
1168 | #ifndef LONG_LONG | |
1169 | fprintf_filtered (stream, | |
1170 | TYPE_UNSIGNED (type) ? "%u" : "%d", | |
1171 | unpack_long (type, valaddr)); | |
1172 | #else | |
1173 | fprintf_filtered (stream, | |
1174 | TYPE_UNSIGNED (type) ? "%llu" : "%lld", | |
1175 | unpack_long (type, valaddr)); | |
1176 | #endif | |
1177 | #endif | |
1178 | ||
1179 | if (TYPE_LENGTH (type) == 1) | |
1180 | { | |
1181 | fprintf_filtered (stream, " '"); | |
1182 | printchar ((unsigned char) unpack_long (type, valaddr), | |
1183 | stream, '\''); | |
1184 | fprintf_filtered (stream, "'"); | |
1185 | } | |
1186 | break; | |
1187 | ||
1188 | case TYPE_CODE_FLT: | |
1189 | if (format) | |
1190 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
1191 | else | |
1192 | print_floating (valaddr, type, stream); | |
1193 | break; | |
1194 | ||
1195 | case TYPE_CODE_VOID: | |
1196 | fprintf_filtered (stream, "void"); | |
1197 | break; | |
1198 | ||
1199 | case TYPE_CODE_UNDEF: | |
1200 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
1201 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" | |
1202 | and no complete type for struct foo in that file. */ | |
1203 | fprintf_filtered (stream, "<unknown struct>"); | |
1204 | break; | |
1205 | ||
1206 | case TYPE_CODE_ERROR: | |
1207 | fprintf_filtered (stream, "?"); | |
1208 | break; | |
1209 | ||
1210 | default: | |
1211 | error ("Invalid type code in symbol table."); | |
1212 | } | |
1213 | fflush (stream); | |
1214 | return 0; | |
1215 | } | |
1216 | \f | |
1217 | /* Print a description of a type TYPE | |
1218 | in the form of a declaration of a variable named VARSTRING. | |
1219 | (VARSTRING is demangled if necessary.) | |
1220 | Output goes to STREAM (via stdio). | |
1221 | If SHOW is positive, we show the contents of the outermost level | |
1222 | of structure even if there is a type name that could be used instead. | |
1223 | If SHOW is negative, we never show the details of elements' types. */ | |
1224 | ||
1225 | void | |
1226 | type_print (type, varstring, stream, show) | |
1227 | struct type *type; | |
1228 | char *varstring; | |
1229 | FILE *stream; | |
1230 | int show; | |
1231 | { | |
1232 | type_print_1 (type, varstring, stream, show, 0); | |
1233 | } | |
1234 | ||
1235 | /* LEVEL is the depth to indent lines by. */ | |
1236 | ||
1237 | void | |
1238 | type_print_1 (type, varstring, stream, show, level) | |
1239 | struct type *type; | |
1240 | char *varstring; | |
1241 | FILE *stream; | |
1242 | int show; | |
1243 | int level; | |
1244 | { | |
1245 | register enum type_code code; | |
1246 | type_print_base (type, stream, show, level); | |
1247 | code = TYPE_CODE (type); | |
1248 | if ((varstring && *varstring) | |
1249 | || | |
1250 | /* Need a space if going to print stars or brackets; | |
1251 | but not if we will print just a type name. */ | |
1252 | ((show > 0 || TYPE_NAME (type) == 0) | |
1253 | && | |
1254 | (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC | |
1255 | || code == TYPE_CODE_METHOD | |
1256 | || code == TYPE_CODE_ARRAY | |
1257 | || code == TYPE_CODE_MEMBER | |
1258 | || code == TYPE_CODE_REF))) | |
1259 | fprintf_filtered (stream, " "); | |
1260 | type_print_varspec_prefix (type, stream, show, 0); | |
1261 | fputs_demangled (varstring, stream, -1); /* Print demangled name | |
1262 | without arguments */ | |
1263 | type_print_varspec_suffix (type, stream, show, 0); | |
1264 | } | |
1265 | ||
1266 | /* Print the method arguments ARGS to the file STREAM. */ | |
1267 | static void | |
1268 | type_print_method_args (args, prefix, varstring, staticp, stream) | |
1269 | struct type **args; | |
1270 | char *prefix, *varstring; | |
1271 | int staticp; | |
1272 | FILE *stream; | |
1273 | { | |
1274 | int i; | |
1275 | ||
1276 | fputs_filtered (" ", stream); | |
1277 | fputs_demangled (prefix, stream, 1); | |
1278 | fputs_demangled (varstring, stream, 1); | |
1279 | fputs_filtered (" (", stream); | |
1280 | if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID) | |
1281 | { | |
1282 | i = !staticp; /* skip the class variable */ | |
1283 | while (1) | |
1284 | { | |
1285 | type_print (args[i++], "", stream, 0); | |
1286 | if (!args[i]) | |
1287 | { | |
1288 | fprintf_filtered (stream, " ..."); | |
1289 | break; | |
1290 | } | |
1291 | else if (args[i]->code != TYPE_CODE_VOID) | |
1292 | { | |
1293 | fprintf_filtered (stream, ", "); | |
1294 | } | |
1295 | else break; | |
1296 | } | |
1297 | } | |
1298 | fprintf_filtered (stream, ")"); | |
1299 | } | |
1300 | ||
1301 | /* If TYPE is a derived type, then print out derivation | |
1302 | information. Print out all layers of the type heirarchy | |
1303 | until we encounter one with multiple inheritance. | |
1304 | At that point, print out that ply, and return. */ | |
1305 | static void | |
1306 | type_print_derivation_info (stream, type) | |
1307 | FILE *stream; | |
1308 | struct type *type; | |
1309 | { | |
1310 | char *name; | |
1311 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); | |
1312 | struct type *basetype = 0; | |
1313 | ||
1314 | while (type && n_baseclasses > 0) | |
1315 | { | |
1316 | /* Not actually sure about this one -- Bryan. */ | |
1317 | check_stub_type (type); | |
1318 | ||
1319 | fprintf_filtered (stream, ": "); | |
1320 | for (i = 0; ;) | |
1321 | { | |
1322 | basetype = TYPE_BASECLASS (type, i); | |
1323 | if (name = type_name_no_tag (basetype)) | |
1324 | { | |
1325 | fprintf_filtered (stream, "%s%s ", | |
1326 | BASETYPE_VIA_PUBLIC(type, i) ? "public" : "private", | |
1327 | BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : ""); | |
1328 | fputs_filtered (name, stream); | |
1329 | } | |
1330 | i++; | |
1331 | if (i >= n_baseclasses) | |
1332 | break; | |
1333 | fprintf_filtered (stream, ", "); | |
1334 | } | |
1335 | ||
1336 | fprintf_filtered (stream, " "); | |
1337 | if (n_baseclasses != 1) | |
1338 | break; | |
1339 | n_baseclasses = TYPE_N_BASECLASSES (basetype); | |
1340 | type = basetype; | |
1341 | } | |
1342 | } | |
1343 | ||
1344 | /* Print any asterisks or open-parentheses needed before the | |
1345 | variable name (to describe its type). | |
1346 | ||
1347 | On outermost call, pass 0 for PASSED_A_PTR. | |
1348 | On outermost call, SHOW > 0 means should ignore | |
1349 | any typename for TYPE and show its details. | |
1350 | SHOW is always zero on recursive calls. */ | |
1351 | ||
1352 | static void | |
1353 | type_print_varspec_prefix (type, stream, show, passed_a_ptr) | |
1354 | struct type *type; | |
1355 | FILE *stream; | |
1356 | int show; | |
1357 | int passed_a_ptr; | |
1358 | { | |
1359 | if (type == 0) | |
1360 | return; | |
1361 | ||
1362 | if (TYPE_NAME (type) && show <= 0) | |
1363 | return; | |
1364 | ||
1365 | QUIT; | |
1366 | ||
1367 | switch (TYPE_CODE (type)) | |
1368 | { | |
1369 | case TYPE_CODE_PTR: | |
1370 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
1371 | fprintf_filtered (stream, "*"); | |
1372 | break; | |
1373 | ||
1374 | case TYPE_CODE_MEMBER: | |
1375 | if (passed_a_ptr) | |
1376 | fprintf_filtered (stream, "("); | |
1377 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, | |
1378 | 0); | |
1379 | fprintf_filtered (stream, " "); | |
1380 | type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, | |
1381 | passed_a_ptr); | |
1382 | fprintf_filtered (stream, "::"); | |
1383 | break; | |
1384 | ||
1385 | case TYPE_CODE_METHOD: | |
1386 | if (passed_a_ptr) | |
1387 | fprintf (stream, "("); | |
1388 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, | |
1389 | 0); | |
0dce3774 JK |
1390 | if (passed_a_ptr) |
1391 | { | |
1392 | fprintf_filtered (stream, " "); | |
1393 | type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, | |
1394 | passed_a_ptr); | |
1395 | fprintf_filtered (stream, "::"); | |
1396 | } | |
bd5635a1 RP |
1397 | break; |
1398 | ||
1399 | case TYPE_CODE_REF: | |
1400 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
1401 | fprintf_filtered (stream, "&"); | |
1402 | break; | |
1403 | ||
1404 | case TYPE_CODE_FUNC: | |
1405 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, | |
1406 | 0); | |
1407 | if (passed_a_ptr) | |
1408 | fprintf_filtered (stream, "("); | |
1409 | break; | |
1410 | ||
1411 | case TYPE_CODE_ARRAY: | |
1412 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, | |
1413 | 0); | |
1414 | if (passed_a_ptr) | |
1415 | fprintf_filtered (stream, "("); | |
1416 | ||
1417 | case TYPE_CODE_UNDEF: | |
1418 | case TYPE_CODE_STRUCT: | |
1419 | case TYPE_CODE_UNION: | |
1420 | case TYPE_CODE_ENUM: | |
1421 | case TYPE_CODE_INT: | |
1422 | case TYPE_CODE_FLT: | |
1423 | case TYPE_CODE_VOID: | |
1424 | case TYPE_CODE_ERROR: | |
1425 | /* These types need no prefix. They are listed here so that | |
1426 | gcc -Wall will reveal any types that haven't been handled. */ | |
1427 | break; | |
1428 | } | |
1429 | } | |
1430 | ||
1431 | /* Print any array sizes, function arguments or close parentheses | |
1432 | needed after the variable name (to describe its type). | |
1433 | Args work like type_print_varspec_prefix. */ | |
1434 | ||
1435 | static void | |
1436 | type_print_varspec_suffix (type, stream, show, passed_a_ptr) | |
1437 | struct type *type; | |
1438 | FILE *stream; | |
1439 | int show; | |
1440 | int passed_a_ptr; | |
1441 | { | |
1442 | if (type == 0) | |
1443 | return; | |
1444 | ||
1445 | if (TYPE_NAME (type) && show <= 0) | |
1446 | return; | |
1447 | ||
1448 | QUIT; | |
1449 | ||
1450 | switch (TYPE_CODE (type)) | |
1451 | { | |
1452 | case TYPE_CODE_ARRAY: | |
1453 | if (passed_a_ptr) | |
1454 | fprintf_filtered (stream, ")"); | |
1455 | ||
1456 | fprintf_filtered (stream, "["); | |
e1ce8aa5 JK |
1457 | if (/* always true */ /* TYPE_LENGTH (type) >= 0 |
1458 | && */ TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
bd5635a1 RP |
1459 | fprintf_filtered (stream, "%d", |
1460 | (TYPE_LENGTH (type) | |
1461 | / TYPE_LENGTH (TYPE_TARGET_TYPE (type)))); | |
1462 | fprintf_filtered (stream, "]"); | |
1463 | ||
1464 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, | |
1465 | 0); | |
1466 | break; | |
1467 | ||
1468 | case TYPE_CODE_MEMBER: | |
1469 | if (passed_a_ptr) | |
1470 | fprintf_filtered (stream, ")"); | |
1471 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
1472 | break; | |
1473 | ||
1474 | case TYPE_CODE_METHOD: | |
1475 | if (passed_a_ptr) | |
1476 | fprintf_filtered (stream, ")"); | |
1477 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
1478 | if (passed_a_ptr) | |
1479 | { | |
1480 | int i; | |
1481 | struct type **args = TYPE_ARG_TYPES (type); | |
1482 | ||
1483 | fprintf_filtered (stream, "("); | |
1484 | if (args[1] == 0) | |
1485 | fprintf_filtered (stream, "..."); | |
1486 | else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++) | |
1487 | { | |
1488 | type_print_1 (args[i], "", stream, -1, 0); | |
1489 | if (args[i+1] == 0) | |
1490 | fprintf_filtered (stream, "..."); | |
1491 | else if (args[i+1]->code != TYPE_CODE_VOID) | |
1492 | fprintf_filtered (stream, ","); | |
1493 | } | |
1494 | fprintf_filtered (stream, ")"); | |
1495 | } | |
1496 | break; | |
1497 | ||
1498 | case TYPE_CODE_PTR: | |
1499 | case TYPE_CODE_REF: | |
1500 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
1501 | break; | |
1502 | ||
1503 | case TYPE_CODE_FUNC: | |
1504 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, | |
1505 | passed_a_ptr); | |
1506 | if (passed_a_ptr) | |
1507 | fprintf_filtered (stream, ")"); | |
1508 | fprintf_filtered (stream, "()"); | |
1509 | break; | |
1510 | ||
1511 | case TYPE_CODE_UNDEF: | |
1512 | case TYPE_CODE_STRUCT: | |
1513 | case TYPE_CODE_UNION: | |
1514 | case TYPE_CODE_ENUM: | |
1515 | case TYPE_CODE_INT: | |
1516 | case TYPE_CODE_FLT: | |
1517 | case TYPE_CODE_VOID: | |
1518 | case TYPE_CODE_ERROR: | |
1519 | /* These types do not need a suffix. They are listed so that | |
1520 | gcc -Wall will report types that may not have been considered. */ | |
1521 | break; | |
1522 | } | |
1523 | } | |
1524 | ||
1525 | /* Print the name of the type (or the ultimate pointer target, | |
1526 | function value or array element), or the description of a | |
1527 | structure or union. | |
1528 | ||
1529 | SHOW nonzero means don't print this type as just its name; | |
1530 | show its real definition even if it has a name. | |
1531 | SHOW zero means print just typename or struct tag if there is one | |
1532 | SHOW negative means abbreviate structure elements. | |
1533 | SHOW is decremented for printing of structure elements. | |
1534 | ||
1535 | LEVEL is the depth to indent by. | |
1536 | We increase it for some recursive calls. */ | |
1537 | ||
1538 | static void | |
1539 | type_print_base (type, stream, show, level) | |
1540 | struct type *type; | |
1541 | FILE *stream; | |
1542 | int show; | |
1543 | int level; | |
1544 | { | |
1545 | char *name; | |
1546 | register int i; | |
1547 | register int len; | |
1548 | register int lastval; | |
1549 | ||
1550 | QUIT; | |
1551 | ||
1552 | if (type == 0) | |
1553 | { | |
1554 | fprintf_filtered (stream, "type unknown"); | |
1555 | return; | |
1556 | } | |
1557 | ||
1558 | if (TYPE_NAME (type) && show <= 0) | |
1559 | { | |
1560 | fputs_filtered (TYPE_NAME (type), stream); | |
1561 | return; | |
1562 | } | |
1563 | ||
1564 | switch (TYPE_CODE (type)) | |
1565 | { | |
1566 | case TYPE_CODE_ARRAY: | |
1567 | case TYPE_CODE_PTR: | |
1568 | case TYPE_CODE_MEMBER: | |
1569 | case TYPE_CODE_REF: | |
1570 | case TYPE_CODE_FUNC: | |
1571 | case TYPE_CODE_METHOD: | |
1572 | type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
1573 | break; | |
1574 | ||
1575 | case TYPE_CODE_STRUCT: | |
1576 | fprintf_filtered (stream, "struct "); | |
1577 | goto struct_union; | |
1578 | ||
1579 | case TYPE_CODE_UNION: | |
1580 | fprintf_filtered (stream, "union "); | |
1581 | struct_union: | |
1582 | if (name = type_name_no_tag (type)) | |
1583 | { | |
1584 | fputs_filtered (name, stream); | |
1585 | fputs_filtered (" ", stream); | |
1586 | } | |
1587 | if (show < 0) | |
1588 | fprintf_filtered (stream, "{...}"); | |
1589 | else | |
1590 | { | |
1591 | check_stub_type (type); | |
1592 | ||
1593 | type_print_derivation_info (stream, type); | |
1594 | ||
1595 | fprintf_filtered (stream, "{"); | |
1596 | len = TYPE_NFIELDS (type); | |
1597 | if (len) | |
1598 | fprintf_filtered (stream, "\n"); | |
1599 | else | |
1600 | { | |
1601 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
1602 | fprintf_filtered (stream, "<incomplete type>\n"); | |
1603 | else | |
1604 | fprintf_filtered (stream, "<no data fields>\n"); | |
1605 | } | |
1606 | ||
1607 | /* If there is a base class for this type, | |
1608 | do not print the field that it occupies. */ | |
1609 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) | |
1610 | { | |
1611 | QUIT; | |
1612 | /* Don't print out virtual function table. */ | |
1613 | if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER && | |
1614 | !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5)) | |
1615 | continue; | |
1616 | ||
1617 | print_spaces_filtered (level + 4, stream); | |
1618 | if (TYPE_FIELD_STATIC (type, i)) | |
1619 | { | |
1620 | fprintf_filtered (stream, "static "); | |
1621 | } | |
1622 | type_print_1 (TYPE_FIELD_TYPE (type, i), | |
1623 | TYPE_FIELD_NAME (type, i), | |
1624 | stream, show - 1, level + 4); | |
1625 | if (!TYPE_FIELD_STATIC (type, i) | |
1626 | && TYPE_FIELD_PACKED (type, i)) | |
1627 | { | |
1628 | /* It is a bitfield. This code does not attempt | |
1629 | to look at the bitpos and reconstruct filler, | |
1630 | unnamed fields. This would lead to misleading | |
1631 | results if the compiler does not put out fields | |
1632 | for such things (I don't know what it does). */ | |
1633 | fprintf_filtered (stream, " : %d", | |
1634 | TYPE_FIELD_BITSIZE (type, i)); | |
1635 | } | |
1636 | fprintf_filtered (stream, ";\n"); | |
1637 | } | |
1638 | ||
1639 | /* C++: print out the methods */ | |
1640 | len = TYPE_NFN_FIELDS (type); | |
1641 | if (len) fprintf_filtered (stream, "\n"); | |
1642 | for (i = 0; i < len; i++) | |
1643 | { | |
1644 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); | |
1645 | int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); | |
1646 | ||
1647 | for (j = 0; j < len2; j++) | |
1648 | { | |
1649 | QUIT; | |
1650 | print_spaces_filtered (level + 4, stream); | |
1651 | if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) | |
1652 | fprintf_filtered (stream, "virtual "); | |
1653 | else if (TYPE_FN_FIELD_STATIC_P (f, j)) | |
1654 | fprintf_filtered (stream, "static "); | |
aec4cb91 MT |
1655 | if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0) |
1656 | { | |
1657 | /* Keep GDB from crashing here. */ | |
1658 | fprintf (stream, "<undefined type> %s;\n", | |
1659 | TYPE_FN_FIELD_PHYSNAME (f, j)); | |
1660 | break; | |
1661 | } | |
1662 | else | |
1663 | type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, 0); | |
bd5635a1 RP |
1664 | if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, j)) & TYPE_FLAG_STUB) |
1665 | { | |
1666 | /* Build something we can demangle. */ | |
1667 | char *strchr (), *gdb_mangle_typename (); | |
1668 | char *inner_name = gdb_mangle_typename (type); | |
1669 | char *mangled_name | |
1670 | = (char *)xmalloc (strlen (TYPE_FN_FIELDLIST_NAME (type, i)) | |
1671 | + strlen (inner_name) | |
1672 | + strlen (TYPE_FN_FIELD_PHYSNAME (f, j)) | |
1673 | + 1); | |
1674 | char *demangled_name, *cplus_demangle (); | |
1675 | strcpy (mangled_name, TYPE_FN_FIELDLIST_NAME (type, i)); | |
1676 | strcat (mangled_name, inner_name); | |
1677 | strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j)); | |
1678 | demangled_name = cplus_demangle (mangled_name, 1); | |
1679 | if (demangled_name == 0) | |
1680 | fprintf_filtered (stream, " <badly mangled name %s>", | |
1681 | mangled_name); | |
1682 | else | |
1683 | { | |
1684 | fprintf_filtered (stream, " %s", | |
1685 | strchr (demangled_name, ':') + 2); | |
1686 | free (demangled_name); | |
1687 | } | |
1688 | free (mangled_name); | |
1689 | } | |
1690 | else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' | |
1691 | && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER) | |
1692 | type_print_method_args | |
1693 | (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", | |
1694 | TYPE_FN_FIELDLIST_NAME (type, i), 0, stream); | |
1695 | else | |
1696 | type_print_method_args | |
1697 | (TYPE_FN_FIELD_ARGS (f, j), "", | |
1698 | TYPE_FN_FIELDLIST_NAME (type, i), | |
1699 | TYPE_FN_FIELD_STATIC_P (f, j), stream); | |
1700 | ||
1701 | fprintf_filtered (stream, ";\n"); | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | print_spaces_filtered (level, stream); | |
1706 | fprintf_filtered (stream, "}"); | |
1707 | } | |
1708 | break; | |
1709 | ||
1710 | case TYPE_CODE_ENUM: | |
1711 | fprintf_filtered (stream, "enum "); | |
1712 | if (name = type_name_no_tag (type)) | |
1713 | { | |
1714 | fputs_filtered (name, stream); | |
1715 | fputs_filtered (" ", stream); | |
1716 | } | |
1717 | if (show < 0) | |
1718 | fprintf_filtered (stream, "{...}"); | |
1719 | else | |
1720 | { | |
1721 | fprintf_filtered (stream, "{"); | |
1722 | len = TYPE_NFIELDS (type); | |
1723 | lastval = 0; | |
1724 | for (i = 0; i < len; i++) | |
1725 | { | |
1726 | QUIT; | |
1727 | if (i) fprintf_filtered (stream, ", "); | |
1728 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
1729 | if (lastval != TYPE_FIELD_BITPOS (type, i)) | |
1730 | { | |
1731 | fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i)); | |
1732 | lastval = TYPE_FIELD_BITPOS (type, i); | |
1733 | } | |
1734 | lastval++; | |
1735 | } | |
1736 | fprintf_filtered (stream, "}"); | |
1737 | } | |
1738 | break; | |
1739 | ||
1740 | case TYPE_CODE_INT: | |
1741 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) | |
1742 | { | |
1743 | fprintf_filtered (stream, "<%d bit integer>", | |
1744 | TYPE_LENGTH (type) * TARGET_CHAR_BIT); | |
1745 | } | |
1746 | else | |
1747 | { | |
1748 | if (TYPE_UNSIGNED (type)) | |
1749 | name = unsigned_type_table[TYPE_LENGTH (type)]; | |
1750 | else | |
1751 | name = signed_type_table[TYPE_LENGTH (type)]; | |
1752 | } | |
1753 | fputs_filtered (name, stream); | |
1754 | break; | |
1755 | ||
1756 | case TYPE_CODE_FLT: | |
1757 | name = float_type_table[TYPE_LENGTH (type)]; | |
1758 | fputs_filtered (name, stream); | |
1759 | break; | |
1760 | ||
1761 | case TYPE_CODE_VOID: | |
1762 | fprintf_filtered (stream, "void"); | |
1763 | break; | |
1764 | ||
1765 | case 0: | |
1766 | fprintf_filtered (stream, "struct unknown"); | |
1767 | break; | |
1768 | ||
1769 | case TYPE_CODE_ERROR: | |
1770 | fprintf_filtered (stream, "<unknown type>"); | |
1771 | break; | |
1772 | ||
1773 | default: | |
1774 | error ("Invalid type code in symbol table."); | |
1775 | } | |
1776 | } | |
1777 | \f | |
e1ce8aa5 | 1778 | #if 0 |
bd5635a1 RP |
1779 | /* Validate an input or output radix setting, and make sure the user |
1780 | knows what they really did here. Radix setting is confusing, e.g. | |
1781 | setting the input radix to "10" never changes it! */ | |
1782 | ||
e1ce8aa5 | 1783 | /* ARGSUSED */ |
bd5635a1 RP |
1784 | static void |
1785 | set_input_radix (args, from_tty, c) | |
1786 | char *args; | |
1787 | int from_tty; | |
1788 | struct cmd_list_element *c; | |
1789 | { | |
1790 | unsigned radix = *(unsigned *)c->var; | |
1791 | ||
1792 | if (from_tty) | |
1793 | printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n", | |
1794 | radix, radix, radix); | |
1795 | } | |
e1ce8aa5 | 1796 | #endif |
bd5635a1 | 1797 | |
e1ce8aa5 | 1798 | /* ARGSUSED */ |
bd5635a1 RP |
1799 | static void |
1800 | set_output_radix (args, from_tty, c) | |
1801 | char *args; | |
1802 | int from_tty; | |
1803 | struct cmd_list_element *c; | |
1804 | { | |
1805 | unsigned radix = *(unsigned *)c->var; | |
1806 | ||
1807 | if (from_tty) | |
1808 | printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n", | |
1809 | radix, radix, radix); | |
1810 | ||
1811 | /* FIXME, we really should be able to validate the setting BEFORE | |
1812 | it takes effect. */ | |
1813 | switch (radix) | |
1814 | { | |
1815 | case 16: | |
1816 | output_format = 'x'; | |
1817 | break; | |
1818 | case 10: | |
1819 | output_format = 0; | |
1820 | break; | |
1821 | case 8: | |
1822 | output_format = 'o'; /* octal */ | |
1823 | break; | |
1824 | default: | |
1825 | output_format = 0; | |
1826 | error ("Unsupported radix ``decimal %d''; using decimal output", | |
1827 | radix); | |
1828 | } | |
1829 | } | |
1830 | ||
1831 | /* Both at once */ | |
1832 | static void | |
1833 | set_radix (arg, from_tty, c) | |
1834 | char *arg; | |
1835 | int from_tty; | |
1836 | struct cmd_list_element *c; | |
1837 | { | |
1838 | unsigned radix = *(unsigned *)c->var; | |
1839 | ||
1840 | if (from_tty) | |
1841 | printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n", | |
1842 | radix, radix, radix); | |
1843 | ||
1844 | input_radix = radix; | |
1845 | output_radix = radix; | |
1846 | ||
1847 | set_output_radix (arg, 0, c); | |
1848 | } | |
1849 | \f | |
f266e564 JK |
1850 | struct cmd_list_element *setprintlist = NULL; |
1851 | struct cmd_list_element *showprintlist = NULL; | |
1852 | ||
1853 | /*ARGSUSED*/ | |
1854 | static void | |
1855 | set_print (arg, from_tty) | |
1856 | char *arg; | |
1857 | int from_tty; | |
1858 | { | |
1859 | printf ( | |
1860 | "\"set print\" must be followed by the name of a print subcommand.\n"); | |
1861 | help_list (setprintlist, "set print ", -1, stdout); | |
1862 | } | |
1863 | ||
1864 | /*ARGSUSED*/ | |
1865 | static void | |
1866 | show_print (args, from_tty) | |
1867 | char *args; | |
1868 | int from_tty; | |
1869 | { | |
1870 | cmd_show_list (showprintlist, from_tty, ""); | |
1871 | } | |
1872 | \f | |
bd5635a1 RP |
1873 | void |
1874 | _initialize_valprint () | |
1875 | { | |
1876 | struct cmd_list_element *c; | |
1877 | ||
f266e564 JK |
1878 | add_prefix_cmd ("print", no_class, set_print, |
1879 | "Generic command for setting how things print.", | |
1880 | &setprintlist, "set print ", 0, &setlist); | |
1881 | add_prefix_cmd ("print", no_class, show_print, | |
1882 | "Generic command for showing print settings.", | |
1883 | &showprintlist, "show print ", 0, &showlist); | |
1884 | ||
bd5635a1 | 1885 | add_show_from_set |
f266e564 | 1886 | (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max, |
bd5635a1 | 1887 | "Set limit on string chars or array elements to print.\n\ |
f266e564 JK |
1888 | \"set print elements 0\" causes there to be no limit.", |
1889 | &setprintlist), | |
1890 | &showprintlist); | |
bd5635a1 RP |
1891 | |
1892 | add_show_from_set | |
f266e564 | 1893 | (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint, |
bd5635a1 | 1894 | "Set prettyprinting of structures.", |
f266e564 JK |
1895 | &setprintlist), |
1896 | &showprintlist); | |
bd5635a1 RP |
1897 | |
1898 | add_show_from_set | |
f266e564 | 1899 | (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint, |
bd5635a1 | 1900 | "Set printing of unions interior to structures.", |
f266e564 JK |
1901 | &setprintlist), |
1902 | &showprintlist); | |
bd5635a1 RP |
1903 | |
1904 | add_show_from_set | |
f266e564 | 1905 | (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint, |
bd5635a1 | 1906 | "Set printing of C++ virtual function tables.", |
f266e564 JK |
1907 | &setprintlist), |
1908 | &showprintlist); | |
bd5635a1 RP |
1909 | |
1910 | add_show_from_set | |
f266e564 | 1911 | (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint, |
bd5635a1 | 1912 | "Set prettyprinting of arrays.", |
f266e564 JK |
1913 | &setprintlist), |
1914 | &showprintlist); | |
bd5635a1 | 1915 | |
0dce3774 JK |
1916 | add_show_from_set |
1917 | (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint, | |
1918 | "Set printing of object's derived type based on vtable info.", | |
1919 | &setprintlist), | |
1920 | &showprintlist); | |
1921 | ||
bd5635a1 | 1922 | add_show_from_set |
f266e564 | 1923 | (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint, |
bd5635a1 | 1924 | "Set printing of addresses.", |
f266e564 JK |
1925 | &setprintlist), |
1926 | &showprintlist); | |
bd5635a1 RP |
1927 | |
1928 | #if 0 | |
1929 | /* The "show radix" cmd isn't good enough to show two separate values. | |
1930 | The rest of the code works, but the show part is confusing, so don't | |
1931 | let them be set separately 'til we work out "show". */ | |
1932 | c = add_set_cmd ("input-radix", class_support, var_uinteger, | |
1933 | (char *)&input_radix, | |
1934 | "Set default input radix for entering numbers.", | |
1935 | &setlist); | |
1936 | add_show_from_set (c, &showlist); | |
1937 | c->function = set_input_radix; | |
1938 | ||
1939 | c = add_set_cmd ("output-radix", class_support, var_uinteger, | |
1940 | (char *)&output_radix, | |
1941 | "Set default output radix for printing of values.", | |
1942 | &setlist); | |
1943 | add_show_from_set (c, &showlist); | |
1944 | c->function = set_output_radix; | |
1945 | #endif | |
1946 | ||
1947 | c = add_set_cmd ("radix", class_support, var_uinteger, | |
1948 | (char *)&output_radix, | |
1949 | "Set default input and output number radix.", | |
1950 | &setlist); | |
1951 | add_show_from_set (c, &showlist); | |
1952 | c->function = set_radix; | |
1953 | ||
1954 | /* Give people the defaults which they are used to. */ | |
1955 | prettyprint = 0; | |
1956 | unionprint = 1; | |
1957 | vtblprint = 0; | |
1958 | arrayprint = 0; | |
1959 | addressprint = 1; | |
0dce3774 | 1960 | objectprint = 0; |
bd5635a1 RP |
1961 | |
1962 | print_max = 200; | |
1963 | ||
1964 | unsigned_type_table | |
1965 | = (char **) xmalloc ((1 + sizeof (unsigned LONGEST)) * sizeof (char *)); | |
1966 | bzero (unsigned_type_table, (1 + sizeof (unsigned LONGEST))); | |
1967 | unsigned_type_table[sizeof (unsigned char)] = "unsigned char"; | |
1968 | unsigned_type_table[sizeof (unsigned short)] = "unsigned short"; | |
1969 | unsigned_type_table[sizeof (unsigned long)] = "unsigned long"; | |
1970 | unsigned_type_table[sizeof (unsigned int)] = "unsigned int"; | |
1971 | #ifdef LONG_LONG | |
1972 | unsigned_type_table[sizeof (unsigned long long)] = "unsigned long long"; | |
1973 | #endif | |
1974 | ||
1975 | signed_type_table | |
1976 | = (char **) xmalloc ((1 + sizeof (LONGEST)) * sizeof (char *)); | |
1977 | bzero (signed_type_table, (1 + sizeof (LONGEST))); | |
1978 | signed_type_table[sizeof (char)] = "char"; | |
1979 | signed_type_table[sizeof (short)] = "short"; | |
1980 | signed_type_table[sizeof (long)] = "long"; | |
1981 | signed_type_table[sizeof (int)] = "int"; | |
1982 | #ifdef LONG_LONG | |
1983 | signed_type_table[sizeof (long long)] = "long long"; | |
1984 | #endif | |
1985 | ||
1986 | float_type_table | |
1987 | = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *)); | |
1988 | bzero (float_type_table, (1 + sizeof (double))); | |
1989 | float_type_table[sizeof (float)] = "float"; | |
1990 | float_type_table[sizeof (double)] = "double"; | |
1991 | obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *)); | |
1992 | } |