1 /* Perform non-arithmetic operations on values, for GDB.
2 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
22 #include "initialize.h"
29 /* Cast value ARG2 to type TYPE and return as a value.
30 More general than a C cast: accepts any two types of the same length,
31 and if ARG2 is an lvalue it can be cast into anything at all. */
34 value_cast (type
, arg2
)
38 register enum type_code code1
;
39 register enum type_code code2
;
42 /* Coerce arrays but not enums. Enums will work as-is
43 and coercing them would cause an infinite recursion. */
44 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_ENUM
)
47 code1
= TYPE_CODE (type
);
48 code2
= TYPE_CODE (VALUE_TYPE (arg2
));
49 scalar
= (code2
== TYPE_CODE_INT
|| code2
== TYPE_CODE_FLT
50 || code2
== TYPE_CODE_ENUM
);
52 if (code1
== TYPE_CODE_FLT
&& scalar
)
53 return value_from_double (type
, value_as_double (arg2
));
54 else if ((code1
== TYPE_CODE_INT
|| code1
== TYPE_CODE_ENUM
)
55 && (scalar
|| code2
== TYPE_CODE_PTR
))
56 return value_from_long (type
, value_as_long (arg2
));
57 else if (TYPE_LENGTH (type
) == TYPE_LENGTH (VALUE_TYPE (arg2
)))
59 VALUE_TYPE (arg2
) = type
;
62 else if (VALUE_LVAL (arg2
) == lval_memory
)
64 return value_at (type
, VALUE_ADDRESS (arg2
) + VALUE_OFFSET (arg2
));
67 error ("Invalid cast.");
70 /* Return the value with a specified type located at specified address. */
77 register value val
= allocate_value (type
);
79 read_memory (addr
, VALUE_CONTENTS (val
), TYPE_LENGTH (type
));
80 VALUE_LVAL (val
) = lval_memory
;
81 VALUE_ADDRESS (val
) = addr
;
86 /* Store the contents of FROMVAL into the location of TOVAL.
87 Return a new value with the location of TOVAL and contents of FROMVAL. */
90 value_assign (toval
, fromval
)
91 register value toval
, fromval
;
93 register struct type
*type
= VALUE_TYPE (toval
);
95 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
96 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
99 COERCE_ARRAY (fromval
);
101 if (VALUE_LVAL (toval
) != lval_internalvar
)
102 fromval
= value_cast (type
, fromval
);
104 /* If TOVAL is a special machine register requiring conversion
105 of program values to a special raw format,
106 convert FROMVAL's contents now, with result in `raw_buffer',
107 and set USE_BUFFER to the number of bytes to write. */
109 if (VALUE_REGNO (toval
) >= 0
110 && REGISTER_CONVERTIBLE (VALUE_REGNO (toval
)))
112 int regno
= VALUE_REGNO (toval
);
113 if (VALUE_TYPE (fromval
) != REGISTER_VIRTUAL_TYPE (regno
))
114 fromval
= value_cast (REGISTER_VIRTUAL_TYPE (regno
), fromval
);
115 bcopy (VALUE_CONTENTS (fromval
), virtual_buffer
,
116 REGISTER_VIRTUAL_SIZE (regno
));
117 REGISTER_CONVERT_TO_RAW (regno
, virtual_buffer
, raw_buffer
);
118 use_buffer
= REGISTER_RAW_SIZE (regno
);
121 switch (VALUE_LVAL (toval
))
123 case lval_internalvar
:
124 set_internalvar (VALUE_INTERNALVAR (toval
), fromval
);
127 case lval_internalvar_component
:
128 set_internalvar_component (VALUE_INTERNALVAR (toval
),
129 VALUE_OFFSET (toval
),
130 VALUE_BITPOS (toval
),
131 VALUE_BITSIZE (toval
),
136 if (VALUE_BITSIZE (toval
))
139 read_memory (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
),
141 modify_field (&val
, value_as_long (fromval
),
142 VALUE_BITPOS (toval
), VALUE_BITSIZE (toval
));
143 write_memory (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
),
147 write_memory (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
),
148 raw_buffer
, use_buffer
);
150 write_memory (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
),
151 VALUE_CONTENTS (fromval
), TYPE_LENGTH (type
));
155 if (VALUE_BITSIZE (toval
))
159 read_register_bytes (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
),
161 modify_field (&val
, value_as_long (fromval
),
162 VALUE_BITPOS (toval
), VALUE_BITSIZE (toval
));
163 write_register_bytes (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
),
167 write_register_bytes (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
),
168 raw_buffer
, use_buffer
);
170 write_register_bytes (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
),
171 VALUE_CONTENTS (fromval
), TYPE_LENGTH (type
));
175 error ("Left side of = operation is not an lvalue.");
178 /* Return a value just like TOVAL except with the contents of FROMVAL. */
180 val
= allocate_value (type
);
181 bcopy (toval
, val
, VALUE_CONTENTS (val
) - (char *) val
);
182 bcopy (VALUE_CONTENTS (fromval
), VALUE_CONTENTS (val
), TYPE_LENGTH (type
));
187 /* Extend a value VAL to COUNT repetitions of its type. */
190 value_repeat (arg1
, count
)
196 if (VALUE_LVAL (arg1
) != lval_memory
)
197 error ("Only values in memory can be extended with '@'.");
199 error ("Invalid number %d of repetitions.", count
);
201 val
= allocate_repeat_value (VALUE_TYPE (arg1
), count
);
203 read_memory (VALUE_ADDRESS (arg1
) + VALUE_OFFSET (arg1
),
204 VALUE_CONTENTS (val
),
205 TYPE_LENGTH (VALUE_TYPE (val
)) * count
);
206 VALUE_LVAL (val
) = lval_memory
;
207 VALUE_ADDRESS (val
) = VALUE_ADDRESS (arg1
) + VALUE_OFFSET (arg1
);
213 value_of_variable (var
)
216 return read_var_value (var
, (CORE_ADDR
) 0);
219 /* Given a value which is an array, return a value which is
220 a pointer to its first element. */
223 value_coerce_array (arg1
)
226 register struct type
*type
;
229 if (VALUE_LVAL (arg1
) != lval_memory
)
230 error ("Attempt to take address of value not located in memory.");
232 /* Get type of elements. */
233 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_ARRAY
)
234 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
236 /* A phony array made by value_repeat.
237 Its type is the type of the elements, not an array type. */
238 type
= VALUE_TYPE (arg1
);
240 /* Get the type of the result. */
241 type
= lookup_pointer_type (type
);
242 val
= value_from_long (builtin_type_long
,
243 VALUE_ADDRESS (arg1
) + VALUE_OFFSET (arg1
));
244 VALUE_TYPE (val
) = type
;
248 /* Return a pointer value for the object for which ARG1 is the contents. */
254 register struct type
*type
;
255 register value val
, arg1_coerced
;
257 /* Taking the address of an array is really a no-op
258 once the array is coerced to a pointer to its first element. */
260 COERCE_ARRAY (arg1_coerced
);
261 if (arg1
!= arg1_coerced
)
264 if (VALUE_LVAL (arg1
) != lval_memory
)
265 error ("Attempt to take address of value not located in memory.");
267 /* Get the type of the result. */
268 type
= lookup_pointer_type (VALUE_TYPE (arg1
));
269 val
= value_from_long (builtin_type_long
,
270 VALUE_ADDRESS (arg1
) + VALUE_OFFSET (arg1
));
271 VALUE_TYPE (val
) = type
;
275 /* Given a value of a pointer type, apply the C unary * operator to it. */
283 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_MEMBER
)
284 error ("not implemented: member types in value_ind");
286 /* Allow * on an integer so we can cast it to whatever we want. */
287 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_INT
)
288 return value_at (builtin_type_long
,
289 (CORE_ADDR
) value_as_long (arg1
));
290 else if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
)
291 return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)),
292 (CORE_ADDR
) value_as_long (arg1
));
293 else if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_REF
)
294 return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)),
295 (CORE_ADDR
) value_as_long (arg1
));
296 error ("Attempt to take contents of a non-pointer value.");
299 /* Pushing small parts of stack frames. */
301 /* Push one word (the size of object that a register holds). */
304 push_word (sp
, buffer
)
306 REGISTER_TYPE buffer
;
308 register int len
= sizeof (REGISTER_TYPE
);
312 write_memory (sp
, &buffer
, len
);
313 #else /* stack grows upward */
314 write_memory (sp
, &buffer
, len
);
316 #endif /* stack grows upward */
321 /* Push LEN bytes with data at BUFFER. */
324 push_bytes (sp
, buffer
, len
)
331 write_memory (sp
, buffer
, len
);
332 #else /* stack grows upward */
333 write_memory (sp
, buffer
, len
);
335 #endif /* stack grows upward */
340 /* Push onto the stack the specified value VALUE. */
344 register CORE_ADDR sp
;
347 register int len
= TYPE_LENGTH (VALUE_TYPE (arg
));
351 write_memory (sp
, VALUE_CONTENTS (arg
), len
);
352 #else /* stack grows upward */
353 write_memory (sp
, VALUE_CONTENTS (arg
), len
);
355 #endif /* stack grows upward */
360 /* Perform the standard coercions that are specified
361 for arguments to be passed to C functions. */
364 value_arg_coerce (arg
)
367 register struct type
*type
;
371 type
= VALUE_TYPE (arg
);
373 if (TYPE_CODE (type
) == TYPE_CODE_INT
374 && TYPE_LENGTH (type
) < sizeof (int))
375 return value_cast (builtin_type_int
, arg
);
377 if (type
== builtin_type_float
)
378 return value_cast (builtin_type_double
, arg
);
383 /* Push the value ARG, first coercing it as an argument
387 value_arg_push (sp
, arg
)
388 register CORE_ADDR sp
;
391 return value_push (sp
, value_arg_coerce (arg
));
394 /* Perform a function call in the inferior.
395 ARGS is a vector of values of arguments (NARGS of them).
396 FUNCTION is a value, the function to be called.
397 Returns a value representing what the function returned.
398 May fail to return, if a breakpoint or signal is hit
399 during the execution of the function. */
402 call_function (function
, nargs
, args
)
407 register CORE_ADDR sp
;
410 static REGISTER_TYPE dummy
[] = CALL_DUMMY
;
411 REGISTER_TYPE dummy1
[sizeof dummy
/ sizeof (REGISTER_TYPE
)];
413 struct type
*value_type
;
418 register CORE_ADDR funaddr
;
419 register struct type
*ftype
= VALUE_TYPE (function
);
420 register enum type_code code
= TYPE_CODE (ftype
);
422 /* If it's a member function, just look at the function
424 if (code
== TYPE_CODE_MEMBER
)
426 ftype
= TYPE_TARGET_TYPE (ftype
);
427 code
= TYPE_CODE (ftype
);
430 /* Determine address to call. */
431 if (code
== TYPE_CODE_FUNC
)
433 funaddr
= VALUE_ADDRESS (function
);
434 value_type
= TYPE_TARGET_TYPE (ftype
);
436 else if (code
== TYPE_CODE_PTR
)
438 funaddr
= value_as_long (function
);
439 if (TYPE_CODE (TYPE_TARGET_TYPE (ftype
))
441 value_type
= TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype
));
443 value_type
= builtin_type_int
;
445 else if (code
== TYPE_CODE_INT
)
447 /* Handle the case of functions lacking debugging info.
448 Their values are characters since their addresses are char */
449 if (TYPE_LENGTH (ftype
) == 1)
450 funaddr
= value_as_long (value_addr (function
));
452 /* Handle integer used as address of a function. */
453 funaddr
= value_as_long (function
);
455 value_type
= builtin_type_int
;
458 error ("Invalid data type for function to be called.");
460 /* Create a call sequence customized for this function
461 and the number of arguments for it. */
462 bcopy (dummy
, dummy1
, sizeof dummy
);
463 FIX_CALL_DUMMY (dummy1
, funaddr
, nargs
);
466 old_sp
= sp
= read_register (SP_REGNUM
);
468 #if 1 INNER_THAN 2 /* Stack grows down */
470 write_memory (sp
, dummy1
, sizeof dummy
);
472 for (i
= nargs
- 1; i
>= 0; i
--)
473 sp
= value_arg_push (sp
, args
[i
]);
474 #else /* Stack grows up */
476 write_memory (sp
, dummy1
, sizeof dummy
);
478 for (i
= 0; i
< nargs
; i
++)
479 sp
= value_arg_push (sp
, args
[i
]);
480 #endif /* Stack grows up */
482 write_register (SP_REGNUM
, sp
);
484 /* Figure out the value returned by the function. */
486 char retbuf
[REGISTER_BYTES
];
488 /* Execute the stack dummy routine, calling FUNCTION.
489 When it is done, discard the empty frame
490 after storing the contents of all regs into retbuf. */
491 run_stack_dummy (start_sp
+ CALL_DUMMY_START_OFFSET
, retbuf
);
493 return value_being_returned (value_type
, retbuf
);
497 /* Create a value for a string constant:
498 Call the function malloc in the inferior to get space for it,
499 then copy the data into that space
500 and then return the address with type char *.
501 PTR points to the string constant data; LEN is number of characters. */
504 value_string (ptr
, len
)
509 register struct symbol
*sym
;
511 register char *copy
= (char *) alloca (len
+ 1);
513 register char *o
= copy
, *ibeg
= ptr
;
516 /* Copy the string into COPY, processing escapes.
517 We could not conveniently process them in expread
518 because the string there wants to be a substring of the input. */
520 while (i
- ibeg
< len
)
525 c
= parse_escape (&i
);
533 /* Get the length of the string after escapes are processed. */
537 /* Find the address of malloc in the inferior. */
539 sym
= lookup_symbol ("malloc", 0, VAR_NAMESPACE
);
542 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
543 error ("\"malloc\" exists in this program but is not a function.");
544 val
= value_of_variable (sym
);
549 for (i
= 0; i
< misc_function_count
; i
++)
550 if (!strcmp (misc_function_vector
[i
].name
, "malloc"))
552 if (i
< misc_function_count
)
553 val
= value_from_long (builtin_type_long
,
554 misc_function_vector
[i
].address
);
556 error ("String constants require the program to have a function \"malloc\".");
559 blocklen
= value_from_long (builtin_type_int
, len
+ 1);
560 val
= call_function (val
, 1, &blocklen
);
561 if (value_zerop (val
))
562 error ("No memory available for string constant.");
563 write_memory (value_as_long (val
), copy
, len
+ 1);
564 VALUE_TYPE (val
) = lookup_pointer_type (builtin_type_char
);
568 /* Given ARG1, a value of type (pointer to a)* structure/union,
569 extract the component named NAME from the ultimate target structure/union
570 and return it as a value with its appropriate type.
571 ERR is used in the error message if ARG1's type is wrong.
573 C++: ARGS is a list of argument types to aid in the selection of
574 an appropriate method. Also, handle derived types.
576 ERR is an error message to be printed in case the field is not found. */
579 value_struct_elt (arg1
, args
, name
, err
)
580 register value arg1
, *args
;
584 register struct type
*t
;
588 struct type
*baseclass
;
592 t
= VALUE_TYPE (arg1
);
594 /* Follow pointers until we get to a non-pointer. */
596 while (TYPE_CODE (t
) == TYPE_CODE_PTR
|| TYPE_CODE (t
) == TYPE_CODE_REF
)
598 arg1
= value_ind (arg1
);
600 t
= VALUE_TYPE (arg1
);
603 if (TYPE_CODE (t
) == TYPE_CODE_MEMBER
)
604 error ("not implemented: member type in value_struct_elt");
606 if (TYPE_CODE (t
) != TYPE_CODE_STRUCT
607 && TYPE_CODE (t
) != TYPE_CODE_UNION
)
608 error ("Attempt to extract a component of a value that is not a %s.", err
);
614 /* if there are no arguments ...do this... */
616 /* Try as a variable first, because if we succeed, there
617 is less work to be done. */
620 for (i
= TYPE_NFIELDS (t
) - 1; i
>= 0; i
--)
622 if (!strcmp (TYPE_FIELD_NAME (t
, i
), name
))
630 return TYPE_FIELD_STATIC (t
, i
)
631 ? value_static_field (t
, name
, i
) : value_field (arg1
, i
);
633 t
= TYPE_BASECLASS (t
);
634 VALUE_TYPE (arg1
) = t
; /* side effect! */
637 /* C++: If it was not found as a data field, then try to
638 return it as a pointer to a method. */
640 VALUE_TYPE (arg1
) = t
; /* side effect! */
642 if (destructor_name_p (name
, t
))
643 error ("use `info method' command to print out value of destructor");
647 for (i
= TYPE_NFN_FIELDS (t
) - 1; i
>= 0; --i
)
649 if (! strcmp (TYPE_FN_FIELDLIST_NAME (t
, i
), name
))
651 error ("use `info method' command to print value of method \"%s\"", name
);
654 t
= TYPE_BASECLASS (t
);
658 error("there is no field named %s", name
);
662 if (destructor_name_p (name
, t
))
666 /* destructors are a special case. */
667 return (value
)value_fn_field (arg1
, 0, TYPE_FN_FIELDLIST_LENGTH (t
, 0));
671 error ("destructor should not have any argument");
675 /* This following loop is for methods with arguments. */
678 /* Look up as method first, because that is where we
679 expect to find it first. */
680 for (i
= TYPE_NFN_FIELDS (t
) - 1; i
>= 0; i
--)
682 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
684 if (!strcmp (TYPE_FN_FIELDLIST_NAME (t
, i
), name
))
687 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
690 for (j
= TYPE_FN_FIELDLIST_LENGTH (t
, i
) - 1; j
>= 0; --j
)
692 if (!typecmp (TYPE_FN_FIELD_ARGS (f
, j
), args
))
694 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
696 /* First, get the virtual function table pointer.
697 That comes with a strange type, so cast
698 it to type `pointer to long' (which
699 should serve just fine as a function type).
700 Then, index into the table, and convert
701 final value to appropriate function type. */
703 value vi
= value_from_long (builtin_type_int
,
704 TYPE_FN_FIELD_VOFFSET (f
, j
));
705 VALUE_TYPE (arg1
) = TYPE_VPTR_BASETYPE (t
);
707 if (TYPE_VPTR_FIELDNO (t
) < 0)
708 TYPE_VPTR_FIELDNO (t
)
709 = fill_in_vptr_fieldno (t
);
711 vtbl
= value_field (arg1
, TYPE_VPTR_FIELDNO (t
));
712 vfn
= value_subscript (vtbl
, vi
);
713 VALUE_TYPE (vfn
) = lookup_pointer_type (TYPE_FN_FIELD_TYPE (f
, j
));
717 return (value
)value_fn_field (arg1
, i
, j
);
722 t
= TYPE_BASECLASS (t
);
723 VALUE_TYPE (arg1
) = t
; /* side effect! */
728 error ("Structure method %s not defined for arglist.", name
);
733 /* See if user tried to invoke data as function */
737 for (i
= TYPE_NFIELDS (t
) - 1; i
>= 0; i
--)
739 if (!strcmp (TYPE_FIELD_NAME (t
, i
), name
))
747 return TYPE_FIELD_STATIC (t
, i
)
748 ? value_static_field (t
, name
, i
) : value_field (arg1
, i
);
750 t
= TYPE_BASECLASS (t
);
751 VALUE_TYPE (arg1
) = t
; /* side effect! */
753 error ("Structure has no component named %s.", name
);
757 /* C++: return 1 is NAME is a legitimate name for the destructor
758 of type TYPE. If TYPE does not have a destructor, or
759 if NAME is inappropriate for TYPE, an error is signaled. */
761 destructor_name_p (name
, type
)
765 /* destructors are a special case. */
766 char *dname
= TYPE_NAME (type
);
770 if (! TYPE_HAS_DESTRUCTOR (type
))
771 error ("type `%s' does not have destructor defined",
773 /* Skip past the "struct " at the front. */
774 while (*dname
++ != ' ') ;
775 if (strcmp (dname
, name
+1))
776 error ("destructor specification error");
783 /* C++: Given ARG1, a value of type (pointer to a)* structure/union,
784 return 1 if the component named NAME from the ultimate
785 target structure/union is defined, otherwise, return 0. */
788 check_field (arg1
, name
)
792 register struct type
*t
;
796 struct type
*baseclass
;
800 t
= VALUE_TYPE (arg1
);
802 /* Follow pointers until we get to a non-pointer. */
804 while (TYPE_CODE (t
) == TYPE_CODE_PTR
|| TYPE_CODE (t
) == TYPE_CODE_REF
)
806 arg1
= value_ind (arg1
);
808 t
= VALUE_TYPE (arg1
);
811 if (TYPE_CODE (t
) == TYPE_CODE_MEMBER
)
812 error ("not implemented: member type in check_field");
814 if (TYPE_CODE (t
) != TYPE_CODE_STRUCT
815 && TYPE_CODE (t
) != TYPE_CODE_UNION
)
816 error ("Internal error: `this' is not an aggregate");
822 for (i
= TYPE_NFIELDS (t
) - 1; i
>= 0; i
--)
824 if (!strcmp (TYPE_FIELD_NAME (t
, i
), name
))
829 t
= TYPE_BASECLASS (t
);
830 VALUE_TYPE (arg1
) = t
; /* side effect! */
833 /* C++: If it was not found as a data field, then try to
834 return it as a pointer to a method. */
836 VALUE_TYPE (arg1
) = t
; /* side effect! */
838 /* Destructors are a special case. */
839 if (destructor_name_p (name
, t
))
844 for (i
= TYPE_NFN_FIELDS (t
) - 1; i
>= 0; --i
)
846 if (!strcmp (TYPE_FN_FIELDLIST_NAME (t
, i
), name
))
849 t
= TYPE_BASECLASS (t
);
854 /* C++: Given an aggregate type DOMAIN, and a member name NAME,
855 return the address of this member as a pointer to member
856 type. If INTYPE is non-null, then it will be the type
857 of the member we are looking for. This will help us resolve
858 pointers to member functions. */
861 value_struct_elt_for_address (domain
, intype
, name
)
862 struct type
*domain
, *intype
;
865 register struct type
*t
= domain
;
870 struct type
*baseclass
;
872 if (TYPE_CODE (t
) != TYPE_CODE_STRUCT
873 && TYPE_CODE (t
) != TYPE_CODE_UNION
)
874 error ("Internal error: non-aggregate type to value_struct_elt_for_address");
880 for (i
= TYPE_NFIELDS (t
) - 1; i
>= 0; i
--)
882 if (!strcmp (TYPE_FIELD_NAME (t
, i
), name
))
884 if (TYPE_FIELD_PACKED (t
, i
))
885 error ("pointers to bitfield members not allowed");
887 v
= value_from_long (builtin_type_int
, TYPE_FIELD_BITPOS (t
, i
) >> 3);
888 VALUE_TYPE (v
) = lookup_member_type (TYPE_FIELD_TYPE (t
, i
), baseclass
);
892 t
= TYPE_BASECLASS (t
);
895 /* C++: If it was not found as a data field, then try to
896 return it as a pointer to a method. */
899 /* Destructors are a special case. */
900 if (destructor_name_p (name
, t
))
902 error ("pointers to destructors not implemented yet");
907 for (i
= TYPE_NFN_FIELDS (t
) - 1; i
>= 0; --i
)
909 if (!strcmp (TYPE_FN_FIELDLIST_NAME (t
, i
), name
))
911 int j
= TYPE_FN_FIELDLIST_LENGTH (t
, i
);
912 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
914 if (intype
== 0 && j
> 1)
915 error ("non-unique member `%s' requires type instantiation", name
);
919 if (TYPE_FN_FIELD_TYPE (f
, j
) == intype
)
922 error ("no member function matches that type instantiation");
927 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
929 v
= value_from_long (builtin_type_long
,
930 TYPE_FN_FIELD_VOFFSET (f
, j
));
934 struct symbol
*s
= lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, j
),
936 v
= locate_var_value (s
, 0);
938 VALUE_TYPE (v
) = lookup_member_type (TYPE_FN_FIELD_TYPE (f
, j
), baseclass
);
942 t
= TYPE_BASECLASS (t
);
947 /* Compare two argument lists and return the position in which they differ,
948 or zero if equal. Note that we ignore the first argument, which is
949 the type of the instance variable. This is because we want to handle
950 derived classes. This is not entirely correct: we should actually
951 check to make sure that a requested operation is type secure,
959 if (t1
[0]->code
== TYPE_CODE_VOID
) return 0;
961 for (i
= 1; t1
[i
]->code
!= TYPE_CODE_VOID
; i
++)
964 || t1
[i
]->code
!= t2
[i
]->type
->code
965 || t1
[i
]->target_type
!= t2
[i
]->type
->target_type
)
970 return t2
[i
] ? i
+1 : 0;
977 /* C++: return the value of the class instance variable, if one exists.
978 Flag COMPLAIN signals an error if the request is made in an
979 inappropriate context. */
981 value_of_this (complain
)
984 extern FRAME selected_frame
;
985 struct symbol
*func
, *sym
;
990 if (selected_frame
== 0)
992 error ("no frame selected");
995 func
= get_frame_function (selected_frame
);
997 funname
= SYMBOL_NAME (func
);
1000 error ("no `this' in nameless context");
1003 b
= SYMBOL_BLOCK_VALUE (func
);
1004 i
= BLOCK_NSYMS (b
);
1007 error ("no args, no `this'");
1010 sym
= BLOCK_SYM (b
, 0);
1011 if (strncmp ("$this", SYMBOL_NAME (sym
), 5))
1013 error ("current stack frame not in method");
1016 return read_var_value (sym
, selected_frame
);