This file is part of GDB.
-GDB is free software; you can redistribute it and/or modify
+This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
-any later version.
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
-GDB is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GDB; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include "defs.h"
return value_from_double (type, value_as_double (arg2));
else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM)
&& (scalar || code2 == TYPE_CODE_PTR))
- return value_from_long (type, value_as_long (arg2));
+ return value_from_longest (type, value_as_long (arg2));
else if (TYPE_LENGTH (type) == TYPE_LENGTH (VALUE_TYPE (arg2)))
{
if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
&& TYPE_NAME (t1) != 0) /* if name unknown, can't have supercl */
{
value v = search_struct_field (type_name_no_tag (t1),
- value_ind (arg2), 0, t2);
+ value_ind (arg2), 0, t2, 1);
if (v)
{
v = value_addr (v);
{
return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
}
+ else if (code1 == TYPE_CODE_VOID)
+ {
+ return value_zero (builtin_type_void, not_lval);
+ }
else
{
error ("Invalid cast.");
data from the user's process, and clears the lazy flag to indicate
that the data in the buffer is valid.
+ If the value is zero-length, we avoid calling read_memory, which would
+ abort. We mark the value as fetched anyway -- all 0 bytes of it.
+
This function returns a value because it is used in the VALUE_CONTENTS
macro as part of an expression, where a void would not work. The
value is ignored. */
{
CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
- read_memory (addr, VALUE_CONTENTS_RAW (val),
- TYPE_LENGTH (VALUE_TYPE (val)));
+ if (TYPE_LENGTH (VALUE_TYPE (val)))
+ read_memory (addr, VALUE_CONTENTS_RAW (val),
+ TYPE_LENGTH (VALUE_TYPE (val)));
VALUE_LAZY (val) = 0;
return 0;
}
}
/* Given a value which is an array, return a value which is
- a pointer to its first element. */
+ a pointer to its first (actually, zeroth) element.
+ FIXME, this should be subtracting the array's lower bound. */
value
value_coerce_array (arg1)
value arg1;
{
register struct type *type;
- register value val;
if (VALUE_LVAL (arg1) != lval_memory)
error ("Attempt to take address of value not located in memory.");
Its type is the type of the elements, not an array type. */
type = VALUE_TYPE (arg1);
- /* Get the type of the result. */
- type = lookup_pointer_type (type);
- val = value_from_long (builtin_type_long,
+ return value_from_longest (lookup_pointer_type (type),
(LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
- VALUE_TYPE (val) = type;
- return val;
}
/* Given a value which is a function, return a value which is a pointer
value_coerce_function (arg1)
value arg1;
{
- register struct type *type;
- register value val;
if (VALUE_LVAL (arg1) != lval_memory)
error ("Attempt to take address of value not located in memory.");
- /* Get the type of the result. */
- type = lookup_pointer_type (VALUE_TYPE (arg1));
- val = value_from_long (builtin_type_long,
+ return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
(LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
- VALUE_TYPE (val) = type;
- return val;
}
/* Return a pointer value for the object for which ARG1 is the contents. */
value_addr (arg1)
value arg1;
{
- register struct type *type;
- register value val;
COERCE_REF(arg1);
- /* Taking the address of an array is really a no-op
- once the array is coerced to a pointer to its first element. */
if (VALUE_REPEATED (arg1)
|| TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY)
return value_coerce_array (arg1);
if (VALUE_LVAL (arg1) != lval_memory)
error ("Attempt to take address of value not located in memory.");
- /* Get the type of the result. */
- type = lookup_pointer_type (VALUE_TYPE (arg1));
- val = value_from_long (builtin_type_long,
+ return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
(LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
- VALUE_TYPE (val) = type;
- return val;
}
/* Given a value of a pointer type, apply the C unary * operator to it. */
(CORE_ADDR) value_as_long (arg1));
else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
return value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
- (CORE_ADDR) value_as_long (arg1));
+ value_as_pointer (arg1));
error ("Attempt to take contents of a non-pointer value.");
return 0; /* For lint -- never reached */
}
}
else if (code == TYPE_CODE_PTR)
{
- funaddr = value_as_long (function);
+ funaddr = value_as_pointer (function);
if (TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_FUNC
|| TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_METHOD)
value_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype));
/* Handle the case of functions lacking debugging info.
Their values are characters since their addresses are char */
if (TYPE_LENGTH (ftype) == 1)
- funaddr = value_as_long (value_addr (function));
+ funaddr = value_as_pointer (value_addr (function));
else
/* Handle integer used as address of a function. */
- funaddr = value_as_long (function);
+ funaddr = (CORE_ADDR) value_as_long (function);
value_type = builtin_type_int;
}
register int i;
CORE_ADDR start_sp;
/* CALL_DUMMY is an array of words (REGISTER_TYPE), but each word
- in in host byte order. It is switched to target byte order before calling
+ is in host byte order. It is switched to target byte order before calling
FIX_CALL_DUMMY. */
static REGISTER_TYPE dummy[] = CALL_DUMMY;
REGISTER_TYPE dummy1[sizeof dummy / sizeof (REGISTER_TYPE)];
/* Convex Unix prohibits executing in the stack segment. */
/* Hope there is empty room at the top of the text segment. */
{
+ extern CORE_ADDR text_end;
static checked = 0;
if (!checked)
for (start_sp = text_end - sizeof dummy; start_sp < text_end; ++start_sp)
}
#else /* After text_end. */
{
+ extern CORE_ADDR text_end;
int errcode;
sp = old_sp;
start_sp = text_end;
#endif
/* The value we're going to pass is the address of the thing
we just pushed. */
- args[i] = value_from_long (builtin_type_long, (LONGEST) addr);
+ args[i] = value_from_longest (lookup_pointer_type (value_type),
+ (LONGEST) addr);
}
}
#endif /* REG_STRUCT_HAS_ADDR. */
register int c;
/* Copy the string into COPY, processing escapes.
- We could not conveniently process them in expread
+ We could not conveniently process them in the parser
because the string there wants to be a substring of the input. */
while (i - ibeg < len)
else
{
register int j;
- for (j = 0; j < misc_function_count; j++)
- if (!strcmp (misc_function_vector[j].name, "malloc"))
- break;
- if (j < misc_function_count)
- val = value_from_long (builtin_type_long,
- (LONGEST) misc_function_vector[j].address);
+ j = lookup_misc_func ("malloc");
+ if (j >= 0)
+ val = value_from_longest (
+ lookup_pointer_type (lookup_function_type (
+ lookup_pointer_type (builtin_type_char))),
+ (LONGEST) misc_function_vector[j].address);
else
error ("String constants require the program to have a function \"malloc\".");
}
- blocklen = value_from_long (builtin_type_int, (LONGEST) (len + 1));
+ blocklen = value_from_longest (builtin_type_int, (LONGEST) (len + 1));
val = target_call_function (val, 1, &blocklen);
if (value_zerop (val))
error ("No memory available for string constant.");
- write_memory ((CORE_ADDR) value_as_long (val), copy, len + 1);
+ write_memory (value_as_pointer (val), copy, len + 1);
VALUE_TYPE (val) = lookup_pointer_type (builtin_type_char);
return val;
}
/* Helper function used by value_struct_elt to recurse through baseclasses.
Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
and treat the result as having type TYPE.
- If found, return value, else return NULL. */
+ If found, return value, else return NULL.
+
+ If LOOKING_FOR_BASECLASS, then instead of looking for struct fields,
+ look for a baseclass named NAME. */
static value
-search_struct_field (name, arg1, offset, type)
+search_struct_field (name, arg1, offset, type, looking_for_baseclass)
char *name;
register value arg1;
int offset;
register struct type *type;
+ int looking_for_baseclass;
{
int i;
check_stub_type (type);
- for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
- {
- char *t_field_name = TYPE_FIELD_NAME (type, i);
- if (t_field_name && !strcmp (t_field_name, name))
- return TYPE_FIELD_STATIC (type, i)
- ? value_static_field (type, name, i)
- : value_primitive_field (arg1, offset, i, type);
- }
+ if (! looking_for_baseclass)
+ for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
+ {
+ char *t_field_name = TYPE_FIELD_NAME (type, i);
+
+ if (t_field_name && !strcmp (t_field_name, name))
+ {
+ value v = (TYPE_FIELD_STATIC (type, i)
+ ? value_static_field (type, name, i)
+ : value_primitive_field (arg1, offset, i, type));
+ if (v == 0)
+ error("there is no field named %s", name);
+ return v;
+ }
+ }
for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
{
value v;
/* If we are looking for baseclasses, this is what we get when we
hit them. */
- int found_baseclass = !strcmp (name, TYPE_BASECLASS_NAME (type, i));
+ int found_baseclass = (looking_for_baseclass
+ && !strcmp (name, TYPE_BASECLASS_NAME (type, i)));
if (BASETYPE_VIA_VIRTUAL (type, i))
{
value v2;
- baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset, &v2);
+ baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset,
+ &v2, (int *)NULL);
if (v2 == 0)
error ("virtual baseclass botch");
if (found_baseclass)
return v2;
- v = search_struct_field (name, v2, 0, TYPE_BASECLASS (type, i));
+ v = search_struct_field (name, v2, 0, TYPE_BASECLASS (type, i),
+ looking_for_baseclass);
if (v) return v;
else continue;
}
else
v = search_struct_field (name, arg1,
offset + TYPE_BASECLASS_BITPOS (type, i) / 8,
- TYPE_BASECLASS (type, i));
+ TYPE_BASECLASS (type, i),
+ looking_for_baseclass);
if (v) return v;
}
return NULL;
char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i);
if (t_field_name && !strcmp (t_field_name, name))
{
- int j;
+ int j = TYPE_FN_FIELDLIST_LENGTH (type, i) - 1;
struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
- for (j = TYPE_FN_FIELDLIST_LENGTH (type, i) - 1; j >= 0; --j)
+ if (j > 0 && args == 0)
+ error ("cannot resolve overloaded method `%s'", name);
+ while (j >= 0)
{
if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, j)) & TYPE_FLAG_STUB)
check_stub_method (type, i, j);
TYPE_FN_FIELD_ARGS (f, j), args))
{
if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
- return (value)value_virtual_fn_field (arg1, f, j);
+ return (value)value_virtual_fn_field (arg1, f, j, type);
if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
*static_memfuncp = 1;
return (value)value_fn_field (arg1, i, j);
}
+ j--;
}
}
}
if (BASETYPE_VIA_VIRTUAL (type, i))
{
value v2;
- baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset, &v2);
+ baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset,
+ &v2, (int *)NULL);
if (v2 == 0)
error ("virtual baseclass botch");
v = search_struct_method (name, v2, args, 0,
char *err;
{
register struct type *t;
- int found = 0; /* FIXME, half the time this doesn't get set */
- value arg1_as_ptr = *argp; /* FIXME, set but not used! */
value v;
COERCE_ARRAY (*argp);
while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
{
- arg1_as_ptr = *argp;
*argp = value_ind (*argp);
/* Don't coerce fn pointer to fn and then back again! */
if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC)
{
/* if there are no arguments ...do this... */
- /* Try as a variable first, because if we succeed, there
+ /* Try as a field first, because if we succeed, there
is less work to be done. */
- v = search_struct_field (name, *argp, 0, t);
+ v = search_struct_field (name, *argp, 0, t, 0);
if (v)
return v;
/* See if user tried to invoke data as function. If so,
hand it back. If it's not callable (i.e., a pointer to function),
gdb should give an error. */
- v = search_struct_field (name, *argp, 0, t);
+ v = search_struct_field (name, *argp, 0, t, 0);
}
if (!v)
struct symbol *sym =
lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
if (! sym) error ("Internal error: could not find physical static variable named %s", phys_name);
- v = value_from_long(builtin_type_long,
- (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
- VALUE_TYPE(v) = lookup_pointer_type (TYPE_FIELD_TYPE (t, i));
- return v;
+ return value_from_longest (
+ lookup_pointer_type (TYPE_FIELD_TYPE (t, i)),
+ (LONGEST)SYMBOL_BLOCK_VALUE (sym));
}
if (TYPE_FIELD_PACKED (t, i))
error ("pointers to bitfield members not allowed");
- v = value_from_long (builtin_type_int,
+ return value_from_longest (
+ lookup_pointer_type (
+ lookup_member_type (TYPE_FIELD_TYPE (t, i), baseclass)),
(LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
- VALUE_TYPE (v)
- = lookup_pointer_type (lookup_member_type (TYPE_FIELD_TYPE (t, i), baseclass));
- return v;
}
}
else
j = 0;
+ check_stub_method (t, i, j);
if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
{
- v = value_from_long (builtin_type_long,
+ return value_from_longest (
+ lookup_pointer_type (
+ lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),
+ baseclass)),
(LONGEST) TYPE_FN_FIELD_VOFFSET (f, j));
}
else
struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
0, VAR_NAMESPACE, 0, NULL);
v = locate_var_value (s, 0);
+ VALUE_TYPE (v) = lookup_pointer_type (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), baseclass));
+ return v;
}
- VALUE_TYPE (v) = lookup_pointer_type (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), baseclass));
- return v;
}
}
{
int i;
+ if (t2 == 0)
+ return 1;
if (staticp && t1 == 0)
return t2[1] != 0;
if (t1 == 0)
int i;
static const char funny_this[] = "this";
value this;
-
if (selected_frame == 0)
if (complain)