/* Perform non-arithmetic operations on values, for GDB.
- Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995
+ Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996
Free Software Foundation, Inc.
This file is part of GDB.
static int typecmp PARAMS ((int staticp, struct type *t1[], value_ptr t2[]));
+#ifdef CALL_DUMMY
static CORE_ADDR find_function_addr PARAMS ((value_ptr, struct type **));
+static value_ptr value_arg_coerce PARAMS ((value_ptr, struct type *));
+#endif
+
#ifndef PUSH_ARGUMENTS
static CORE_ADDR value_push PARAMS ((CORE_ADDR, value_ptr));
static value_ptr cast_into_complex PARAMS ((struct type *, value_ptr));
-static value_ptr value_arg_coerce PARAMS ((value_ptr, struct type *));
-
#define VALUE_SUBSTRING_START(VAL) VALUE_FRAME(VAL)
/* Flag for whether we want to abandon failed expression evals by default. */
low_bound = 0, high_bound = 0;
new_length = val_length / element_length;
if (val_length % element_length != 0)
- warning("array element type size does not divide object size in cast");
+ warning("array element type size does not divide object size in cast");
/* FIXME-type-allocation: need a way to free this type when we are
done with it. */
range_type = create_range_type ((struct type *) NULL,
}
else if (VALUE_LVAL (arg2) == lval_memory)
{
- return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
+ return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2),
+ VALUE_BFD_SECTION (arg2));
}
else if (code1 == TYPE_CODE_VOID)
{
the contents are actually required. */
value_ptr
-value_at (type, addr)
+value_at (type, addr, sect)
struct type *type;
CORE_ADDR addr;
+ asection *sect;
{
register value_ptr val;
val = allocate_value (type);
- read_memory (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (type));
+#ifdef GDB_TARGET_IS_D10V
+ if (TYPE_TARGET_TYPE(type) && TYPE_CODE(TYPE_TARGET_TYPE(type)) == TYPE_CODE_FUNC)
+ {
+ int num;
+ short snum;
+ read_memory (addr, (char *)&snum, 2);
+ num = D10V_MAKE_IADDR(snum);
+ memcpy( VALUE_CONTENTS_RAW (val), &num, 4);
+ }
+ else
+#endif
+
+ read_memory_section (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (type), sect);
VALUE_LVAL (val) = lval_memory;
VALUE_ADDRESS (val) = addr;
+ VALUE_BFD_SECTION (val) = sect;
return val;
}
/* Return a lazy value with type TYPE located at ADDR (cf. value_at). */
value_ptr
-value_at_lazy (type, addr)
+value_at_lazy (type, addr, sect)
struct type *type;
CORE_ADDR addr;
+ asection *sect;
{
register value_ptr val;
VALUE_LVAL (val) = lval_memory;
VALUE_ADDRESS (val) = addr;
VALUE_LAZY (val) = 1;
+ VALUE_BFD_SECTION (val) = sect;
return val;
}
CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
int length = TYPE_LENGTH (VALUE_TYPE (val));
+#ifdef GDB_TARGET_IS_D10V
+ struct type *type = VALUE_TYPE(val);
+ if (TYPE_TARGET_TYPE(type) && TYPE_CODE(TYPE_TARGET_TYPE(type)) == TYPE_CODE_FUNC)
+ {
+ int num;
+ short snum;
+ read_memory (addr, (char *)&snum, 2);
+ num = D10V_MAKE_IADDR(snum);
+ memcpy( VALUE_CONTENTS_RAW (val), &num, 4);
+ }
+ else
+#endif
+
if (length)
- read_memory (addr, VALUE_CONTENTS_RAW (val), length);
+ read_memory_section (addr, VALUE_CONTENTS_RAW (val), length,
+ VALUE_BFD_SECTION (val));
VALUE_LAZY (val) = 0;
return 0;
}
&& (VALUE_BITSIZE (toval) < 8 * (int) sizeof (LONGEST)))
{
LONGEST fieldval = value_as_long (fromval);
- LONGEST valmask = (((unsigned LONGEST) 1) << VALUE_BITSIZE (toval)) - 1;
+ LONGEST valmask = (((ULONGEST) 1) << VALUE_BITSIZE (toval)) - 1;
fieldval &= valmask;
if (!TYPE_UNSIGNED (type) && (fieldval & (valmask ^ (valmask >> 1))))
struct block *b;
{
value_ptr val;
- struct frame_info *frame;
+ struct frame_info *frame = NULL;
- if (b == NULL)
- /* Use selected frame. */
- frame = NULL;
- else
+ if (!b)
+ frame = NULL; /* Use selected frame. */
+ else if (symbol_read_needs_frame (var))
{
frame = block_innermost_frame (b);
- if (frame == NULL && symbol_read_needs_frame (var))
- {
- if (BLOCK_FUNCTION (b) != NULL
- && SYMBOL_NAME (BLOCK_FUNCTION (b)) != NULL)
- error ("No frame is currently executing in block %s.",
- SYMBOL_NAME (BLOCK_FUNCTION (b)));
- else
- error ("No frame is currently executing in specified block");
- }
+ if (!frame)
+ if (BLOCK_FUNCTION (b)
+ && SYMBOL_NAME (BLOCK_FUNCTION (b)))
+ error ("No frame is currently executing in block %s.",
+ SYMBOL_NAME (BLOCK_FUNCTION (b)));
+ else
+ error ("No frame is currently executing in specified block");
}
+
val = read_var_value (var, frame);
- if (val == 0)
+ if (!val)
error ("Address of symbol \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
+
return val;
}
value_coerce_function (arg1)
value_ptr arg1;
{
+ value_ptr retval;
if (VALUE_LVAL (arg1) != lval_memory)
error ("Attempt to take address of value not located in memory.");
- return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
- (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
+ retval = value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
+ (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
+ VALUE_BFD_SECTION (retval) = VALUE_BFD_SECTION (arg1);
+ return retval;
}
/* Return a pointer value for the object for which ARG1 is the contents. */
value_addr (arg1)
value_ptr arg1;
{
+ value_ptr retval;
+
struct type *type = check_typedef (VALUE_TYPE (arg1));
if (TYPE_CODE (type) == TYPE_CODE_REF)
{
if (VALUE_LVAL (arg1) != lval_memory)
error ("Attempt to take address of value not located in memory.");
- return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
- (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
+ retval = value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
+ (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
+ VALUE_BFD_SECTION (retval) = VALUE_BFD_SECTION (arg1);
+ return retval;
}
/* Given a value of a pointer type, apply the C unary * operator to it. */
BUILTIN_TYPE_LONGEST would seem to be a mistake. */
if (TYPE_CODE (type1) == TYPE_CODE_INT)
return value_at (builtin_type_int,
- (CORE_ADDR) value_as_long (arg1));
+ (CORE_ADDR) value_as_long (arg1),
+ VALUE_BFD_SECTION (arg1));
else if (TYPE_CODE (type1) == TYPE_CODE_PTR)
- return value_at_lazy (TYPE_TARGET_TYPE (type1), value_as_pointer (arg1));
+ return value_at_lazy (TYPE_TARGET_TYPE (type1), value_as_pointer (arg1),
+ VALUE_BFD_SECTION (arg1));
error ("Attempt to take contents of a non-pointer value.");
return 0; /* For lint -- never reached */
}
CORE_ADDR
push_word (sp, word)
CORE_ADDR sp;
- unsigned LONGEST word;
+ ULONGEST word;
{
register int len = REGISTER_SIZE;
char buffer[MAX_REGISTER_RAW_SIZE];
#endif /* !PUSH_ARGUMENTS */
+#ifdef CALL_DUMMY
/* Perform the standard coercions that are specified
for arguments to be passed to C functions.
return funaddr;
}
-#if defined (CALL_DUMMY)
/* All this stuff with a dummy frame may seem unnecessarily complicated
(why not just save registers in GDB?). The purpose of pushing a dummy
frame which looks just like a real frame is so that if you call a
CORE_ADDR start_sp;
/* CALL_DUMMY is an array of words (REGISTER_SIZE), but each word
is in host byte order. Before calling FIX_CALL_DUMMY, we byteswap it
- and remove any extra bytes which might exist because unsigned LONGEST is
+ and remove any extra bytes which might exist because ULONGEST is
bigger than REGISTER_SIZE. */
- static unsigned LONGEST dummy[] = CALL_DUMMY;
- char dummy1[REGISTER_SIZE * sizeof dummy / sizeof (unsigned LONGEST)];
+ static ULONGEST dummy[] = CALL_DUMMY;
+ char dummy1[REGISTER_SIZE * sizeof dummy / sizeof (ULONGEST)];
CORE_ADDR old_sp;
struct type *value_type;
unsigned char struct_return;
struct inferior_status inf_status;
struct cleanup *old_chain;
CORE_ADDR funaddr;
- int using_gcc;
+ int using_gcc; /* Set to version of gcc in use, or zero if not gcc */
CORE_ADDR real_pc;
struct type *ftype = check_typedef (SYMBOL_TYPE (function));
{
struct block *b = block_for_pc (funaddr);
- /* If compiled without -g, assume GCC. */
- using_gcc = b == NULL ? 0 : BLOCK_GCC_COMPILED (b);
+ /* If compiled without -g, assume GCC 2. */
+ using_gcc = (b == NULL ? 2 : BLOCK_GCC_COMPILED (b));
}
/* Are we returning a value using a structure return or a normal
for (i = 0; i < (int) (sizeof (dummy) / sizeof (dummy[0])); i++)
store_unsigned_integer (&dummy1[i * REGISTER_SIZE],
REGISTER_SIZE,
- (unsigned LONGEST)dummy[i]);
+ (ULONGEST)dummy[i]);
#ifdef GDB_TARGET_IS_HPPA
real_pc = FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args,
CORE_ADDR addr;
int len = TYPE_LENGTH (arg_type);
#ifdef STACK_ALIGN
+ /* MVS 11/22/96: I think at least some of this stack_align code is
+ really broken. Better to let PUSH_ARGUMENTS adjust the stack in
+ a target-defined manner. */
int aligned_len = STACK_ALIGN (len);
#else
int aligned_len = len;
{
int len = TYPE_LENGTH (value_type);
#ifdef STACK_ALIGN
+ /* MVS 11/22/96: I think at least some of this stack_align code is
+ really broken. Better to let PUSH_ARGUMENTS adjust the stack in
+ a target-defined manner. */
len = STACK_ALIGN (len);
#endif
#if 1 INNER_THAN 2
#endif
}
-#ifdef STACK_ALIGN
- /* If stack grows down, we must leave a hole at the top. */
+#if defined(STACK_ALIGN) && (1 INNER_THAN 2)
+ /* MVS 11/22/96: I think at least some of this stack_align code is
+ really broken. Better to let PUSH_ARGUMENTS adjust the stack in
+ a target-defined manner. */
{
+ /* If stack grows down, we must leave a hole at the top. */
int len = 0;
for (i = nargs - 1; i >= 0; i--)
#ifdef CALL_DUMMY_STACK_ADJUST
len += CALL_DUMMY_STACK_ADJUST;
#endif
-#if 1 INNER_THAN 2
sp -= STACK_ALIGN (len) - len;
-#else
- sp += STACK_ALIGN (len) - len;
-#endif
}
#endif /* STACK_ALIGN */
sp = value_push (sp, args[i]);
#endif /* !PUSH_ARGUMENTS */
+#ifdef PUSH_RETURN_ADDRESS /* for targets that use no CALL_DUMMY */
+ /* There are a number of targets now which actually don't write any
+ CALL_DUMMY instructions into the target, but instead just save the
+ machine state, push the arguments, and jump directly to the callee
+ function. Since this doesn't actually involve executing a JSR/BSR
+ instruction, the return address must be set up by hand, either by
+ pushing onto the stack or copying into a return-address register
+ as appropriate. Formerly this has been done in PUSH_ARGUMENTS,
+ but that's overloading its functionality a bit, so I'm making it
+ explicit to do it here. */
+ sp = PUSH_RETURN_ADDRESS(real_pc, sp);
+#endif /* PUSH_RETURN_ADDRESS */
+
+#if defined(STACK_ALIGN) && !(1 INNER_THAN 2)
+ {
+ /* If stack grows up, we must leave a hole at the bottom, note
+ that sp already has been advanced for the arguments! */
+#ifdef CALL_DUMMY_STACK_ADJUST
+ sp += CALL_DUMMY_STACK_ADJUST;
+#endif
+ sp = STACK_ALIGN (sp);
+ }
+#endif /* STACK_ALIGN */
+
+/* XXX This seems wrong. For stacks that grow down we shouldn't do
+ anything here! */
+ /* MVS 11/22/96: I think at least some of this stack_align code is
+ really broken. Better to let PUSH_ARGUMENTS adjust the stack in
+ a target-defined manner. */
#ifdef CALL_DUMMY_STACK_ADJUST
#if 1 INNER_THAN 2
sp -= CALL_DUMMY_STACK_ADJUST;
-#else
- sp += CALL_DUMMY_STACK_ADJUST;
#endif
#endif /* CALL_DUMMY_STACK_ADJUST */
VALUE_CONTENTS (elemvec[idx]),
typelength);
}
+ VALUE_BFD_SECTION (val) = VALUE_BFD_SECTION (elemvec[0]);
return val;
}
/* Create the array type and set up an array value to be evaluated lazily. */
- val = value_at_lazy (arraytype, addr);
+ val = value_at_lazy (arraytype, addr, VALUE_BFD_SECTION (elemvec[0]));
return (val);
}
addr = allocate_space_in_inferior (len);
write_memory (addr, ptr, len);
- val = value_at_lazy (stringtype, addr);
+ val = value_at_lazy (stringtype, addr, NULL);
return (val);
}
error ("Internal error: could not find physical static variable named %s",
phys_name);
v = value_at (TYPE_FIELD_TYPE (type, i),
- (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
+ SYMBOL_VALUE_ADDRESS (sym), SYMBOL_BFD_SECTION (sym));
}
else
v = value_primitive_field (arg1, offset, i, type);
{
if (!args[1])
{
- /* destructors are a special case. */
- v = value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, 0),
- TYPE_FN_FIELDLIST_LENGTH (t, 0), 0, 0);
- if (!v) error("could not find destructor function named %s.", name);
- else return v;
+ /* Destructors are a special case. */
+ int m_index, f_index;
+
+ v = NULL;
+ if (get_destructor_fn_field (t, &m_index, &f_index))
+ {
+ v = value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, m_index),
+ f_index, NULL, 0);
+ }
+ if (v == NULL)
+ error ("could not find destructor function named %s.", name);
+ else
+ return v;
}
else
{
/* Destructors are a special case. */
if (destructor_name_p (name, type))
- return 1;
+ {
+ int m_index, f_index;
+
+ return get_destructor_fn_field (type, &m_index, &f_index);
+ }
for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
{
error ("Internal error: could not find physical static variable named %s",
phys_name);
return value_at (SYMBOL_TYPE (sym),
- (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
+ SYMBOL_VALUE_ADDRESS (sym),
+ SYMBOL_BFD_SECTION (sym));
}
if (TYPE_FIELD_PACKED (t, i))
error ("pointers to bitfield members not allowed");