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