1 /* Perform non-arithmetic operations on values, for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
34 /* Local functions. */
36 static int typecmp PARAMS ((int staticp, struct type *t1[], value_ptr t2[]));
38 static CORE_ADDR find_function_addr PARAMS ((value_ptr, struct type **));
40 static CORE_ADDR value_push PARAMS ((CORE_ADDR, value_ptr));
42 static CORE_ADDR value_arg_push PARAMS ((CORE_ADDR, value_ptr));
44 static value_ptr search_struct_field PARAMS ((char *, value_ptr, int,
47 static value_ptr search_struct_method PARAMS ((char *, value_ptr *,
49 int, int *, struct type *));
51 static int check_field_in PARAMS ((struct type *, const char *));
53 static CORE_ADDR allocate_space_in_inferior PARAMS ((int));
55 static value_ptr f77_cast_into_complex PARAMS ((struct type *, value_ptr));
57 static value_ptr f77_assign_from_literal_string PARAMS ((value_ptr,
60 static value_ptr f77_assign_from_literal_complex PARAMS ((value_ptr,
63 #define VALUE_SUBSTRING_START(VAL) VALUE_FRAME(VAL)
66 /* Allocate NBYTES of space in the inferior using the inferior's malloc
67 and return a value that is a pointer to the allocated space. */
70 allocate_space_in_inferior (len)
73 register value_ptr val;
74 register struct symbol *sym;
75 struct minimal_symbol *msymbol;
80 /* Find the address of malloc in the inferior. */
82 sym = lookup_symbol ("malloc", 0, VAR_NAMESPACE, 0, NULL);
85 if (SYMBOL_CLASS (sym) != LOC_BLOCK)
87 error ("\"malloc\" exists in this program but is not a function.");
89 val = value_of_variable (sym, NULL);
93 msymbol = lookup_minimal_symbol ("malloc", (struct objfile *) NULL);
96 type = lookup_pointer_type (builtin_type_char);
97 type = lookup_function_type (type);
98 type = lookup_pointer_type (type);
99 maddr = (LONGEST) SYMBOL_VALUE_ADDRESS (msymbol);
100 val = value_from_longest (type, maddr);
104 error ("evaluation of this expression requires the program to have a function \"malloc\".");
108 blocklen = value_from_longest (builtin_type_int, (LONGEST) len);
109 val = call_function_by_hand (val, 1, &blocklen);
110 if (value_logical_not (val))
112 error ("No memory available to program.");
114 return (value_as_long (val));
117 /* Cast value ARG2 to type TYPE and return as a value.
118 More general than a C cast: accepts any two types of the same length,
119 and if ARG2 is an lvalue it can be cast into anything at all. */
120 /* In C++, casts may change pointer or object representations. */
123 value_cast (type, arg2)
125 register value_ptr arg2;
127 register enum type_code code1;
128 register enum type_code code2;
131 /* Coerce arrays but not enums. Enums will work as-is
132 and coercing them would cause an infinite recursion. */
133 if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_ENUM)
136 code1 = TYPE_CODE (type);
137 code2 = TYPE_CODE (VALUE_TYPE (arg2));
139 if (code1 == TYPE_CODE_COMPLEX)
140 return f77_cast_into_complex (type, arg2);
141 if (code1 == TYPE_CODE_BOOL)
142 code1 = TYPE_CODE_INT;
143 if (code2 == TYPE_CODE_BOOL)
144 code2 = TYPE_CODE_INT;
146 scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
147 || code2 == TYPE_CODE_ENUM);
149 if ( code1 == TYPE_CODE_STRUCT
150 && code2 == TYPE_CODE_STRUCT
151 && TYPE_NAME (type) != 0)
153 /* Look in the type of the source to see if it contains the
154 type of the target as a superclass. If so, we'll need to
155 offset the object in addition to changing its type. */
156 value_ptr v = search_struct_field (type_name_no_tag (type),
157 arg2, 0, VALUE_TYPE (arg2), 1);
160 VALUE_TYPE (v) = type;
164 if (code1 == TYPE_CODE_FLT && scalar)
165 return value_from_double (type, value_as_double (arg2));
166 else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM)
167 && (scalar || code2 == TYPE_CODE_PTR))
168 return value_from_longest (type, value_as_long (arg2));
169 else if (TYPE_LENGTH (type) == TYPE_LENGTH (VALUE_TYPE (arg2)))
171 if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
173 /* Look in the type of the source to see if it contains the
174 type of the target as a superclass. If so, we'll need to
175 offset the pointer rather than just change its type. */
176 struct type *t1 = TYPE_TARGET_TYPE (type);
177 struct type *t2 = TYPE_TARGET_TYPE (VALUE_TYPE (arg2));
178 if ( TYPE_CODE (t1) == TYPE_CODE_STRUCT
179 && TYPE_CODE (t2) == TYPE_CODE_STRUCT
180 && TYPE_NAME (t1) != 0) /* if name unknown, can't have supercl */
182 value_ptr v = search_struct_field (type_name_no_tag (t1),
183 value_ind (arg2), 0, t2, 1);
187 VALUE_TYPE (v) = type;
191 /* No superclass found, just fall through to change ptr type. */
193 VALUE_TYPE (arg2) = type;
196 else if (VALUE_LVAL (arg2) == lval_memory)
198 return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
200 else if (code1 == TYPE_CODE_VOID)
202 return value_zero (builtin_type_void, not_lval);
206 error ("Invalid cast.");
211 /* Create a value of type TYPE that is zero, and return it. */
214 value_zero (type, lv)
218 register value_ptr val = allocate_value (type);
220 memset (VALUE_CONTENTS (val), 0, TYPE_LENGTH (type));
221 VALUE_LVAL (val) = lv;
226 /* Return a value with type TYPE located at ADDR.
228 Call value_at only if the data needs to be fetched immediately;
229 if we can be 'lazy' and defer the fetch, perhaps indefinately, call
230 value_at_lazy instead. value_at_lazy simply records the address of
231 the data and sets the lazy-evaluation-required flag. The lazy flag
232 is tested in the VALUE_CONTENTS macro, which is used if and when
233 the contents are actually required. */
236 value_at (type, addr)
240 register value_ptr val;
242 if (TYPE_CODE (type) == TYPE_CODE_VOID)
243 error ("Attempt to dereference a generic pointer.");
245 val = allocate_value (type);
247 read_memory (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (type));
249 VALUE_LVAL (val) = lval_memory;
250 VALUE_ADDRESS (val) = addr;
255 /* Return a lazy value with type TYPE located at ADDR (cf. value_at). */
258 value_at_lazy (type, addr)
262 register value_ptr val;
264 if (TYPE_CODE (type) == TYPE_CODE_VOID)
265 error ("Attempt to dereference a generic pointer.");
267 val = allocate_value (type);
269 VALUE_LVAL (val) = lval_memory;
270 VALUE_ADDRESS (val) = addr;
271 VALUE_LAZY (val) = 1;
276 /* Called only from the VALUE_CONTENTS macro, if the current data for
277 a variable needs to be loaded into VALUE_CONTENTS(VAL). Fetches the
278 data from the user's process, and clears the lazy flag to indicate
279 that the data in the buffer is valid.
281 If the value is zero-length, we avoid calling read_memory, which would
282 abort. We mark the value as fetched anyway -- all 0 bytes of it.
284 This function returns a value because it is used in the VALUE_CONTENTS
285 macro as part of an expression, where a void would not work. The
289 value_fetch_lazy (val)
290 register value_ptr val;
292 CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
294 if (TYPE_LENGTH (VALUE_TYPE (val)))
295 read_memory (addr, VALUE_CONTENTS_RAW (val),
296 TYPE_LENGTH (VALUE_TYPE (val)));
297 VALUE_LAZY (val) = 0;
302 /* Store the contents of FROMVAL into the location of TOVAL.
303 Return a new value with the location of TOVAL and contents of FROMVAL. */
306 value_assign (toval, fromval)
307 register value_ptr toval, fromval;
309 register struct type *type;
310 register value_ptr val;
311 char raw_buffer[MAX_REGISTER_RAW_SIZE];
314 if (current_language->la_language == language_fortran)
316 /* Deal with literal assignment in F77. All composite (i.e. string
317 and complex number types) types are allocated in the superior
318 NOT the inferior. Therefore assigment is somewhat tricky. */
320 if (TYPE_CODE (VALUE_TYPE (fromval)) == TYPE_CODE_LITERAL_STRING)
321 return f77_assign_from_literal_string (toval, fromval);
323 if (TYPE_CODE (VALUE_TYPE (fromval)) == TYPE_CODE_LITERAL_COMPLEX)
324 return f77_assign_from_literal_complex (toval, fromval);
327 if (!toval->modifiable)
328 error ("Left operand of assignment is not a modifiable lvalue.");
330 COERCE_ARRAY (fromval);
333 type = VALUE_TYPE (toval);
334 if (VALUE_LVAL (toval) != lval_internalvar)
335 fromval = value_cast (type, fromval);
337 /* If TOVAL is a special machine register requiring conversion
338 of program values to a special raw format,
339 convert FROMVAL's contents now, with result in `raw_buffer',
340 and set USE_BUFFER to the number of bytes to write. */
342 #ifdef REGISTER_CONVERTIBLE
343 if (VALUE_REGNO (toval) >= 0
344 && REGISTER_CONVERTIBLE (VALUE_REGNO (toval)))
346 int regno = VALUE_REGNO (toval);
347 if (REGISTER_CONVERTIBLE (regno))
349 REGISTER_CONVERT_TO_RAW (VALUE_TYPE (fromval), regno,
350 VALUE_CONTENTS (fromval), raw_buffer);
351 use_buffer = REGISTER_RAW_SIZE (regno);
356 switch (VALUE_LVAL (toval))
358 case lval_internalvar:
359 set_internalvar (VALUE_INTERNALVAR (toval), fromval);
362 case lval_internalvar_component:
363 set_internalvar_component (VALUE_INTERNALVAR (toval),
364 VALUE_OFFSET (toval),
365 VALUE_BITPOS (toval),
366 VALUE_BITSIZE (toval),
371 if (VALUE_BITSIZE (toval))
373 char buffer[sizeof (LONGEST)];
374 /* We assume that the argument to read_memory is in units of
375 host chars. FIXME: Is that correct? */
376 int len = (VALUE_BITPOS (toval)
377 + VALUE_BITSIZE (toval)
381 if (len > sizeof (LONGEST))
382 error ("Can't handle bitfields which don't fit in a %d bit word.",
383 sizeof (LONGEST) * HOST_CHAR_BIT);
385 read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
387 modify_field (buffer, value_as_long (fromval),
388 VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
389 write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
393 write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
394 raw_buffer, use_buffer);
396 write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
397 VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
401 if (VALUE_BITSIZE (toval))
403 char buffer[sizeof (LONGEST)];
404 int len = REGISTER_RAW_SIZE (VALUE_REGNO (toval));
406 if (len > sizeof (LONGEST))
407 error ("Can't handle bitfields in registers larger than %d bits.",
408 sizeof (LONGEST) * HOST_CHAR_BIT);
410 if (VALUE_BITPOS (toval) + VALUE_BITSIZE (toval)
411 > len * HOST_CHAR_BIT)
412 /* Getting this right would involve being very careful about
415 Can't handle bitfield which doesn't fit in a single register.");
417 read_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
419 modify_field (buffer, value_as_long (fromval),
420 VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
421 write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
425 write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
426 raw_buffer, use_buffer);
429 /* Do any conversion necessary when storing this type to more
430 than one register. */
431 #ifdef REGISTER_CONVERT_FROM_TYPE
432 memcpy (raw_buffer, VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
433 REGISTER_CONVERT_FROM_TYPE(VALUE_REGNO (toval), type, raw_buffer);
434 write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
435 raw_buffer, TYPE_LENGTH (type));
437 write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
438 VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
441 /* Assigning to the stack pointer, frame pointer, and other
442 (architecture and calling convention specific) registers may
443 cause the frame cache to be out of date. We just do this
444 on all assignments to registers for simplicity; I doubt the slowdown
446 reinit_frame_cache ();
449 case lval_reg_frame_relative:
451 /* value is stored in a series of registers in the frame
452 specified by the structure. Copy that value out, modify
453 it, and copy it back in. */
454 int amount_to_copy = (VALUE_BITSIZE (toval) ? 1 : TYPE_LENGTH (type));
455 int reg_size = REGISTER_RAW_SIZE (VALUE_FRAME_REGNUM (toval));
456 int byte_offset = VALUE_OFFSET (toval) % reg_size;
457 int reg_offset = VALUE_OFFSET (toval) / reg_size;
460 /* Make the buffer large enough in all cases. */
461 char *buffer = (char *) alloca (amount_to_copy
463 + MAX_REGISTER_RAW_SIZE);
468 /* Figure out which frame this is in currently. */
469 for (frame = get_current_frame ();
470 frame && FRAME_FP (frame) != VALUE_FRAME (toval);
471 frame = get_prev_frame (frame))
475 error ("Value being assigned to is no longer active.");
477 amount_to_copy += (reg_size - amount_to_copy % reg_size);
480 for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
482 amount_copied < amount_to_copy;
483 amount_copied += reg_size, regno++)
485 get_saved_register (buffer + amount_copied,
486 (int *)NULL, (CORE_ADDR *)NULL,
487 frame, regno, (enum lval_type *)NULL);
490 /* Modify what needs to be modified. */
491 if (VALUE_BITSIZE (toval))
492 modify_field (buffer + byte_offset,
493 value_as_long (fromval),
494 VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
496 memcpy (buffer + byte_offset, raw_buffer, use_buffer);
498 memcpy (buffer + byte_offset, VALUE_CONTENTS (fromval),
502 for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
504 amount_copied < amount_to_copy;
505 amount_copied += reg_size, regno++)
511 /* Just find out where to put it. */
512 get_saved_register ((char *)NULL,
513 &optim, &addr, frame, regno, &lval);
516 error ("Attempt to assign to a value that was optimized out.");
517 if (lval == lval_memory)
518 write_memory (addr, buffer + amount_copied, reg_size);
519 else if (lval == lval_register)
520 write_register_bytes (addr, buffer + amount_copied, reg_size);
522 error ("Attempt to assign to an unmodifiable value.");
529 error ("Left operand of assignment is not an lvalue.");
532 /* Return a value just like TOVAL except with the contents of FROMVAL
533 (except in the case of the type if TOVAL is an internalvar). */
535 if (VALUE_LVAL (toval) == lval_internalvar
536 || VALUE_LVAL (toval) == lval_internalvar_component)
538 type = VALUE_TYPE (fromval);
541 val = allocate_value (type);
542 memcpy (val, toval, VALUE_CONTENTS_RAW (val) - (char *) val);
543 memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval),
545 VALUE_TYPE (val) = type;
550 /* Extend a value VAL to COUNT repetitions of its type. */
553 value_repeat (arg1, count)
557 register value_ptr val;
559 if (VALUE_LVAL (arg1) != lval_memory)
560 error ("Only values in memory can be extended with '@'.");
562 error ("Invalid number %d of repetitions.", count);
564 val = allocate_repeat_value (VALUE_TYPE (arg1), count);
566 read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1),
567 VALUE_CONTENTS_RAW (val),
568 TYPE_LENGTH (VALUE_TYPE (val)) * count);
569 VALUE_LVAL (val) = lval_memory;
570 VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1);
576 value_of_variable (var, b)
584 /* Use selected frame. */
588 fr = block_innermost_frame (b);
589 if (fr == NULL && symbol_read_needs_frame (var))
591 if (BLOCK_FUNCTION (b) != NULL
592 && SYMBOL_NAME (BLOCK_FUNCTION (b)) != NULL)
593 error ("No frame is currently executing in block %s.",
594 SYMBOL_NAME (BLOCK_FUNCTION (b)));
596 error ("No frame is currently executing in specified block");
599 val = read_var_value (var, fr);
601 error ("Address of symbol \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
605 /* Given a value which is an array, return a value which is a pointer to its
606 first element, regardless of whether or not the array has a nonzero lower
609 FIXME: A previous comment here indicated that this routine should be
610 substracting the array's lower bound. It's not clear to me that this
611 is correct. Given an array subscripting operation, it would certainly
612 work to do the adjustment here, essentially computing:
614 (&array[0] - (lowerbound * sizeof array[0])) + (index * sizeof array[0])
616 However I believe a more appropriate and logical place to account for
617 the lower bound is to do so in value_subscript, essentially computing:
619 (&array[0] + ((index - lowerbound) * sizeof array[0]))
621 As further evidence consider what would happen with operations other
622 than array subscripting, where the caller would get back a value that
623 had an address somewhere before the actual first element of the array,
624 and the information about the lower bound would be lost because of
625 the coercion to pointer type.
629 value_coerce_array (arg1)
632 register struct type *type;
634 if (VALUE_LVAL (arg1) != lval_memory)
635 error ("Attempt to take address of value not located in memory.");
637 /* Get type of elements. */
638 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY
639 || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_STRING)
640 type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1));
642 /* A phony array made by value_repeat.
643 Its type is the type of the elements, not an array type. */
644 type = VALUE_TYPE (arg1);
646 return value_from_longest (lookup_pointer_type (type),
647 (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
650 /* Given a value which is a function, return a value which is a pointer
654 value_coerce_function (arg1)
658 if (VALUE_LVAL (arg1) != lval_memory)
659 error ("Attempt to take address of value not located in memory.");
661 return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
662 (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
665 /* Return a pointer value for the object for which ARG1 is the contents. */
671 struct type *type = VALUE_TYPE (arg1);
672 if (TYPE_CODE (type) == TYPE_CODE_REF)
674 /* Copy the value, but change the type from (T&) to (T*).
675 We keep the same location information, which is efficient,
676 and allows &(&X) to get the location containing the reference. */
677 value_ptr arg2 = value_copy (arg1);
678 VALUE_TYPE (arg2) = lookup_pointer_type (TYPE_TARGET_TYPE (type));
681 if (VALUE_REPEATED (arg1)
682 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
683 return value_coerce_array (arg1);
684 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
685 return value_coerce_function (arg1);
687 if (VALUE_LVAL (arg1) != lval_memory)
688 error ("Attempt to take address of value not located in memory.");
690 return value_from_longest (lookup_pointer_type (type),
691 (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
694 /* Given a value of a pointer type, apply the C unary * operator to it. */
702 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_MEMBER)
703 error ("not implemented: member types in value_ind");
705 /* Allow * on an integer so we can cast it to whatever we want.
706 This returns an int, which seems like the most C-like thing
707 to do. "long long" variables are rare enough that
708 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
709 if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT)
710 return value_at (builtin_type_int,
711 (CORE_ADDR) value_as_long (arg1));
712 else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
713 return value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
714 value_as_pointer (arg1));
715 error ("Attempt to take contents of a non-pointer value.");
716 return 0; /* For lint -- never reached */
719 /* Pushing small parts of stack frames. */
721 /* Push one word (the size of object that a register holds). */
726 unsigned LONGEST word;
728 register int len = REGISTER_SIZE;
729 char buffer[MAX_REGISTER_RAW_SIZE];
731 store_unsigned_integer (buffer, len, word);
734 write_memory (sp, buffer, len);
735 #else /* stack grows upward */
736 write_memory (sp, buffer, len);
738 #endif /* stack grows upward */
743 /* Push LEN bytes with data at BUFFER. */
746 push_bytes (sp, buffer, len)
753 write_memory (sp, buffer, len);
754 #else /* stack grows upward */
755 write_memory (sp, buffer, len);
757 #endif /* stack grows upward */
762 /* Push onto the stack the specified value VALUE. */
766 register CORE_ADDR sp;
769 register int len = TYPE_LENGTH (VALUE_TYPE (arg));
773 write_memory (sp, VALUE_CONTENTS (arg), len);
774 #else /* stack grows upward */
775 write_memory (sp, VALUE_CONTENTS (arg), len);
777 #endif /* stack grows upward */
782 /* Perform the standard coercions that are specified
783 for arguments to be passed to C functions. */
786 value_arg_coerce (arg)
789 register struct type *type;
791 /* FIXME: We should coerce this according to the prototype (if we have
792 one). Right now we do a little bit of this in typecmp(), but that
793 doesn't always get called. For example, if passing a ref to a function
794 without a prototype, we probably should de-reference it. Currently
797 if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM)
798 arg = value_cast (builtin_type_unsigned_int, arg);
800 #if 1 /* FIXME: This is only a temporary patch. -fnf */
801 if (VALUE_REPEATED (arg)
802 || TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY)
803 arg = value_coerce_array (arg);
804 if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_FUNC)
805 arg = value_coerce_function (arg);
808 type = VALUE_TYPE (arg);
810 if (TYPE_CODE (type) == TYPE_CODE_INT
811 && TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int))
812 return value_cast (builtin_type_int, arg);
814 if (TYPE_CODE (type) == TYPE_CODE_FLT
815 && TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_double))
816 return value_cast (builtin_type_double, arg);
821 /* Push the value ARG, first coercing it as an argument
825 value_arg_push (sp, arg)
826 register CORE_ADDR sp;
829 return value_push (sp, value_arg_coerce (arg));
832 /* Determine a function's address and its return type from its value.
833 Calls error() if the function is not valid for calling. */
836 find_function_addr (function, retval_type)
838 struct type **retval_type;
840 register struct type *ftype = VALUE_TYPE (function);
841 register enum type_code code = TYPE_CODE (ftype);
842 struct type *value_type;
845 /* If it's a member function, just look at the function
848 /* Determine address to call. */
849 if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
851 funaddr = VALUE_ADDRESS (function);
852 value_type = TYPE_TARGET_TYPE (ftype);
854 else if (code == TYPE_CODE_PTR)
856 funaddr = value_as_pointer (function);
857 if (TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_FUNC
858 || TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_METHOD)
860 #ifdef CONVERT_FROM_FUNC_PTR_ADDR
861 /* FIXME: This is a workaround for the unusual function
862 pointer representation on the RS/6000, see comment
863 in config/rs6000/tm-rs6000.h */
864 funaddr = CONVERT_FROM_FUNC_PTR_ADDR (funaddr);
866 value_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype));
869 value_type = builtin_type_int;
871 else if (code == TYPE_CODE_INT)
873 /* Handle the case of functions lacking debugging info.
874 Their values are characters since their addresses are char */
875 if (TYPE_LENGTH (ftype) == 1)
876 funaddr = value_as_pointer (value_addr (function));
878 /* Handle integer used as address of a function. */
879 funaddr = (CORE_ADDR) value_as_long (function);
881 value_type = builtin_type_int;
884 error ("Invalid data type for function to be called.");
886 *retval_type = value_type;
890 #if defined (CALL_DUMMY)
891 /* All this stuff with a dummy frame may seem unnecessarily complicated
892 (why not just save registers in GDB?). The purpose of pushing a dummy
893 frame which looks just like a real frame is so that if you call a
894 function and then hit a breakpoint (get a signal, etc), "backtrace"
895 will look right. Whether the backtrace needs to actually show the
896 stack at the time the inferior function was called is debatable, but
897 it certainly needs to not display garbage. So if you are contemplating
898 making dummy frames be different from normal frames, consider that. */
900 /* Perform a function call in the inferior.
901 ARGS is a vector of values of arguments (NARGS of them).
902 FUNCTION is a value, the function to be called.
903 Returns a value representing what the function returned.
904 May fail to return, if a breakpoint or signal is hit
905 during the execution of the function. */
908 call_function_by_hand (function, nargs, args)
913 register CORE_ADDR sp;
916 /* CALL_DUMMY is an array of words (REGISTER_SIZE), but each word
917 is in host byte order. Before calling FIX_CALL_DUMMY, we byteswap it
918 and remove any extra bytes which might exist because unsigned LONGEST is
919 bigger than REGISTER_SIZE. */
920 static unsigned LONGEST dummy[] = CALL_DUMMY;
921 char dummy1[REGISTER_SIZE * sizeof dummy / sizeof (unsigned LONGEST)];
923 struct type *value_type;
924 unsigned char struct_return;
925 CORE_ADDR struct_addr;
926 struct inferior_status inf_status;
927 struct cleanup *old_chain;
932 if (!target_has_execution)
935 save_inferior_status (&inf_status, 1);
936 old_chain = make_cleanup (restore_inferior_status, &inf_status);
938 /* PUSH_DUMMY_FRAME is responsible for saving the inferior registers
939 (and POP_FRAME for restoring them). (At least on most machines)
940 they are saved on the stack in the inferior. */
943 old_sp = sp = read_sp ();
945 #if 1 INNER_THAN 2 /* Stack grows down */
948 #else /* Stack grows up */
953 funaddr = find_function_addr (function, &value_type);
956 struct block *b = block_for_pc (funaddr);
957 /* If compiled without -g, assume GCC. */
958 using_gcc = b == NULL || BLOCK_GCC_COMPILED (b);
961 /* Are we returning a value using a structure return or a normal
964 struct_return = using_struct_return (function, funaddr, value_type,
967 /* Create a call sequence customized for this function
968 and the number of arguments for it. */
969 for (i = 0; i < sizeof dummy / sizeof (dummy[0]); i++)
970 store_unsigned_integer (&dummy1[i * REGISTER_SIZE],
972 (unsigned LONGEST)dummy[i]);
974 #ifdef GDB_TARGET_IS_HPPA
975 real_pc = FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args,
976 value_type, using_gcc);
978 FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args,
979 value_type, using_gcc);
983 #if CALL_DUMMY_LOCATION == ON_STACK
984 write_memory (start_sp, (char *)dummy1, sizeof dummy1);
985 #endif /* On stack. */
987 #if CALL_DUMMY_LOCATION == BEFORE_TEXT_END
988 /* Convex Unix prohibits executing in the stack segment. */
989 /* Hope there is empty room at the top of the text segment. */
991 extern CORE_ADDR text_end;
994 for (start_sp = text_end - sizeof dummy1; start_sp < text_end; ++start_sp)
995 if (read_memory_integer (start_sp, 1) != 0)
996 error ("text segment full -- no place to put call");
999 real_pc = text_end - sizeof dummy1;
1000 write_memory (real_pc, (char *)dummy1, sizeof dummy1);
1002 #endif /* Before text_end. */
1004 #if CALL_DUMMY_LOCATION == AFTER_TEXT_END
1006 extern CORE_ADDR text_end;
1010 errcode = target_write_memory (real_pc, (char *)dummy1, sizeof dummy1);
1012 error ("Cannot write text segment -- call_function failed");
1014 #endif /* After text_end. */
1016 #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT
1018 #endif /* At entry point. */
1021 sp = old_sp; /* It really is used, for some ifdef's... */
1025 /* If stack grows down, we must leave a hole at the top. */
1029 /* Reserve space for the return structure to be written on the
1030 stack, if necessary */
1033 len += TYPE_LENGTH (value_type);
1035 for (i = nargs - 1; i >= 0; i--)
1036 len += TYPE_LENGTH (VALUE_TYPE (value_arg_coerce (args[i])));
1037 #ifdef CALL_DUMMY_STACK_ADJUST
1038 len += CALL_DUMMY_STACK_ADJUST;
1041 sp -= STACK_ALIGN (len) - len;
1043 sp += STACK_ALIGN (len) - len;
1046 #endif /* STACK_ALIGN */
1048 /* Reserve space for the return structure to be written on the
1049 stack, if necessary */
1054 sp -= TYPE_LENGTH (value_type);
1058 sp += TYPE_LENGTH (value_type);
1062 #if defined (REG_STRUCT_HAS_ADDR)
1064 /* This is a machine like the sparc, where we may need to pass a pointer
1065 to the structure, not the structure itself. */
1066 for (i = nargs - 1; i >= 0; i--)
1067 if (TYPE_CODE (VALUE_TYPE (args[i])) == TYPE_CODE_STRUCT
1068 && REG_STRUCT_HAS_ADDR (using_gcc, VALUE_TYPE (args[i])))
1071 #if !(1 INNER_THAN 2)
1072 /* The stack grows up, so the address of the thing we push
1073 is the stack pointer before we push it. */
1076 /* Push the structure. */
1077 sp = value_push (sp, args[i]);
1079 /* The stack grows down, so the address of the thing we push
1080 is the stack pointer after we push it. */
1083 /* The value we're going to pass is the address of the thing
1085 args[i] = value_from_longest (lookup_pointer_type (value_type),
1089 #endif /* REG_STRUCT_HAS_ADDR. */
1091 #ifdef PUSH_ARGUMENTS
1092 PUSH_ARGUMENTS(nargs, args, sp, struct_return, struct_addr);
1093 #else /* !PUSH_ARGUMENTS */
1094 for (i = nargs - 1; i >= 0; i--)
1095 sp = value_arg_push (sp, args[i]);
1096 #endif /* !PUSH_ARGUMENTS */
1098 #ifdef CALL_DUMMY_STACK_ADJUST
1100 sp -= CALL_DUMMY_STACK_ADJUST;
1102 sp += CALL_DUMMY_STACK_ADJUST;
1104 #endif /* CALL_DUMMY_STACK_ADJUST */
1106 /* Store the address at which the structure is supposed to be
1107 written. Note that this (and the code which reserved the space
1108 above) assumes that gcc was used to compile this function. Since
1109 it doesn't cost us anything but space and if the function is pcc
1110 it will ignore this value, we will make that assumption.
1112 Also note that on some machines (like the sparc) pcc uses a
1113 convention like gcc's. */
1116 STORE_STRUCT_RETURN (struct_addr, sp);
1118 /* Write the stack pointer. This is here because the statements above
1119 might fool with it. On SPARC, this write also stores the register
1120 window into the right place in the new stack frame, which otherwise
1121 wouldn't happen. (See store_inferior_registers in sparc-nat.c.) */
1125 char retbuf[REGISTER_BYTES];
1127 struct symbol *symbol;
1130 symbol = find_pc_function (funaddr);
1133 name = SYMBOL_SOURCE_NAME (symbol);
1137 /* Try the minimal symbols. */
1138 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr);
1142 name = SYMBOL_SOURCE_NAME (msymbol);
1148 sprintf (format, "at %s", local_hex_format ());
1150 /* FIXME-32x64: assumes funaddr fits in a long. */
1151 sprintf (name, format, (unsigned long) funaddr);
1154 /* Execute the stack dummy routine, calling FUNCTION.
1155 When it is done, discard the empty frame
1156 after storing the contents of all regs into retbuf. */
1157 if (run_stack_dummy (real_pc + CALL_DUMMY_START_OFFSET, retbuf))
1159 /* We stopped somewhere besides the call dummy. */
1161 /* If we did the cleanups, we would print a spurious error message
1162 (Unable to restore previously selected frame), would write the
1163 registers from the inf_status (which is wrong), and would do other
1164 wrong things (like set stop_bpstat to the wrong thing). */
1165 discard_cleanups (old_chain);
1166 /* Prevent memory leak. */
1167 bpstat_clear (&inf_status.stop_bpstat);
1169 /* The following error message used to say "The expression
1170 which contained the function call has been discarded." It
1171 is a hard concept to explain in a few words. Ideally, GDB
1172 would be able to resume evaluation of the expression when
1173 the function finally is done executing. Perhaps someday
1174 this will be implemented (it would not be easy). */
1176 /* FIXME: Insert a bunch of wrap_here; name can be very long if it's
1177 a C++ name with arguments and stuff. */
1179 The program being debugged stopped while in a function called from GDB.\n\
1180 When the function (%s) is done executing, GDB will silently\n\
1181 stop (instead of continuing to evaluate the expression containing\n\
1182 the function call).", name);
1185 do_cleanups (old_chain);
1187 /* Figure out the value returned by the function. */
1188 return value_being_returned (value_type, retbuf, struct_return);
1191 #else /* no CALL_DUMMY. */
1193 call_function_by_hand (function, nargs, args)
1198 error ("Cannot invoke functions on this machine.");
1200 #endif /* no CALL_DUMMY. */
1203 /* Create a value for an array by allocating space in the inferior, copying
1204 the data into that space, and then setting up an array value.
1206 The array bounds are set from LOWBOUND and HIGHBOUND, and the array is
1207 populated from the values passed in ELEMVEC.
1209 The element type of the array is inherited from the type of the
1210 first element, and all elements must have the same size (though we
1211 don't currently enforce any restriction on their types). */
1214 value_array (lowbound, highbound, elemvec)
1223 struct type *rangetype;
1224 struct type *arraytype;
1227 /* Validate that the bounds are reasonable and that each of the elements
1228 have the same size. */
1230 nelem = highbound - lowbound + 1;
1233 error ("bad array bounds (%d, %d)", lowbound, highbound);
1235 typelength = TYPE_LENGTH (VALUE_TYPE (elemvec[0]));
1236 for (idx = 0; idx < nelem; idx++)
1238 if (TYPE_LENGTH (VALUE_TYPE (elemvec[idx])) != typelength)
1240 error ("array elements must all be the same size");
1244 /* Allocate space to store the array in the inferior, and then initialize
1245 it by copying in each element. FIXME: Is it worth it to create a
1246 local buffer in which to collect each value and then write all the
1247 bytes in one operation? */
1249 addr = allocate_space_in_inferior (nelem * typelength);
1250 for (idx = 0; idx < nelem; idx++)
1252 write_memory (addr + (idx * typelength), VALUE_CONTENTS (elemvec[idx]),
1256 /* Create the array type and set up an array value to be evaluated lazily. */
1258 rangetype = create_range_type ((struct type *) NULL, builtin_type_int,
1259 lowbound, highbound);
1260 arraytype = create_array_type ((struct type *) NULL,
1261 VALUE_TYPE (elemvec[0]), rangetype);
1262 val = value_at_lazy (arraytype, addr);
1266 /* Create a value for a string constant by allocating space in the inferior,
1267 copying the data into that space, and returning the address with type
1268 TYPE_CODE_STRING. PTR points to the string constant data; LEN is number
1270 Note that string types are like array of char types with a lower bound of
1271 zero and an upper bound of LEN - 1. Also note that the string may contain
1272 embedded null bytes. */
1275 value_string (ptr, len)
1280 struct type *rangetype;
1281 struct type *stringtype;
1284 /* Allocate space to store the string in the inferior, and then
1285 copy LEN bytes from PTR in gdb to that address in the inferior. */
1287 addr = allocate_space_in_inferior (len);
1288 write_memory (addr, ptr, len);
1290 /* Create the string type and set up a string value to be evaluated
1293 rangetype = create_range_type ((struct type *) NULL, builtin_type_int,
1295 stringtype = create_string_type ((struct type *) NULL, rangetype);
1296 val = value_at_lazy (stringtype, addr);
1300 /* See if we can pass arguments in T2 to a function which takes arguments
1301 of types T1. Both t1 and t2 are NULL-terminated vectors. If some
1302 arguments need coercion of some sort, then the coerced values are written
1303 into T2. Return value is 0 if the arguments could be matched, or the
1304 position at which they differ if not.
1306 STATICP is nonzero if the T1 argument list came from a
1307 static member function.
1309 For non-static member functions, we ignore the first argument,
1310 which is the type of the instance variable. This is because we want
1311 to handle calls with objects from derived classes. This is not
1312 entirely correct: we should actually check to make sure that a
1313 requested operation is type secure, shouldn't we? FIXME. */
1316 typecmp (staticp, t1, t2)
1325 if (staticp && t1 == 0)
1329 if (TYPE_CODE (t1[0]) == TYPE_CODE_VOID) return 0;
1330 if (t1[!staticp] == 0) return 0;
1331 for (i = !staticp; t1[i] && TYPE_CODE (t1[i]) != TYPE_CODE_VOID; i++)
1333 struct type *tt1, *tt2;
1337 tt2 = VALUE_TYPE(t2[i]);
1338 if (TYPE_CODE (tt1) == TYPE_CODE_REF
1339 /* We should be doing hairy argument matching, as below. */
1340 && (TYPE_CODE (TYPE_TARGET_TYPE (tt1)) == TYPE_CODE (tt2)))
1342 t2[i] = value_addr (t2[i]);
1346 while (TYPE_CODE (tt1) == TYPE_CODE_PTR
1347 && (TYPE_CODE(tt2)==TYPE_CODE_ARRAY || TYPE_CODE(tt2)==TYPE_CODE_PTR))
1349 tt1 = TYPE_TARGET_TYPE(tt1);
1350 tt2 = TYPE_TARGET_TYPE(tt2);
1352 if (TYPE_CODE(tt1) == TYPE_CODE(tt2)) continue;
1353 /* Array to pointer is a `trivial conversion' according to the ARM. */
1355 /* We should be doing much hairier argument matching (see section 13.2
1356 of the ARM), but as a quick kludge, just check for the same type
1358 if (TYPE_CODE (t1[i]) != TYPE_CODE (VALUE_TYPE (t2[i])))
1361 if (!t1[i]) return 0;
1362 return t2[i] ? i+1 : 0;
1365 /* Helper function used by value_struct_elt to recurse through baseclasses.
1366 Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
1367 and search in it assuming it has (class) type TYPE.
1368 If found, return value, else return NULL.
1370 If LOOKING_FOR_BASECLASS, then instead of looking for struct fields,
1371 look for a baseclass named NAME. */
1374 search_struct_field (name, arg1, offset, type, looking_for_baseclass)
1376 register value_ptr arg1;
1378 register struct type *type;
1379 int looking_for_baseclass;
1383 check_stub_type (type);
1385 if (! looking_for_baseclass)
1386 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1388 char *t_field_name = TYPE_FIELD_NAME (type, i);
1390 if (t_field_name && STREQ (t_field_name, name))
1393 if (TYPE_FIELD_STATIC (type, i))
1395 char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, i);
1396 struct symbol *sym =
1397 lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
1399 error ("Internal error: could not find physical static variable named %s",
1401 v = value_at (TYPE_FIELD_TYPE (type, i),
1402 (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
1405 v = value_primitive_field (arg1, offset, i, type);
1407 error("there is no field named %s", name);
1412 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1415 /* If we are looking for baseclasses, this is what we get when we
1416 hit them. But it could happen that the base part's member name
1417 is not yet filled in. */
1418 int found_baseclass = (looking_for_baseclass
1419 && TYPE_BASECLASS_NAME (type, i) != NULL
1420 && STREQ (name, TYPE_BASECLASS_NAME (type, i)));
1422 if (BASETYPE_VIA_VIRTUAL (type, i))
1425 /* Fix to use baseclass_offset instead. FIXME */
1426 baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset,
1429 error ("virtual baseclass botch");
1430 if (found_baseclass)
1432 v = search_struct_field (name, v2, 0, TYPE_BASECLASS (type, i),
1433 looking_for_baseclass);
1435 else if (found_baseclass)
1436 v = value_primitive_field (arg1, offset, i, type);
1438 v = search_struct_field (name, arg1,
1439 offset + TYPE_BASECLASS_BITPOS (type, i) / 8,
1440 TYPE_BASECLASS (type, i),
1441 looking_for_baseclass);
1447 /* Helper function used by value_struct_elt to recurse through baseclasses.
1448 Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
1449 and search in it assuming it has (class) type TYPE.
1450 If found, return value, else if name matched and args not return (value)-1,
1451 else return NULL. */
1454 search_struct_method (name, arg1p, args, offset, static_memfuncp, type)
1456 register value_ptr *arg1p, *args;
1457 int offset, *static_memfuncp;
1458 register struct type *type;
1462 int name_matched = 0;
1463 char dem_opname[64];
1465 check_stub_type (type);
1466 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; i--)
1468 char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1469 if (strncmp(t_field_name, "__", 2)==0 ||
1470 strncmp(t_field_name, "op", 2)==0 ||
1471 strncmp(t_field_name, "type", 4)==0 )
1473 if (cplus_demangle_opname(t_field_name, dem_opname, DMGL_ANSI))
1474 t_field_name = dem_opname;
1475 else if (cplus_demangle_opname(t_field_name, dem_opname, 0))
1476 t_field_name = dem_opname;
1478 if (t_field_name && STREQ (t_field_name, name))
1480 int j = TYPE_FN_FIELDLIST_LENGTH (type, i) - 1;
1481 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1484 if (j > 0 && args == 0)
1485 error ("cannot resolve overloaded method `%s'", name);
1488 if (TYPE_FN_FIELD_STUB (f, j))
1489 check_stub_method (type, i, j);
1490 if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
1491 TYPE_FN_FIELD_ARGS (f, j), args))
1493 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1494 return value_virtual_fn_field (arg1p, f, j, type, offset);
1495 if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
1496 *static_memfuncp = 1;
1497 v = value_fn_field (arg1p, f, j, type, offset);
1498 if (v != NULL) return v;
1505 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1509 if (BASETYPE_VIA_VIRTUAL (type, i))
1511 base_offset = baseclass_offset (type, i, *arg1p, offset);
1512 if (base_offset == -1)
1513 error ("virtual baseclass botch");
1517 base_offset = TYPE_BASECLASS_BITPOS (type, i) / 8;
1519 v = search_struct_method (name, arg1p, args, base_offset + offset,
1520 static_memfuncp, TYPE_BASECLASS (type, i));
1521 if (v == (value_ptr) -1)
1527 /* FIXME-bothner: Why is this commented out? Why is it here? */
1528 /* *arg1p = arg1_tmp;*/
1532 if (name_matched) return (value_ptr) -1;
1536 /* Given *ARGP, a value of type (pointer to a)* structure/union,
1537 extract the component named NAME from the ultimate target structure/union
1538 and return it as a value with its appropriate type.
1539 ERR is used in the error message if *ARGP's type is wrong.
1541 C++: ARGS is a list of argument types to aid in the selection of
1542 an appropriate method. Also, handle derived types.
1544 STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location
1545 where the truthvalue of whether the function that was resolved was
1546 a static member function or not is stored.
1548 ERR is an error message to be printed in case the field is not found. */
1551 value_struct_elt (argp, args, name, static_memfuncp, err)
1552 register value_ptr *argp, *args;
1554 int *static_memfuncp;
1557 register struct type *t;
1560 COERCE_ARRAY (*argp);
1562 t = VALUE_TYPE (*argp);
1564 /* Follow pointers until we get to a non-pointer. */
1566 while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
1568 *argp = value_ind (*argp);
1569 /* Don't coerce fn pointer to fn and then back again! */
1570 if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC)
1571 COERCE_ARRAY (*argp);
1572 t = VALUE_TYPE (*argp);
1575 if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
1576 error ("not implemented: member type in value_struct_elt");
1578 if ( TYPE_CODE (t) != TYPE_CODE_STRUCT
1579 && TYPE_CODE (t) != TYPE_CODE_UNION)
1580 error ("Attempt to extract a component of a value that is not a %s.", err);
1582 /* Assume it's not, unless we see that it is. */
1583 if (static_memfuncp)
1584 *static_memfuncp =0;
1588 /* if there are no arguments ...do this... */
1590 /* Try as a field first, because if we succeed, there
1591 is less work to be done. */
1592 v = search_struct_field (name, *argp, 0, t, 0);
1596 /* C++: If it was not found as a data field, then try to
1597 return it as a pointer to a method. */
1599 if (destructor_name_p (name, t))
1600 error ("Cannot get value of destructor");
1602 v = search_struct_method (name, argp, args, 0, static_memfuncp, t);
1604 if (v == (value_ptr) -1)
1605 error ("Cannot take address of a method");
1608 if (TYPE_NFN_FIELDS (t))
1609 error ("There is no member or method named %s.", name);
1611 error ("There is no member named %s.", name);
1616 if (destructor_name_p (name, t))
1620 /* destructors are a special case. */
1621 v = value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, 0),
1622 TYPE_FN_FIELDLIST_LENGTH (t, 0), 0, 0);
1623 if (!v) error("could not find destructor function named %s.", name);
1628 error ("destructor should not have any argument");
1632 v = search_struct_method (name, argp, args, 0, static_memfuncp, t);
1634 if (v == (value_ptr) -1)
1636 error("Argument list of %s mismatch with component in the structure.", name);
1640 /* See if user tried to invoke data as function. If so,
1641 hand it back. If it's not callable (i.e., a pointer to function),
1642 gdb should give an error. */
1643 v = search_struct_field (name, *argp, 0, t, 0);
1647 error ("Structure has no component named %s.", name);
1651 /* C++: return 1 is NAME is a legitimate name for the destructor
1652 of type TYPE. If TYPE does not have a destructor, or
1653 if NAME is inappropriate for TYPE, an error is signaled. */
1655 destructor_name_p (name, type)
1657 const struct type *type;
1659 /* destructors are a special case. */
1663 char *dname = type_name_no_tag (type);
1664 if (!STREQ (dname, name+1))
1665 error ("name of destructor must equal name of class");
1672 /* Helper function for check_field: Given TYPE, a structure/union,
1673 return 1 if the component named NAME from the ultimate
1674 target structure/union is defined, otherwise, return 0. */
1677 check_field_in (type, name)
1678 register struct type *type;
1683 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1685 char *t_field_name = TYPE_FIELD_NAME (type, i);
1686 if (t_field_name && STREQ (t_field_name, name))
1690 /* C++: If it was not found as a data field, then try to
1691 return it as a pointer to a method. */
1693 /* Destructors are a special case. */
1694 if (destructor_name_p (name, type))
1697 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
1699 if (STREQ (TYPE_FN_FIELDLIST_NAME (type, i), name))
1703 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1704 if (check_field_in (TYPE_BASECLASS (type, i), name))
1711 /* C++: Given ARG1, a value of type (pointer to a)* structure/union,
1712 return 1 if the component named NAME from the ultimate
1713 target structure/union is defined, otherwise, return 0. */
1716 check_field (arg1, name)
1717 register value_ptr arg1;
1720 register struct type *t;
1722 COERCE_ARRAY (arg1);
1724 t = VALUE_TYPE (arg1);
1726 /* Follow pointers until we get to a non-pointer. */
1728 while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
1729 t = TYPE_TARGET_TYPE (t);
1731 if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
1732 error ("not implemented: member type in check_field");
1734 if ( TYPE_CODE (t) != TYPE_CODE_STRUCT
1735 && TYPE_CODE (t) != TYPE_CODE_UNION)
1736 error ("Internal error: `this' is not an aggregate");
1738 return check_field_in (t, name);
1741 /* C++: Given an aggregate type CURTYPE, and a member name NAME,
1742 return the address of this member as a "pointer to member"
1743 type. If INTYPE is non-null, then it will be the type
1744 of the member we are looking for. This will help us resolve
1745 "pointers to member functions". This function is used
1746 to resolve user expressions of the form "DOMAIN::NAME". */
1749 value_struct_elt_for_reference (domain, offset, curtype, name, intype)
1750 struct type *domain, *curtype, *intype;
1754 register struct type *t = curtype;
1758 if ( TYPE_CODE (t) != TYPE_CODE_STRUCT
1759 && TYPE_CODE (t) != TYPE_CODE_UNION)
1760 error ("Internal error: non-aggregate type to value_struct_elt_for_reference");
1762 for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); i--)
1764 char *t_field_name = TYPE_FIELD_NAME (t, i);
1766 if (t_field_name && STREQ (t_field_name, name))
1768 if (TYPE_FIELD_STATIC (t, i))
1770 char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (t, i);
1771 struct symbol *sym =
1772 lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
1774 error ("Internal error: could not find physical static variable named %s",
1776 return value_at (SYMBOL_TYPE (sym),
1777 (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
1779 if (TYPE_FIELD_PACKED (t, i))
1780 error ("pointers to bitfield members not allowed");
1782 return value_from_longest
1783 (lookup_reference_type (lookup_member_type (TYPE_FIELD_TYPE (t, i),
1785 offset + (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
1789 /* C++: If it was not found as a data field, then try to
1790 return it as a pointer to a method. */
1792 /* Destructors are a special case. */
1793 if (destructor_name_p (name, t))
1795 error ("member pointers to destructors not implemented yet");
1798 /* Perform all necessary dereferencing. */
1799 while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR)
1800 intype = TYPE_TARGET_TYPE (intype);
1802 for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
1804 char *t_field_name = TYPE_FN_FIELDLIST_NAME (t, i);
1805 char dem_opname[64];
1807 if (strncmp(t_field_name, "__", 2)==0 ||
1808 strncmp(t_field_name, "op", 2)==0 ||
1809 strncmp(t_field_name, "type", 4)==0 )
1811 if (cplus_demangle_opname(t_field_name, dem_opname, DMGL_ANSI))
1812 t_field_name = dem_opname;
1813 else if (cplus_demangle_opname(t_field_name, dem_opname, 0))
1814 t_field_name = dem_opname;
1816 if (t_field_name && STREQ (t_field_name, name))
1818 int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
1819 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1821 if (intype == 0 && j > 1)
1822 error ("non-unique member `%s' requires type instantiation", name);
1826 if (TYPE_FN_FIELD_TYPE (f, j) == intype)
1829 error ("no member function matches that type instantiation");
1834 if (TYPE_FN_FIELD_STUB (f, j))
1835 check_stub_method (t, i, j);
1836 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1838 return value_from_longest
1839 (lookup_reference_type
1840 (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),
1842 (LONGEST) METHOD_PTR_FROM_VOFFSET
1843 (TYPE_FN_FIELD_VOFFSET (f, j)));
1847 struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
1848 0, VAR_NAMESPACE, 0, NULL);
1855 v = read_var_value (s, 0);
1857 VALUE_TYPE (v) = lookup_reference_type
1858 (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),
1866 for (i = TYPE_N_BASECLASSES (t) - 1; i >= 0; i--)
1871 if (BASETYPE_VIA_VIRTUAL (t, i))
1874 base_offset = TYPE_BASECLASS_BITPOS (t, i) / 8;
1875 v = value_struct_elt_for_reference (domain,
1876 offset + base_offset,
1877 TYPE_BASECLASS (t, i),
1886 /* C++: return the value of the class instance variable, if one exists.
1887 Flag COMPLAIN signals an error if the request is made in an
1888 inappropriate context. */
1890 value_of_this (complain)
1893 extern FRAME selected_frame;
1894 struct symbol *func, *sym;
1897 static const char funny_this[] = "this";
1900 if (selected_frame == 0)
1902 error ("no frame selected");
1905 func = get_frame_function (selected_frame);
1909 error ("no `this' in nameless context");
1913 b = SYMBOL_BLOCK_VALUE (func);
1914 i = BLOCK_NSYMS (b);
1917 error ("no args, no `this'");
1920 /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER
1921 symbol instead of the LOC_ARG one (if both exist). */
1922 sym = lookup_block_symbol (b, funny_this, VAR_NAMESPACE);
1926 error ("current stack frame not in method");
1931 this = read_var_value (sym, selected_frame);
1932 if (this == 0 && complain)
1933 error ("`this' argument at unknown address");
1937 /* Create a value for a literal string. We copy data into a local
1938 (NOT inferior's memory) buffer, and then set up an array value.
1940 The array bounds are set from LOWBOUND and HIGHBOUND, and the array is
1941 populated from the values passed in ELEMVEC.
1943 The element type of the array is inherited from the type of the
1944 first element, and all elements must have the same size (though we
1945 don't currently enforce any restriction on their types). */
1948 f77_value_literal_string (lowbound, highbound, elemvec)
1956 register value_ptr val;
1957 struct type *rangetype;
1958 struct type *arraytype;
1961 /* Validate that the bounds are reasonable and that each of the elements
1962 have the same size. */
1964 nelem = highbound - lowbound + 1;
1966 error ("bad array bounds (%d, %d)", lowbound, highbound);
1967 typelength = TYPE_LENGTH (VALUE_TYPE (elemvec[0]));
1968 for (idx = 0; idx < nelem; idx++)
1970 if (TYPE_LENGTH (VALUE_TYPE (elemvec[idx])) != typelength)
1971 error ("array elements must all be the same size");
1974 /* Make sure we are dealing with characters */
1976 if (typelength != 1)
1977 error ("Found a non character type in a literal string ");
1979 /* Allocate space to store the array */
1981 addr = xmalloc (nelem);
1982 for (idx = 0; idx < nelem; idx++)
1984 memcpy (addr + (idx), VALUE_CONTENTS (elemvec[idx]), 1);
1987 rangetype = create_range_type ((struct type *) NULL, builtin_type_int,
1988 lowbound, highbound);
1990 arraytype = f77_create_literal_string_type ((struct type *) NULL,
1993 val = allocate_value (arraytype);
1995 /* Make sure that this the rest of the world knows that this is
1996 a standard literal string, not one that is a substring of
1999 VALUE_SUBSTRING_MEMADDR (val) = (CORE_ADDR)0;
2001 VALUE_LAZY (val) = 0;
2002 VALUE_LITERAL_DATA (val) = addr;
2004 /* Since this is a standard literal string with no real lval,
2005 make sure that value_lval indicates this fact */
2007 VALUE_LVAL (val) = not_lval;
2011 /* Create a value for a substring. We copy data into a local
2012 (NOT inferior's memory) buffer, and then set up an array value.
2014 The array bounds for the string are (1:(to-from +1))
2015 The elements of the string are all characters. */
2018 f77_value_substring (str, from, to)
2024 register value_ptr val;
2025 struct type *rangetype;
2026 struct type *arraytype;
2027 struct internalvar *var;
2030 /* Validate that the bounds are reasonable. */
2032 nelem = to - from + 1;
2034 error ("bad substring bounds (%d, %d)", from, to);
2036 rangetype = create_range_type ((struct type *) NULL, builtin_type_int,
2039 arraytype = f77_create_literal_string_type ((struct type *) NULL,
2042 val = allocate_value (arraytype);
2044 /* Allocate space to store the substring array */
2046 addr = xmalloc (nelem);
2048 /* Copy over the data */
2050 /* In case we ever try to use this substring on the LHS of an assignment
2051 remember where the SOURCE substring begins, for lval_memory
2052 types this ptr is to a location in legal inferior memory,
2053 for lval_internalvars it is a ptr. to superior memory. This
2054 helps us out later when we do assigments like:
2056 set var ARR(2:3) = 'ab'
2061 if (VALUE_LVAL (str) == lval_memory)
2063 if (VALUE_SUBSTRING_MEMADDR (str) == (CORE_ADDR)0)
2065 /* This is a regular lval_memory string located in the
2068 VALUE_SUBSTRING_MEMADDR (val) = VALUE_ADDRESS (str) + (from - 1);
2069 target_read_memory (VALUE_SUBSTRING_MEMADDR (val), addr, nelem);
2075 /* str is a substring allocated in the superior. Just
2078 VALUE_SUBSTRING_MYADDR (val) = VALUE_LITERAL_DATA(str)+(from - 1);
2079 memcpy(addr, VALUE_SUBSTRING_MYADDR (val), nelem);
2081 error ("Cannot get substrings of substrings");
2086 if (VALUE_LVAL(str) == lval_internalvar)
2088 /* Internal variables of type TYPE_CODE_LITERAL_STRING
2089 have their data located in the superior
2090 process not the inferior */
2092 var = VALUE_INTERNALVAR (str);
2094 if (VALUE_SUBSTRING_MEMADDR (str) == (CORE_ADDR)0)
2095 VALUE_SUBSTRING_MYADDR (val) =
2096 ((char *) VALUE_LITERAL_DATA (var->value)) + (from - 1);
2099 VALUE_SUBSTRING_MYADDR (val) = VALUE_LITERAL_DATA(str)+(from -1);
2101 error ("Cannot get substrings of substrings");
2103 memcpy (addr, VALUE_SUBSTRING_MYADDR (val), nelem);
2106 error ("Substrings can not be applied to this data item");
2108 VALUE_LAZY (val) = 0;
2109 VALUE_LITERAL_DATA (val) = addr;
2111 /* This literal string's *data* is located in the superior BUT
2112 we do need to know where it came from (i.e. was the source
2113 string an internalvar or a regular lval_memory variable), so
2114 we set the lval field to indicate this. This will be useful
2115 when we use this value on the LHS of an expr. */
2117 VALUE_LVAL (val) = VALUE_LVAL (str);
2121 /* Create a value for a FORTRAN complex number. Currently most of
2122 the time values are coerced to COMPLEX*16 (i.e. a complex number
2123 composed of 2 doubles. This really should be a smarter routine
2124 that figures out precision inteligently as opposed to assuming
2125 doubles. FIXME: fmb */
2128 f77_value_literal_complex (arg1, arg2, size)
2133 struct type *complex_type;
2134 register value_ptr val;
2137 if (size != 8 && size != 16 && size != 32)
2138 error ("Cannot create number of type 'complex*%d'", size);
2140 /* If either value comprising a complex number is a non-floating
2141 type, cast to double. */
2143 if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_FLT)
2144 arg1 = value_cast (builtin_type_f_real_s8, arg1);
2146 if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_FLT)
2147 arg2 = value_cast (builtin_type_f_real_s8, arg2);
2149 complex_type = f77_create_literal_complex_type (VALUE_TYPE (arg1),
2152 /* FIXME: does f77_create_literal_complex_type need to do something with
2159 val = allocate_value (complex_type);
2161 /* Now create a pointer to enough memory to hold the the two args */
2163 addr = xmalloc (TYPE_LENGTH (complex_type));
2165 /* Copy over the two components */
2167 memcpy (addr, VALUE_CONTENTS_RAW (arg1), TYPE_LENGTH (VALUE_TYPE (arg1)));
2169 memcpy (addr + TYPE_LENGTH (VALUE_TYPE (arg1)), VALUE_CONTENTS_RAW (arg2),
2170 TYPE_LENGTH (VALUE_TYPE (arg2)));
2172 VALUE_ADDRESS (val) = 0; /* Not located in the inferior */
2173 VALUE_LAZY (val) = 0;
2174 VALUE_LITERAL_DATA (val) = addr;
2176 /* Since this is a literal value, make sure that value_lval indicates
2179 VALUE_LVAL (val) = not_lval;
2183 /* Cast a value into the appropriate complex data type. Only works
2184 if both values are complex. */
2187 f77_cast_into_complex (type, val)
2189 register value_ptr val;
2191 register enum type_code valcode;
2194 register value_ptr piece1, piece2;
2198 valcode = TYPE_CODE (VALUE_TYPE (val));
2200 /* This casting will only work if the right hand side is
2201 either a regular complex type or a literal complex type.
2202 I.e: this casting is only for size adjustment of
2203 complex numbers not anything else. */
2205 if ((valcode != TYPE_CODE_COMPLEX) &&
2206 (valcode != TYPE_CODE_LITERAL_COMPLEX))
2207 error ("Cannot cast from a non complex type!");
2209 lenfrom = TYPE_LENGTH (VALUE_TYPE (val));
2210 lento = TYPE_LENGTH (type);
2212 if (lento == lenfrom)
2213 error ("Value to be cast is already of type %s", TYPE_NAME (type));
2215 if (lento == 32 || lenfrom == 32)
2216 error ("Casting into/out of complex*32 unsupported");
2222 /* Since we have excluded lenfrom == 32 and
2223 lenfrom == 16, it MUST be 8 */
2225 if (valcode == TYPE_CODE_LITERAL_COMPLEX)
2227 /* Located in superior's memory. Routine should
2228 deal with both real literal complex numbers
2229 as well as internal vars */
2231 /* Grab the two 4 byte reals that make up the complex*8 */
2233 tmp_f = *((float *) VALUE_LITERAL_DATA (val));
2235 piece1 = value_from_double(builtin_type_f_real_s8,tmp_f);
2237 tmp_f = *((float *) (((char *) VALUE_LITERAL_DATA (val))
2240 piece2 = value_from_double (builtin_type_f_real_s8, tmp_f);
2244 /* Located in inferior memory, so first we need
2245 to read the 2 floats that make up the 8 byte
2246 complex we are are casting from */
2248 read_memory ((CORE_ADDR) VALUE_CONTENTS (val),
2249 (char *) &tmp_f, sizeof(float));
2251 piece1 = value_from_double (builtin_type_f_real_s8, tmp_f);
2253 read_memory ((CORE_ADDR) VALUE_CONTENTS (val) + sizeof(float),
2254 (char *) &tmp_f, sizeof(float));
2256 piece2 = value_from_double (builtin_type_f_real_s8, tmp_f);
2258 return f77_value_literal_complex (piece1, piece2, 16);
2263 /* Since we have excluded lenfrom == 32 and
2264 lenfrom == 8, it MUST be 16. NOTE: in this
2265 case data may be since we are dropping precison */
2267 if (valcode == TYPE_CODE_LITERAL_COMPLEX)
2269 /* Located in superior's memory. Routine should
2270 deal with both real literal complex numbers
2271 as well as internal vars */
2273 /* Grab the two 8 byte reals that make up the complex*16 */
2275 tmp_d = *((double *) VALUE_LITERAL_DATA (val));
2277 piece1 = value_from_double (builtin_type_f_real, tmp_d);
2279 tmp_d = *((double *) (((char *) VALUE_LITERAL_DATA (val))
2282 piece2 = value_from_double (builtin_type_f_real, tmp_d);
2286 /* Located in inferior memory, so first we need to read the
2287 2 floats that make up the 8 byte complex we are are
2290 read_memory ((CORE_ADDR) VALUE_CONTENTS (val),
2291 (char *) &tmp_d, sizeof(double));
2293 piece1 = value_from_double (builtin_type_f_real, tmp_d);
2295 read_memory ((CORE_ADDR) VALUE_CONTENTS (val) + sizeof(double),
2296 (char *) &tmp_f, sizeof(double));
2298 piece2 = value_from_double (builtin_type_f_real, tmp_d);
2300 return f77_value_literal_complex (piece1, piece2, 8);
2304 error ("Invalid F77 complex number cast");
2308 /* The following function is called in order to assign
2309 a literal F77 array to either an internal GDB variable
2310 or to a real array variable in the inferior.
2311 This function is necessary because in F77, literal
2312 arrays are allocated in the superior's memory space
2313 NOT the inferior's. This function provides a way to
2314 get the F77 stuff to work without messing with the
2315 way C deals with this issue. NOTE: we are assuming
2316 that all F77 array literals are STRING array literals. F77
2317 users have no good way of expressing non-string
2320 This routine now also handles assignment TO literal strings
2321 in the peculiar case of substring assignments of the
2329 f77_assign_from_literal_string (toval, fromval)
2330 register value_ptr toval, fromval;
2332 register struct type *type = VALUE_TYPE (toval);
2333 register value_ptr val;
2334 struct internalvar *var;
2339 lenfrom = TYPE_LENGTH (VALUE_TYPE (fromval));
2340 lento = TYPE_LENGTH (VALUE_TYPE (toval));
2342 if ((VALUE_LVAL (toval) == lval_internalvar
2343 || VALUE_LVAL (toval) == lval_memory)
2344 && VALUE_SUBSTRING_START (toval) != 0)
2346 /* We are assigning TO a substring type. This is of the form:
2350 The result of this will be a modified toval not a brand new
2351 value. This is high F77 weirdness. */
2353 /* Simply overwrite the relevant memory, wherever it
2354 exists. Use standard F77 character assignment rules
2355 (if len(toval) > len(fromval) pad with blanks,
2356 if len(toval) < len(fromval) truncate else just copy. */
2358 if (VALUE_LVAL (toval) == lval_internalvar)
2360 /* Memory in superior. */
2361 var = VALUE_INTERNALVAR (toval);
2362 memcpy ((char *) VALUE_SUBSTRING_START (toval),
2363 (char *) VALUE_LITERAL_DATA (fromval),
2364 (lento > lenfrom) ? lenfrom : lento);
2366 /* Check to see if we have to pad. */
2368 if (lento > lenfrom)
2370 memset((char *) VALUE_SUBSTRING_START(toval) + lenfrom,
2371 ' ', lento - lenfrom);
2376 /* Memory in inferior. */
2377 write_memory ((CORE_ADDR) VALUE_SUBSTRING_START (toval),
2378 (char *) VALUE_LITERAL_DATA (fromval),
2379 (lento > lenfrom) ? lenfrom : lento);
2381 /* Check to see if we have to pad. */
2383 if (lento > lenfrom)
2385 c = alloca (lento-lenfrom);
2386 memset (c, ' ', lento - lenfrom);
2388 tmp_addr = VALUE_SUBSTRING_START (toval) + lenfrom;
2389 write_memory (tmp_addr, c, lento - lenfrom);
2396 if (VALUE_LVAL (toval) == lval_internalvar)
2397 type = VALUE_TYPE (fromval);
2399 val = allocate_value (type);
2401 switch (VALUE_LVAL (toval))
2403 case lval_internalvar:
2405 /* Internal variables are funny. Their value information
2406 is stored in the location.internalvar sub structure. */
2408 var = VALUE_INTERNALVAR (toval);
2410 /* The item in toval is a regular internal variable
2411 and this assignment is of the form:
2413 set var $foo = 'hello' */
2415 /* First free up any old stuff in this internalvar. */
2417 free (VALUE_LITERAL_DATA (var->value));
2418 VALUE_LITERAL_DATA (var->value) = 0;
2419 VALUE_LAZY (var->value) = 0; /* Disable lazy fetches since this
2420 is not located in inferior. */
2422 /* Copy over the relevant value data from 'fromval' */
2424 set_internalvar (VALUE_INTERNALVAR (toval), fromval);
2426 /* Now replicate the VALUE_LITERAL_DATA field so that
2427 we may later safely de-allocate fromval. */
2429 VALUE_LITERAL_DATA (var->value) =
2430 malloc (TYPE_LENGTH (VALUE_TYPE (fromval)));
2432 memcpy((char *) VALUE_LITERAL_DATA (var->value),
2433 (char *) VALUE_LITERAL_DATA (fromval),
2436 /* Copy over all relevant value data from 'toval'. into
2437 the structure to returned */
2439 memcpy (val, toval, sizeof(struct value));
2441 /* Lastly copy the pointer to the area where the
2442 internalvar data is stored to the VALUE_CONTENTS field.
2443 This will be a helpful shortcut for printout
2446 VALUE_LITERAL_DATA (val) = VALUE_LITERAL_DATA (var->value);
2451 /* We are copying memory from the local (superior)
2452 literal string to a legitimate address in the
2453 inferior. VALUE_ADDRESS is the address in
2454 the inferior. VALUE_OFFSET is not used because
2455 structs do not exist in F77. */
2457 /* Copy over all relevant value data from 'toval'. */
2459 memcpy (val, toval, sizeof(struct value));
2461 write_memory ((CORE_ADDR) VALUE_ADDRESS (val),
2462 (char *) VALUE_LITERAL_DATA (fromval),
2463 (lento > lenfrom) ? lenfrom : lento);
2465 /* Check to see if we have to pad */
2467 if (lento > lenfrom)
2469 c = alloca (lento - lenfrom);
2470 memset (c, ' ', lento - lenfrom);
2471 tmp_addr = VALUE_ADDRESS (val) + lenfrom;
2472 write_memory (tmp_addr, c, lento - lenfrom);
2477 error ("Unknown lval type in f77_assign_from_literal_string");
2480 /* Now free up the transient literal string's storage. */
2482 free (VALUE_LITERAL_DATA (fromval));
2484 VALUE_TYPE (val) = type;
2491 /* The following function is called in order to assign a literal F77
2492 complex to either an internal GDB variable or to a real complex
2493 variable in the inferior. This function is necessary because in F77,
2494 composite literals are allocated in the superior's memory space
2495 NOT the inferior's. This function provides a way to get the F77 stuff
2496 to work without messing with the way C deals with this issue. */
2499 f77_assign_from_literal_complex (toval, fromval)
2500 register value_ptr toval, fromval;
2502 register struct type *type = VALUE_TYPE (toval);
2503 register value_ptr val;
2504 struct internalvar *var;
2506 double tmp_double = 0;
2508 if (VALUE_LVAL (toval) == lval_internalvar)
2509 type = VALUE_TYPE (fromval);
2511 /* Allocate a value node for the result. */
2513 val = allocate_value (type);
2515 if (VALUE_LVAL (toval) == lval_internalvar)
2517 /* Internal variables are funny. Their value information
2518 is stored in the location.internalvar sub structure. */
2520 var = VALUE_INTERNALVAR (toval);
2522 /* First free up any old stuff in this internalvar. */
2524 free (VALUE_LITERAL_DATA (var->value));
2525 VALUE_LITERAL_DATA (var->value) = 0;
2526 VALUE_LAZY (var->value) = 0; /* Disable lazy fetches since
2527 this is not located in inferior. */
2529 /* Copy over the relevant value data from 'fromval'. */
2531 set_internalvar (VALUE_INTERNALVAR (toval), fromval);
2533 /* Now replicate the VALUE_LITERAL_DATA field so that
2534 we may later safely de-allocate fromval. */
2536 VALUE_LITERAL_DATA (var->value) =
2537 malloc (TYPE_LENGTH (VALUE_TYPE (fromval)));
2539 memcpy ((char *) VALUE_LITERAL_DATA (var->value),
2540 (char *) VALUE_LITERAL_DATA (fromval),
2541 TYPE_LENGTH (VALUE_TYPE (fromval)));
2543 /* Copy over all relevant value data from 'toval' into the
2544 structure to be returned. */
2546 memcpy (val, toval, sizeof(struct value));
2550 /* We are copying memory from the local (superior) process to a
2551 legitimate address in the inferior. VALUE_ADDRESS is the
2552 address in the inferior. */
2554 /* Copy over all relevant value data from 'toval'. */
2556 memcpy (val, toval, sizeof(struct value));
2558 if (TYPE_LENGTH (VALUE_TYPE (fromval))
2559 > TYPE_LENGTH (VALUE_TYPE (toval)))
2561 /* Since all literals are actually complex*16 types, deal with
2562 the case when one tries to assign a literal to a complex*8. */
2564 if ((TYPE_LENGTH(VALUE_TYPE(fromval)) == 16) &&
2565 (TYPE_LENGTH(VALUE_TYPE(toval)) == 8))
2567 tmp_double = *((double *) VALUE_LITERAL_DATA (fromval));
2569 tmp_float = (float) tmp_double;
2571 write_memory (VALUE_ADDRESS(val),
2572 (char *) &tmp_float, sizeof(float));
2574 tmp_double = *((double *)
2575 (((char *) VALUE_LITERAL_DATA (fromval))
2578 tmp_float = (float) tmp_double;
2580 write_memory(VALUE_ADDRESS(val) + sizeof(float),
2581 (char *) &tmp_float, sizeof(float));
2584 error ("Cannot assign literal complex to variable!");
2588 write_memory (VALUE_ADDRESS (val),
2589 (char *) VALUE_LITERAL_DATA (fromval),
2590 TYPE_LENGTH (VALUE_TYPE (fromval)));
2594 /* Now free up the transient literal string's storage */
2596 free (VALUE_LITERAL_DATA (fromval));
2598 VALUE_TYPE (val) = type;