]>
Commit | Line | Data |
---|---|---|
a8a69e63 FF |
1 | /* Support for printing Chill values for GDB, the GNU debugger. |
2 | Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program 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 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program 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 this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "obstack.h" | |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "valprint.h" | |
25 | #include "expression.h" | |
26 | #include "language.h" | |
27 | ||
28 | \f | |
29 | /* Print data of type TYPE located at VALADDR (within GDB), which came from | |
30 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
31 | FORMAT (a letter or 0 for natural format). The data at VALADDR is in | |
32 | target byte order. | |
33 | ||
34 | If the data are a string pointer, returns the number of string characters | |
35 | printed. | |
36 | ||
37 | If DEREF_REF is nonzero, then dereference references, otherwise just print | |
38 | them like pointers. | |
39 | ||
40 | The PRETTY parameter controls prettyprinting. */ | |
41 | ||
42 | int | |
43 | chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse, | |
44 | pretty) | |
45 | struct type *type; | |
46 | char *valaddr; | |
47 | CORE_ADDR address; | |
48 | FILE *stream; | |
49 | int format; | |
50 | int deref_ref; | |
51 | int recurse; | |
52 | enum val_prettyprint pretty; | |
53 | { | |
a8a69e63 | 54 | LONGEST val; |
c7da3ed3 FF |
55 | unsigned int i; |
56 | struct type *elttype; | |
57 | unsigned eltlen; | |
58 | CORE_ADDR addr; | |
a8a69e63 FF |
59 | |
60 | switch (TYPE_CODE (type)) | |
61 | { | |
62 | case TYPE_CODE_ARRAY: | |
63 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
64 | { | |
a8a69e63 FF |
65 | if (prettyprint_arrays) |
66 | { | |
67 | print_spaces_filtered (2 + 2 * recurse, stream); | |
68 | } | |
69 | fprintf_filtered (stream, "["); | |
a9b37611 FF |
70 | val_print_array_elements (type, valaddr, address, stream, format, |
71 | deref_ref, recurse, pretty, 0); | |
a8a69e63 FF |
72 | fprintf_filtered (stream, "]"); |
73 | } | |
74 | else | |
75 | { | |
76 | error ("unimplemented in chill_val_print; unspecified array length"); | |
77 | } | |
78 | break; | |
79 | ||
80 | case TYPE_CODE_INT: | |
81 | format = format ? format : output_format; | |
82 | if (format) | |
83 | { | |
84 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
85 | } | |
86 | else | |
87 | { | |
88 | val_print_type_code_int (type, valaddr, stream); | |
89 | } | |
90 | break; | |
91 | ||
92 | case TYPE_CODE_CHAR: | |
93 | format = format ? format : output_format; | |
94 | if (format) | |
95 | { | |
96 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
97 | } | |
98 | else | |
99 | { | |
100 | LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr), | |
101 | stream); | |
102 | } | |
103 | break; | |
104 | ||
105 | case TYPE_CODE_FLT: | |
106 | if (format) | |
107 | { | |
108 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
109 | } | |
110 | else | |
111 | { | |
112 | print_floating (valaddr, type, stream); | |
113 | } | |
114 | break; | |
115 | ||
116 | case TYPE_CODE_BOOL: | |
117 | format = format ? format : output_format; | |
118 | if (format) | |
119 | { | |
120 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
121 | } | |
122 | else | |
123 | { | |
124 | val = unpack_long (builtin_type_chill_bool, valaddr); | |
125 | fprintf_filtered (stream, val ? "TRUE" : "FALSE"); | |
126 | } | |
127 | break; | |
128 | ||
129 | case TYPE_CODE_UNDEF: | |
130 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
131 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" | |
132 | and no complete type for struct foo in that file. */ | |
133 | fprintf_filtered (stream, "<incomplete type>"); | |
134 | break; | |
135 | ||
136 | case TYPE_CODE_PTR: | |
c7da3ed3 FF |
137 | if (format && format != 's') |
138 | { | |
139 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
140 | break; | |
141 | } | |
142 | addr = unpack_pointer (type, valaddr); | |
143 | elttype = TYPE_TARGET_TYPE (type); | |
144 | ||
145 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
146 | { | |
147 | /* Try to print what function it points to. */ | |
148 | print_address_demangle (addr, stream, demangle); | |
149 | /* Return value is irrelevant except for string pointers. */ | |
150 | return (0); | |
151 | } | |
152 | if (addressprint && format != 's') | |
153 | { | |
154 | fprintf_filtered (stream, "0x%x", addr); | |
155 | } | |
156 | ||
157 | /* For a pointer to char or unsigned char, also print the string | |
158 | pointed to, unless pointer is null. */ | |
159 | i = 0; /* Number of characters printed. */ | |
160 | if (TYPE_LENGTH (elttype) == 1 | |
161 | && TYPE_CODE (elttype) == TYPE_CODE_CHAR | |
162 | && (format == 0 || format == 's') | |
163 | && addr != 0 | |
164 | && /* If print_max is UINT_MAX, the alloca below will fail. | |
165 | In that case don't try to print the string. */ | |
166 | print_max < UINT_MAX) | |
167 | { | |
168 | i = val_print_string (addr, stream); | |
169 | } | |
170 | /* Return number of characters printed, plus one for the | |
171 | terminating null if we have "reached the end". */ | |
172 | return (i + (print_max && i != print_max)); | |
173 | break; | |
174 | ||
a8a69e63 FF |
175 | case TYPE_CODE_MEMBER: |
176 | case TYPE_CODE_REF: | |
177 | case TYPE_CODE_UNION: | |
178 | case TYPE_CODE_STRUCT: | |
179 | case TYPE_CODE_ENUM: | |
180 | case TYPE_CODE_FUNC: | |
181 | case TYPE_CODE_VOID: | |
182 | case TYPE_CODE_ERROR: | |
183 | case TYPE_CODE_RANGE: | |
184 | error ("Unimplemented chill_val_print support for type %d", | |
185 | TYPE_CODE (type)); | |
186 | break; | |
187 | ||
188 | default: | |
189 | error ("Invalid Chill type code %d in symbol table.", TYPE_CODE (type)); | |
190 | } | |
191 | fflush (stream); | |
192 | return (0); | |
193 | } |