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