]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Perform non-arithmetic operations on values, for GDB. |
2b576293 | 2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995 |
67e9b3b3 | 3 | Free Software Foundation, Inc. |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
06b6c733 | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
06b6c733 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
06b6c733 | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
06b6c733 | 18 | along with this program; if not, write to the Free Software |
b4680522 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 | 20 | |
bd5635a1 | 21 | #include "defs.h" |
bd5635a1 | 22 | #include "symtab.h" |
01be6913 | 23 | #include "gdbtypes.h" |
bd5635a1 RP |
24 | #include "value.h" |
25 | #include "frame.h" | |
26 | #include "inferior.h" | |
27 | #include "gdbcore.h" | |
28 | #include "target.h" | |
2e4964ad | 29 | #include "demangle.h" |
54023465 | 30 | #include "language.h" |
bd5635a1 RP |
31 | |
32 | #include <errno.h> | |
2b576293 | 33 | #include "gdb_string.h" |
bd5635a1 | 34 | |
75225aa2 FF |
35 | /* Default to coercing float to double in function calls only when there is |
36 | no prototype. Otherwise on targets where the debug information is incorrect | |
37 | for either the prototype or non-prototype case, we can force it by defining | |
38 | COERCE_FLOAT_TO_DOUBLE in the target configuration file. */ | |
39 | ||
40 | #ifndef COERCE_FLOAT_TO_DOUBLE | |
41 | #define COERCE_FLOAT_TO_DOUBLE (param_type == NULL) | |
42 | #endif | |
43 | ||
bd5635a1 | 44 | /* Local functions. */ |
01be6913 | 45 | |
a91a6192 | 46 | static int typecmp PARAMS ((int staticp, struct type *t1[], value_ptr t2[])); |
01be6913 | 47 | |
a91a6192 | 48 | static CORE_ADDR find_function_addr PARAMS ((value_ptr, struct type **)); |
01be6913 | 49 | |
3f550b59 | 50 | #ifndef PUSH_ARGUMENTS |
a91a6192 | 51 | static CORE_ADDR value_push PARAMS ((CORE_ADDR, value_ptr)); |
3f550b59 | 52 | #endif |
01be6913 | 53 | |
a91a6192 SS |
54 | static value_ptr search_struct_field PARAMS ((char *, value_ptr, int, |
55 | struct type *, int)); | |
01be6913 | 56 | |
a91a6192 SS |
57 | static value_ptr search_struct_method PARAMS ((char *, value_ptr *, |
58 | value_ptr *, | |
59 | int, int *, struct type *)); | |
01be6913 | 60 | |
a91a6192 | 61 | static int check_field_in PARAMS ((struct type *, const char *)); |
a163ddec | 62 | |
a91a6192 | 63 | static CORE_ADDR allocate_space_in_inferior PARAMS ((int)); |
9ed8604f | 64 | |
5222ca60 | 65 | static value_ptr cast_into_complex PARAMS ((struct type *, value_ptr)); |
9ed8604f | 66 | |
b607efe7 FF |
67 | static value_ptr value_arg_coerce PARAMS ((value_ptr, struct type *)); |
68 | ||
9ed8604f PS |
69 | #define VALUE_SUBSTRING_START(VAL) VALUE_FRAME(VAL) |
70 | ||
5e548861 PB |
71 | /* Flag for whether we want to abandon failed expression evals by default. */ |
72 | ||
b52cac6b | 73 | #if 0 |
5e548861 | 74 | static int auto_abandon = 0; |
b52cac6b | 75 | #endif |
5e548861 | 76 | |
bd5635a1 | 77 | \f |
09af5868 | 78 | /* Find the address of function name NAME in the inferior. */ |
a163ddec | 79 | |
09af5868 PS |
80 | value_ptr |
81 | find_function_in_inferior (name) | |
82 | char *name; | |
a163ddec | 83 | { |
a163ddec | 84 | register struct symbol *sym; |
09af5868 | 85 | sym = lookup_symbol (name, 0, VAR_NAMESPACE, 0, NULL); |
a163ddec MT |
86 | if (sym != NULL) |
87 | { | |
88 | if (SYMBOL_CLASS (sym) != LOC_BLOCK) | |
89 | { | |
09af5868 PS |
90 | error ("\"%s\" exists in this program but is not a function.", |
91 | name); | |
a163ddec | 92 | } |
09af5868 | 93 | return value_of_variable (sym, NULL); |
a163ddec MT |
94 | } |
95 | else | |
96 | { | |
09af5868 | 97 | struct minimal_symbol *msymbol = lookup_minimal_symbol(name, NULL, NULL); |
a163ddec MT |
98 | if (msymbol != NULL) |
99 | { | |
09af5868 PS |
100 | struct type *type; |
101 | LONGEST maddr; | |
a163ddec MT |
102 | type = lookup_pointer_type (builtin_type_char); |
103 | type = lookup_function_type (type); | |
104 | type = lookup_pointer_type (type); | |
105 | maddr = (LONGEST) SYMBOL_VALUE_ADDRESS (msymbol); | |
09af5868 | 106 | return value_from_longest (type, maddr); |
a163ddec MT |
107 | } |
108 | else | |
109 | { | |
09af5868 | 110 | error ("evaluation of this expression requires the program to have a function \"%s\".", name); |
a163ddec MT |
111 | } |
112 | } | |
09af5868 PS |
113 | } |
114 | ||
115 | /* Allocate NBYTES of space in the inferior using the inferior's malloc | |
116 | and return a value that is a pointer to the allocated space. */ | |
117 | ||
118 | value_ptr | |
119 | value_allocate_space_in_inferior (len) | |
120 | int len; | |
121 | { | |
122 | value_ptr blocklen; | |
123 | register value_ptr val = find_function_in_inferior ("malloc"); | |
a163ddec MT |
124 | |
125 | blocklen = value_from_longest (builtin_type_int, (LONGEST) len); | |
126 | val = call_function_by_hand (val, 1, &blocklen); | |
127 | if (value_logical_not (val)) | |
128 | { | |
129 | error ("No memory available to program."); | |
130 | } | |
09af5868 PS |
131 | return val; |
132 | } | |
133 | ||
134 | static CORE_ADDR | |
135 | allocate_space_in_inferior (len) | |
136 | int len; | |
137 | { | |
138 | return value_as_long (value_allocate_space_in_inferior (len)); | |
a163ddec MT |
139 | } |
140 | ||
bd5635a1 RP |
141 | /* Cast value ARG2 to type TYPE and return as a value. |
142 | More general than a C cast: accepts any two types of the same length, | |
143 | and if ARG2 is an lvalue it can be cast into anything at all. */ | |
54023465 | 144 | /* In C++, casts may change pointer or object representations. */ |
bd5635a1 | 145 | |
a91a6192 | 146 | value_ptr |
bd5635a1 RP |
147 | value_cast (type, arg2) |
148 | struct type *type; | |
a91a6192 | 149 | register value_ptr arg2; |
bd5635a1 | 150 | { |
5e548861 | 151 | register enum type_code code1; |
bd5635a1 RP |
152 | register enum type_code code2; |
153 | register int scalar; | |
5e548861 | 154 | struct type *type2; |
bd5635a1 | 155 | |
f91a9e05 PB |
156 | if (VALUE_TYPE (arg2) == type) |
157 | return arg2; | |
158 | ||
5e548861 PB |
159 | CHECK_TYPEDEF (type); |
160 | code1 = TYPE_CODE (type); | |
f7a69ed7 | 161 | COERCE_REF(arg2); |
5e548861 | 162 | type2 = check_typedef (VALUE_TYPE (arg2)); |
13ffa6be JL |
163 | |
164 | /* A cast to an undetermined-length array_type, such as (TYPE [])OBJECT, | |
165 | is treated like a cast to (TYPE [N])OBJECT, | |
166 | where N is sizeof(OBJECT)/sizeof(TYPE). */ | |
5e548861 | 167 | if (code1 == TYPE_CODE_ARRAY) |
13ffa6be JL |
168 | { |
169 | struct type *element_type = TYPE_TARGET_TYPE (type); | |
5e548861 PB |
170 | unsigned element_length = TYPE_LENGTH (check_typedef (element_type)); |
171 | if (element_length > 0 | |
172 | && TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED) | |
173 | { | |
174 | struct type *range_type = TYPE_INDEX_TYPE (type); | |
175 | int val_length = TYPE_LENGTH (type2); | |
176 | LONGEST low_bound, high_bound, new_length; | |
177 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) | |
178 | low_bound = 0, high_bound = 0; | |
179 | new_length = val_length / element_length; | |
180 | if (val_length % element_length != 0) | |
181 | warning("array element type size does not divide object size in cast"); | |
182 | /* FIXME-type-allocation: need a way to free this type when we are | |
183 | done with it. */ | |
184 | range_type = create_range_type ((struct type *) NULL, | |
185 | TYPE_TARGET_TYPE (range_type), | |
186 | low_bound, | |
187 | new_length + low_bound - 1); | |
188 | VALUE_TYPE (arg2) = create_array_type ((struct type *) NULL, | |
189 | element_type, range_type); | |
190 | return arg2; | |
191 | } | |
13ffa6be | 192 | } |
9ed8604f | 193 | |
f7a69ed7 | 194 | if (current_language->c_style_arrays |
5e548861 | 195 | && TYPE_CODE (type2) == TYPE_CODE_ARRAY) |
e70bba9f | 196 | arg2 = value_coerce_array (arg2); |
f7a69ed7 | 197 | |
5e548861 | 198 | if (TYPE_CODE (type2) == TYPE_CODE_FUNC) |
f7a69ed7 PB |
199 | arg2 = value_coerce_function (arg2); |
200 | ||
5e548861 PB |
201 | type2 = check_typedef (VALUE_TYPE (arg2)); |
202 | COERCE_VARYING_ARRAY (arg2, type2); | |
203 | code2 = TYPE_CODE (type2); | |
f7a69ed7 | 204 | |
34cfa2da PB |
205 | if (code1 == TYPE_CODE_COMPLEX) |
206 | return cast_into_complex (type, arg2); | |
207 | if (code1 == TYPE_CODE_BOOL || code1 == TYPE_CODE_CHAR) | |
f7a69ed7 | 208 | code1 = TYPE_CODE_INT; |
34cfa2da | 209 | if (code2 == TYPE_CODE_BOOL || code2 == TYPE_CODE_CHAR) |
f7a69ed7 PB |
210 | code2 = TYPE_CODE_INT; |
211 | ||
bd5635a1 | 212 | scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT |
f91a9e05 | 213 | || code2 == TYPE_CODE_ENUM || code2 == TYPE_CODE_RANGE); |
bd5635a1 | 214 | |
54023465 JK |
215 | if ( code1 == TYPE_CODE_STRUCT |
216 | && code2 == TYPE_CODE_STRUCT | |
217 | && TYPE_NAME (type) != 0) | |
218 | { | |
219 | /* Look in the type of the source to see if it contains the | |
220 | type of the target as a superclass. If so, we'll need to | |
221 | offset the object in addition to changing its type. */ | |
a91a6192 | 222 | value_ptr v = search_struct_field (type_name_no_tag (type), |
5e548861 | 223 | arg2, 0, type2, 1); |
54023465 JK |
224 | if (v) |
225 | { | |
226 | VALUE_TYPE (v) = type; | |
227 | return v; | |
228 | } | |
229 | } | |
bd5635a1 RP |
230 | if (code1 == TYPE_CODE_FLT && scalar) |
231 | return value_from_double (type, value_as_double (arg2)); | |
f91a9e05 PB |
232 | else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM |
233 | || code1 == TYPE_CODE_RANGE) | |
bd5635a1 | 234 | && (scalar || code2 == TYPE_CODE_PTR)) |
06b6c733 | 235 | return value_from_longest (type, value_as_long (arg2)); |
5e548861 | 236 | else if (TYPE_LENGTH (type) == TYPE_LENGTH (type2)) |
bd5635a1 RP |
237 | { |
238 | if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR) | |
239 | { | |
240 | /* Look in the type of the source to see if it contains the | |
241 | type of the target as a superclass. If so, we'll need to | |
242 | offset the pointer rather than just change its type. */ | |
5e548861 PB |
243 | struct type *t1 = check_typedef (TYPE_TARGET_TYPE (type)); |
244 | struct type *t2 = check_typedef (TYPE_TARGET_TYPE (type2)); | |
2a5ec41d | 245 | if ( TYPE_CODE (t1) == TYPE_CODE_STRUCT |
bd5635a1 RP |
246 | && TYPE_CODE (t2) == TYPE_CODE_STRUCT |
247 | && TYPE_NAME (t1) != 0) /* if name unknown, can't have supercl */ | |
248 | { | |
a91a6192 SS |
249 | value_ptr v = search_struct_field (type_name_no_tag (t1), |
250 | value_ind (arg2), 0, t2, 1); | |
bd5635a1 RP |
251 | if (v) |
252 | { | |
253 | v = value_addr (v); | |
254 | VALUE_TYPE (v) = type; | |
255 | return v; | |
256 | } | |
257 | } | |
258 | /* No superclass found, just fall through to change ptr type. */ | |
259 | } | |
260 | VALUE_TYPE (arg2) = type; | |
261 | return arg2; | |
262 | } | |
f91a9e05 PB |
263 | else if (chill_varying_type (type)) |
264 | { | |
265 | struct type *range1, *range2, *eltype1, *eltype2; | |
266 | value_ptr val; | |
267 | int count1, count2; | |
5e548861 | 268 | LONGEST low_bound, high_bound; |
f91a9e05 PB |
269 | char *valaddr, *valaddr_data; |
270 | if (code2 == TYPE_CODE_BITSTRING) | |
271 | error ("not implemented: converting bitstring to varying type"); | |
272 | if ((code2 != TYPE_CODE_ARRAY && code2 != TYPE_CODE_STRING) | |
5e548861 PB |
273 | || (eltype1 = check_typedef (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 1))), |
274 | eltype2 = check_typedef (TYPE_TARGET_TYPE (type2)), | |
f91a9e05 PB |
275 | (TYPE_LENGTH (eltype1) != TYPE_LENGTH (eltype2) |
276 | /* || TYPE_CODE (eltype1) != TYPE_CODE (eltype2) */ ))) | |
277 | error ("Invalid conversion to varying type"); | |
278 | range1 = TYPE_FIELD_TYPE (TYPE_FIELD_TYPE (type, 1), 0); | |
5e548861 PB |
279 | range2 = TYPE_FIELD_TYPE (type2, 0); |
280 | if (get_discrete_bounds (range1, &low_bound, &high_bound) < 0) | |
281 | count1 = -1; | |
282 | else | |
283 | count1 = high_bound - low_bound + 1; | |
284 | if (get_discrete_bounds (range2, &low_bound, &high_bound) < 0) | |
285 | count1 = -1, count2 = 0; /* To force error before */ | |
286 | else | |
287 | count2 = high_bound - low_bound + 1; | |
f91a9e05 PB |
288 | if (count2 > count1) |
289 | error ("target varying type is too small"); | |
290 | val = allocate_value (type); | |
291 | valaddr = VALUE_CONTENTS_RAW (val); | |
292 | valaddr_data = valaddr + TYPE_FIELD_BITPOS (type, 1) / 8; | |
293 | /* Set val's __var_length field to count2. */ | |
294 | store_signed_integer (valaddr, TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)), | |
295 | count2); | |
296 | /* Set the __var_data field to count2 elements copied from arg2. */ | |
297 | memcpy (valaddr_data, VALUE_CONTENTS (arg2), | |
298 | count2 * TYPE_LENGTH (eltype2)); | |
299 | /* Zero the rest of the __var_data field of val. */ | |
300 | memset (valaddr_data + count2 * TYPE_LENGTH (eltype2), '\0', | |
301 | (count1 - count2) * TYPE_LENGTH (eltype2)); | |
302 | return val; | |
303 | } | |
bd5635a1 RP |
304 | else if (VALUE_LVAL (arg2) == lval_memory) |
305 | { | |
306 | return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2)); | |
307 | } | |
d11c44f1 JG |
308 | else if (code1 == TYPE_CODE_VOID) |
309 | { | |
310 | return value_zero (builtin_type_void, not_lval); | |
311 | } | |
bd5635a1 RP |
312 | else |
313 | { | |
314 | error ("Invalid cast."); | |
315 | return 0; | |
316 | } | |
317 | } | |
318 | ||
319 | /* Create a value of type TYPE that is zero, and return it. */ | |
320 | ||
a91a6192 | 321 | value_ptr |
bd5635a1 RP |
322 | value_zero (type, lv) |
323 | struct type *type; | |
324 | enum lval_type lv; | |
325 | { | |
a91a6192 | 326 | register value_ptr val = allocate_value (type); |
bd5635a1 | 327 | |
5e548861 | 328 | memset (VALUE_CONTENTS (val), 0, TYPE_LENGTH (check_typedef (type))); |
bd5635a1 RP |
329 | VALUE_LVAL (val) = lv; |
330 | ||
331 | return val; | |
332 | } | |
333 | ||
334 | /* Return a value with type TYPE located at ADDR. | |
335 | ||
336 | Call value_at only if the data needs to be fetched immediately; | |
337 | if we can be 'lazy' and defer the fetch, perhaps indefinately, call | |
338 | value_at_lazy instead. value_at_lazy simply records the address of | |
339 | the data and sets the lazy-evaluation-required flag. The lazy flag | |
340 | is tested in the VALUE_CONTENTS macro, which is used if and when | |
341 | the contents are actually required. */ | |
342 | ||
a91a6192 | 343 | value_ptr |
bd5635a1 RP |
344 | value_at (type, addr) |
345 | struct type *type; | |
346 | CORE_ADDR addr; | |
347 | { | |
a91a6192 SS |
348 | register value_ptr val; |
349 | ||
5e548861 | 350 | if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID) |
a91a6192 SS |
351 | error ("Attempt to dereference a generic pointer."); |
352 | ||
353 | val = allocate_value (type); | |
bd5635a1 RP |
354 | |
355 | read_memory (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (type)); | |
356 | ||
357 | VALUE_LVAL (val) = lval_memory; | |
358 | VALUE_ADDRESS (val) = addr; | |
359 | ||
360 | return val; | |
361 | } | |
362 | ||
363 | /* Return a lazy value with type TYPE located at ADDR (cf. value_at). */ | |
364 | ||
a91a6192 | 365 | value_ptr |
bd5635a1 RP |
366 | value_at_lazy (type, addr) |
367 | struct type *type; | |
368 | CORE_ADDR addr; | |
369 | { | |
a91a6192 SS |
370 | register value_ptr val; |
371 | ||
5e548861 | 372 | if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID) |
a91a6192 SS |
373 | error ("Attempt to dereference a generic pointer."); |
374 | ||
375 | val = allocate_value (type); | |
bd5635a1 RP |
376 | |
377 | VALUE_LVAL (val) = lval_memory; | |
378 | VALUE_ADDRESS (val) = addr; | |
379 | VALUE_LAZY (val) = 1; | |
380 | ||
381 | return val; | |
382 | } | |
383 | ||
384 | /* Called only from the VALUE_CONTENTS macro, if the current data for | |
385 | a variable needs to be loaded into VALUE_CONTENTS(VAL). Fetches the | |
386 | data from the user's process, and clears the lazy flag to indicate | |
387 | that the data in the buffer is valid. | |
388 | ||
9cb602e1 JG |
389 | If the value is zero-length, we avoid calling read_memory, which would |
390 | abort. We mark the value as fetched anyway -- all 0 bytes of it. | |
391 | ||
bd5635a1 RP |
392 | This function returns a value because it is used in the VALUE_CONTENTS |
393 | macro as part of an expression, where a void would not work. The | |
394 | value is ignored. */ | |
395 | ||
396 | int | |
397 | value_fetch_lazy (val) | |
a91a6192 | 398 | register value_ptr val; |
bd5635a1 RP |
399 | { |
400 | CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val); | |
5e548861 | 401 | int length = TYPE_LENGTH (VALUE_TYPE (val)); |
bd5635a1 | 402 | |
5e548861 PB |
403 | if (length) |
404 | read_memory (addr, VALUE_CONTENTS_RAW (val), length); | |
bd5635a1 RP |
405 | VALUE_LAZY (val) = 0; |
406 | return 0; | |
407 | } | |
408 | ||
409 | ||
410 | /* Store the contents of FROMVAL into the location of TOVAL. | |
411 | Return a new value with the location of TOVAL and contents of FROMVAL. */ | |
412 | ||
a91a6192 | 413 | value_ptr |
bd5635a1 | 414 | value_assign (toval, fromval) |
a91a6192 | 415 | register value_ptr toval, fromval; |
bd5635a1 | 416 | { |
67e9b3b3 | 417 | register struct type *type; |
a91a6192 | 418 | register value_ptr val; |
bd5635a1 | 419 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; |
bd5635a1 RP |
420 | int use_buffer = 0; |
421 | ||
30974778 JK |
422 | if (!toval->modifiable) |
423 | error ("Left operand of assignment is not a modifiable lvalue."); | |
424 | ||
8e9a3f3b | 425 | COERCE_REF (toval); |
bd5635a1 | 426 | |
67e9b3b3 | 427 | type = VALUE_TYPE (toval); |
bd5635a1 RP |
428 | if (VALUE_LVAL (toval) != lval_internalvar) |
429 | fromval = value_cast (type, fromval); | |
aa220473 SG |
430 | else |
431 | COERCE_ARRAY (fromval); | |
5e548861 | 432 | CHECK_TYPEDEF (type); |
bd5635a1 RP |
433 | |
434 | /* If TOVAL is a special machine register requiring conversion | |
435 | of program values to a special raw format, | |
436 | convert FROMVAL's contents now, with result in `raw_buffer', | |
437 | and set USE_BUFFER to the number of bytes to write. */ | |
438 | ||
ad09cb2b | 439 | #ifdef REGISTER_CONVERTIBLE |
bd5635a1 RP |
440 | if (VALUE_REGNO (toval) >= 0 |
441 | && REGISTER_CONVERTIBLE (VALUE_REGNO (toval))) | |
442 | { | |
443 | int regno = VALUE_REGNO (toval); | |
ad09cb2b PS |
444 | if (REGISTER_CONVERTIBLE (regno)) |
445 | { | |
5e548861 PB |
446 | struct type *fromtype = check_typedef (VALUE_TYPE (fromval)); |
447 | REGISTER_CONVERT_TO_RAW (fromtype, regno, | |
ad09cb2b PS |
448 | VALUE_CONTENTS (fromval), raw_buffer); |
449 | use_buffer = REGISTER_RAW_SIZE (regno); | |
450 | } | |
bd5635a1 | 451 | } |
ad09cb2b | 452 | #endif |
bd5635a1 RP |
453 | |
454 | switch (VALUE_LVAL (toval)) | |
455 | { | |
456 | case lval_internalvar: | |
457 | set_internalvar (VALUE_INTERNALVAR (toval), fromval); | |
75225aa2 | 458 | return value_copy (VALUE_INTERNALVAR (toval)->value); |
bd5635a1 RP |
459 | |
460 | case lval_internalvar_component: | |
461 | set_internalvar_component (VALUE_INTERNALVAR (toval), | |
462 | VALUE_OFFSET (toval), | |
463 | VALUE_BITPOS (toval), | |
464 | VALUE_BITSIZE (toval), | |
465 | fromval); | |
466 | break; | |
467 | ||
468 | case lval_memory: | |
469 | if (VALUE_BITSIZE (toval)) | |
470 | { | |
4d52ec86 JK |
471 | char buffer[sizeof (LONGEST)]; |
472 | /* We assume that the argument to read_memory is in units of | |
473 | host chars. FIXME: Is that correct? */ | |
474 | int len = (VALUE_BITPOS (toval) | |
475 | + VALUE_BITSIZE (toval) | |
476 | + HOST_CHAR_BIT - 1) | |
477 | / HOST_CHAR_BIT; | |
ad09cb2b | 478 | |
b52cac6b | 479 | if (len > (int) sizeof (LONGEST)) |
ad09cb2b PS |
480 | error ("Can't handle bitfields which don't fit in a %d bit word.", |
481 | sizeof (LONGEST) * HOST_CHAR_BIT); | |
4d52ec86 | 482 | |
bd5635a1 | 483 | read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), |
4d52ec86 JK |
484 | buffer, len); |
485 | modify_field (buffer, value_as_long (fromval), | |
bd5635a1 RP |
486 | VALUE_BITPOS (toval), VALUE_BITSIZE (toval)); |
487 | write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), | |
4d52ec86 | 488 | buffer, len); |
bd5635a1 RP |
489 | } |
490 | else if (use_buffer) | |
491 | write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), | |
492 | raw_buffer, use_buffer); | |
493 | else | |
494 | write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), | |
495 | VALUE_CONTENTS (fromval), TYPE_LENGTH (type)); | |
496 | break; | |
497 | ||
498 | case lval_register: | |
499 | if (VALUE_BITSIZE (toval)) | |
500 | { | |
ad09cb2b | 501 | char buffer[sizeof (LONGEST)]; |
4d52ec86 | 502 | int len = REGISTER_RAW_SIZE (VALUE_REGNO (toval)); |
ad09cb2b | 503 | |
b52cac6b | 504 | if (len > (int) sizeof (LONGEST)) |
ad09cb2b PS |
505 | error ("Can't handle bitfields in registers larger than %d bits.", |
506 | sizeof (LONGEST) * HOST_CHAR_BIT); | |
507 | ||
508 | if (VALUE_BITPOS (toval) + VALUE_BITSIZE (toval) | |
509 | > len * HOST_CHAR_BIT) | |
510 | /* Getting this right would involve being very careful about | |
511 | byte order. */ | |
512 | error ("\ | |
513 | Can't handle bitfield which doesn't fit in a single register."); | |
514 | ||
4d52ec86 JK |
515 | read_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), |
516 | buffer, len); | |
517 | modify_field (buffer, value_as_long (fromval), | |
518 | VALUE_BITPOS (toval), VALUE_BITSIZE (toval)); | |
519 | write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), | |
520 | buffer, len); | |
bd5635a1 RP |
521 | } |
522 | else if (use_buffer) | |
523 | write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), | |
524 | raw_buffer, use_buffer); | |
525 | else | |
54023465 JK |
526 | { |
527 | /* Do any conversion necessary when storing this type to more | |
528 | than one register. */ | |
529 | #ifdef REGISTER_CONVERT_FROM_TYPE | |
530 | memcpy (raw_buffer, VALUE_CONTENTS (fromval), TYPE_LENGTH (type)); | |
531 | REGISTER_CONVERT_FROM_TYPE(VALUE_REGNO (toval), type, raw_buffer); | |
532 | write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), | |
533 | raw_buffer, TYPE_LENGTH (type)); | |
534 | #else | |
535 | write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), | |
536 | VALUE_CONTENTS (fromval), TYPE_LENGTH (type)); | |
537 | #endif | |
538 | } | |
79971d11 JK |
539 | /* Assigning to the stack pointer, frame pointer, and other |
540 | (architecture and calling convention specific) registers may | |
541 | cause the frame cache to be out of date. We just do this | |
542 | on all assignments to registers for simplicity; I doubt the slowdown | |
543 | matters. */ | |
544 | reinit_frame_cache (); | |
bd5635a1 RP |
545 | break; |
546 | ||
547 | case lval_reg_frame_relative: | |
548 | { | |
549 | /* value is stored in a series of registers in the frame | |
550 | specified by the structure. Copy that value out, modify | |
551 | it, and copy it back in. */ | |
552 | int amount_to_copy = (VALUE_BITSIZE (toval) ? 1 : TYPE_LENGTH (type)); | |
553 | int reg_size = REGISTER_RAW_SIZE (VALUE_FRAME_REGNUM (toval)); | |
554 | int byte_offset = VALUE_OFFSET (toval) % reg_size; | |
555 | int reg_offset = VALUE_OFFSET (toval) / reg_size; | |
556 | int amount_copied; | |
4d52ec86 JK |
557 | |
558 | /* Make the buffer large enough in all cases. */ | |
559 | char *buffer = (char *) alloca (amount_to_copy | |
560 | + sizeof (LONGEST) | |
561 | + MAX_REGISTER_RAW_SIZE); | |
562 | ||
bd5635a1 | 563 | int regno; |
6d34c236 | 564 | struct frame_info *frame; |
bd5635a1 RP |
565 | |
566 | /* Figure out which frame this is in currently. */ | |
567 | for (frame = get_current_frame (); | |
568 | frame && FRAME_FP (frame) != VALUE_FRAME (toval); | |
569 | frame = get_prev_frame (frame)) | |
570 | ; | |
571 | ||
572 | if (!frame) | |
573 | error ("Value being assigned to is no longer active."); | |
574 | ||
575 | amount_to_copy += (reg_size - amount_to_copy % reg_size); | |
576 | ||
577 | /* Copy it out. */ | |
578 | for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset, | |
579 | amount_copied = 0); | |
580 | amount_copied < amount_to_copy; | |
581 | amount_copied += reg_size, regno++) | |
582 | { | |
583 | get_saved_register (buffer + amount_copied, | |
51b57ded | 584 | (int *)NULL, (CORE_ADDR *)NULL, |
bd5635a1 RP |
585 | frame, regno, (enum lval_type *)NULL); |
586 | } | |
587 | ||
588 | /* Modify what needs to be modified. */ | |
589 | if (VALUE_BITSIZE (toval)) | |
590 | modify_field (buffer + byte_offset, | |
479fdd26 | 591 | value_as_long (fromval), |
bd5635a1 RP |
592 | VALUE_BITPOS (toval), VALUE_BITSIZE (toval)); |
593 | else if (use_buffer) | |
4ed3a9ea | 594 | memcpy (buffer + byte_offset, raw_buffer, use_buffer); |
bd5635a1 | 595 | else |
4ed3a9ea FF |
596 | memcpy (buffer + byte_offset, VALUE_CONTENTS (fromval), |
597 | TYPE_LENGTH (type)); | |
bd5635a1 RP |
598 | |
599 | /* Copy it back. */ | |
600 | for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset, | |
601 | amount_copied = 0); | |
602 | amount_copied < amount_to_copy; | |
603 | amount_copied += reg_size, regno++) | |
604 | { | |
605 | enum lval_type lval; | |
606 | CORE_ADDR addr; | |
607 | int optim; | |
608 | ||
609 | /* Just find out where to put it. */ | |
610 | get_saved_register ((char *)NULL, | |
611 | &optim, &addr, frame, regno, &lval); | |
612 | ||
613 | if (optim) | |
614 | error ("Attempt to assign to a value that was optimized out."); | |
615 | if (lval == lval_memory) | |
616 | write_memory (addr, buffer + amount_copied, reg_size); | |
617 | else if (lval == lval_register) | |
618 | write_register_bytes (addr, buffer + amount_copied, reg_size); | |
619 | else | |
620 | error ("Attempt to assign to an unmodifiable value."); | |
621 | } | |
622 | } | |
623 | break; | |
624 | ||
625 | ||
626 | default: | |
30974778 | 627 | error ("Left operand of assignment is not an lvalue."); |
bd5635a1 RP |
628 | } |
629 | ||
b4680522 PB |
630 | /* If the field does not entirely fill a LONGEST, then zero the sign bits. |
631 | If the field is signed, and is negative, then sign extend. */ | |
632 | if ((VALUE_BITSIZE (toval) > 0) | |
b52cac6b | 633 | && (VALUE_BITSIZE (toval) < 8 * (int) sizeof (LONGEST))) |
b4680522 PB |
634 | { |
635 | LONGEST fieldval = value_as_long (fromval); | |
636 | LONGEST valmask = (((unsigned LONGEST) 1) << VALUE_BITSIZE (toval)) - 1; | |
637 | ||
638 | fieldval &= valmask; | |
639 | if (!TYPE_UNSIGNED (type) && (fieldval & (valmask ^ (valmask >> 1)))) | |
640 | fieldval |= ~valmask; | |
641 | ||
642 | fromval = value_from_longest (type, fieldval); | |
643 | } | |
644 | ||
b4680522 | 645 | val = value_copy (toval); |
4ed3a9ea FF |
646 | memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval), |
647 | TYPE_LENGTH (type)); | |
bd5635a1 RP |
648 | VALUE_TYPE (val) = type; |
649 | ||
650 | return val; | |
651 | } | |
652 | ||
653 | /* Extend a value VAL to COUNT repetitions of its type. */ | |
654 | ||
a91a6192 | 655 | value_ptr |
bd5635a1 | 656 | value_repeat (arg1, count) |
a91a6192 | 657 | value_ptr arg1; |
bd5635a1 RP |
658 | int count; |
659 | { | |
a91a6192 | 660 | register value_ptr val; |
bd5635a1 RP |
661 | |
662 | if (VALUE_LVAL (arg1) != lval_memory) | |
663 | error ("Only values in memory can be extended with '@'."); | |
664 | if (count < 1) | |
665 | error ("Invalid number %d of repetitions.", count); | |
666 | ||
667 | val = allocate_repeat_value (VALUE_TYPE (arg1), count); | |
668 | ||
669 | read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1), | |
670 | VALUE_CONTENTS_RAW (val), | |
09af5868 | 671 | TYPE_LENGTH (VALUE_TYPE (val))); |
bd5635a1 RP |
672 | VALUE_LVAL (val) = lval_memory; |
673 | VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1); | |
674 | ||
675 | return val; | |
676 | } | |
677 | ||
a91a6192 | 678 | value_ptr |
479fdd26 | 679 | value_of_variable (var, b) |
bd5635a1 | 680 | struct symbol *var; |
479fdd26 | 681 | struct block *b; |
bd5635a1 | 682 | { |
a91a6192 | 683 | value_ptr val; |
6d34c236 | 684 | struct frame_info *frame; |
bd5635a1 | 685 | |
479fdd26 JK |
686 | if (b == NULL) |
687 | /* Use selected frame. */ | |
6d34c236 | 688 | frame = NULL; |
479fdd26 JK |
689 | else |
690 | { | |
6d34c236 PB |
691 | frame = block_innermost_frame (b); |
692 | if (frame == NULL && symbol_read_needs_frame (var)) | |
479fdd26 JK |
693 | { |
694 | if (BLOCK_FUNCTION (b) != NULL | |
695 | && SYMBOL_NAME (BLOCK_FUNCTION (b)) != NULL) | |
696 | error ("No frame is currently executing in block %s.", | |
697 | SYMBOL_NAME (BLOCK_FUNCTION (b))); | |
698 | else | |
699 | error ("No frame is currently executing in specified block"); | |
700 | } | |
701 | } | |
6d34c236 | 702 | val = read_var_value (var, frame); |
bd5635a1 | 703 | if (val == 0) |
2e4964ad | 704 | error ("Address of symbol \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var)); |
bd5635a1 RP |
705 | return val; |
706 | } | |
707 | ||
a163ddec MT |
708 | /* Given a value which is an array, return a value which is a pointer to its |
709 | first element, regardless of whether or not the array has a nonzero lower | |
710 | bound. | |
711 | ||
712 | FIXME: A previous comment here indicated that this routine should be | |
713 | substracting the array's lower bound. It's not clear to me that this | |
714 | is correct. Given an array subscripting operation, it would certainly | |
715 | work to do the adjustment here, essentially computing: | |
716 | ||
717 | (&array[0] - (lowerbound * sizeof array[0])) + (index * sizeof array[0]) | |
718 | ||
719 | However I believe a more appropriate and logical place to account for | |
720 | the lower bound is to do so in value_subscript, essentially computing: | |
721 | ||
722 | (&array[0] + ((index - lowerbound) * sizeof array[0])) | |
723 | ||
724 | As further evidence consider what would happen with operations other | |
725 | than array subscripting, where the caller would get back a value that | |
726 | had an address somewhere before the actual first element of the array, | |
727 | and the information about the lower bound would be lost because of | |
728 | the coercion to pointer type. | |
729 | */ | |
bd5635a1 | 730 | |
a91a6192 | 731 | value_ptr |
bd5635a1 | 732 | value_coerce_array (arg1) |
a91a6192 | 733 | value_ptr arg1; |
bd5635a1 | 734 | { |
5e548861 | 735 | register struct type *type = check_typedef (VALUE_TYPE (arg1)); |
bd5635a1 RP |
736 | |
737 | if (VALUE_LVAL (arg1) != lval_memory) | |
738 | error ("Attempt to take address of value not located in memory."); | |
739 | ||
5e548861 | 740 | return value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type)), |
bd5635a1 | 741 | (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1))); |
bd5635a1 RP |
742 | } |
743 | ||
744 | /* Given a value which is a function, return a value which is a pointer | |
745 | to it. */ | |
746 | ||
a91a6192 | 747 | value_ptr |
bd5635a1 | 748 | value_coerce_function (arg1) |
a91a6192 | 749 | value_ptr arg1; |
bd5635a1 | 750 | { |
bd5635a1 RP |
751 | |
752 | if (VALUE_LVAL (arg1) != lval_memory) | |
753 | error ("Attempt to take address of value not located in memory."); | |
754 | ||
06b6c733 | 755 | return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)), |
bd5635a1 | 756 | (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1))); |
bd5635a1 RP |
757 | } |
758 | ||
759 | /* Return a pointer value for the object for which ARG1 is the contents. */ | |
760 | ||
a91a6192 | 761 | value_ptr |
bd5635a1 | 762 | value_addr (arg1) |
a91a6192 | 763 | value_ptr arg1; |
bd5635a1 | 764 | { |
5e548861 | 765 | struct type *type = check_typedef (VALUE_TYPE (arg1)); |
8e9a3f3b PB |
766 | if (TYPE_CODE (type) == TYPE_CODE_REF) |
767 | { | |
768 | /* Copy the value, but change the type from (T&) to (T*). | |
769 | We keep the same location information, which is efficient, | |
770 | and allows &(&X) to get the location containing the reference. */ | |
a91a6192 | 771 | value_ptr arg2 = value_copy (arg1); |
8e9a3f3b PB |
772 | VALUE_TYPE (arg2) = lookup_pointer_type (TYPE_TARGET_TYPE (type)); |
773 | return arg2; | |
774 | } | |
8e9a3f3b | 775 | if (TYPE_CODE (type) == TYPE_CODE_FUNC) |
bd5635a1 RP |
776 | return value_coerce_function (arg1); |
777 | ||
778 | if (VALUE_LVAL (arg1) != lval_memory) | |
779 | error ("Attempt to take address of value not located in memory."); | |
780 | ||
5e548861 | 781 | return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)), |
bd5635a1 | 782 | (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1))); |
bd5635a1 RP |
783 | } |
784 | ||
785 | /* Given a value of a pointer type, apply the C unary * operator to it. */ | |
786 | ||
a91a6192 | 787 | value_ptr |
bd5635a1 | 788 | value_ind (arg1) |
a91a6192 | 789 | value_ptr arg1; |
bd5635a1 | 790 | { |
5e548861 | 791 | struct type *type1; |
bd5635a1 | 792 | COERCE_ARRAY (arg1); |
5e548861 | 793 | type1 = check_typedef (VALUE_TYPE (arg1)); |
bd5635a1 | 794 | |
5e548861 | 795 | if (TYPE_CODE (type1) == TYPE_CODE_MEMBER) |
bd5635a1 RP |
796 | error ("not implemented: member types in value_ind"); |
797 | ||
798 | /* Allow * on an integer so we can cast it to whatever we want. | |
799 | This returns an int, which seems like the most C-like thing | |
800 | to do. "long long" variables are rare enough that | |
801 | BUILTIN_TYPE_LONGEST would seem to be a mistake. */ | |
5e548861 | 802 | if (TYPE_CODE (type1) == TYPE_CODE_INT) |
bd5635a1 RP |
803 | return value_at (builtin_type_int, |
804 | (CORE_ADDR) value_as_long (arg1)); | |
5e548861 PB |
805 | else if (TYPE_CODE (type1) == TYPE_CODE_PTR) |
806 | return value_at_lazy (TYPE_TARGET_TYPE (type1), value_as_pointer (arg1)); | |
bd5635a1 RP |
807 | error ("Attempt to take contents of a non-pointer value."); |
808 | return 0; /* For lint -- never reached */ | |
809 | } | |
810 | \f | |
811 | /* Pushing small parts of stack frames. */ | |
812 | ||
813 | /* Push one word (the size of object that a register holds). */ | |
814 | ||
815 | CORE_ADDR | |
34df79fc | 816 | push_word (sp, word) |
bd5635a1 | 817 | CORE_ADDR sp; |
67e9b3b3 | 818 | unsigned LONGEST word; |
bd5635a1 | 819 | { |
67e9b3b3 | 820 | register int len = REGISTER_SIZE; |
479fdd26 | 821 | char buffer[MAX_REGISTER_RAW_SIZE]; |
bd5635a1 | 822 | |
479fdd26 | 823 | store_unsigned_integer (buffer, len, word); |
bd5635a1 RP |
824 | #if 1 INNER_THAN 2 |
825 | sp -= len; | |
479fdd26 | 826 | write_memory (sp, buffer, len); |
bd5635a1 | 827 | #else /* stack grows upward */ |
479fdd26 | 828 | write_memory (sp, buffer, len); |
bd5635a1 RP |
829 | sp += len; |
830 | #endif /* stack grows upward */ | |
831 | ||
832 | return sp; | |
833 | } | |
834 | ||
835 | /* Push LEN bytes with data at BUFFER. */ | |
836 | ||
837 | CORE_ADDR | |
838 | push_bytes (sp, buffer, len) | |
839 | CORE_ADDR sp; | |
840 | char *buffer; | |
841 | int len; | |
842 | { | |
843 | #if 1 INNER_THAN 2 | |
844 | sp -= len; | |
845 | write_memory (sp, buffer, len); | |
846 | #else /* stack grows upward */ | |
847 | write_memory (sp, buffer, len); | |
848 | sp += len; | |
849 | #endif /* stack grows upward */ | |
850 | ||
851 | return sp; | |
852 | } | |
853 | ||
854 | /* Push onto the stack the specified value VALUE. */ | |
855 | ||
3f550b59 FF |
856 | #ifndef PUSH_ARGUMENTS |
857 | ||
01be6913 | 858 | static CORE_ADDR |
bd5635a1 RP |
859 | value_push (sp, arg) |
860 | register CORE_ADDR sp; | |
a91a6192 | 861 | value_ptr arg; |
bd5635a1 RP |
862 | { |
863 | register int len = TYPE_LENGTH (VALUE_TYPE (arg)); | |
864 | ||
865 | #if 1 INNER_THAN 2 | |
866 | sp -= len; | |
867 | write_memory (sp, VALUE_CONTENTS (arg), len); | |
868 | #else /* stack grows upward */ | |
869 | write_memory (sp, VALUE_CONTENTS (arg), len); | |
870 | sp += len; | |
871 | #endif /* stack grows upward */ | |
872 | ||
873 | return sp; | |
874 | } | |
875 | ||
3f550b59 FF |
876 | #endif /* !PUSH_ARGUMENTS */ |
877 | ||
bd5635a1 | 878 | /* Perform the standard coercions that are specified |
5222ca60 | 879 | for arguments to be passed to C functions. |
bd5635a1 | 880 | |
5222ca60 PB |
881 | If PARAM_TYPE is non-NULL, it is the expected parameter type. */ |
882 | ||
883 | static value_ptr | |
884 | value_arg_coerce (arg, param_type) | |
a91a6192 | 885 | value_ptr arg; |
5222ca60 | 886 | struct type *param_type; |
bd5635a1 | 887 | { |
5e548861 PB |
888 | register struct type *arg_type = check_typedef (VALUE_TYPE (arg)); |
889 | register struct type *type | |
890 | = param_type ? check_typedef (param_type) : arg_type; | |
bd5635a1 | 891 | |
5222ca60 PB |
892 | switch (TYPE_CODE (type)) |
893 | { | |
894 | case TYPE_CODE_REF: | |
5e548861 | 895 | if (TYPE_CODE (arg_type) != TYPE_CODE_REF) |
5222ca60 PB |
896 | { |
897 | arg = value_addr (arg); | |
898 | VALUE_TYPE (arg) = param_type; | |
899 | return arg; | |
900 | } | |
901 | break; | |
902 | case TYPE_CODE_INT: | |
903 | case TYPE_CODE_CHAR: | |
904 | case TYPE_CODE_BOOL: | |
905 | case TYPE_CODE_ENUM: | |
906 | if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int)) | |
907 | type = builtin_type_int; | |
908 | break; | |
aa220473 SG |
909 | case TYPE_CODE_FLT: |
910 | /* coerce float to double, unless the function prototype specifies float */ | |
75225aa2 | 911 | if (COERCE_FLOAT_TO_DOUBLE) |
aa220473 SG |
912 | { |
913 | if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_double)) | |
914 | type = builtin_type_double; | |
915 | else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin_type_double)) | |
916 | type = builtin_type_long_double; | |
917 | } | |
918 | break; | |
5222ca60 PB |
919 | case TYPE_CODE_FUNC: |
920 | type = lookup_pointer_type (type); | |
921 | break; | |
5e548861 PB |
922 | case TYPE_CODE_ARRAY: |
923 | if (current_language->c_style_arrays) | |
924 | type = lookup_pointer_type (TYPE_TARGET_TYPE (type)); | |
925 | break; | |
2b576293 C |
926 | case TYPE_CODE_UNDEF: |
927 | case TYPE_CODE_PTR: | |
2b576293 C |
928 | case TYPE_CODE_STRUCT: |
929 | case TYPE_CODE_UNION: | |
930 | case TYPE_CODE_VOID: | |
931 | case TYPE_CODE_SET: | |
932 | case TYPE_CODE_RANGE: | |
933 | case TYPE_CODE_STRING: | |
934 | case TYPE_CODE_BITSTRING: | |
935 | case TYPE_CODE_ERROR: | |
936 | case TYPE_CODE_MEMBER: | |
937 | case TYPE_CODE_METHOD: | |
938 | case TYPE_CODE_COMPLEX: | |
939 | default: | |
940 | break; | |
5222ca60 | 941 | } |
479fdd26 | 942 | |
5222ca60 | 943 | return value_cast (type, arg); |
bd5635a1 RP |
944 | } |
945 | ||
946 | /* Determine a function's address and its return type from its value. | |
947 | Calls error() if the function is not valid for calling. */ | |
948 | ||
01be6913 | 949 | static CORE_ADDR |
bd5635a1 | 950 | find_function_addr (function, retval_type) |
a91a6192 | 951 | value_ptr function; |
bd5635a1 RP |
952 | struct type **retval_type; |
953 | { | |
5e548861 | 954 | register struct type *ftype = check_typedef (VALUE_TYPE (function)); |
bd5635a1 RP |
955 | register enum type_code code = TYPE_CODE (ftype); |
956 | struct type *value_type; | |
957 | CORE_ADDR funaddr; | |
958 | ||
959 | /* If it's a member function, just look at the function | |
960 | part of it. */ | |
961 | ||
962 | /* Determine address to call. */ | |
963 | if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD) | |
964 | { | |
965 | funaddr = VALUE_ADDRESS (function); | |
966 | value_type = TYPE_TARGET_TYPE (ftype); | |
967 | } | |
968 | else if (code == TYPE_CODE_PTR) | |
969 | { | |
d11c44f1 | 970 | funaddr = value_as_pointer (function); |
5e548861 PB |
971 | ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); |
972 | if (TYPE_CODE (ftype) == TYPE_CODE_FUNC | |
973 | || TYPE_CODE (ftype) == TYPE_CODE_METHOD) | |
9ed8604f PS |
974 | { |
975 | #ifdef CONVERT_FROM_FUNC_PTR_ADDR | |
976 | /* FIXME: This is a workaround for the unusual function | |
977 | pointer representation on the RS/6000, see comment | |
978 | in config/rs6000/tm-rs6000.h */ | |
979 | funaddr = CONVERT_FROM_FUNC_PTR_ADDR (funaddr); | |
980 | #endif | |
5e548861 | 981 | value_type = TYPE_TARGET_TYPE (ftype); |
9ed8604f | 982 | } |
bd5635a1 RP |
983 | else |
984 | value_type = builtin_type_int; | |
985 | } | |
986 | else if (code == TYPE_CODE_INT) | |
987 | { | |
988 | /* Handle the case of functions lacking debugging info. | |
989 | Their values are characters since their addresses are char */ | |
990 | if (TYPE_LENGTH (ftype) == 1) | |
d11c44f1 | 991 | funaddr = value_as_pointer (value_addr (function)); |
bd5635a1 RP |
992 | else |
993 | /* Handle integer used as address of a function. */ | |
d11c44f1 | 994 | funaddr = (CORE_ADDR) value_as_long (function); |
bd5635a1 RP |
995 | |
996 | value_type = builtin_type_int; | |
997 | } | |
998 | else | |
999 | error ("Invalid data type for function to be called."); | |
1000 | ||
1001 | *retval_type = value_type; | |
1002 | return funaddr; | |
1003 | } | |
1004 | ||
1005 | #if defined (CALL_DUMMY) | |
1006 | /* All this stuff with a dummy frame may seem unnecessarily complicated | |
1007 | (why not just save registers in GDB?). The purpose of pushing a dummy | |
1008 | frame which looks just like a real frame is so that if you call a | |
1009 | function and then hit a breakpoint (get a signal, etc), "backtrace" | |
1010 | will look right. Whether the backtrace needs to actually show the | |
1011 | stack at the time the inferior function was called is debatable, but | |
1012 | it certainly needs to not display garbage. So if you are contemplating | |
1013 | making dummy frames be different from normal frames, consider that. */ | |
1014 | ||
1015 | /* Perform a function call in the inferior. | |
1016 | ARGS is a vector of values of arguments (NARGS of them). | |
1017 | FUNCTION is a value, the function to be called. | |
1018 | Returns a value representing what the function returned. | |
1019 | May fail to return, if a breakpoint or signal is hit | |
5222ca60 PB |
1020 | during the execution of the function. |
1021 | ||
1022 | ARGS is modified to contain coerced values. */ | |
bd5635a1 | 1023 | |
a91a6192 | 1024 | value_ptr |
bd5635a1 | 1025 | call_function_by_hand (function, nargs, args) |
a91a6192 | 1026 | value_ptr function; |
bd5635a1 | 1027 | int nargs; |
a91a6192 | 1028 | value_ptr *args; |
bd5635a1 RP |
1029 | { |
1030 | register CORE_ADDR sp; | |
1031 | register int i; | |
1032 | CORE_ADDR start_sp; | |
67e9b3b3 PS |
1033 | /* CALL_DUMMY is an array of words (REGISTER_SIZE), but each word |
1034 | is in host byte order. Before calling FIX_CALL_DUMMY, we byteswap it | |
1035 | and remove any extra bytes which might exist because unsigned LONGEST is | |
1036 | bigger than REGISTER_SIZE. */ | |
1037 | static unsigned LONGEST dummy[] = CALL_DUMMY; | |
1038 | char dummy1[REGISTER_SIZE * sizeof dummy / sizeof (unsigned LONGEST)]; | |
bd5635a1 RP |
1039 | CORE_ADDR old_sp; |
1040 | struct type *value_type; | |
1041 | unsigned char struct_return; | |
b607efe7 | 1042 | CORE_ADDR struct_addr = 0; |
bd5635a1 RP |
1043 | struct inferior_status inf_status; |
1044 | struct cleanup *old_chain; | |
1045 | CORE_ADDR funaddr; | |
1046 | int using_gcc; | |
9f739abd | 1047 | CORE_ADDR real_pc; |
5e548861 | 1048 | struct type *ftype = check_typedef (SYMBOL_TYPE (function)); |
bd5635a1 | 1049 | |
e17960fb JG |
1050 | if (!target_has_execution) |
1051 | noprocess(); | |
1052 | ||
bd5635a1 RP |
1053 | save_inferior_status (&inf_status, 1); |
1054 | old_chain = make_cleanup (restore_inferior_status, &inf_status); | |
1055 | ||
1056 | /* PUSH_DUMMY_FRAME is responsible for saving the inferior registers | |
1057 | (and POP_FRAME for restoring them). (At least on most machines) | |
1058 | they are saved on the stack in the inferior. */ | |
1059 | PUSH_DUMMY_FRAME; | |
1060 | ||
54023465 | 1061 | old_sp = sp = read_sp (); |
bd5635a1 RP |
1062 | |
1063 | #if 1 INNER_THAN 2 /* Stack grows down */ | |
9ed8604f | 1064 | sp -= sizeof dummy1; |
bd5635a1 RP |
1065 | start_sp = sp; |
1066 | #else /* Stack grows up */ | |
1067 | start_sp = sp; | |
9ed8604f | 1068 | sp += sizeof dummy1; |
bd5635a1 RP |
1069 | #endif |
1070 | ||
1071 | funaddr = find_function_addr (function, &value_type); | |
5e548861 | 1072 | CHECK_TYPEDEF (value_type); |
bd5635a1 RP |
1073 | |
1074 | { | |
1075 | struct block *b = block_for_pc (funaddr); | |
1076 | /* If compiled without -g, assume GCC. */ | |
f7a69ed7 | 1077 | using_gcc = b == NULL ? 0 : BLOCK_GCC_COMPILED (b); |
bd5635a1 RP |
1078 | } |
1079 | ||
1080 | /* Are we returning a value using a structure return or a normal | |
1081 | value return? */ | |
1082 | ||
1083 | struct_return = using_struct_return (function, funaddr, value_type, | |
1084 | using_gcc); | |
1085 | ||
1086 | /* Create a call sequence customized for this function | |
1087 | and the number of arguments for it. */ | |
b52cac6b | 1088 | for (i = 0; i < (int) (sizeof (dummy) / sizeof (dummy[0])); i++) |
67e9b3b3 PS |
1089 | store_unsigned_integer (&dummy1[i * REGISTER_SIZE], |
1090 | REGISTER_SIZE, | |
34df79fc | 1091 | (unsigned LONGEST)dummy[i]); |
9f739abd SG |
1092 | |
1093 | #ifdef GDB_TARGET_IS_HPPA | |
b5728692 SG |
1094 | real_pc = FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args, |
1095 | value_type, using_gcc); | |
9f739abd | 1096 | #else |
bd5635a1 RP |
1097 | FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args, |
1098 | value_type, using_gcc); | |
9f739abd SG |
1099 | real_pc = start_sp; |
1100 | #endif | |
bd5635a1 RP |
1101 | |
1102 | #if CALL_DUMMY_LOCATION == ON_STACK | |
9ed8604f | 1103 | write_memory (start_sp, (char *)dummy1, sizeof dummy1); |
cef4c2e7 | 1104 | #endif /* On stack. */ |
bd5635a1 | 1105 | |
bd5635a1 RP |
1106 | #if CALL_DUMMY_LOCATION == BEFORE_TEXT_END |
1107 | /* Convex Unix prohibits executing in the stack segment. */ | |
1108 | /* Hope there is empty room at the top of the text segment. */ | |
1109 | { | |
84d82b1c | 1110 | extern CORE_ADDR text_end; |
bd5635a1 RP |
1111 | static checked = 0; |
1112 | if (!checked) | |
9ed8604f | 1113 | for (start_sp = text_end - sizeof dummy1; start_sp < text_end; ++start_sp) |
bd5635a1 RP |
1114 | if (read_memory_integer (start_sp, 1) != 0) |
1115 | error ("text segment full -- no place to put call"); | |
1116 | checked = 1; | |
1117 | sp = old_sp; | |
9ed8604f PS |
1118 | real_pc = text_end - sizeof dummy1; |
1119 | write_memory (real_pc, (char *)dummy1, sizeof dummy1); | |
bd5635a1 | 1120 | } |
cef4c2e7 PS |
1121 | #endif /* Before text_end. */ |
1122 | ||
1123 | #if CALL_DUMMY_LOCATION == AFTER_TEXT_END | |
bd5635a1 | 1124 | { |
84d82b1c | 1125 | extern CORE_ADDR text_end; |
bd5635a1 RP |
1126 | int errcode; |
1127 | sp = old_sp; | |
30d20d15 | 1128 | real_pc = text_end; |
9ed8604f | 1129 | errcode = target_write_memory (real_pc, (char *)dummy1, sizeof dummy1); |
bd5635a1 RP |
1130 | if (errcode != 0) |
1131 | error ("Cannot write text segment -- call_function failed"); | |
1132 | } | |
1133 | #endif /* After text_end. */ | |
cef4c2e7 PS |
1134 | |
1135 | #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT | |
1136 | real_pc = funaddr; | |
1137 | #endif /* At entry point. */ | |
bd5635a1 RP |
1138 | |
1139 | #ifdef lint | |
1140 | sp = old_sp; /* It really is used, for some ifdef's... */ | |
1141 | #endif | |
1142 | ||
f7a69ed7 PB |
1143 | if (nargs < TYPE_NFIELDS (ftype)) |
1144 | error ("too few arguments in function call"); | |
1145 | ||
5222ca60 PB |
1146 | for (i = nargs - 1; i >= 0; i--) |
1147 | { | |
1148 | struct type *param_type; | |
1149 | if (TYPE_NFIELDS (ftype) > i) | |
1150 | param_type = TYPE_FIELD_TYPE (ftype, i); | |
1151 | else | |
1152 | param_type = 0; | |
1153 | args[i] = value_arg_coerce (args[i], param_type); | |
1154 | } | |
1155 | ||
bd5635a1 RP |
1156 | #if defined (REG_STRUCT_HAS_ADDR) |
1157 | { | |
a91a6192 | 1158 | /* This is a machine like the sparc, where we may need to pass a pointer |
bd5635a1 | 1159 | to the structure, not the structure itself. */ |
a91a6192 | 1160 | for (i = nargs - 1; i >= 0; i--) |
5e548861 PB |
1161 | { |
1162 | struct type *arg_type = check_typedef (VALUE_TYPE (args[i])); | |
1163 | if ((TYPE_CODE (arg_type) == TYPE_CODE_STRUCT | |
1164 | || TYPE_CODE (arg_type) == TYPE_CODE_UNION | |
1165 | || TYPE_CODE (arg_type) == TYPE_CODE_ARRAY | |
34cfa2da PB |
1166 | || TYPE_CODE (arg_type) == TYPE_CODE_STRING |
1167 | || TYPE_CODE (arg_type) == TYPE_CODE_BITSTRING | |
aa220473 SG |
1168 | || TYPE_CODE (arg_type) == TYPE_CODE_SET |
1169 | || (TYPE_CODE (arg_type) == TYPE_CODE_FLT | |
1170 | && TYPE_LENGTH (arg_type) > 8) | |
1171 | ) | |
5e548861 PB |
1172 | && REG_STRUCT_HAS_ADDR (using_gcc, arg_type)) |
1173 | { | |
1174 | CORE_ADDR addr; | |
1175 | int len = TYPE_LENGTH (arg_type); | |
f7a69ed7 | 1176 | #ifdef STACK_ALIGN |
5e548861 | 1177 | int aligned_len = STACK_ALIGN (len); |
f7a69ed7 | 1178 | #else |
5e548861 | 1179 | int aligned_len = len; |
f7a69ed7 | 1180 | #endif |
bd5635a1 | 1181 | #if !(1 INNER_THAN 2) |
5e548861 PB |
1182 | /* The stack grows up, so the address of the thing we push |
1183 | is the stack pointer before we push it. */ | |
1184 | addr = sp; | |
f7a69ed7 | 1185 | #else |
5e548861 | 1186 | sp -= aligned_len; |
bd5635a1 | 1187 | #endif |
5e548861 PB |
1188 | /* Push the structure. */ |
1189 | write_memory (sp, VALUE_CONTENTS (args[i]), len); | |
bd5635a1 | 1190 | #if 1 INNER_THAN 2 |
5e548861 PB |
1191 | /* The stack grows down, so the address of the thing we push |
1192 | is the stack pointer after we push it. */ | |
1193 | addr = sp; | |
f7a69ed7 | 1194 | #else |
5e548861 | 1195 | sp += aligned_len; |
bd5635a1 | 1196 | #endif |
5e548861 PB |
1197 | /* The value we're going to pass is the address of the thing |
1198 | we just pushed. */ | |
1199 | args[i] = value_from_longest (lookup_pointer_type (value_type), | |
1200 | (LONGEST) addr); | |
1201 | } | |
1202 | } | |
bd5635a1 RP |
1203 | } |
1204 | #endif /* REG_STRUCT_HAS_ADDR. */ | |
1205 | ||
f7a69ed7 PB |
1206 | /* Reserve space for the return structure to be written on the |
1207 | stack, if necessary */ | |
1208 | ||
1209 | if (struct_return) | |
1210 | { | |
1211 | int len = TYPE_LENGTH (value_type); | |
1212 | #ifdef STACK_ALIGN | |
1213 | len = STACK_ALIGN (len); | |
1214 | #endif | |
1215 | #if 1 INNER_THAN 2 | |
1216 | sp -= len; | |
1217 | struct_addr = sp; | |
1218 | #else | |
1219 | struct_addr = sp; | |
1220 | sp += len; | |
1221 | #endif | |
1222 | } | |
1223 | ||
1224 | #ifdef STACK_ALIGN | |
1225 | /* If stack grows down, we must leave a hole at the top. */ | |
1226 | { | |
1227 | int len = 0; | |
1228 | ||
1229 | for (i = nargs - 1; i >= 0; i--) | |
1230 | len += TYPE_LENGTH (VALUE_TYPE (args[i])); | |
1231 | #ifdef CALL_DUMMY_STACK_ADJUST | |
1232 | len += CALL_DUMMY_STACK_ADJUST; | |
1233 | #endif | |
1234 | #if 1 INNER_THAN 2 | |
1235 | sp -= STACK_ALIGN (len) - len; | |
1236 | #else | |
1237 | sp += STACK_ALIGN (len) - len; | |
1238 | #endif | |
1239 | } | |
1240 | #endif /* STACK_ALIGN */ | |
1241 | ||
bd5635a1 RP |
1242 | #ifdef PUSH_ARGUMENTS |
1243 | PUSH_ARGUMENTS(nargs, args, sp, struct_return, struct_addr); | |
1244 | #else /* !PUSH_ARGUMENTS */ | |
1245 | for (i = nargs - 1; i >= 0; i--) | |
5222ca60 | 1246 | sp = value_push (sp, args[i]); |
bd5635a1 RP |
1247 | #endif /* !PUSH_ARGUMENTS */ |
1248 | ||
1249 | #ifdef CALL_DUMMY_STACK_ADJUST | |
1250 | #if 1 INNER_THAN 2 | |
1251 | sp -= CALL_DUMMY_STACK_ADJUST; | |
1252 | #else | |
1253 | sp += CALL_DUMMY_STACK_ADJUST; | |
1254 | #endif | |
1255 | #endif /* CALL_DUMMY_STACK_ADJUST */ | |
1256 | ||
1257 | /* Store the address at which the structure is supposed to be | |
1258 | written. Note that this (and the code which reserved the space | |
1259 | above) assumes that gcc was used to compile this function. Since | |
1260 | it doesn't cost us anything but space and if the function is pcc | |
1261 | it will ignore this value, we will make that assumption. | |
1262 | ||
1263 | Also note that on some machines (like the sparc) pcc uses a | |
1264 | convention like gcc's. */ | |
1265 | ||
1266 | if (struct_return) | |
1267 | STORE_STRUCT_RETURN (struct_addr, sp); | |
1268 | ||
1269 | /* Write the stack pointer. This is here because the statements above | |
1270 | might fool with it. On SPARC, this write also stores the register | |
1271 | window into the right place in the new stack frame, which otherwise | |
5632cd56 | 1272 | wouldn't happen. (See store_inferior_registers in sparc-nat.c.) */ |
54023465 | 1273 | write_sp (sp); |
bd5635a1 | 1274 | |
bd5635a1 RP |
1275 | { |
1276 | char retbuf[REGISTER_BYTES]; | |
54023465 JK |
1277 | char *name; |
1278 | struct symbol *symbol; | |
1279 | ||
1280 | name = NULL; | |
1281 | symbol = find_pc_function (funaddr); | |
1282 | if (symbol) | |
1283 | { | |
1284 | name = SYMBOL_SOURCE_NAME (symbol); | |
1285 | } | |
1286 | else | |
1287 | { | |
1288 | /* Try the minimal symbols. */ | |
1289 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr); | |
1290 | ||
1291 | if (msymbol) | |
1292 | { | |
1293 | name = SYMBOL_SOURCE_NAME (msymbol); | |
1294 | } | |
1295 | } | |
1296 | if (name == NULL) | |
1297 | { | |
1298 | char format[80]; | |
1299 | sprintf (format, "at %s", local_hex_format ()); | |
1300 | name = alloca (80); | |
30974778 | 1301 | /* FIXME-32x64: assumes funaddr fits in a long. */ |
cef4c2e7 | 1302 | sprintf (name, format, (unsigned long) funaddr); |
54023465 | 1303 | } |
bd5635a1 RP |
1304 | |
1305 | /* Execute the stack dummy routine, calling FUNCTION. | |
1306 | When it is done, discard the empty frame | |
1307 | after storing the contents of all regs into retbuf. */ | |
860a1754 JK |
1308 | if (run_stack_dummy (real_pc + CALL_DUMMY_START_OFFSET, retbuf)) |
1309 | { | |
1310 | /* We stopped somewhere besides the call dummy. */ | |
1311 | ||
1312 | /* If we did the cleanups, we would print a spurious error message | |
1313 | (Unable to restore previously selected frame), would write the | |
1314 | registers from the inf_status (which is wrong), and would do other | |
1315 | wrong things (like set stop_bpstat to the wrong thing). */ | |
1316 | discard_cleanups (old_chain); | |
1317 | /* Prevent memory leak. */ | |
30d20d15 | 1318 | bpstat_clear (&inf_status.stop_bpstat); |
860a1754 JK |
1319 | |
1320 | /* The following error message used to say "The expression | |
1321 | which contained the function call has been discarded." It | |
1322 | is a hard concept to explain in a few words. Ideally, GDB | |
1323 | would be able to resume evaluation of the expression when | |
1324 | the function finally is done executing. Perhaps someday | |
1325 | this will be implemented (it would not be easy). */ | |
1326 | ||
1327 | /* FIXME: Insert a bunch of wrap_here; name can be very long if it's | |
1328 | a C++ name with arguments and stuff. */ | |
1329 | error ("\ | |
1330 | The program being debugged stopped while in a function called from GDB.\n\ | |
1331 | When the function (%s) is done executing, GDB will silently\n\ | |
1332 | stop (instead of continuing to evaluate the expression containing\n\ | |
1333 | the function call).", name); | |
1334 | } | |
bd5635a1 RP |
1335 | |
1336 | do_cleanups (old_chain); | |
1337 | ||
860a1754 | 1338 | /* Figure out the value returned by the function. */ |
bd5635a1 RP |
1339 | return value_being_returned (value_type, retbuf, struct_return); |
1340 | } | |
1341 | } | |
1342 | #else /* no CALL_DUMMY. */ | |
a91a6192 | 1343 | value_ptr |
bd5635a1 | 1344 | call_function_by_hand (function, nargs, args) |
a91a6192 | 1345 | value_ptr function; |
bd5635a1 | 1346 | int nargs; |
a91a6192 | 1347 | value_ptr *args; |
bd5635a1 RP |
1348 | { |
1349 | error ("Cannot invoke functions on this machine."); | |
1350 | } | |
1351 | #endif /* no CALL_DUMMY. */ | |
a163ddec | 1352 | |
bd5635a1 | 1353 | \f |
a163ddec MT |
1354 | /* Create a value for an array by allocating space in the inferior, copying |
1355 | the data into that space, and then setting up an array value. | |
1356 | ||
1357 | The array bounds are set from LOWBOUND and HIGHBOUND, and the array is | |
1358 | populated from the values passed in ELEMVEC. | |
1359 | ||
1360 | The element type of the array is inherited from the type of the | |
1361 | first element, and all elements must have the same size (though we | |
1362 | don't currently enforce any restriction on their types). */ | |
bd5635a1 | 1363 | |
a91a6192 | 1364 | value_ptr |
a163ddec MT |
1365 | value_array (lowbound, highbound, elemvec) |
1366 | int lowbound; | |
1367 | int highbound; | |
a91a6192 | 1368 | value_ptr *elemvec; |
bd5635a1 | 1369 | { |
a163ddec MT |
1370 | int nelem; |
1371 | int idx; | |
b52cac6b | 1372 | unsigned int typelength; |
a91a6192 | 1373 | value_ptr val; |
a163ddec MT |
1374 | struct type *rangetype; |
1375 | struct type *arraytype; | |
1376 | CORE_ADDR addr; | |
bd5635a1 | 1377 | |
a163ddec MT |
1378 | /* Validate that the bounds are reasonable and that each of the elements |
1379 | have the same size. */ | |
bd5635a1 | 1380 | |
a163ddec MT |
1381 | nelem = highbound - lowbound + 1; |
1382 | if (nelem <= 0) | |
bd5635a1 | 1383 | { |
a163ddec | 1384 | error ("bad array bounds (%d, %d)", lowbound, highbound); |
bd5635a1 | 1385 | } |
a163ddec | 1386 | typelength = TYPE_LENGTH (VALUE_TYPE (elemvec[0])); |
5e548861 | 1387 | for (idx = 1; idx < nelem; idx++) |
bd5635a1 | 1388 | { |
a163ddec MT |
1389 | if (TYPE_LENGTH (VALUE_TYPE (elemvec[idx])) != typelength) |
1390 | { | |
1391 | error ("array elements must all be the same size"); | |
1392 | } | |
bd5635a1 RP |
1393 | } |
1394 | ||
aa220473 SG |
1395 | rangetype = create_range_type ((struct type *) NULL, builtin_type_int, |
1396 | lowbound, highbound); | |
1397 | arraytype = create_array_type ((struct type *) NULL, | |
1398 | VALUE_TYPE (elemvec[0]), rangetype); | |
1399 | ||
1400 | if (!current_language->c_style_arrays) | |
1401 | { | |
1402 | val = allocate_value (arraytype); | |
1403 | for (idx = 0; idx < nelem; idx++) | |
1404 | { | |
1405 | memcpy (VALUE_CONTENTS_RAW (val) + (idx * typelength), | |
1406 | VALUE_CONTENTS (elemvec[idx]), | |
1407 | typelength); | |
1408 | } | |
1409 | return val; | |
1410 | } | |
1411 | ||
a163ddec MT |
1412 | /* Allocate space to store the array in the inferior, and then initialize |
1413 | it by copying in each element. FIXME: Is it worth it to create a | |
1414 | local buffer in which to collect each value and then write all the | |
1415 | bytes in one operation? */ | |
1416 | ||
1417 | addr = allocate_space_in_inferior (nelem * typelength); | |
1418 | for (idx = 0; idx < nelem; idx++) | |
1419 | { | |
1420 | write_memory (addr + (idx * typelength), VALUE_CONTENTS (elemvec[idx]), | |
1421 | typelength); | |
1422 | } | |
1423 | ||
1424 | /* Create the array type and set up an array value to be evaluated lazily. */ | |
1425 | ||
a163ddec MT |
1426 | val = value_at_lazy (arraytype, addr); |
1427 | return (val); | |
1428 | } | |
1429 | ||
1430 | /* Create a value for a string constant by allocating space in the inferior, | |
1431 | copying the data into that space, and returning the address with type | |
1432 | TYPE_CODE_STRING. PTR points to the string constant data; LEN is number | |
1433 | of characters. | |
1434 | Note that string types are like array of char types with a lower bound of | |
1435 | zero and an upper bound of LEN - 1. Also note that the string may contain | |
1436 | embedded null bytes. */ | |
1437 | ||
a91a6192 | 1438 | value_ptr |
a163ddec MT |
1439 | value_string (ptr, len) |
1440 | char *ptr; | |
1441 | int len; | |
1442 | { | |
a91a6192 | 1443 | value_ptr val; |
5222ca60 | 1444 | int lowbound = current_language->string_lower_bound; |
f91a9e05 | 1445 | struct type *rangetype = create_range_type ((struct type *) NULL, |
5222ca60 PB |
1446 | builtin_type_int, |
1447 | lowbound, len + lowbound - 1); | |
f91a9e05 PB |
1448 | struct type *stringtype |
1449 | = create_string_type ((struct type *) NULL, rangetype); | |
a163ddec MT |
1450 | CORE_ADDR addr; |
1451 | ||
f91a9e05 PB |
1452 | if (current_language->c_style_arrays == 0) |
1453 | { | |
1454 | val = allocate_value (stringtype); | |
1455 | memcpy (VALUE_CONTENTS_RAW (val), ptr, len); | |
1456 | return val; | |
1457 | } | |
1458 | ||
1459 | ||
a163ddec MT |
1460 | /* Allocate space to store the string in the inferior, and then |
1461 | copy LEN bytes from PTR in gdb to that address in the inferior. */ | |
1462 | ||
1463 | addr = allocate_space_in_inferior (len); | |
1464 | write_memory (addr, ptr, len); | |
1465 | ||
a163ddec MT |
1466 | val = value_at_lazy (stringtype, addr); |
1467 | return (val); | |
bd5635a1 | 1468 | } |
6d34c236 PB |
1469 | |
1470 | value_ptr | |
1471 | value_bitstring (ptr, len) | |
1472 | char *ptr; | |
1473 | int len; | |
1474 | { | |
1475 | value_ptr val; | |
1476 | struct type *domain_type = create_range_type (NULL, builtin_type_int, | |
1477 | 0, len - 1); | |
1478 | struct type *type = create_set_type ((struct type*) NULL, domain_type); | |
1479 | TYPE_CODE (type) = TYPE_CODE_BITSTRING; | |
1480 | val = allocate_value (type); | |
b4680522 | 1481 | memcpy (VALUE_CONTENTS_RAW (val), ptr, TYPE_LENGTH (type)); |
6d34c236 PB |
1482 | return val; |
1483 | } | |
bd5635a1 | 1484 | \f |
479fdd26 JK |
1485 | /* See if we can pass arguments in T2 to a function which takes arguments |
1486 | of types T1. Both t1 and t2 are NULL-terminated vectors. If some | |
1487 | arguments need coercion of some sort, then the coerced values are written | |
1488 | into T2. Return value is 0 if the arguments could be matched, or the | |
1489 | position at which they differ if not. | |
a163ddec MT |
1490 | |
1491 | STATICP is nonzero if the T1 argument list came from a | |
1492 | static member function. | |
1493 | ||
1494 | For non-static member functions, we ignore the first argument, | |
1495 | which is the type of the instance variable. This is because we want | |
1496 | to handle calls with objects from derived classes. This is not | |
1497 | entirely correct: we should actually check to make sure that a | |
1498 | requested operation is type secure, shouldn't we? FIXME. */ | |
1499 | ||
1500 | static int | |
1501 | typecmp (staticp, t1, t2) | |
1502 | int staticp; | |
1503 | struct type *t1[]; | |
a91a6192 | 1504 | value_ptr t2[]; |
a163ddec MT |
1505 | { |
1506 | int i; | |
1507 | ||
1508 | if (t2 == 0) | |
1509 | return 1; | |
1510 | if (staticp && t1 == 0) | |
1511 | return t2[1] != 0; | |
1512 | if (t1 == 0) | |
1513 | return 1; | |
1514 | if (TYPE_CODE (t1[0]) == TYPE_CODE_VOID) return 0; | |
1515 | if (t1[!staticp] == 0) return 0; | |
1516 | for (i = !staticp; t1[i] && TYPE_CODE (t1[i]) != TYPE_CODE_VOID; i++) | |
1517 | { | |
40620258 | 1518 | struct type *tt1, *tt2; |
a163ddec MT |
1519 | if (! t2[i]) |
1520 | return i+1; | |
5e548861 PB |
1521 | tt1 = check_typedef (t1[i]); |
1522 | tt2 = check_typedef (VALUE_TYPE(t2[i])); | |
40620258 | 1523 | if (TYPE_CODE (tt1) == TYPE_CODE_REF |
479fdd26 | 1524 | /* We should be doing hairy argument matching, as below. */ |
5e548861 | 1525 | && (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (tt1))) == TYPE_CODE (tt2))) |
479fdd26 | 1526 | { |
09af5868 | 1527 | if (TYPE_CODE (tt2) == TYPE_CODE_ARRAY) |
2b576293 C |
1528 | t2[i] = value_coerce_array (t2[i]); |
1529 | else | |
1530 | t2[i] = value_addr (t2[i]); | |
479fdd26 JK |
1531 | continue; |
1532 | } | |
1533 | ||
40620258 | 1534 | while (TYPE_CODE (tt1) == TYPE_CODE_PTR |
5e548861 PB |
1535 | && ( TYPE_CODE (tt2) == TYPE_CODE_ARRAY |
1536 | || TYPE_CODE (tt2) == TYPE_CODE_PTR)) | |
40620258 | 1537 | { |
5e548861 PB |
1538 | tt1 = check_typedef (TYPE_TARGET_TYPE(tt1)); |
1539 | tt2 = check_typedef (TYPE_TARGET_TYPE(tt2)); | |
40620258 KH |
1540 | } |
1541 | if (TYPE_CODE(tt1) == TYPE_CODE(tt2)) continue; | |
1542 | /* Array to pointer is a `trivial conversion' according to the ARM. */ | |
479fdd26 JK |
1543 | |
1544 | /* We should be doing much hairier argument matching (see section 13.2 | |
1545 | of the ARM), but as a quick kludge, just check for the same type | |
1546 | code. */ | |
a163ddec MT |
1547 | if (TYPE_CODE (t1[i]) != TYPE_CODE (VALUE_TYPE (t2[i]))) |
1548 | return i+1; | |
1549 | } | |
1550 | if (!t1[i]) return 0; | |
1551 | return t2[i] ? i+1 : 0; | |
1552 | } | |
1553 | ||
bd5635a1 RP |
1554 | /* Helper function used by value_struct_elt to recurse through baseclasses. |
1555 | Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes, | |
2a5ec41d | 1556 | and search in it assuming it has (class) type TYPE. |
d3bab255 JK |
1557 | If found, return value, else return NULL. |
1558 | ||
1559 | If LOOKING_FOR_BASECLASS, then instead of looking for struct fields, | |
1560 | look for a baseclass named NAME. */ | |
bd5635a1 | 1561 | |
a91a6192 | 1562 | static value_ptr |
d3bab255 | 1563 | search_struct_field (name, arg1, offset, type, looking_for_baseclass) |
bd5635a1 | 1564 | char *name; |
a91a6192 | 1565 | register value_ptr arg1; |
bd5635a1 RP |
1566 | int offset; |
1567 | register struct type *type; | |
d3bab255 | 1568 | int looking_for_baseclass; |
bd5635a1 RP |
1569 | { |
1570 | int i; | |
1571 | ||
5e548861 | 1572 | CHECK_TYPEDEF (type); |
bd5635a1 | 1573 | |
d3bab255 JK |
1574 | if (! looking_for_baseclass) |
1575 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
1576 | { | |
1577 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
1578 | ||
2e4964ad | 1579 | if (t_field_name && STREQ (t_field_name, name)) |
d3bab255 | 1580 | { |
a91a6192 | 1581 | value_ptr v; |
01be6913 PB |
1582 | if (TYPE_FIELD_STATIC (type, i)) |
1583 | { | |
1584 | char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, i); | |
1585 | struct symbol *sym = | |
2e4964ad FF |
1586 | lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL); |
1587 | if (sym == NULL) | |
1588 | error ("Internal error: could not find physical static variable named %s", | |
1589 | phys_name); | |
01be6913 PB |
1590 | v = value_at (TYPE_FIELD_TYPE (type, i), |
1591 | (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym)); | |
1592 | } | |
1593 | else | |
1594 | v = value_primitive_field (arg1, offset, i, type); | |
d3bab255 JK |
1595 | if (v == 0) |
1596 | error("there is no field named %s", name); | |
1597 | return v; | |
1598 | } | |
37d190e0 | 1599 | |
4c2260aa PB |
1600 | if (t_field_name |
1601 | && (t_field_name[0] == '\0' | |
1602 | || (TYPE_CODE (type) == TYPE_CODE_UNION | |
1603 | && STREQ (t_field_name, "else")))) | |
6d34c236 | 1604 | { |
37d190e0 PB |
1605 | struct type *field_type = TYPE_FIELD_TYPE (type, i); |
1606 | if (TYPE_CODE (field_type) == TYPE_CODE_UNION | |
1607 | || TYPE_CODE (field_type) == TYPE_CODE_STRUCT) | |
1608 | { | |
1609 | /* Look for a match through the fields of an anonymous union, | |
1610 | or anonymous struct. C++ provides anonymous unions. | |
1611 | ||
1612 | In the GNU Chill implementation of variant record types, | |
1613 | each <alternative field> has an (anonymous) union type, | |
1614 | each member of the union represents a <variant alternative>. | |
1615 | Each <variant alternative> is represented as a struct, | |
1616 | with a member for each <variant field>. */ | |
1617 | ||
1618 | value_ptr v; | |
1619 | int new_offset = offset; | |
1620 | ||
1621 | /* This is pretty gross. In G++, the offset in an anonymous | |
1622 | union is relative to the beginning of the enclosing struct. | |
1623 | In the GNU Chill implementation of variant records, | |
1624 | the bitpos is zero in an anonymous union field, so we | |
1625 | have to add the offset of the union here. */ | |
1626 | if (TYPE_CODE (field_type) == TYPE_CODE_STRUCT | |
1627 | || (TYPE_NFIELDS (field_type) > 0 | |
1628 | && TYPE_FIELD_BITPOS (field_type, 0) == 0)) | |
1629 | new_offset += TYPE_FIELD_BITPOS (type, i) / 8; | |
1630 | ||
1631 | v = search_struct_field (name, arg1, new_offset, field_type, | |
1632 | looking_for_baseclass); | |
1633 | if (v) | |
1634 | return v; | |
1635 | } | |
6d34c236 | 1636 | } |
d3bab255 | 1637 | } |
bd5635a1 RP |
1638 | |
1639 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
1640 | { | |
a91a6192 | 1641 | value_ptr v; |
5e548861 | 1642 | struct type *basetype = check_typedef (TYPE_BASECLASS (type, i)); |
bd5635a1 | 1643 | /* If we are looking for baseclasses, this is what we get when we |
54023465 JK |
1644 | hit them. But it could happen that the base part's member name |
1645 | is not yet filled in. */ | |
d3bab255 | 1646 | int found_baseclass = (looking_for_baseclass |
54023465 | 1647 | && TYPE_BASECLASS_NAME (type, i) != NULL |
2e4964ad | 1648 | && STREQ (name, TYPE_BASECLASS_NAME (type, i))); |
bd5635a1 RP |
1649 | |
1650 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
1651 | { | |
5e548861 PB |
1652 | int boffset = VALUE_OFFSET (arg1) + offset; |
1653 | boffset = baseclass_offset (type, i, | |
1654 | VALUE_CONTENTS (arg1) + boffset, | |
1655 | VALUE_ADDRESS (arg1) + boffset); | |
1656 | if (boffset == -1) | |
bd5635a1 RP |
1657 | error ("virtual baseclass botch"); |
1658 | if (found_baseclass) | |
5e548861 PB |
1659 | { |
1660 | value_ptr v2 = allocate_value (basetype); | |
1661 | VALUE_LVAL (v2) = VALUE_LVAL (arg1); | |
1662 | VALUE_ADDRESS (v2) = VALUE_ADDRESS (arg1); | |
1663 | VALUE_OFFSET (v2) = VALUE_OFFSET (arg1) + offset + boffset; | |
1664 | if (VALUE_LAZY (arg1)) | |
1665 | VALUE_LAZY (v2) = 1; | |
1666 | else | |
1667 | memcpy (VALUE_CONTENTS_RAW (v2), | |
1668 | VALUE_CONTENTS_RAW (arg1) + offset + boffset, | |
1669 | TYPE_LENGTH (basetype)); | |
1670 | return v2; | |
1671 | } | |
1672 | v = search_struct_field (name, arg1, offset + boffset, | |
1673 | TYPE_BASECLASS (type, i), | |
d3bab255 | 1674 | looking_for_baseclass); |
bd5635a1 | 1675 | } |
01be6913 | 1676 | else if (found_baseclass) |
bd5635a1 RP |
1677 | v = value_primitive_field (arg1, offset, i, type); |
1678 | else | |
1679 | v = search_struct_field (name, arg1, | |
1680 | offset + TYPE_BASECLASS_BITPOS (type, i) / 8, | |
5e548861 | 1681 | basetype, looking_for_baseclass); |
bd5635a1 RP |
1682 | if (v) return v; |
1683 | } | |
1684 | return NULL; | |
1685 | } | |
1686 | ||
1687 | /* Helper function used by value_struct_elt to recurse through baseclasses. | |
1688 | Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes, | |
2a5ec41d | 1689 | and search in it assuming it has (class) type TYPE. |
cef4c2e7 | 1690 | If found, return value, else if name matched and args not return (value)-1, |
5b5c6d94 | 1691 | else return NULL. */ |
bd5635a1 | 1692 | |
a91a6192 | 1693 | static value_ptr |
bac89d6c | 1694 | search_struct_method (name, arg1p, args, offset, static_memfuncp, type) |
bd5635a1 | 1695 | char *name; |
a91a6192 | 1696 | register value_ptr *arg1p, *args; |
bd5635a1 RP |
1697 | int offset, *static_memfuncp; |
1698 | register struct type *type; | |
1699 | { | |
1700 | int i; | |
a91a6192 | 1701 | value_ptr v; |
67e9b3b3 | 1702 | int name_matched = 0; |
6ebc9cdd | 1703 | char dem_opname[64]; |
bd5635a1 | 1704 | |
5e548861 | 1705 | CHECK_TYPEDEF (type); |
bd5635a1 RP |
1706 | for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; i--) |
1707 | { | |
1708 | char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
b607efe7 | 1709 | /* FIXME! May need to check for ARM demangling here */ |
6ebc9cdd KH |
1710 | if (strncmp(t_field_name, "__", 2)==0 || |
1711 | strncmp(t_field_name, "op", 2)==0 || | |
1712 | strncmp(t_field_name, "type", 4)==0 ) | |
1713 | { | |
1714 | if (cplus_demangle_opname(t_field_name, dem_opname, DMGL_ANSI)) | |
1715 | t_field_name = dem_opname; | |
1716 | else if (cplus_demangle_opname(t_field_name, dem_opname, 0)) | |
1717 | t_field_name = dem_opname; | |
1718 | } | |
2e4964ad | 1719 | if (t_field_name && STREQ (t_field_name, name)) |
bd5635a1 | 1720 | { |
d3bab255 | 1721 | int j = TYPE_FN_FIELDLIST_LENGTH (type, i) - 1; |
bd5635a1 | 1722 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); |
5b5c6d94 | 1723 | name_matched = 1; |
bd5635a1 | 1724 | |
d3bab255 JK |
1725 | if (j > 0 && args == 0) |
1726 | error ("cannot resolve overloaded method `%s'", name); | |
1727 | while (j >= 0) | |
bd5635a1 | 1728 | { |
8e9a3f3b | 1729 | if (TYPE_FN_FIELD_STUB (f, j)) |
bd5635a1 RP |
1730 | check_stub_method (type, i, j); |
1731 | if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j), | |
1732 | TYPE_FN_FIELD_ARGS (f, j), args)) | |
1733 | { | |
1734 | if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) | |
a91a6192 | 1735 | return value_virtual_fn_field (arg1p, f, j, type, offset); |
bd5635a1 RP |
1736 | if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp) |
1737 | *static_memfuncp = 1; | |
a91a6192 SS |
1738 | v = value_fn_field (arg1p, f, j, type, offset); |
1739 | if (v != NULL) return v; | |
bd5635a1 | 1740 | } |
d3bab255 | 1741 | j--; |
bd5635a1 RP |
1742 | } |
1743 | } | |
1744 | } | |
1745 | ||
1746 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
1747 | { | |
01be6913 | 1748 | int base_offset; |
bd5635a1 RP |
1749 | |
1750 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
1751 | { | |
5e548861 PB |
1752 | base_offset = VALUE_OFFSET (*arg1p) + offset; |
1753 | base_offset = | |
1754 | baseclass_offset (type, i, | |
1755 | VALUE_CONTENTS (*arg1p) + base_offset, | |
1756 | VALUE_ADDRESS (*arg1p) + base_offset); | |
bac89d6c | 1757 | if (base_offset == -1) |
bd5635a1 | 1758 | error ("virtual baseclass botch"); |
bd5635a1 | 1759 | } |
01be6913 PB |
1760 | else |
1761 | { | |
01be6913 PB |
1762 | base_offset = TYPE_BASECLASS_BITPOS (type, i) / 8; |
1763 | } | |
bac89d6c | 1764 | v = search_struct_method (name, arg1p, args, base_offset + offset, |
bd5635a1 | 1765 | static_memfuncp, TYPE_BASECLASS (type, i)); |
a91a6192 | 1766 | if (v == (value_ptr) -1) |
5b5c6d94 KH |
1767 | { |
1768 | name_matched = 1; | |
1769 | } | |
1770 | else if (v) | |
bac89d6c FF |
1771 | { |
1772 | /* FIXME-bothner: Why is this commented out? Why is it here? */ | |
1773 | /* *arg1p = arg1_tmp;*/ | |
1774 | return v; | |
1775 | } | |
bd5635a1 | 1776 | } |
a91a6192 | 1777 | if (name_matched) return (value_ptr) -1; |
5b5c6d94 | 1778 | else return NULL; |
bd5635a1 RP |
1779 | } |
1780 | ||
1781 | /* Given *ARGP, a value of type (pointer to a)* structure/union, | |
1782 | extract the component named NAME from the ultimate target structure/union | |
1783 | and return it as a value with its appropriate type. | |
1784 | ERR is used in the error message if *ARGP's type is wrong. | |
1785 | ||
1786 | C++: ARGS is a list of argument types to aid in the selection of | |
1787 | an appropriate method. Also, handle derived types. | |
1788 | ||
1789 | STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location | |
1790 | where the truthvalue of whether the function that was resolved was | |
1791 | a static member function or not is stored. | |
1792 | ||
1793 | ERR is an error message to be printed in case the field is not found. */ | |
1794 | ||
a91a6192 | 1795 | value_ptr |
bd5635a1 | 1796 | value_struct_elt (argp, args, name, static_memfuncp, err) |
a91a6192 | 1797 | register value_ptr *argp, *args; |
bd5635a1 RP |
1798 | char *name; |
1799 | int *static_memfuncp; | |
1800 | char *err; | |
1801 | { | |
1802 | register struct type *t; | |
a91a6192 | 1803 | value_ptr v; |
bd5635a1 RP |
1804 | |
1805 | COERCE_ARRAY (*argp); | |
1806 | ||
5e548861 | 1807 | t = check_typedef (VALUE_TYPE (*argp)); |
bd5635a1 RP |
1808 | |
1809 | /* Follow pointers until we get to a non-pointer. */ | |
1810 | ||
1811 | while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF) | |
1812 | { | |
bd5635a1 | 1813 | *argp = value_ind (*argp); |
f2ebc25f JK |
1814 | /* Don't coerce fn pointer to fn and then back again! */ |
1815 | if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC) | |
1816 | COERCE_ARRAY (*argp); | |
5e548861 | 1817 | t = check_typedef (VALUE_TYPE (*argp)); |
bd5635a1 RP |
1818 | } |
1819 | ||
1820 | if (TYPE_CODE (t) == TYPE_CODE_MEMBER) | |
1821 | error ("not implemented: member type in value_struct_elt"); | |
1822 | ||
2a5ec41d | 1823 | if ( TYPE_CODE (t) != TYPE_CODE_STRUCT |
bd5635a1 RP |
1824 | && TYPE_CODE (t) != TYPE_CODE_UNION) |
1825 | error ("Attempt to extract a component of a value that is not a %s.", err); | |
1826 | ||
1827 | /* Assume it's not, unless we see that it is. */ | |
1828 | if (static_memfuncp) | |
1829 | *static_memfuncp =0; | |
1830 | ||
1831 | if (!args) | |
1832 | { | |
1833 | /* if there are no arguments ...do this... */ | |
1834 | ||
d3bab255 | 1835 | /* Try as a field first, because if we succeed, there |
bd5635a1 | 1836 | is less work to be done. */ |
d3bab255 | 1837 | v = search_struct_field (name, *argp, 0, t, 0); |
bd5635a1 RP |
1838 | if (v) |
1839 | return v; | |
1840 | ||
1841 | /* C++: If it was not found as a data field, then try to | |
1842 | return it as a pointer to a method. */ | |
1843 | ||
1844 | if (destructor_name_p (name, t)) | |
1845 | error ("Cannot get value of destructor"); | |
1846 | ||
bac89d6c | 1847 | v = search_struct_method (name, argp, args, 0, static_memfuncp, t); |
bd5635a1 | 1848 | |
a91a6192 | 1849 | if (v == (value_ptr) -1) |
67e9b3b3 PS |
1850 | error ("Cannot take address of a method"); |
1851 | else if (v == 0) | |
bd5635a1 RP |
1852 | { |
1853 | if (TYPE_NFN_FIELDS (t)) | |
1854 | error ("There is no member or method named %s.", name); | |
1855 | else | |
1856 | error ("There is no member named %s.", name); | |
1857 | } | |
1858 | return v; | |
1859 | } | |
1860 | ||
1861 | if (destructor_name_p (name, t)) | |
1862 | { | |
1863 | if (!args[1]) | |
1864 | { | |
1865 | /* destructors are a special case. */ | |
a91a6192 SS |
1866 | v = value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, 0), |
1867 | TYPE_FN_FIELDLIST_LENGTH (t, 0), 0, 0); | |
40620258 KH |
1868 | if (!v) error("could not find destructor function named %s.", name); |
1869 | else return v; | |
bd5635a1 RP |
1870 | } |
1871 | else | |
1872 | { | |
1873 | error ("destructor should not have any argument"); | |
1874 | } | |
1875 | } | |
1876 | else | |
bac89d6c | 1877 | v = search_struct_method (name, argp, args, 0, static_memfuncp, t); |
bd5635a1 | 1878 | |
a91a6192 | 1879 | if (v == (value_ptr) -1) |
5b5c6d94 KH |
1880 | { |
1881 | error("Argument list of %s mismatch with component in the structure.", name); | |
1882 | } | |
1883 | else if (v == 0) | |
bd5635a1 RP |
1884 | { |
1885 | /* See if user tried to invoke data as function. If so, | |
1886 | hand it back. If it's not callable (i.e., a pointer to function), | |
1887 | gdb should give an error. */ | |
d3bab255 | 1888 | v = search_struct_field (name, *argp, 0, t, 0); |
bd5635a1 RP |
1889 | } |
1890 | ||
1891 | if (!v) | |
1892 | error ("Structure has no component named %s.", name); | |
1893 | return v; | |
1894 | } | |
1895 | ||
1896 | /* C++: return 1 is NAME is a legitimate name for the destructor | |
1897 | of type TYPE. If TYPE does not have a destructor, or | |
1898 | if NAME is inappropriate for TYPE, an error is signaled. */ | |
1899 | int | |
1900 | destructor_name_p (name, type) | |
7919c3ed JG |
1901 | const char *name; |
1902 | const struct type *type; | |
bd5635a1 RP |
1903 | { |
1904 | /* destructors are a special case. */ | |
1905 | ||
1906 | if (name[0] == '~') | |
1907 | { | |
1908 | char *dname = type_name_no_tag (type); | |
6d34c236 | 1909 | char *cp = strchr (dname, '<'); |
b52cac6b | 1910 | unsigned int len; |
6d34c236 PB |
1911 | |
1912 | /* Do not compare the template part for template classes. */ | |
1913 | if (cp == NULL) | |
1914 | len = strlen (dname); | |
1915 | else | |
1916 | len = cp - dname; | |
1917 | if (strlen (name + 1) != len || !STREQN (dname, name + 1, len)) | |
bd5635a1 RP |
1918 | error ("name of destructor must equal name of class"); |
1919 | else | |
1920 | return 1; | |
1921 | } | |
1922 | return 0; | |
1923 | } | |
1924 | ||
1925 | /* Helper function for check_field: Given TYPE, a structure/union, | |
1926 | return 1 if the component named NAME from the ultimate | |
1927 | target structure/union is defined, otherwise, return 0. */ | |
1928 | ||
1929 | static int | |
1930 | check_field_in (type, name) | |
1931 | register struct type *type; | |
01be6913 | 1932 | const char *name; |
bd5635a1 RP |
1933 | { |
1934 | register int i; | |
1935 | ||
1936 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
1937 | { | |
1938 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
2e4964ad | 1939 | if (t_field_name && STREQ (t_field_name, name)) |
bd5635a1 RP |
1940 | return 1; |
1941 | } | |
1942 | ||
1943 | /* C++: If it was not found as a data field, then try to | |
1944 | return it as a pointer to a method. */ | |
1945 | ||
1946 | /* Destructors are a special case. */ | |
1947 | if (destructor_name_p (name, type)) | |
1948 | return 1; | |
1949 | ||
1950 | for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i) | |
1951 | { | |
2e4964ad | 1952 | if (STREQ (TYPE_FN_FIELDLIST_NAME (type, i), name)) |
bd5635a1 RP |
1953 | return 1; |
1954 | } | |
1955 | ||
1956 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
1957 | if (check_field_in (TYPE_BASECLASS (type, i), name)) | |
1958 | return 1; | |
1959 | ||
1960 | return 0; | |
1961 | } | |
1962 | ||
1963 | ||
1964 | /* C++: Given ARG1, a value of type (pointer to a)* structure/union, | |
1965 | return 1 if the component named NAME from the ultimate | |
1966 | target structure/union is defined, otherwise, return 0. */ | |
1967 | ||
1968 | int | |
1969 | check_field (arg1, name) | |
a91a6192 | 1970 | register value_ptr arg1; |
7919c3ed | 1971 | const char *name; |
bd5635a1 RP |
1972 | { |
1973 | register struct type *t; | |
1974 | ||
1975 | COERCE_ARRAY (arg1); | |
1976 | ||
1977 | t = VALUE_TYPE (arg1); | |
1978 | ||
1979 | /* Follow pointers until we get to a non-pointer. */ | |
1980 | ||
5e548861 PB |
1981 | for (;;) |
1982 | { | |
1983 | CHECK_TYPEDEF (t); | |
1984 | if (TYPE_CODE (t) != TYPE_CODE_PTR && TYPE_CODE (t) != TYPE_CODE_REF) | |
1985 | break; | |
1986 | t = TYPE_TARGET_TYPE (t); | |
1987 | } | |
bd5635a1 RP |
1988 | |
1989 | if (TYPE_CODE (t) == TYPE_CODE_MEMBER) | |
1990 | error ("not implemented: member type in check_field"); | |
1991 | ||
2a5ec41d | 1992 | if ( TYPE_CODE (t) != TYPE_CODE_STRUCT |
bd5635a1 RP |
1993 | && TYPE_CODE (t) != TYPE_CODE_UNION) |
1994 | error ("Internal error: `this' is not an aggregate"); | |
1995 | ||
1996 | return check_field_in (t, name); | |
1997 | } | |
1998 | ||
01be6913 | 1999 | /* C++: Given an aggregate type CURTYPE, and a member name NAME, |
2a5ec41d | 2000 | return the address of this member as a "pointer to member" |
bd5635a1 RP |
2001 | type. If INTYPE is non-null, then it will be the type |
2002 | of the member we are looking for. This will help us resolve | |
01be6913 PB |
2003 | "pointers to member functions". This function is used |
2004 | to resolve user expressions of the form "DOMAIN::NAME". */ | |
bd5635a1 | 2005 | |
a91a6192 | 2006 | value_ptr |
51b57ded | 2007 | value_struct_elt_for_reference (domain, offset, curtype, name, intype) |
01be6913 | 2008 | struct type *domain, *curtype, *intype; |
51b57ded | 2009 | int offset; |
bd5635a1 RP |
2010 | char *name; |
2011 | { | |
01be6913 | 2012 | register struct type *t = curtype; |
bd5635a1 | 2013 | register int i; |
a91a6192 | 2014 | value_ptr v; |
bd5635a1 | 2015 | |
2a5ec41d | 2016 | if ( TYPE_CODE (t) != TYPE_CODE_STRUCT |
bd5635a1 | 2017 | && TYPE_CODE (t) != TYPE_CODE_UNION) |
01be6913 | 2018 | error ("Internal error: non-aggregate type to value_struct_elt_for_reference"); |
bd5635a1 | 2019 | |
01be6913 | 2020 | for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); i--) |
bd5635a1 | 2021 | { |
01be6913 PB |
2022 | char *t_field_name = TYPE_FIELD_NAME (t, i); |
2023 | ||
2e4964ad | 2024 | if (t_field_name && STREQ (t_field_name, name)) |
bd5635a1 | 2025 | { |
01be6913 | 2026 | if (TYPE_FIELD_STATIC (t, i)) |
bd5635a1 | 2027 | { |
01be6913 PB |
2028 | char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (t, i); |
2029 | struct symbol *sym = | |
2030 | lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL); | |
2e4964ad FF |
2031 | if (sym == NULL) |
2032 | error ("Internal error: could not find physical static variable named %s", | |
01be6913 PB |
2033 | phys_name); |
2034 | return value_at (SYMBOL_TYPE (sym), | |
2035 | (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym)); | |
bd5635a1 | 2036 | } |
01be6913 PB |
2037 | if (TYPE_FIELD_PACKED (t, i)) |
2038 | error ("pointers to bitfield members not allowed"); | |
2039 | ||
2040 | return value_from_longest | |
2041 | (lookup_reference_type (lookup_member_type (TYPE_FIELD_TYPE (t, i), | |
2042 | domain)), | |
51b57ded | 2043 | offset + (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3)); |
bd5635a1 | 2044 | } |
bd5635a1 RP |
2045 | } |
2046 | ||
2047 | /* C++: If it was not found as a data field, then try to | |
2048 | return it as a pointer to a method. */ | |
bd5635a1 RP |
2049 | |
2050 | /* Destructors are a special case. */ | |
2051 | if (destructor_name_p (name, t)) | |
2052 | { | |
2a5ec41d | 2053 | error ("member pointers to destructors not implemented yet"); |
bd5635a1 RP |
2054 | } |
2055 | ||
2056 | /* Perform all necessary dereferencing. */ | |
2057 | while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR) | |
2058 | intype = TYPE_TARGET_TYPE (intype); | |
2059 | ||
01be6913 | 2060 | for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i) |
bd5635a1 | 2061 | { |
852b3831 PB |
2062 | char *t_field_name = TYPE_FN_FIELDLIST_NAME (t, i); |
2063 | char dem_opname[64]; | |
2064 | ||
2065 | if (strncmp(t_field_name, "__", 2)==0 || | |
2066 | strncmp(t_field_name, "op", 2)==0 || | |
2067 | strncmp(t_field_name, "type", 4)==0 ) | |
2068 | { | |
2069 | if (cplus_demangle_opname(t_field_name, dem_opname, DMGL_ANSI)) | |
2070 | t_field_name = dem_opname; | |
2071 | else if (cplus_demangle_opname(t_field_name, dem_opname, 0)) | |
2072 | t_field_name = dem_opname; | |
2073 | } | |
2074 | if (t_field_name && STREQ (t_field_name, name)) | |
bd5635a1 | 2075 | { |
01be6913 PB |
2076 | int j = TYPE_FN_FIELDLIST_LENGTH (t, i); |
2077 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); | |
2078 | ||
2079 | if (intype == 0 && j > 1) | |
2080 | error ("non-unique member `%s' requires type instantiation", name); | |
2081 | if (intype) | |
bd5635a1 | 2082 | { |
01be6913 PB |
2083 | while (j--) |
2084 | if (TYPE_FN_FIELD_TYPE (f, j) == intype) | |
2085 | break; | |
2086 | if (j < 0) | |
2087 | error ("no member function matches that type instantiation"); | |
2088 | } | |
2089 | else | |
2090 | j = 0; | |
2091 | ||
2092 | if (TYPE_FN_FIELD_STUB (f, j)) | |
2093 | check_stub_method (t, i, j); | |
2094 | if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) | |
2095 | { | |
2096 | return value_from_longest | |
2097 | (lookup_reference_type | |
2098 | (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), | |
2099 | domain)), | |
13ffa6be | 2100 | (LONGEST) METHOD_PTR_FROM_VOFFSET (TYPE_FN_FIELD_VOFFSET (f, j))); |
01be6913 PB |
2101 | } |
2102 | else | |
2103 | { | |
2104 | struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j), | |
2105 | 0, VAR_NAMESPACE, 0, NULL); | |
35fcebce PB |
2106 | if (s == NULL) |
2107 | { | |
2108 | v = 0; | |
2109 | } | |
2110 | else | |
2111 | { | |
2112 | v = read_var_value (s, 0); | |
01be6913 | 2113 | #if 0 |
35fcebce PB |
2114 | VALUE_TYPE (v) = lookup_reference_type |
2115 | (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), | |
2116 | domain)); | |
01be6913 | 2117 | #endif |
bd5635a1 | 2118 | } |
35fcebce | 2119 | return v; |
bd5635a1 RP |
2120 | } |
2121 | } | |
35fcebce | 2122 | } |
01be6913 PB |
2123 | for (i = TYPE_N_BASECLASSES (t) - 1; i >= 0; i--) |
2124 | { | |
a91a6192 | 2125 | value_ptr v; |
51b57ded FF |
2126 | int base_offset; |
2127 | ||
2128 | if (BASETYPE_VIA_VIRTUAL (t, i)) | |
2129 | base_offset = 0; | |
2130 | else | |
2131 | base_offset = TYPE_BASECLASS_BITPOS (t, i) / 8; | |
01be6913 | 2132 | v = value_struct_elt_for_reference (domain, |
51b57ded | 2133 | offset + base_offset, |
01be6913 PB |
2134 | TYPE_BASECLASS (t, i), |
2135 | name, | |
2136 | intype); | |
2137 | if (v) | |
2138 | return v; | |
bd5635a1 RP |
2139 | } |
2140 | return 0; | |
2141 | } | |
2142 | ||
bd5635a1 RP |
2143 | /* C++: return the value of the class instance variable, if one exists. |
2144 | Flag COMPLAIN signals an error if the request is made in an | |
2145 | inappropriate context. */ | |
6d34c236 | 2146 | |
a91a6192 | 2147 | value_ptr |
bd5635a1 RP |
2148 | value_of_this (complain) |
2149 | int complain; | |
2150 | { | |
bd5635a1 RP |
2151 | struct symbol *func, *sym; |
2152 | struct block *b; | |
2153 | int i; | |
2154 | static const char funny_this[] = "this"; | |
a91a6192 | 2155 | value_ptr this; |
bd5635a1 RP |
2156 | |
2157 | if (selected_frame == 0) | |
2158 | if (complain) | |
2159 | error ("no frame selected"); | |
2160 | else return 0; | |
2161 | ||
2162 | func = get_frame_function (selected_frame); | |
2163 | if (!func) | |
2164 | { | |
2165 | if (complain) | |
2166 | error ("no `this' in nameless context"); | |
2167 | else return 0; | |
2168 | } | |
2169 | ||
2170 | b = SYMBOL_BLOCK_VALUE (func); | |
2171 | i = BLOCK_NSYMS (b); | |
2172 | if (i <= 0) | |
2173 | if (complain) | |
2174 | error ("no args, no `this'"); | |
2175 | else return 0; | |
2176 | ||
2177 | /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER | |
2178 | symbol instead of the LOC_ARG one (if both exist). */ | |
2179 | sym = lookup_block_symbol (b, funny_this, VAR_NAMESPACE); | |
2180 | if (sym == NULL) | |
2181 | { | |
2182 | if (complain) | |
2183 | error ("current stack frame not in method"); | |
2184 | else | |
2185 | return NULL; | |
2186 | } | |
2187 | ||
2188 | this = read_var_value (sym, selected_frame); | |
2189 | if (this == 0 && complain) | |
2190 | error ("`this' argument at unknown address"); | |
2191 | return this; | |
2192 | } | |
a91a6192 | 2193 | |
f91a9e05 PB |
2194 | /* Create a slice (sub-string, sub-array) of ARRAY, that is LENGTH elements |
2195 | long, starting at LOWBOUND. The result has the same lower bound as | |
2196 | the original ARRAY. */ | |
2197 | ||
2198 | value_ptr | |
2199 | value_slice (array, lowbound, length) | |
2200 | value_ptr array; | |
2201 | int lowbound, length; | |
2202 | { | |
5f3e7bfc PB |
2203 | struct type *slice_range_type, *slice_type, *range_type; |
2204 | LONGEST lowerbound, upperbound, offset; | |
2205 | value_ptr slice; | |
5e548861 PB |
2206 | struct type *array_type; |
2207 | array_type = check_typedef (VALUE_TYPE (array)); | |
2208 | COERCE_VARYING_ARRAY (array, array_type); | |
5e548861 | 2209 | if (TYPE_CODE (array_type) != TYPE_CODE_ARRAY |
5f3e7bfc PB |
2210 | && TYPE_CODE (array_type) != TYPE_CODE_STRING |
2211 | && TYPE_CODE (array_type) != TYPE_CODE_BITSTRING) | |
f91a9e05 | 2212 | error ("cannot take slice of non-array"); |
5f3e7bfc PB |
2213 | range_type = TYPE_INDEX_TYPE (array_type); |
2214 | if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) | |
2215 | error ("slice from bad array or bitstring"); | |
2216 | if (lowbound < lowerbound || length < 0 | |
2217 | || lowbound + length - 1 > upperbound | |
2218 | /* Chill allows zero-length strings but not arrays. */ | |
2219 | || (current_language->la_language == language_chill | |
2220 | && length == 0 && TYPE_CODE (array_type) == TYPE_CODE_ARRAY)) | |
2221 | error ("slice out of range"); | |
2222 | /* FIXME-type-allocation: need a way to free this type when we are | |
2223 | done with it. */ | |
2224 | slice_range_type = create_range_type ((struct type*) NULL, | |
2225 | TYPE_TARGET_TYPE (range_type), | |
b607efe7 | 2226 | lowbound, lowbound + length - 1); |
5f3e7bfc PB |
2227 | if (TYPE_CODE (array_type) == TYPE_CODE_BITSTRING) |
2228 | { | |
2229 | int i; | |
2230 | slice_type = create_set_type ((struct type*) NULL, slice_range_type); | |
2231 | TYPE_CODE (slice_type) = TYPE_CODE_BITSTRING; | |
2232 | slice = value_zero (slice_type, not_lval); | |
2233 | for (i = 0; i < length; i++) | |
2234 | { | |
2235 | int element = value_bit_index (array_type, | |
2236 | VALUE_CONTENTS (array), | |
2237 | lowbound + i); | |
2238 | if (element < 0) | |
2239 | error ("internal error accessing bitstring"); | |
2240 | else if (element > 0) | |
2241 | { | |
2242 | int j = i % TARGET_CHAR_BIT; | |
2243 | if (BITS_BIG_ENDIAN) | |
2244 | j = TARGET_CHAR_BIT - 1 - j; | |
2245 | VALUE_CONTENTS_RAW (slice)[i / TARGET_CHAR_BIT] |= (1 << j); | |
2246 | } | |
2247 | } | |
2248 | /* We should set the address, bitssize, and bitspos, so the clice | |
2249 | can be used on the LHS, but that may require extensions to | |
2250 | value_assign. For now, just leave as a non_lval. FIXME. */ | |
2251 | } | |
f91a9e05 PB |
2252 | else |
2253 | { | |
5e548861 | 2254 | struct type *element_type = TYPE_TARGET_TYPE (array_type); |
5e548861 PB |
2255 | offset |
2256 | = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type)); | |
f91a9e05 PB |
2257 | slice_type = create_array_type ((struct type*) NULL, element_type, |
2258 | slice_range_type); | |
5e548861 | 2259 | TYPE_CODE (slice_type) = TYPE_CODE (array_type); |
f91a9e05 PB |
2260 | slice = allocate_value (slice_type); |
2261 | if (VALUE_LAZY (array)) | |
2262 | VALUE_LAZY (slice) = 1; | |
2263 | else | |
2264 | memcpy (VALUE_CONTENTS (slice), VALUE_CONTENTS (array) + offset, | |
2265 | TYPE_LENGTH (slice_type)); | |
2266 | if (VALUE_LVAL (array) == lval_internalvar) | |
2267 | VALUE_LVAL (slice) = lval_internalvar_component; | |
2268 | else | |
2269 | VALUE_LVAL (slice) = VALUE_LVAL (array); | |
2270 | VALUE_ADDRESS (slice) = VALUE_ADDRESS (array); | |
2271 | VALUE_OFFSET (slice) = VALUE_OFFSET (array) + offset; | |
f91a9e05 | 2272 | } |
5f3e7bfc | 2273 | return slice; |
f91a9e05 PB |
2274 | } |
2275 | ||
2276 | /* Assuming chill_varying_type (VARRAY) is true, return an equivalent | |
2277 | value as a fixed-length array. */ | |
2278 | ||
2279 | value_ptr | |
2280 | varying_to_slice (varray) | |
2281 | value_ptr varray; | |
2282 | { | |
5e548861 | 2283 | struct type *vtype = check_typedef (VALUE_TYPE (varray)); |
f91a9e05 PB |
2284 | LONGEST length = unpack_long (TYPE_FIELD_TYPE (vtype, 0), |
2285 | VALUE_CONTENTS (varray) | |
2286 | + TYPE_FIELD_BITPOS (vtype, 0) / 8); | |
2287 | return value_slice (value_primitive_field (varray, 0, 1, vtype), 0, length); | |
2288 | } | |
2289 | ||
a91a6192 SS |
2290 | /* Create a value for a FORTRAN complex number. Currently most of |
2291 | the time values are coerced to COMPLEX*16 (i.e. a complex number | |
2292 | composed of 2 doubles. This really should be a smarter routine | |
2293 | that figures out precision inteligently as opposed to assuming | |
2294 | doubles. FIXME: fmb */ | |
2295 | ||
2296 | value_ptr | |
5222ca60 | 2297 | value_literal_complex (arg1, arg2, type) |
a91a6192 SS |
2298 | value_ptr arg1; |
2299 | value_ptr arg2; | |
5222ca60 | 2300 | struct type *type; |
a91a6192 | 2301 | { |
a91a6192 | 2302 | register value_ptr val; |
5222ca60 | 2303 | struct type *real_type = TYPE_TARGET_TYPE (type); |
a91a6192 | 2304 | |
5222ca60 PB |
2305 | val = allocate_value (type); |
2306 | arg1 = value_cast (real_type, arg1); | |
2307 | arg2 = value_cast (real_type, arg2); | |
a91a6192 | 2308 | |
5222ca60 PB |
2309 | memcpy (VALUE_CONTENTS_RAW (val), |
2310 | VALUE_CONTENTS (arg1), TYPE_LENGTH (real_type)); | |
2311 | memcpy (VALUE_CONTENTS_RAW (val) + TYPE_LENGTH (real_type), | |
2312 | VALUE_CONTENTS (arg2), TYPE_LENGTH (real_type)); | |
a91a6192 SS |
2313 | return val; |
2314 | } | |
9ed8604f | 2315 | |
5222ca60 | 2316 | /* Cast a value into the appropriate complex data type. */ |
9ed8604f PS |
2317 | |
2318 | static value_ptr | |
5222ca60 | 2319 | cast_into_complex (type, val) |
9ed8604f PS |
2320 | struct type *type; |
2321 | register value_ptr val; | |
2322 | { | |
5222ca60 PB |
2323 | struct type *real_type = TYPE_TARGET_TYPE (type); |
2324 | if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_COMPLEX) | |
9ed8604f | 2325 | { |
5222ca60 PB |
2326 | struct type *val_real_type = TYPE_TARGET_TYPE (VALUE_TYPE (val)); |
2327 | value_ptr re_val = allocate_value (val_real_type); | |
2328 | value_ptr im_val = allocate_value (val_real_type); | |
9ed8604f | 2329 | |
5222ca60 PB |
2330 | memcpy (VALUE_CONTENTS_RAW (re_val), |
2331 | VALUE_CONTENTS (val), TYPE_LENGTH (val_real_type)); | |
2332 | memcpy (VALUE_CONTENTS_RAW (im_val), | |
2333 | VALUE_CONTENTS (val) + TYPE_LENGTH (val_real_type), | |
2334 | TYPE_LENGTH (val_real_type)); | |
9ed8604f | 2335 | |
5222ca60 | 2336 | return value_literal_complex (re_val, im_val, type); |
9ed8604f | 2337 | } |
5222ca60 PB |
2338 | else if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FLT |
2339 | || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT) | |
2340 | return value_literal_complex (val, value_zero (real_type, not_lval), type); | |
9ed8604f | 2341 | else |
5222ca60 | 2342 | error ("cannot cast non-number to complex"); |
9ed8604f | 2343 | } |
5e548861 PB |
2344 | |
2345 | void | |
2346 | _initialize_valops () | |
2347 | { | |
2348 | #if 0 | |
2349 | add_show_from_set | |
2350 | (add_set_cmd ("abandon", class_support, var_boolean, (char *)&auto_abandon, | |
2351 | "Set automatic abandonment of expressions upon failure.", | |
2352 | &setlist), | |
2353 | &showlist); | |
2354 | #endif | |
2355 | } |