1 /* Perform non-arithmetic operations on values, for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "gdb_string.h"
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. */
40 #ifndef COERCE_FLOAT_TO_DOUBLE
41 #define COERCE_FLOAT_TO_DOUBLE (param_type == NULL)
44 /* Local functions. */
46 static int typecmp PARAMS ((int staticp, struct type *t1[], value_ptr t2[]));
48 static CORE_ADDR find_function_addr PARAMS ((value_ptr, struct type **));
50 #ifndef PUSH_ARGUMENTS
51 static CORE_ADDR value_push PARAMS ((CORE_ADDR, value_ptr));
54 static value_ptr search_struct_field PARAMS ((char *, value_ptr, int,
57 static value_ptr search_struct_method PARAMS ((char *, value_ptr *,
59 int, int *, struct type *));
61 static int check_field_in PARAMS ((struct type *, const char *));
63 static CORE_ADDR allocate_space_in_inferior PARAMS ((int));
65 static value_ptr cast_into_complex PARAMS ((struct type *, value_ptr));
67 static value_ptr value_arg_coerce PARAMS ((value_ptr, struct type *));
69 #define VALUE_SUBSTRING_START(VAL) VALUE_FRAME(VAL)
71 /* Flag for whether we want to abandon failed expression evals by default. */
74 static int auto_abandon = 0;
78 /* Find the address of function name NAME in the inferior. */
81 find_function_in_inferior (name)
84 register struct symbol *sym;
85 sym = lookup_symbol (name, 0, VAR_NAMESPACE, 0, NULL);
88 if (SYMBOL_CLASS (sym) != LOC_BLOCK)
90 error ("\"%s\" exists in this program but is not a function.",
93 return value_of_variable (sym, NULL);
97 struct minimal_symbol *msymbol = lookup_minimal_symbol(name, NULL, NULL);
102 type = lookup_pointer_type (builtin_type_char);
103 type = lookup_function_type (type);
104 type = lookup_pointer_type (type);
105 maddr = (LONGEST) SYMBOL_VALUE_ADDRESS (msymbol);
106 return value_from_longest (type, maddr);
110 error ("evaluation of this expression requires the program to have a function \"%s\".", name);
115 /* Allocate NBYTES of space in the inferior using the inferior's malloc
116 and return a value that is a pointer to the allocated space. */
119 value_allocate_space_in_inferior (len)
123 register value_ptr val = find_function_in_inferior ("malloc");
125 blocklen = value_from_longest (builtin_type_int, (LONGEST) len);
126 val = call_function_by_hand (val, 1, &blocklen);
127 if (value_logical_not (val))
129 error ("No memory available to program.");
135 allocate_space_in_inferior (len)
138 return value_as_long (value_allocate_space_in_inferior (len));
141 /* Cast value ARG2 to type TYPE and return as a value.
142 More general than a C cast: accepts any two types of the same length,
143 and if ARG2 is an lvalue it can be cast into anything at all. */
144 /* In C++, casts may change pointer or object representations. */
147 value_cast (type, arg2)
149 register value_ptr arg2;
151 register enum type_code code1;
152 register enum type_code code2;
156 if (VALUE_TYPE (arg2) == type)
159 CHECK_TYPEDEF (type);
160 code1 = TYPE_CODE (type);
162 type2 = check_typedef (VALUE_TYPE (arg2));
164 /* A cast to an undetermined-length array_type, such as (TYPE [])OBJECT,
165 is treated like a cast to (TYPE [N])OBJECT,
166 where N is sizeof(OBJECT)/sizeof(TYPE). */
167 if (code1 == TYPE_CODE_ARRAY)
169 struct type *element_type = TYPE_TARGET_TYPE (type);
170 unsigned element_length = TYPE_LENGTH (check_typedef (element_type));
171 if (element_length > 0
172 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
174 struct type *range_type = TYPE_INDEX_TYPE (type);
175 int val_length = TYPE_LENGTH (type2);
176 LONGEST low_bound, high_bound, new_length;
177 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
178 low_bound = 0, high_bound = 0;
179 new_length = val_length / element_length;
180 if (val_length % element_length != 0)
181 warning("array element type size does not divide object size in cast");
182 /* FIXME-type-allocation: need a way to free this type when we are
184 range_type = create_range_type ((struct type *) NULL,
185 TYPE_TARGET_TYPE (range_type),
187 new_length + low_bound - 1);
188 VALUE_TYPE (arg2) = create_array_type ((struct type *) NULL,
189 element_type, range_type);
194 if (current_language->c_style_arrays
195 && TYPE_CODE (type2) == TYPE_CODE_ARRAY)
196 arg2 = value_coerce_array (arg2);
198 if (TYPE_CODE (type2) == TYPE_CODE_FUNC)
199 arg2 = value_coerce_function (arg2);
201 type2 = check_typedef (VALUE_TYPE (arg2));
202 COERCE_VARYING_ARRAY (arg2, type2);
203 code2 = TYPE_CODE (type2);
205 if (code1 == TYPE_CODE_COMPLEX)
206 return cast_into_complex (type, arg2);
207 if (code1 == TYPE_CODE_BOOL || code1 == TYPE_CODE_CHAR)
208 code1 = TYPE_CODE_INT;
209 if (code2 == TYPE_CODE_BOOL || code2 == TYPE_CODE_CHAR)
210 code2 = TYPE_CODE_INT;
212 scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
213 || code2 == TYPE_CODE_ENUM || code2 == TYPE_CODE_RANGE);
215 if ( code1 == TYPE_CODE_STRUCT
216 && code2 == TYPE_CODE_STRUCT
217 && TYPE_NAME (type) != 0)
219 /* Look in the type of the source to see if it contains the
220 type of the target as a superclass. If so, we'll need to
221 offset the object in addition to changing its type. */
222 value_ptr v = search_struct_field (type_name_no_tag (type),
226 VALUE_TYPE (v) = type;
230 if (code1 == TYPE_CODE_FLT && scalar)
231 return value_from_double (type, value_as_double (arg2));
232 else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM
233 || code1 == TYPE_CODE_RANGE)
234 && (scalar || code2 == TYPE_CODE_PTR))
235 return value_from_longest (type, value_as_long (arg2));
236 else if (TYPE_LENGTH (type) == TYPE_LENGTH (type2))
238 if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
240 /* Look in the type of the source to see if it contains the
241 type of the target as a superclass. If so, we'll need to
242 offset the pointer rather than just change its type. */
243 struct type *t1 = check_typedef (TYPE_TARGET_TYPE (type));
244 struct type *t2 = check_typedef (TYPE_TARGET_TYPE (type2));
245 if ( TYPE_CODE (t1) == TYPE_CODE_STRUCT
246 && TYPE_CODE (t2) == TYPE_CODE_STRUCT
247 && TYPE_NAME (t1) != 0) /* if name unknown, can't have supercl */
249 value_ptr v = search_struct_field (type_name_no_tag (t1),
250 value_ind (arg2), 0, t2, 1);
254 VALUE_TYPE (v) = type;
258 /* No superclass found, just fall through to change ptr type. */
260 VALUE_TYPE (arg2) = type;
263 else if (chill_varying_type (type))
265 struct type *range1, *range2, *eltype1, *eltype2;
268 LONGEST low_bound, high_bound;
269 char *valaddr, *valaddr_data;
270 if (code2 == TYPE_CODE_BITSTRING)
271 error ("not implemented: converting bitstring to varying type");
272 if ((code2 != TYPE_CODE_ARRAY && code2 != TYPE_CODE_STRING)
273 || (eltype1 = check_typedef (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 1))),
274 eltype2 = check_typedef (TYPE_TARGET_TYPE (type2)),
275 (TYPE_LENGTH (eltype1) != TYPE_LENGTH (eltype2)
276 /* || TYPE_CODE (eltype1) != TYPE_CODE (eltype2) */ )))
277 error ("Invalid conversion to varying type");
278 range1 = TYPE_FIELD_TYPE (TYPE_FIELD_TYPE (type, 1), 0);
279 range2 = TYPE_FIELD_TYPE (type2, 0);
280 if (get_discrete_bounds (range1, &low_bound, &high_bound) < 0)
283 count1 = high_bound - low_bound + 1;
284 if (get_discrete_bounds (range2, &low_bound, &high_bound) < 0)
285 count1 = -1, count2 = 0; /* To force error before */
287 count2 = high_bound - low_bound + 1;
289 error ("target varying type is too small");
290 val = allocate_value (type);
291 valaddr = VALUE_CONTENTS_RAW (val);
292 valaddr_data = valaddr + TYPE_FIELD_BITPOS (type, 1) / 8;
293 /* Set val's __var_length field to count2. */
294 store_signed_integer (valaddr, TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)),
296 /* Set the __var_data field to count2 elements copied from arg2. */
297 memcpy (valaddr_data, VALUE_CONTENTS (arg2),
298 count2 * TYPE_LENGTH (eltype2));
299 /* Zero the rest of the __var_data field of val. */
300 memset (valaddr_data + count2 * TYPE_LENGTH (eltype2), '\0',
301 (count1 - count2) * TYPE_LENGTH (eltype2));
304 else if (VALUE_LVAL (arg2) == lval_memory)
306 return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
308 else if (code1 == TYPE_CODE_VOID)
310 return value_zero (builtin_type_void, not_lval);
314 error ("Invalid cast.");
319 /* Create a value of type TYPE that is zero, and return it. */
322 value_zero (type, lv)
326 register value_ptr val = allocate_value (type);
328 memset (VALUE_CONTENTS (val), 0, TYPE_LENGTH (check_typedef (type)));
329 VALUE_LVAL (val) = lv;
334 /* Return a value with type TYPE located at ADDR.
336 Call value_at only if the data needs to be fetched immediately;
337 if we can be 'lazy' and defer the fetch, perhaps indefinately, call
338 value_at_lazy instead. value_at_lazy simply records the address of
339 the data and sets the lazy-evaluation-required flag. The lazy flag
340 is tested in the VALUE_CONTENTS macro, which is used if and when
341 the contents are actually required. */
344 value_at (type, addr)
348 register value_ptr val;
350 if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
351 error ("Attempt to dereference a generic pointer.");
353 val = allocate_value (type);
355 /* start-sanitize-d10v */
356 #ifdef GDB_TARGET_IS_D10V
357 if (TYPE_TARGET_TYPE(type) && TYPE_CODE(TYPE_TARGET_TYPE(type)) == TYPE_CODE_FUNC)
361 read_memory (addr, (char *)&snum, 2);
362 num = D10V_MAKE_IADDR(snum);
363 memcpy( VALUE_CONTENTS_RAW (val), &num, 4);
367 /* end-sanitize-d10v */
369 read_memory (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (type));
371 VALUE_LVAL (val) = lval_memory;
372 VALUE_ADDRESS (val) = addr;
377 /* Return a lazy value with type TYPE located at ADDR (cf. value_at). */
380 value_at_lazy (type, addr)
384 register value_ptr val;
386 if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
387 error ("Attempt to dereference a generic pointer.");
389 val = allocate_value (type);
391 VALUE_LVAL (val) = lval_memory;
392 VALUE_ADDRESS (val) = addr;
393 VALUE_LAZY (val) = 1;
398 /* Called only from the VALUE_CONTENTS macro, if the current data for
399 a variable needs to be loaded into VALUE_CONTENTS(VAL). Fetches the
400 data from the user's process, and clears the lazy flag to indicate
401 that the data in the buffer is valid.
403 If the value is zero-length, we avoid calling read_memory, which would
404 abort. We mark the value as fetched anyway -- all 0 bytes of it.
406 This function returns a value because it is used in the VALUE_CONTENTS
407 macro as part of an expression, where a void would not work. The
411 value_fetch_lazy (val)
412 register value_ptr val;
414 CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
415 int length = TYPE_LENGTH (VALUE_TYPE (val));
417 /* start-sanitize-d10v */
418 #ifdef GDB_TARGET_IS_D10V
419 struct type *type = VALUE_TYPE(val);
420 if (TYPE_TARGET_TYPE(type) && TYPE_CODE(TYPE_TARGET_TYPE(type)) == TYPE_CODE_FUNC)
424 read_memory (addr, (char *)&snum, 2);
425 num = D10V_MAKE_IADDR(snum);
426 memcpy( VALUE_CONTENTS_RAW (val), &num, 4);
430 /* end-sanitize-d10v */
433 read_memory (addr, VALUE_CONTENTS_RAW (val), length);
434 VALUE_LAZY (val) = 0;
439 /* Store the contents of FROMVAL into the location of TOVAL.
440 Return a new value with the location of TOVAL and contents of FROMVAL. */
443 value_assign (toval, fromval)
444 register value_ptr toval, fromval;
446 register struct type *type;
447 register value_ptr val;
448 char raw_buffer[MAX_REGISTER_RAW_SIZE];
451 if (!toval->modifiable)
452 error ("Left operand of assignment is not a modifiable lvalue.");
456 type = VALUE_TYPE (toval);
457 if (VALUE_LVAL (toval) != lval_internalvar)
458 fromval = value_cast (type, fromval);
460 COERCE_ARRAY (fromval);
461 CHECK_TYPEDEF (type);
463 /* If TOVAL is a special machine register requiring conversion
464 of program values to a special raw format,
465 convert FROMVAL's contents now, with result in `raw_buffer',
466 and set USE_BUFFER to the number of bytes to write. */
468 #ifdef REGISTER_CONVERTIBLE
469 if (VALUE_REGNO (toval) >= 0
470 && REGISTER_CONVERTIBLE (VALUE_REGNO (toval)))
472 int regno = VALUE_REGNO (toval);
473 if (REGISTER_CONVERTIBLE (regno))
475 struct type *fromtype = check_typedef (VALUE_TYPE (fromval));
476 REGISTER_CONVERT_TO_RAW (fromtype, regno,
477 VALUE_CONTENTS (fromval), raw_buffer);
478 use_buffer = REGISTER_RAW_SIZE (regno);
483 switch (VALUE_LVAL (toval))
485 case lval_internalvar:
486 set_internalvar (VALUE_INTERNALVAR (toval), fromval);
487 return value_copy (VALUE_INTERNALVAR (toval)->value);
489 case lval_internalvar_component:
490 set_internalvar_component (VALUE_INTERNALVAR (toval),
491 VALUE_OFFSET (toval),
492 VALUE_BITPOS (toval),
493 VALUE_BITSIZE (toval),
498 if (VALUE_BITSIZE (toval))
500 char buffer[sizeof (LONGEST)];
501 /* We assume that the argument to read_memory is in units of
502 host chars. FIXME: Is that correct? */
503 int len = (VALUE_BITPOS (toval)
504 + VALUE_BITSIZE (toval)
508 if (len > (int) sizeof (LONGEST))
509 error ("Can't handle bitfields which don't fit in a %d bit word.",
510 sizeof (LONGEST) * HOST_CHAR_BIT);
512 read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
514 modify_field (buffer, value_as_long (fromval),
515 VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
516 write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
520 write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
521 raw_buffer, use_buffer);
523 write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
524 VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
528 if (VALUE_BITSIZE (toval))
530 char buffer[sizeof (LONGEST)];
531 int len = REGISTER_RAW_SIZE (VALUE_REGNO (toval));
533 if (len > (int) sizeof (LONGEST))
534 error ("Can't handle bitfields in registers larger than %d bits.",
535 sizeof (LONGEST) * HOST_CHAR_BIT);
537 if (VALUE_BITPOS (toval) + VALUE_BITSIZE (toval)
538 > len * HOST_CHAR_BIT)
539 /* Getting this right would involve being very careful about
542 Can't handle bitfield which doesn't fit in a single register.");
544 read_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
546 modify_field (buffer, value_as_long (fromval),
547 VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
548 write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
552 write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
553 raw_buffer, use_buffer);
556 /* Do any conversion necessary when storing this type to more
557 than one register. */
558 #ifdef REGISTER_CONVERT_FROM_TYPE
559 memcpy (raw_buffer, VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
560 REGISTER_CONVERT_FROM_TYPE(VALUE_REGNO (toval), type, raw_buffer);
561 write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
562 raw_buffer, TYPE_LENGTH (type));
564 write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
565 VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
568 /* Assigning to the stack pointer, frame pointer, and other
569 (architecture and calling convention specific) registers may
570 cause the frame cache to be out of date. We just do this
571 on all assignments to registers for simplicity; I doubt the slowdown
573 reinit_frame_cache ();
576 case lval_reg_frame_relative:
578 /* value is stored in a series of registers in the frame
579 specified by the structure. Copy that value out, modify
580 it, and copy it back in. */
581 int amount_to_copy = (VALUE_BITSIZE (toval) ? 1 : TYPE_LENGTH (type));
582 int reg_size = REGISTER_RAW_SIZE (VALUE_FRAME_REGNUM (toval));
583 int byte_offset = VALUE_OFFSET (toval) % reg_size;
584 int reg_offset = VALUE_OFFSET (toval) / reg_size;
587 /* Make the buffer large enough in all cases. */
588 char *buffer = (char *) alloca (amount_to_copy
590 + MAX_REGISTER_RAW_SIZE);
593 struct frame_info *frame;
595 /* Figure out which frame this is in currently. */
596 for (frame = get_current_frame ();
597 frame && FRAME_FP (frame) != VALUE_FRAME (toval);
598 frame = get_prev_frame (frame))
602 error ("Value being assigned to is no longer active.");
604 amount_to_copy += (reg_size - amount_to_copy % reg_size);
607 for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
609 amount_copied < amount_to_copy;
610 amount_copied += reg_size, regno++)
612 get_saved_register (buffer + amount_copied,
613 (int *)NULL, (CORE_ADDR *)NULL,
614 frame, regno, (enum lval_type *)NULL);
617 /* Modify what needs to be modified. */
618 if (VALUE_BITSIZE (toval))
619 modify_field (buffer + byte_offset,
620 value_as_long (fromval),
621 VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
623 memcpy (buffer + byte_offset, raw_buffer, use_buffer);
625 memcpy (buffer + byte_offset, VALUE_CONTENTS (fromval),
629 for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
631 amount_copied < amount_to_copy;
632 amount_copied += reg_size, regno++)
638 /* Just find out where to put it. */
639 get_saved_register ((char *)NULL,
640 &optim, &addr, frame, regno, &lval);
643 error ("Attempt to assign to a value that was optimized out.");
644 if (lval == lval_memory)
645 write_memory (addr, buffer + amount_copied, reg_size);
646 else if (lval == lval_register)
647 write_register_bytes (addr, buffer + amount_copied, reg_size);
649 error ("Attempt to assign to an unmodifiable value.");
656 error ("Left operand of assignment is not an lvalue.");
659 /* If the field does not entirely fill a LONGEST, then zero the sign bits.
660 If the field is signed, and is negative, then sign extend. */
661 if ((VALUE_BITSIZE (toval) > 0)
662 && (VALUE_BITSIZE (toval) < 8 * (int) sizeof (LONGEST)))
664 LONGEST fieldval = value_as_long (fromval);
665 LONGEST valmask = (((ULONGEST) 1) << VALUE_BITSIZE (toval)) - 1;
668 if (!TYPE_UNSIGNED (type) && (fieldval & (valmask ^ (valmask >> 1))))
669 fieldval |= ~valmask;
671 fromval = value_from_longest (type, fieldval);
674 val = value_copy (toval);
675 memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval),
677 VALUE_TYPE (val) = type;
682 /* Extend a value VAL to COUNT repetitions of its type. */
685 value_repeat (arg1, count)
689 register value_ptr val;
691 if (VALUE_LVAL (arg1) != lval_memory)
692 error ("Only values in memory can be extended with '@'.");
694 error ("Invalid number %d of repetitions.", count);
696 val = allocate_repeat_value (VALUE_TYPE (arg1), count);
698 read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1),
699 VALUE_CONTENTS_RAW (val),
700 TYPE_LENGTH (VALUE_TYPE (val)));
701 VALUE_LVAL (val) = lval_memory;
702 VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1);
708 value_of_variable (var, b)
713 struct frame_info *frame;
716 frame = NULL; /* Use selected frame. */
717 else if (symbol_read_needs_frame (var))
719 frame = block_innermost_frame (b);
721 if (BLOCK_FUNCTION (b)
722 && SYMBOL_NAME (BLOCK_FUNCTION (b)))
723 error ("No frame is currently executing in block %s.",
724 SYMBOL_NAME (BLOCK_FUNCTION (b)));
726 error ("No frame is currently executing in specified block");
729 val = read_var_value (var, frame);
731 error ("Address of symbol \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
736 /* Given a value which is an array, return a value which is a pointer to its
737 first element, regardless of whether or not the array has a nonzero lower
740 FIXME: A previous comment here indicated that this routine should be
741 substracting the array's lower bound. It's not clear to me that this
742 is correct. Given an array subscripting operation, it would certainly
743 work to do the adjustment here, essentially computing:
745 (&array[0] - (lowerbound * sizeof array[0])) + (index * sizeof array[0])
747 However I believe a more appropriate and logical place to account for
748 the lower bound is to do so in value_subscript, essentially computing:
750 (&array[0] + ((index - lowerbound) * sizeof array[0]))
752 As further evidence consider what would happen with operations other
753 than array subscripting, where the caller would get back a value that
754 had an address somewhere before the actual first element of the array,
755 and the information about the lower bound would be lost because of
756 the coercion to pointer type.
760 value_coerce_array (arg1)
763 register struct type *type = check_typedef (VALUE_TYPE (arg1));
765 if (VALUE_LVAL (arg1) != lval_memory)
766 error ("Attempt to take address of value not located in memory.");
768 return value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
769 (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
772 /* Given a value which is a function, return a value which is a pointer
776 value_coerce_function (arg1)
780 if (VALUE_LVAL (arg1) != lval_memory)
781 error ("Attempt to take address of value not located in memory.");
783 return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
784 (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
787 /* Return a pointer value for the object for which ARG1 is the contents. */
793 struct type *type = check_typedef (VALUE_TYPE (arg1));
794 if (TYPE_CODE (type) == TYPE_CODE_REF)
796 /* Copy the value, but change the type from (T&) to (T*).
797 We keep the same location information, which is efficient,
798 and allows &(&X) to get the location containing the reference. */
799 value_ptr arg2 = value_copy (arg1);
800 VALUE_TYPE (arg2) = lookup_pointer_type (TYPE_TARGET_TYPE (type));
803 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
804 return value_coerce_function (arg1);
806 if (VALUE_LVAL (arg1) != lval_memory)
807 error ("Attempt to take address of value not located in memory.");
809 return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
810 (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
813 /* Given a value of a pointer type, apply the C unary * operator to it. */
821 type1 = check_typedef (VALUE_TYPE (arg1));
823 if (TYPE_CODE (type1) == TYPE_CODE_MEMBER)
824 error ("not implemented: member types in value_ind");
826 /* Allow * on an integer so we can cast it to whatever we want.
827 This returns an int, which seems like the most C-like thing
828 to do. "long long" variables are rare enough that
829 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
830 if (TYPE_CODE (type1) == TYPE_CODE_INT)
831 return value_at (builtin_type_int,
832 (CORE_ADDR) value_as_long (arg1));
833 else if (TYPE_CODE (type1) == TYPE_CODE_PTR)
834 return value_at_lazy (TYPE_TARGET_TYPE (type1), value_as_pointer (arg1));
835 error ("Attempt to take contents of a non-pointer value.");
836 return 0; /* For lint -- never reached */
839 /* Pushing small parts of stack frames. */
841 /* Push one word (the size of object that a register holds). */
848 register int len = REGISTER_SIZE;
849 char buffer[MAX_REGISTER_RAW_SIZE];
851 store_unsigned_integer (buffer, len, word);
854 write_memory (sp, buffer, len);
855 #else /* stack grows upward */
856 write_memory (sp, buffer, len);
858 #endif /* stack grows upward */
863 /* Push LEN bytes with data at BUFFER. */
866 push_bytes (sp, buffer, len)
873 write_memory (sp, buffer, len);
874 #else /* stack grows upward */
875 write_memory (sp, buffer, len);
877 #endif /* stack grows upward */
882 /* Push onto the stack the specified value VALUE. */
884 #ifndef PUSH_ARGUMENTS
888 register CORE_ADDR sp;
891 register int len = TYPE_LENGTH (VALUE_TYPE (arg));
895 write_memory (sp, VALUE_CONTENTS (arg), len);
896 #else /* stack grows upward */
897 write_memory (sp, VALUE_CONTENTS (arg), len);
899 #endif /* stack grows upward */
904 #endif /* !PUSH_ARGUMENTS */
906 /* Perform the standard coercions that are specified
907 for arguments to be passed to C functions.
909 If PARAM_TYPE is non-NULL, it is the expected parameter type. */
912 value_arg_coerce (arg, param_type)
914 struct type *param_type;
916 register struct type *arg_type = check_typedef (VALUE_TYPE (arg));
917 register struct type *type
918 = param_type ? check_typedef (param_type) : arg_type;
920 switch (TYPE_CODE (type))
923 if (TYPE_CODE (arg_type) != TYPE_CODE_REF)
925 arg = value_addr (arg);
926 VALUE_TYPE (arg) = param_type;
934 if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int))
935 type = builtin_type_int;
938 /* coerce float to double, unless the function prototype specifies float */
939 if (COERCE_FLOAT_TO_DOUBLE)
941 if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_double))
942 type = builtin_type_double;
943 else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin_type_double))
944 type = builtin_type_long_double;
948 type = lookup_pointer_type (type);
950 case TYPE_CODE_ARRAY:
951 if (current_language->c_style_arrays)
952 type = lookup_pointer_type (TYPE_TARGET_TYPE (type));
954 case TYPE_CODE_UNDEF:
956 case TYPE_CODE_STRUCT:
957 case TYPE_CODE_UNION:
960 case TYPE_CODE_RANGE:
961 case TYPE_CODE_STRING:
962 case TYPE_CODE_BITSTRING:
963 case TYPE_CODE_ERROR:
964 case TYPE_CODE_MEMBER:
965 case TYPE_CODE_METHOD:
966 case TYPE_CODE_COMPLEX:
971 return value_cast (type, arg);
974 /* Determine a function's address and its return type from its value.
975 Calls error() if the function is not valid for calling. */
978 find_function_addr (function, retval_type)
980 struct type **retval_type;
982 register struct type *ftype = check_typedef (VALUE_TYPE (function));
983 register enum type_code code = TYPE_CODE (ftype);
984 struct type *value_type;
987 /* If it's a member function, just look at the function
990 /* Determine address to call. */
991 if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
993 funaddr = VALUE_ADDRESS (function);
994 value_type = TYPE_TARGET_TYPE (ftype);
996 else if (code == TYPE_CODE_PTR)
998 funaddr = value_as_pointer (function);
999 ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
1000 if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
1001 || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
1003 #ifdef CONVERT_FROM_FUNC_PTR_ADDR
1004 /* FIXME: This is a workaround for the unusual function
1005 pointer representation on the RS/6000, see comment
1006 in config/rs6000/tm-rs6000.h */
1007 funaddr = CONVERT_FROM_FUNC_PTR_ADDR (funaddr);
1009 value_type = TYPE_TARGET_TYPE (ftype);
1012 value_type = builtin_type_int;
1014 else if (code == TYPE_CODE_INT)
1016 /* Handle the case of functions lacking debugging info.
1017 Their values are characters since their addresses are char */
1018 if (TYPE_LENGTH (ftype) == 1)
1019 funaddr = value_as_pointer (value_addr (function));
1021 /* Handle integer used as address of a function. */
1022 funaddr = (CORE_ADDR) value_as_long (function);
1024 value_type = builtin_type_int;
1027 error ("Invalid data type for function to be called.");
1029 *retval_type = value_type;
1033 #if defined (CALL_DUMMY)
1034 /* All this stuff with a dummy frame may seem unnecessarily complicated
1035 (why not just save registers in GDB?). The purpose of pushing a dummy
1036 frame which looks just like a real frame is so that if you call a
1037 function and then hit a breakpoint (get a signal, etc), "backtrace"
1038 will look right. Whether the backtrace needs to actually show the
1039 stack at the time the inferior function was called is debatable, but
1040 it certainly needs to not display garbage. So if you are contemplating
1041 making dummy frames be different from normal frames, consider that. */
1043 /* Perform a function call in the inferior.
1044 ARGS is a vector of values of arguments (NARGS of them).
1045 FUNCTION is a value, the function to be called.
1046 Returns a value representing what the function returned.
1047 May fail to return, if a breakpoint or signal is hit
1048 during the execution of the function.
1050 ARGS is modified to contain coerced values. */
1053 call_function_by_hand (function, nargs, args)
1058 register CORE_ADDR sp;
1061 /* CALL_DUMMY is an array of words (REGISTER_SIZE), but each word
1062 is in host byte order. Before calling FIX_CALL_DUMMY, we byteswap it
1063 and remove any extra bytes which might exist because ULONGEST is
1064 bigger than REGISTER_SIZE. */
1065 static ULONGEST dummy[] = CALL_DUMMY;
1066 char dummy1[REGISTER_SIZE * sizeof dummy / sizeof (ULONGEST)];
1068 struct type *value_type;
1069 unsigned char struct_return;
1070 CORE_ADDR struct_addr = 0;
1071 struct inferior_status inf_status;
1072 struct cleanup *old_chain;
1074 int using_gcc; /* Set to version of gcc in use, or zero if not gcc */
1076 struct type *ftype = check_typedef (SYMBOL_TYPE (function));
1078 if (!target_has_execution)
1081 save_inferior_status (&inf_status, 1);
1082 old_chain = make_cleanup (restore_inferior_status, &inf_status);
1084 /* PUSH_DUMMY_FRAME is responsible for saving the inferior registers
1085 (and POP_FRAME for restoring them). (At least on most machines)
1086 they are saved on the stack in the inferior. */
1089 old_sp = sp = read_sp ();
1091 #if 1 INNER_THAN 2 /* Stack grows down */
1092 sp -= sizeof dummy1;
1094 #else /* Stack grows up */
1096 sp += sizeof dummy1;
1099 funaddr = find_function_addr (function, &value_type);
1100 CHECK_TYPEDEF (value_type);
1103 struct block *b = block_for_pc (funaddr);
1104 /* If compiled without -g, assume GCC 2. */
1105 using_gcc = (b == NULL ? 2 : BLOCK_GCC_COMPILED (b));
1108 /* Are we returning a value using a structure return or a normal
1111 struct_return = using_struct_return (function, funaddr, value_type,
1114 /* Create a call sequence customized for this function
1115 and the number of arguments for it. */
1116 for (i = 0; i < (int) (sizeof (dummy) / sizeof (dummy[0])); i++)
1117 store_unsigned_integer (&dummy1[i * REGISTER_SIZE],
1119 (ULONGEST)dummy[i]);
1121 #ifdef GDB_TARGET_IS_HPPA
1122 real_pc = FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args,
1123 value_type, using_gcc);
1125 FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args,
1126 value_type, using_gcc);
1130 #if CALL_DUMMY_LOCATION == ON_STACK
1131 write_memory (start_sp, (char *)dummy1, sizeof dummy1);
1132 #endif /* On stack. */
1134 #if CALL_DUMMY_LOCATION == BEFORE_TEXT_END
1135 /* Convex Unix prohibits executing in the stack segment. */
1136 /* Hope there is empty room at the top of the text segment. */
1138 extern CORE_ADDR text_end;
1141 for (start_sp = text_end - sizeof dummy1; start_sp < text_end; ++start_sp)
1142 if (read_memory_integer (start_sp, 1) != 0)
1143 error ("text segment full -- no place to put call");
1146 real_pc = text_end - sizeof dummy1;
1147 write_memory (real_pc, (char *)dummy1, sizeof dummy1);
1149 #endif /* Before text_end. */
1151 #if CALL_DUMMY_LOCATION == AFTER_TEXT_END
1153 extern CORE_ADDR text_end;
1157 errcode = target_write_memory (real_pc, (char *)dummy1, sizeof dummy1);
1159 error ("Cannot write text segment -- call_function failed");
1161 #endif /* After text_end. */
1163 #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT
1165 #endif /* At entry point. */
1168 sp = old_sp; /* It really is used, for some ifdef's... */
1171 if (nargs < TYPE_NFIELDS (ftype))
1172 error ("too few arguments in function call");
1174 for (i = nargs - 1; i >= 0; i--)
1176 struct type *param_type;
1177 if (TYPE_NFIELDS (ftype) > i)
1178 param_type = TYPE_FIELD_TYPE (ftype, i);
1181 args[i] = value_arg_coerce (args[i], param_type);
1184 #if defined (REG_STRUCT_HAS_ADDR)
1186 /* This is a machine like the sparc, where we may need to pass a pointer
1187 to the structure, not the structure itself. */
1188 for (i = nargs - 1; i >= 0; i--)
1190 struct type *arg_type = check_typedef (VALUE_TYPE (args[i]));
1191 if ((TYPE_CODE (arg_type) == TYPE_CODE_STRUCT
1192 || TYPE_CODE (arg_type) == TYPE_CODE_UNION
1193 || TYPE_CODE (arg_type) == TYPE_CODE_ARRAY
1194 || TYPE_CODE (arg_type) == TYPE_CODE_STRING
1195 || TYPE_CODE (arg_type) == TYPE_CODE_BITSTRING
1196 || TYPE_CODE (arg_type) == TYPE_CODE_SET
1197 || (TYPE_CODE (arg_type) == TYPE_CODE_FLT
1198 && TYPE_LENGTH (arg_type) > 8)
1200 && REG_STRUCT_HAS_ADDR (using_gcc, arg_type))
1203 int len = TYPE_LENGTH (arg_type);
1205 /* MVS 11/22/96: I think at least some of this stack_align code is
1206 really broken. Better to let PUSH_ARGUMENTS adjust the stack in
1207 a target-defined manner. */
1208 int aligned_len = STACK_ALIGN (len);
1210 int aligned_len = len;
1212 #if !(1 INNER_THAN 2)
1213 /* The stack grows up, so the address of the thing we push
1214 is the stack pointer before we push it. */
1219 /* Push the structure. */
1220 write_memory (sp, VALUE_CONTENTS (args[i]), len);
1222 /* The stack grows down, so the address of the thing we push
1223 is the stack pointer after we push it. */
1228 /* The value we're going to pass is the address of the thing
1230 args[i] = value_from_longest (lookup_pointer_type (value_type),
1235 #endif /* REG_STRUCT_HAS_ADDR. */
1237 /* Reserve space for the return structure to be written on the
1238 stack, if necessary */
1242 int len = TYPE_LENGTH (value_type);
1244 /* MVS 11/22/96: I think at least some of this stack_align code is
1245 really broken. Better to let PUSH_ARGUMENTS adjust the stack in
1246 a target-defined manner. */
1247 len = STACK_ALIGN (len);
1258 #if defined(STACK_ALIGN) && (1 INNER_THAN 2)
1259 /* MVS 11/22/96: I think at least some of this stack_align code is
1260 really broken. Better to let PUSH_ARGUMENTS adjust the stack in
1261 a target-defined manner. */
1263 /* If stack grows down, we must leave a hole at the top. */
1266 for (i = nargs - 1; i >= 0; i--)
1267 len += TYPE_LENGTH (VALUE_TYPE (args[i]));
1268 #ifdef CALL_DUMMY_STACK_ADJUST
1269 len += CALL_DUMMY_STACK_ADJUST;
1271 sp -= STACK_ALIGN (len) - len;
1273 #endif /* STACK_ALIGN */
1275 #ifdef PUSH_ARGUMENTS
1276 PUSH_ARGUMENTS(nargs, args, sp, struct_return, struct_addr);
1277 #else /* !PUSH_ARGUMENTS */
1278 for (i = nargs - 1; i >= 0; i--)
1279 sp = value_push (sp, args[i]);
1280 #endif /* !PUSH_ARGUMENTS */
1282 #ifdef PUSH_RETURN_ADDRESS /* for targets that use no CALL_DUMMY */
1283 /* There are a number of targets now which actually don't write any
1284 CALL_DUMMY instructions into the target, but instead just save the
1285 machine state, push the arguments, and jump directly to the callee
1286 function. Since this doesn't actually involve executing a JSR/BSR
1287 instruction, the return address must be set up by hand, either by
1288 pushing onto the stack or copying into a return-address register
1289 as appropriate. Formerly this has been done in PUSH_ARGUMENTS,
1290 but that's overloading its functionality a bit, so I'm making it
1291 explicit to do it here. */
1292 sp = PUSH_RETURN_ADDRESS(real_pc, sp);
1293 #endif /* PUSH_RETURN_ADDRESS */
1295 #if defined(STACK_ALIGN) && !(1 INNER_THAN 2)
1297 /* If stack grows up, we must leave a hole at the bottom, note
1298 that sp already has been advanced for the arguments! */
1299 #ifdef CALL_DUMMY_STACK_ADJUST
1300 sp += CALL_DUMMY_STACK_ADJUST;
1302 sp = STACK_ALIGN (sp);
1304 #endif /* STACK_ALIGN */
1306 /* XXX This seems wrong. For stacks that grow down we shouldn't do
1308 /* MVS 11/22/96: I think at least some of this stack_align code is
1309 really broken. Better to let PUSH_ARGUMENTS adjust the stack in
1310 a target-defined manner. */
1311 #ifdef CALL_DUMMY_STACK_ADJUST
1313 sp -= CALL_DUMMY_STACK_ADJUST;
1315 #endif /* CALL_DUMMY_STACK_ADJUST */
1317 /* Store the address at which the structure is supposed to be
1318 written. Note that this (and the code which reserved the space
1319 above) assumes that gcc was used to compile this function. Since
1320 it doesn't cost us anything but space and if the function is pcc
1321 it will ignore this value, we will make that assumption.
1323 Also note that on some machines (like the sparc) pcc uses a
1324 convention like gcc's. */
1327 STORE_STRUCT_RETURN (struct_addr, sp);
1329 /* Write the stack pointer. This is here because the statements above
1330 might fool with it. On SPARC, this write also stores the register
1331 window into the right place in the new stack frame, which otherwise
1332 wouldn't happen. (See store_inferior_registers in sparc-nat.c.) */
1336 char retbuf[REGISTER_BYTES];
1338 struct symbol *symbol;
1341 symbol = find_pc_function (funaddr);
1344 name = SYMBOL_SOURCE_NAME (symbol);
1348 /* Try the minimal symbols. */
1349 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr);
1353 name = SYMBOL_SOURCE_NAME (msymbol);
1359 sprintf (format, "at %s", local_hex_format ());
1361 /* FIXME-32x64: assumes funaddr fits in a long. */
1362 sprintf (name, format, (unsigned long) funaddr);
1365 /* Execute the stack dummy routine, calling FUNCTION.
1366 When it is done, discard the empty frame
1367 after storing the contents of all regs into retbuf. */
1368 if (run_stack_dummy (real_pc + CALL_DUMMY_START_OFFSET, retbuf))
1370 /* We stopped somewhere besides the call dummy. */
1372 /* If we did the cleanups, we would print a spurious error message
1373 (Unable to restore previously selected frame), would write the
1374 registers from the inf_status (which is wrong), and would do other
1375 wrong things (like set stop_bpstat to the wrong thing). */
1376 discard_cleanups (old_chain);
1377 /* Prevent memory leak. */
1378 bpstat_clear (&inf_status.stop_bpstat);
1380 /* The following error message used to say "The expression
1381 which contained the function call has been discarded." It
1382 is a hard concept to explain in a few words. Ideally, GDB
1383 would be able to resume evaluation of the expression when
1384 the function finally is done executing. Perhaps someday
1385 this will be implemented (it would not be easy). */
1387 /* FIXME: Insert a bunch of wrap_here; name can be very long if it's
1388 a C++ name with arguments and stuff. */
1390 The program being debugged stopped while in a function called from GDB.\n\
1391 When the function (%s) is done executing, GDB will silently\n\
1392 stop (instead of continuing to evaluate the expression containing\n\
1393 the function call).", name);
1396 do_cleanups (old_chain);
1398 /* Figure out the value returned by the function. */
1399 return value_being_returned (value_type, retbuf, struct_return);
1402 #else /* no CALL_DUMMY. */
1404 call_function_by_hand (function, nargs, args)
1409 error ("Cannot invoke functions on this machine.");
1411 #endif /* no CALL_DUMMY. */
1414 /* Create a value for an array by allocating space in the inferior, copying
1415 the data into that space, and then setting up an array value.
1417 The array bounds are set from LOWBOUND and HIGHBOUND, and the array is
1418 populated from the values passed in ELEMVEC.
1420 The element type of the array is inherited from the type of the
1421 first element, and all elements must have the same size (though we
1422 don't currently enforce any restriction on their types). */
1425 value_array (lowbound, highbound, elemvec)
1432 unsigned int typelength;
1434 struct type *rangetype;
1435 struct type *arraytype;
1438 /* Validate that the bounds are reasonable and that each of the elements
1439 have the same size. */
1441 nelem = highbound - lowbound + 1;
1444 error ("bad array bounds (%d, %d)", lowbound, highbound);
1446 typelength = TYPE_LENGTH (VALUE_TYPE (elemvec[0]));
1447 for (idx = 1; idx < nelem; idx++)
1449 if (TYPE_LENGTH (VALUE_TYPE (elemvec[idx])) != typelength)
1451 error ("array elements must all be the same size");
1455 rangetype = create_range_type ((struct type *) NULL, builtin_type_int,
1456 lowbound, highbound);
1457 arraytype = create_array_type ((struct type *) NULL,
1458 VALUE_TYPE (elemvec[0]), rangetype);
1460 if (!current_language->c_style_arrays)
1462 val = allocate_value (arraytype);
1463 for (idx = 0; idx < nelem; idx++)
1465 memcpy (VALUE_CONTENTS_RAW (val) + (idx * typelength),
1466 VALUE_CONTENTS (elemvec[idx]),
1472 /* Allocate space to store the array in the inferior, and then initialize
1473 it by copying in each element. FIXME: Is it worth it to create a
1474 local buffer in which to collect each value and then write all the
1475 bytes in one operation? */
1477 addr = allocate_space_in_inferior (nelem * typelength);
1478 for (idx = 0; idx < nelem; idx++)
1480 write_memory (addr + (idx * typelength), VALUE_CONTENTS (elemvec[idx]),
1484 /* Create the array type and set up an array value to be evaluated lazily. */
1486 val = value_at_lazy (arraytype, addr);
1490 /* Create a value for a string constant by allocating space in the inferior,
1491 copying the data into that space, and returning the address with type
1492 TYPE_CODE_STRING. PTR points to the string constant data; LEN is number
1494 Note that string types are like array of char types with a lower bound of
1495 zero and an upper bound of LEN - 1. Also note that the string may contain
1496 embedded null bytes. */
1499 value_string (ptr, len)
1504 int lowbound = current_language->string_lower_bound;
1505 struct type *rangetype = create_range_type ((struct type *) NULL,
1507 lowbound, len + lowbound - 1);
1508 struct type *stringtype
1509 = create_string_type ((struct type *) NULL, rangetype);
1512 if (current_language->c_style_arrays == 0)
1514 val = allocate_value (stringtype);
1515 memcpy (VALUE_CONTENTS_RAW (val), ptr, len);
1520 /* Allocate space to store the string in the inferior, and then
1521 copy LEN bytes from PTR in gdb to that address in the inferior. */
1523 addr = allocate_space_in_inferior (len);
1524 write_memory (addr, ptr, len);
1526 val = value_at_lazy (stringtype, addr);
1531 value_bitstring (ptr, len)
1536 struct type *domain_type = create_range_type (NULL, builtin_type_int,
1538 struct type *type = create_set_type ((struct type*) NULL, domain_type);
1539 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
1540 val = allocate_value (type);
1541 memcpy (VALUE_CONTENTS_RAW (val), ptr, TYPE_LENGTH (type));
1545 /* See if we can pass arguments in T2 to a function which takes arguments
1546 of types T1. Both t1 and t2 are NULL-terminated vectors. If some
1547 arguments need coercion of some sort, then the coerced values are written
1548 into T2. Return value is 0 if the arguments could be matched, or the
1549 position at which they differ if not.
1551 STATICP is nonzero if the T1 argument list came from a
1552 static member function.
1554 For non-static member functions, we ignore the first argument,
1555 which is the type of the instance variable. This is because we want
1556 to handle calls with objects from derived classes. This is not
1557 entirely correct: we should actually check to make sure that a
1558 requested operation is type secure, shouldn't we? FIXME. */
1561 typecmp (staticp, t1, t2)
1570 if (staticp && t1 == 0)
1574 if (TYPE_CODE (t1[0]) == TYPE_CODE_VOID) return 0;
1575 if (t1[!staticp] == 0) return 0;
1576 for (i = !staticp; t1[i] && TYPE_CODE (t1[i]) != TYPE_CODE_VOID; i++)
1578 struct type *tt1, *tt2;
1581 tt1 = check_typedef (t1[i]);
1582 tt2 = check_typedef (VALUE_TYPE(t2[i]));
1583 if (TYPE_CODE (tt1) == TYPE_CODE_REF
1584 /* We should be doing hairy argument matching, as below. */
1585 && (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (tt1))) == TYPE_CODE (tt2)))
1587 if (TYPE_CODE (tt2) == TYPE_CODE_ARRAY)
1588 t2[i] = value_coerce_array (t2[i]);
1590 t2[i] = value_addr (t2[i]);
1594 while (TYPE_CODE (tt1) == TYPE_CODE_PTR
1595 && ( TYPE_CODE (tt2) == TYPE_CODE_ARRAY
1596 || TYPE_CODE (tt2) == TYPE_CODE_PTR))
1598 tt1 = check_typedef (TYPE_TARGET_TYPE(tt1));
1599 tt2 = check_typedef (TYPE_TARGET_TYPE(tt2));
1601 if (TYPE_CODE(tt1) == TYPE_CODE(tt2)) continue;
1602 /* Array to pointer is a `trivial conversion' according to the ARM. */
1604 /* We should be doing much hairier argument matching (see section 13.2
1605 of the ARM), but as a quick kludge, just check for the same type
1607 if (TYPE_CODE (t1[i]) != TYPE_CODE (VALUE_TYPE (t2[i])))
1610 if (!t1[i]) return 0;
1611 return t2[i] ? i+1 : 0;
1614 /* Helper function used by value_struct_elt to recurse through baseclasses.
1615 Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
1616 and search in it assuming it has (class) type TYPE.
1617 If found, return value, else return NULL.
1619 If LOOKING_FOR_BASECLASS, then instead of looking for struct fields,
1620 look for a baseclass named NAME. */
1623 search_struct_field (name, arg1, offset, type, looking_for_baseclass)
1625 register value_ptr arg1;
1627 register struct type *type;
1628 int looking_for_baseclass;
1632 CHECK_TYPEDEF (type);
1634 if (! looking_for_baseclass)
1635 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1637 char *t_field_name = TYPE_FIELD_NAME (type, i);
1639 if (t_field_name && STREQ (t_field_name, name))
1642 if (TYPE_FIELD_STATIC (type, i))
1644 char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, i);
1645 struct symbol *sym =
1646 lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
1648 error ("Internal error: could not find physical static variable named %s",
1650 v = value_at (TYPE_FIELD_TYPE (type, i),
1651 SYMBOL_VALUE_ADDRESS (sym));
1654 v = value_primitive_field (arg1, offset, i, type);
1656 error("there is no field named %s", name);
1661 && (t_field_name[0] == '\0'
1662 || (TYPE_CODE (type) == TYPE_CODE_UNION
1663 && STREQ (t_field_name, "else"))))
1665 struct type *field_type = TYPE_FIELD_TYPE (type, i);
1666 if (TYPE_CODE (field_type) == TYPE_CODE_UNION
1667 || TYPE_CODE (field_type) == TYPE_CODE_STRUCT)
1669 /* Look for a match through the fields of an anonymous union,
1670 or anonymous struct. C++ provides anonymous unions.
1672 In the GNU Chill implementation of variant record types,
1673 each <alternative field> has an (anonymous) union type,
1674 each member of the union represents a <variant alternative>.
1675 Each <variant alternative> is represented as a struct,
1676 with a member for each <variant field>. */
1679 int new_offset = offset;
1681 /* This is pretty gross. In G++, the offset in an anonymous
1682 union is relative to the beginning of the enclosing struct.
1683 In the GNU Chill implementation of variant records,
1684 the bitpos is zero in an anonymous union field, so we
1685 have to add the offset of the union here. */
1686 if (TYPE_CODE (field_type) == TYPE_CODE_STRUCT
1687 || (TYPE_NFIELDS (field_type) > 0
1688 && TYPE_FIELD_BITPOS (field_type, 0) == 0))
1689 new_offset += TYPE_FIELD_BITPOS (type, i) / 8;
1691 v = search_struct_field (name, arg1, new_offset, field_type,
1692 looking_for_baseclass);
1699 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1702 struct type *basetype = check_typedef (TYPE_BASECLASS (type, i));
1703 /* If we are looking for baseclasses, this is what we get when we
1704 hit them. But it could happen that the base part's member name
1705 is not yet filled in. */
1706 int found_baseclass = (looking_for_baseclass
1707 && TYPE_BASECLASS_NAME (type, i) != NULL
1708 && STREQ (name, TYPE_BASECLASS_NAME (type, i)));
1710 if (BASETYPE_VIA_VIRTUAL (type, i))
1712 int boffset = VALUE_OFFSET (arg1) + offset;
1713 boffset = baseclass_offset (type, i,
1714 VALUE_CONTENTS (arg1) + boffset,
1715 VALUE_ADDRESS (arg1) + boffset);
1717 error ("virtual baseclass botch");
1718 if (found_baseclass)
1720 value_ptr v2 = allocate_value (basetype);
1721 VALUE_LVAL (v2) = VALUE_LVAL (arg1);
1722 VALUE_ADDRESS (v2) = VALUE_ADDRESS (arg1);
1723 VALUE_OFFSET (v2) = VALUE_OFFSET (arg1) + offset + boffset;
1724 if (VALUE_LAZY (arg1))
1725 VALUE_LAZY (v2) = 1;
1727 memcpy (VALUE_CONTENTS_RAW (v2),
1728 VALUE_CONTENTS_RAW (arg1) + offset + boffset,
1729 TYPE_LENGTH (basetype));
1732 v = search_struct_field (name, arg1, offset + boffset,
1733 TYPE_BASECLASS (type, i),
1734 looking_for_baseclass);
1736 else if (found_baseclass)
1737 v = value_primitive_field (arg1, offset, i, type);
1739 v = search_struct_field (name, arg1,
1740 offset + TYPE_BASECLASS_BITPOS (type, i) / 8,
1741 basetype, looking_for_baseclass);
1747 /* Helper function used by value_struct_elt to recurse through baseclasses.
1748 Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
1749 and search in it assuming it has (class) type TYPE.
1750 If found, return value, else if name matched and args not return (value)-1,
1751 else return NULL. */
1754 search_struct_method (name, arg1p, args, offset, static_memfuncp, type)
1756 register value_ptr *arg1p, *args;
1757 int offset, *static_memfuncp;
1758 register struct type *type;
1762 int name_matched = 0;
1763 char dem_opname[64];
1765 CHECK_TYPEDEF (type);
1766 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; i--)
1768 char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1769 /* FIXME! May need to check for ARM demangling here */
1770 if (strncmp(t_field_name, "__", 2)==0 ||
1771 strncmp(t_field_name, "op", 2)==0 ||
1772 strncmp(t_field_name, "type", 4)==0 )
1774 if (cplus_demangle_opname(t_field_name, dem_opname, DMGL_ANSI))
1775 t_field_name = dem_opname;
1776 else if (cplus_demangle_opname(t_field_name, dem_opname, 0))
1777 t_field_name = dem_opname;
1779 if (t_field_name && STREQ (t_field_name, name))
1781 int j = TYPE_FN_FIELDLIST_LENGTH (type, i) - 1;
1782 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1785 if (j > 0 && args == 0)
1786 error ("cannot resolve overloaded method `%s'", name);
1789 if (TYPE_FN_FIELD_STUB (f, j))
1790 check_stub_method (type, i, j);
1791 if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
1792 TYPE_FN_FIELD_ARGS (f, j), args))
1794 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1795 return value_virtual_fn_field (arg1p, f, j, type, offset);
1796 if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
1797 *static_memfuncp = 1;
1798 v = value_fn_field (arg1p, f, j, type, offset);
1799 if (v != NULL) return v;
1806 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1810 if (BASETYPE_VIA_VIRTUAL (type, i))
1812 base_offset = VALUE_OFFSET (*arg1p) + offset;
1814 baseclass_offset (type, i,
1815 VALUE_CONTENTS (*arg1p) + base_offset,
1816 VALUE_ADDRESS (*arg1p) + base_offset);
1817 if (base_offset == -1)
1818 error ("virtual baseclass botch");
1822 base_offset = TYPE_BASECLASS_BITPOS (type, i) / 8;
1824 v = search_struct_method (name, arg1p, args, base_offset + offset,
1825 static_memfuncp, TYPE_BASECLASS (type, i));
1826 if (v == (value_ptr) -1)
1832 /* FIXME-bothner: Why is this commented out? Why is it here? */
1833 /* *arg1p = arg1_tmp;*/
1837 if (name_matched) return (value_ptr) -1;
1841 /* Given *ARGP, a value of type (pointer to a)* structure/union,
1842 extract the component named NAME from the ultimate target structure/union
1843 and return it as a value with its appropriate type.
1844 ERR is used in the error message if *ARGP's type is wrong.
1846 C++: ARGS is a list of argument types to aid in the selection of
1847 an appropriate method. Also, handle derived types.
1849 STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location
1850 where the truthvalue of whether the function that was resolved was
1851 a static member function or not is stored.
1853 ERR is an error message to be printed in case the field is not found. */
1856 value_struct_elt (argp, args, name, static_memfuncp, err)
1857 register value_ptr *argp, *args;
1859 int *static_memfuncp;
1862 register struct type *t;
1865 COERCE_ARRAY (*argp);
1867 t = check_typedef (VALUE_TYPE (*argp));
1869 /* Follow pointers until we get to a non-pointer. */
1871 while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
1873 *argp = value_ind (*argp);
1874 /* Don't coerce fn pointer to fn and then back again! */
1875 if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC)
1876 COERCE_ARRAY (*argp);
1877 t = check_typedef (VALUE_TYPE (*argp));
1880 if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
1881 error ("not implemented: member type in value_struct_elt");
1883 if ( TYPE_CODE (t) != TYPE_CODE_STRUCT
1884 && TYPE_CODE (t) != TYPE_CODE_UNION)
1885 error ("Attempt to extract a component of a value that is not a %s.", err);
1887 /* Assume it's not, unless we see that it is. */
1888 if (static_memfuncp)
1889 *static_memfuncp =0;
1893 /* if there are no arguments ...do this... */
1895 /* Try as a field first, because if we succeed, there
1896 is less work to be done. */
1897 v = search_struct_field (name, *argp, 0, t, 0);
1901 /* C++: If it was not found as a data field, then try to
1902 return it as a pointer to a method. */
1904 if (destructor_name_p (name, t))
1905 error ("Cannot get value of destructor");
1907 v = search_struct_method (name, argp, args, 0, static_memfuncp, t);
1909 if (v == (value_ptr) -1)
1910 error ("Cannot take address of a method");
1913 if (TYPE_NFN_FIELDS (t))
1914 error ("There is no member or method named %s.", name);
1916 error ("There is no member named %s.", name);
1921 if (destructor_name_p (name, t))
1925 /* Destructors are a special case. */
1926 int m_index, f_index;
1929 if (get_destructor_fn_field (t, &m_index, &f_index))
1931 v = value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, m_index),
1935 error ("could not find destructor function named %s.", name);
1941 error ("destructor should not have any argument");
1945 v = search_struct_method (name, argp, args, 0, static_memfuncp, t);
1947 if (v == (value_ptr) -1)
1949 error("Argument list of %s mismatch with component in the structure.", name);
1953 /* See if user tried to invoke data as function. If so,
1954 hand it back. If it's not callable (i.e., a pointer to function),
1955 gdb should give an error. */
1956 v = search_struct_field (name, *argp, 0, t, 0);
1960 error ("Structure has no component named %s.", name);
1964 /* C++: return 1 is NAME is a legitimate name for the destructor
1965 of type TYPE. If TYPE does not have a destructor, or
1966 if NAME is inappropriate for TYPE, an error is signaled. */
1968 destructor_name_p (name, type)
1970 const struct type *type;
1972 /* destructors are a special case. */
1976 char *dname = type_name_no_tag (type);
1977 char *cp = strchr (dname, '<');
1980 /* Do not compare the template part for template classes. */
1982 len = strlen (dname);
1985 if (strlen (name + 1) != len || !STREQN (dname, name + 1, len))
1986 error ("name of destructor must equal name of class");
1993 /* Helper function for check_field: Given TYPE, a structure/union,
1994 return 1 if the component named NAME from the ultimate
1995 target structure/union is defined, otherwise, return 0. */
1998 check_field_in (type, name)
1999 register struct type *type;
2004 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
2006 char *t_field_name = TYPE_FIELD_NAME (type, i);
2007 if (t_field_name && STREQ (t_field_name, name))
2011 /* C++: If it was not found as a data field, then try to
2012 return it as a pointer to a method. */
2014 /* Destructors are a special case. */
2015 if (destructor_name_p (name, type))
2017 int m_index, f_index;
2019 return get_destructor_fn_field (type, &m_index, &f_index);
2022 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
2024 if (STREQ (TYPE_FN_FIELDLIST_NAME (type, i), name))
2028 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
2029 if (check_field_in (TYPE_BASECLASS (type, i), name))
2036 /* C++: Given ARG1, a value of type (pointer to a)* structure/union,
2037 return 1 if the component named NAME from the ultimate
2038 target structure/union is defined, otherwise, return 0. */
2041 check_field (arg1, name)
2042 register value_ptr arg1;
2045 register struct type *t;
2047 COERCE_ARRAY (arg1);
2049 t = VALUE_TYPE (arg1);
2051 /* Follow pointers until we get to a non-pointer. */
2056 if (TYPE_CODE (t) != TYPE_CODE_PTR && TYPE_CODE (t) != TYPE_CODE_REF)
2058 t = TYPE_TARGET_TYPE (t);
2061 if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
2062 error ("not implemented: member type in check_field");
2064 if ( TYPE_CODE (t) != TYPE_CODE_STRUCT
2065 && TYPE_CODE (t) != TYPE_CODE_UNION)
2066 error ("Internal error: `this' is not an aggregate");
2068 return check_field_in (t, name);
2071 /* C++: Given an aggregate type CURTYPE, and a member name NAME,
2072 return the address of this member as a "pointer to member"
2073 type. If INTYPE is non-null, then it will be the type
2074 of the member we are looking for. This will help us resolve
2075 "pointers to member functions". This function is used
2076 to resolve user expressions of the form "DOMAIN::NAME". */
2079 value_struct_elt_for_reference (domain, offset, curtype, name, intype)
2080 struct type *domain, *curtype, *intype;
2084 register struct type *t = curtype;
2088 if ( TYPE_CODE (t) != TYPE_CODE_STRUCT
2089 && TYPE_CODE (t) != TYPE_CODE_UNION)
2090 error ("Internal error: non-aggregate type to value_struct_elt_for_reference");
2092 for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); i--)
2094 char *t_field_name = TYPE_FIELD_NAME (t, i);
2096 if (t_field_name && STREQ (t_field_name, name))
2098 if (TYPE_FIELD_STATIC (t, i))
2100 char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (t, i);
2101 struct symbol *sym =
2102 lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
2104 error ("Internal error: could not find physical static variable named %s",
2106 return value_at (SYMBOL_TYPE (sym),
2107 SYMBOL_VALUE_ADDRESS (sym));
2109 if (TYPE_FIELD_PACKED (t, i))
2110 error ("pointers to bitfield members not allowed");
2112 return value_from_longest
2113 (lookup_reference_type (lookup_member_type (TYPE_FIELD_TYPE (t, i),
2115 offset + (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
2119 /* C++: If it was not found as a data field, then try to
2120 return it as a pointer to a method. */
2122 /* Destructors are a special case. */
2123 if (destructor_name_p (name, t))
2125 error ("member pointers to destructors not implemented yet");
2128 /* Perform all necessary dereferencing. */
2129 while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR)
2130 intype = TYPE_TARGET_TYPE (intype);
2132 for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
2134 char *t_field_name = TYPE_FN_FIELDLIST_NAME (t, i);
2135 char dem_opname[64];
2137 if (strncmp(t_field_name, "__", 2)==0 ||
2138 strncmp(t_field_name, "op", 2)==0 ||
2139 strncmp(t_field_name, "type", 4)==0 )
2141 if (cplus_demangle_opname(t_field_name, dem_opname, DMGL_ANSI))
2142 t_field_name = dem_opname;
2143 else if (cplus_demangle_opname(t_field_name, dem_opname, 0))
2144 t_field_name = dem_opname;
2146 if (t_field_name && STREQ (t_field_name, name))
2148 int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
2149 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
2151 if (intype == 0 && j > 1)
2152 error ("non-unique member `%s' requires type instantiation", name);
2156 if (TYPE_FN_FIELD_TYPE (f, j) == intype)
2159 error ("no member function matches that type instantiation");
2164 if (TYPE_FN_FIELD_STUB (f, j))
2165 check_stub_method (t, i, j);
2166 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
2168 return value_from_longest
2169 (lookup_reference_type
2170 (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),
2172 (LONGEST) METHOD_PTR_FROM_VOFFSET (TYPE_FN_FIELD_VOFFSET (f, j)));
2176 struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
2177 0, VAR_NAMESPACE, 0, NULL);
2184 v = read_var_value (s, 0);
2186 VALUE_TYPE (v) = lookup_reference_type
2187 (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),
2195 for (i = TYPE_N_BASECLASSES (t) - 1; i >= 0; i--)
2200 if (BASETYPE_VIA_VIRTUAL (t, i))
2203 base_offset = TYPE_BASECLASS_BITPOS (t, i) / 8;
2204 v = value_struct_elt_for_reference (domain,
2205 offset + base_offset,
2206 TYPE_BASECLASS (t, i),
2215 /* C++: return the value of the class instance variable, if one exists.
2216 Flag COMPLAIN signals an error if the request is made in an
2217 inappropriate context. */
2220 value_of_this (complain)
2223 struct symbol *func, *sym;
2226 static const char funny_this[] = "this";
2229 if (selected_frame == 0)
2231 error ("no frame selected");
2234 func = get_frame_function (selected_frame);
2238 error ("no `this' in nameless context");
2242 b = SYMBOL_BLOCK_VALUE (func);
2243 i = BLOCK_NSYMS (b);
2246 error ("no args, no `this'");
2249 /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER
2250 symbol instead of the LOC_ARG one (if both exist). */
2251 sym = lookup_block_symbol (b, funny_this, VAR_NAMESPACE);
2255 error ("current stack frame not in method");
2260 this = read_var_value (sym, selected_frame);
2261 if (this == 0 && complain)
2262 error ("`this' argument at unknown address");
2266 /* Create a slice (sub-string, sub-array) of ARRAY, that is LENGTH elements
2267 long, starting at LOWBOUND. The result has the same lower bound as
2268 the original ARRAY. */
2271 value_slice (array, lowbound, length)
2273 int lowbound, length;
2275 struct type *slice_range_type, *slice_type, *range_type;
2276 LONGEST lowerbound, upperbound, offset;
2278 struct type *array_type;
2279 array_type = check_typedef (VALUE_TYPE (array));
2280 COERCE_VARYING_ARRAY (array, array_type);
2281 if (TYPE_CODE (array_type) != TYPE_CODE_ARRAY
2282 && TYPE_CODE (array_type) != TYPE_CODE_STRING
2283 && TYPE_CODE (array_type) != TYPE_CODE_BITSTRING)
2284 error ("cannot take slice of non-array");
2285 range_type = TYPE_INDEX_TYPE (array_type);
2286 if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
2287 error ("slice from bad array or bitstring");
2288 if (lowbound < lowerbound || length < 0
2289 || lowbound + length - 1 > upperbound
2290 /* Chill allows zero-length strings but not arrays. */
2291 || (current_language->la_language == language_chill
2292 && length == 0 && TYPE_CODE (array_type) == TYPE_CODE_ARRAY))
2293 error ("slice out of range");
2294 /* FIXME-type-allocation: need a way to free this type when we are
2296 slice_range_type = create_range_type ((struct type*) NULL,
2297 TYPE_TARGET_TYPE (range_type),
2298 lowbound, lowbound + length - 1);
2299 if (TYPE_CODE (array_type) == TYPE_CODE_BITSTRING)
2302 slice_type = create_set_type ((struct type*) NULL, slice_range_type);
2303 TYPE_CODE (slice_type) = TYPE_CODE_BITSTRING;
2304 slice = value_zero (slice_type, not_lval);
2305 for (i = 0; i < length; i++)
2307 int element = value_bit_index (array_type,
2308 VALUE_CONTENTS (array),
2311 error ("internal error accessing bitstring");
2312 else if (element > 0)
2314 int j = i % TARGET_CHAR_BIT;
2315 if (BITS_BIG_ENDIAN)
2316 j = TARGET_CHAR_BIT - 1 - j;
2317 VALUE_CONTENTS_RAW (slice)[i / TARGET_CHAR_BIT] |= (1 << j);
2320 /* We should set the address, bitssize, and bitspos, so the clice
2321 can be used on the LHS, but that may require extensions to
2322 value_assign. For now, just leave as a non_lval. FIXME. */
2326 struct type *element_type = TYPE_TARGET_TYPE (array_type);
2328 = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
2329 slice_type = create_array_type ((struct type*) NULL, element_type,
2331 TYPE_CODE (slice_type) = TYPE_CODE (array_type);
2332 slice = allocate_value (slice_type);
2333 if (VALUE_LAZY (array))
2334 VALUE_LAZY (slice) = 1;
2336 memcpy (VALUE_CONTENTS (slice), VALUE_CONTENTS (array) + offset,
2337 TYPE_LENGTH (slice_type));
2338 if (VALUE_LVAL (array) == lval_internalvar)
2339 VALUE_LVAL (slice) = lval_internalvar_component;
2341 VALUE_LVAL (slice) = VALUE_LVAL (array);
2342 VALUE_ADDRESS (slice) = VALUE_ADDRESS (array);
2343 VALUE_OFFSET (slice) = VALUE_OFFSET (array) + offset;
2348 /* Assuming chill_varying_type (VARRAY) is true, return an equivalent
2349 value as a fixed-length array. */
2352 varying_to_slice (varray)
2355 struct type *vtype = check_typedef (VALUE_TYPE (varray));
2356 LONGEST length = unpack_long (TYPE_FIELD_TYPE (vtype, 0),
2357 VALUE_CONTENTS (varray)
2358 + TYPE_FIELD_BITPOS (vtype, 0) / 8);
2359 return value_slice (value_primitive_field (varray, 0, 1, vtype), 0, length);
2362 /* Create a value for a FORTRAN complex number. Currently most of
2363 the time values are coerced to COMPLEX*16 (i.e. a complex number
2364 composed of 2 doubles. This really should be a smarter routine
2365 that figures out precision inteligently as opposed to assuming
2366 doubles. FIXME: fmb */
2369 value_literal_complex (arg1, arg2, type)
2374 register value_ptr val;
2375 struct type *real_type = TYPE_TARGET_TYPE (type);
2377 val = allocate_value (type);
2378 arg1 = value_cast (real_type, arg1);
2379 arg2 = value_cast (real_type, arg2);
2381 memcpy (VALUE_CONTENTS_RAW (val),
2382 VALUE_CONTENTS (arg1), TYPE_LENGTH (real_type));
2383 memcpy (VALUE_CONTENTS_RAW (val) + TYPE_LENGTH (real_type),
2384 VALUE_CONTENTS (arg2), TYPE_LENGTH (real_type));
2388 /* Cast a value into the appropriate complex data type. */
2391 cast_into_complex (type, val)
2393 register value_ptr val;
2395 struct type *real_type = TYPE_TARGET_TYPE (type);
2396 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_COMPLEX)
2398 struct type *val_real_type = TYPE_TARGET_TYPE (VALUE_TYPE (val));
2399 value_ptr re_val = allocate_value (val_real_type);
2400 value_ptr im_val = allocate_value (val_real_type);
2402 memcpy (VALUE_CONTENTS_RAW (re_val),
2403 VALUE_CONTENTS (val), TYPE_LENGTH (val_real_type));
2404 memcpy (VALUE_CONTENTS_RAW (im_val),
2405 VALUE_CONTENTS (val) + TYPE_LENGTH (val_real_type),
2406 TYPE_LENGTH (val_real_type));
2408 return value_literal_complex (re_val, im_val, type);
2410 else if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FLT
2411 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
2412 return value_literal_complex (val, value_zero (real_type, not_lval), type);
2414 error ("cannot cast non-number to complex");
2418 _initialize_valops ()
2422 (add_set_cmd ("abandon", class_support, var_boolean, (char *)&auto_abandon,
2423 "Set automatic abandonment of expressions upon failure.",