#include "cp-support.h"
#include "dfp.h"
#include "user-regs.h"
-
+#include "tracepoint.h"
#include <errno.h>
#include "gdb_string.h"
#include "gdb_assert.h"
static int
dynamic_cast_check_1 (struct type *desired_type,
- const bfd_byte *contents,
+ const gdb_byte *valaddr,
+ int embedded_offset,
CORE_ADDR address,
+ struct value *val,
struct type *search_type,
CORE_ADDR arg_addr,
struct type *arg_type,
for (i = 0; i < TYPE_N_BASECLASSES (search_type) && result_count < 2; ++i)
{
- int offset = baseclass_offset (search_type, i, contents, address);
+ int offset = baseclass_offset (search_type, i, valaddr, embedded_offset,
+ address, val);
- if (offset == -1)
- error (_("virtual baseclass botch"));
if (class_types_same_p (desired_type, TYPE_BASECLASS (search_type, i)))
{
- if (address + offset >= arg_addr
- && address + offset < arg_addr + TYPE_LENGTH (arg_type))
+ if (address + embedded_offset + offset >= arg_addr
+ && address + embedded_offset + offset < arg_addr + TYPE_LENGTH (arg_type))
{
++result_count;
if (!*result)
*result = value_at_lazy (TYPE_BASECLASS (search_type, i),
- address + offset);
+ address + embedded_offset + offset);
}
}
else
result_count += dynamic_cast_check_1 (desired_type,
- contents + offset,
- address + offset,
+ valaddr,
+ embedded_offset + offset,
+ address, val,
TYPE_BASECLASS (search_type, i),
arg_addr,
arg_type,
static int
dynamic_cast_check_2 (struct type *desired_type,
- const bfd_byte *contents,
+ const gdb_byte *valaddr,
+ int embedded_offset,
CORE_ADDR address,
+ struct value *val,
struct type *search_type,
struct value **result)
{
if (! BASETYPE_VIA_PUBLIC (search_type, i))
continue;
- offset = baseclass_offset (search_type, i, contents, address);
- if (offset == -1)
- error (_("virtual baseclass botch"));
+ offset = baseclass_offset (search_type, i, valaddr, embedded_offset,
+ address, val);
if (class_types_same_p (desired_type, TYPE_BASECLASS (search_type, i)))
{
++result_count;
if (*result == NULL)
*result = value_at_lazy (TYPE_BASECLASS (search_type, i),
- address + offset);
+ address + embedded_offset + offset);
}
else
result_count += dynamic_cast_check_2 (desired_type,
- contents + offset,
- address + offset,
+ valaddr,
+ embedded_offset + offset,
+ address, val,
TYPE_BASECLASS (search_type, i),
result);
}
return tem;
result = NULL;
if (dynamic_cast_check_1 (TYPE_TARGET_TYPE (resolved_type),
- value_contents (tem), value_address (tem),
+ value_contents_for_printing (tem),
+ value_embedded_offset (tem),
+ value_address (tem), tem,
rtti_type, addr,
arg_type,
&result) == 1)
result = NULL;
if (is_public_ancestor (arg_type, rtti_type)
&& dynamic_cast_check_2 (TYPE_TARGET_TYPE (resolved_type),
- value_contents (tem), value_address (tem),
+ value_contents_for_printing (tem),
+ value_embedded_offset (tem),
+ value_address (tem), tem,
rtti_type, &result) == 1)
return value_cast (type,
is_ref ? value_ref (result) : value_addr (result));
{
struct value *val = allocate_value (type);
- VALUE_LVAL (val) = lv;
+ VALUE_LVAL (val) = (lv == lval_computed ? not_lval : lv);
return val;
}
if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
error (_("Attempt to dereference a generic pointer."));
- if (lazy)
- {
- val = allocate_value_lazy (type);
- }
- else
- {
- val = allocate_value (type);
- read_memory (addr, value_contents_all_raw (val), TYPE_LENGTH (type));
- }
+ val = value_from_contents_and_address (type, NULL, addr);
- VALUE_LVAL (val) = lval_memory;
- set_value_address (val, addr);
+ if (!lazy)
+ value_fetch_lazy (val);
return val;
}
enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
struct value *parent = value_parent (val);
LONGEST offset = value_offset (val);
- LONGEST num = unpack_bits_as_long (value_type (val),
- (value_contents_for_printing (parent)
- + offset),
- value_bitpos (val),
- value_bitsize (val));
+ LONGEST num;
int length = TYPE_LENGTH (type);
if (!value_bits_valid (val,
value_bitsize (val)))
error (_("value has been optimized out"));
- store_signed_integer (value_contents_raw (val), length, byte_order, num);
+ if (!unpack_value_bits_as_long (value_type (val),
+ value_contents_for_printing (parent),
+ offset,
+ value_bitpos (val),
+ value_bitsize (val), parent, &num))
+ mark_value_bytes_unavailable (val,
+ value_embedded_offset (val),
+ length);
+ else
+ store_signed_integer (value_contents_raw (val), length,
+ byte_order, num);
}
else if (VALUE_LVAL (val) == lval_memory)
{
int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
if (length)
- {
- if (value_stack (val))
- read_stack (addr, value_contents_all_raw (val), length);
- else
- read_memory (addr, value_contents_all_raw (val), length);
- }
+ read_value_memory (val, 0, value_stack (val),
+ addr, value_contents_all_raw (val), length);
}
else if (VALUE_LVAL (val) == lval_register)
{
if (value_lazy (new_val))
value_fetch_lazy (new_val);
- /* If the register was not saved, mark it unavailable. */
+ /* If the register was not saved, mark it optimized out. */
if (value_optimized_out (new_val))
set_value_optimized_out (val, 1);
else
- memcpy (value_contents_raw (val), value_contents (new_val),
- TYPE_LENGTH (type));
+ {
+ set_value_lazy (val, 0);
+ value_contents_copy (val, value_embedded_offset (val),
+ new_val, value_embedded_offset (new_val),
+ TYPE_LENGTH (type));
+ }
if (frame_debug)
{
}
else if (VALUE_LVAL (val) == lval_computed)
value_computed_funcs (val)->read (val);
+ else if (value_optimized_out (val))
+ /* Keep it optimized out. */;
else
internal_error (__FILE__, __LINE__, _("Unexpected lazy value type."));
return 0;
}
+void
+read_value_memory (struct value *val, int embedded_offset,
+ int stack, CORE_ADDR memaddr,
+ gdb_byte *buffer, size_t length)
+{
+ if (length)
+ {
+ VEC(mem_range_s) *available_memory;
+
+ if (get_traceframe_number () < 0
+ || !traceframe_available_memory (&available_memory, memaddr, length))
+ {
+ if (stack)
+ read_stack (memaddr, buffer, length);
+ else
+ read_memory (memaddr, buffer, length);
+ }
+ else
+ {
+ struct target_section_table *table;
+ struct cleanup *old_chain;
+ CORE_ADDR unavail;
+ mem_range_s *r;
+ int i;
+
+ /* Fallback to reading from read-only sections. */
+ table = target_get_section_table (&exec_ops);
+ available_memory =
+ section_table_available_memory (available_memory,
+ memaddr, length,
+ table->sections,
+ table->sections_end);
+
+ old_chain = make_cleanup (VEC_cleanup(mem_range_s),
+ &available_memory);
+
+ normalize_mem_ranges (available_memory);
+
+ /* Mark which bytes are unavailable, and read those which
+ are available. */
+
+ unavail = memaddr;
+
+ for (i = 0;
+ VEC_iterate (mem_range_s, available_memory, i, r);
+ i++)
+ {
+ if (mem_ranges_overlap (r->start, r->length,
+ memaddr, length))
+ {
+ CORE_ADDR lo1, hi1, lo2, hi2;
+ CORE_ADDR start, end;
+
+ /* Get the intersection window. */
+ lo1 = memaddr;
+ hi1 = memaddr + length;
+ lo2 = r->start;
+ hi2 = r->start + r->length;
+ start = max (lo1, lo2);
+ end = min (hi1, hi2);
+
+ gdb_assert (end - memaddr <= length);
+
+ if (start > unavail)
+ mark_value_bytes_unavailable (val,
+ (embedded_offset
+ + unavail - memaddr),
+ start - unavail);
+ unavail = end;
+
+ read_memory (start, buffer + start - memaddr, end - start);
+ }
+ }
+
+ if (unavail != memaddr + length)
+ mark_value_bytes_unavailable (val,
+ embedded_offset + unavail - memaddr,
+ (memaddr + length) - unavail);
+
+ do_cleanups (old_chain);
+ }
+ }
+}
/* Store the contents of FROMVAL into the location of TOVAL.
Return a new value with the location of TOVAL and contents of FROMVAL. */
int offset = value_offset (parent) + value_offset (toval);
int changed_len;
gdb_byte buffer[sizeof (LONGEST)];
+ int optim, unavail;
changed_len = (value_bitpos (toval)
+ value_bitsize (toval)
"don't fit in a %d bit word."),
(int) sizeof (LONGEST) * HOST_CHAR_BIT);
- get_frame_register_bytes (frame, value_reg, offset,
- changed_len, buffer);
+ if (!get_frame_register_bytes (frame, value_reg, offset,
+ changed_len, buffer,
+ &optim, &unavail))
+ {
+ if (optim)
+ error (_("value has been optimized out"));
+ if (unavail)
+ throw_error (NOT_AVAILABLE_ERROR,
+ _("value is not available"));
+ }
modify_field (type, buffer, value_as_long (fromval),
value_bitpos (toval), value_bitsize (toval));
case lval_computed:
{
- struct lval_funcs *funcs = value_computed_funcs (toval);
+ const struct lval_funcs *funcs = value_computed_funcs (toval);
funcs->write (toval, fromval);
}
val = allocate_repeat_value (value_enclosing_type (arg1), count);
- read_memory (value_address (arg1),
- value_contents_all_raw (val),
- TYPE_LENGTH (value_enclosing_type (val)));
VALUE_LVAL (val) = lval_memory;
set_value_address (val, value_address (arg1));
+ read_value_memory (val, 0, value_stack (val), value_address (val),
+ value_contents_all_raw (val),
+ TYPE_LENGTH (value_enclosing_type (val)));
+
return val;
}
if (VALUE_LVAL (arg1) == lval_computed)
{
- struct lval_funcs *funcs = value_computed_funcs (arg1);
+ const struct lval_funcs *funcs = value_computed_funcs (arg1);
if (funcs->indirect)
{
return 0; /* For lint -- never reached. */
}
\f
-/* Create a value for an array by allocating space in GDB, copying
- copying the data into that space, and then setting up an array
- value.
+/* Create a value for an array by allocating space in GDB, copying the
+ data into that space, and then setting up an array value.
The array bounds are set from LOWBOUND and HIGHBOUND, and the array
is populated from the values passed in ELEMVEC.
{
val = allocate_value (arraytype);
for (idx = 0; idx < nelem; idx++)
- {
- memcpy (value_contents_all_raw (val) + (idx * typelength),
- value_contents_all (elemvec[idx]),
- typelength);
- }
+ value_contents_copy (val, idx * typelength, elemvec[idx], 0,
+ typelength);
return val;
}
val = allocate_value (arraytype);
for (idx = 0; idx < nelem; idx++)
- memcpy (value_contents_writeable (val) + (idx * typelength),
- value_contents_all (elemvec[idx]),
- typelength);
+ value_contents_copy (val, idx * typelength, elemvec[idx], 0, typelength);
return val;
}
struct value *v2;
boffset = baseclass_offset (type, i,
- value_contents (arg1) + offset,
- value_address (arg1)
- + value_embedded_offset (arg1)
- + offset);
- if (boffset == -1)
- error (_("virtual baseclass botch"));
+ value_contents_for_printing (arg1),
+ value_embedded_offset (arg1) + offset,
+ value_address (arg1),
+ arg1);
/* The virtual base class pointer might have been clobbered
by the user program. Make sure that it still points to a
for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
{
int base_offset;
+ int skip = 0;
+ int this_offset;
if (BASETYPE_VIA_VIRTUAL (type, i))
{
struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
+ struct value *base_val;
const gdb_byte *base_valaddr;
/* The virtual base class pointer might have been
if (offset < 0 || offset >= TYPE_LENGTH (type))
{
gdb_byte *tmp = alloca (TYPE_LENGTH (baseclass));
+ CORE_ADDR address = value_address (*arg1p);
- if (target_read_memory (value_address (*arg1p) + offset,
+ if (target_read_memory (address + offset,
tmp, TYPE_LENGTH (baseclass)) != 0)
error (_("virtual baseclass botch"));
- base_valaddr = tmp;
+
+ base_val = value_from_contents_and_address (baseclass,
+ tmp,
+ address + offset);
+ base_valaddr = value_contents_for_printing (base_val);
+ this_offset = 0;
}
else
- base_valaddr = value_contents (*arg1p) + offset;
+ {
+ base_val = *arg1p;
+ base_valaddr = value_contents_for_printing (*arg1p);
+ this_offset = offset;
+ }
base_offset = baseclass_offset (type, i, base_valaddr,
- value_address (*arg1p) + offset);
- if (base_offset == -1)
- error (_("virtual baseclass botch"));
+ this_offset, value_address (base_val),
+ base_val);
}
else
{
if (BASETYPE_VIA_VIRTUAL (type, i))
{
- base_offset = value_offset (*argp) + offset;
base_offset = baseclass_offset (type, i,
- value_contents (*argp) + base_offset,
- value_address (*argp) + base_offset);
- if (base_offset == -1)
- error (_("virtual baseclass botch"));
+ value_contents_for_printing (*argp),
+ value_offset (*argp) + offset,
+ value_address (*argp), *argp);
}
else /* Non-virtual base, simply use bit position from debug
info. */
if (*valp)
{
*staticp = 1;
+ do_cleanups (all_cleanups);
return 0;
}
}
{
const char *qualified_name = NULL;
- /* If the the overload match is being search for both
- as a method and non member function, the first argument
- must now be dereferenced. */
+ /* If the overload match is being search for both as a method
+ and non member function, the first argument must now be
+ dereferenced. */
if (method == BOTH)
arg_types[0] = TYPE_TARGET_TYPE (arg_types[0]);
if (func_name == NULL)
{
*symp = fsym;
+ do_cleanups (all_cleanups);
return 0;
}
switch (compare_badness (func_badness, method_badness))
{
case 0: /* Top two contenders are equally good. */
- /* FIXME: GDB does not support the general ambiguous
- case. All candidates should be collected and presented
- the the user. */
+ /* FIXME: GDB does not support the general ambiguous case.
+ All candidates should be collected and presented the
+ user. */
error (_("Ambiguous overload resolution"));
break;
case 1: /* Incomparable top contenders. */
/* C++: return 1 is NAME is a legitimate name for the destructor of
type TYPE. If TYPE does not have a destructor, or if NAME is
- inappropriate for TYPE, an error is signaled. */
+ inappropriate for TYPE, an error is signaled. Parameter TYPE should not yet
+ have CHECK_TYPEDEF applied, this function will apply it itself. */
+
int
-destructor_name_p (const char *name, const struct type *type)
+destructor_name_p (const char *name, struct type *type)
{
if (name[0] == '~')
{
- char *dname = type_name_no_tag (type);
- char *cp = strchr (dname, '<');
+ const char *dname = type_name_no_tag_or_error (type);
+ const char *cp = strchr (dname, '<');
unsigned int len;
/* Do not compare the template part for template classes. */
}
/* Compares the two method/function types T1 and T2 for "equality"
- with respect to the the methods' parameters. If the types of the
+ with respect to the methods' parameters. If the types of the
two parameter lists are the same, returns 1; 0 otherwise. This
comparison may ignore any artificial parameters in T1 if
SKIP_ARTIFICIAL is non-zero. This function will ALWAYS skip
{
int start = 0;
- if (TYPE_FIELD_ARTIFICIAL (t1, 0))
+ if (TYPE_NFIELDS (t1) > 0 && TYPE_FIELD_ARTIFICIAL (t1, 0))
++start;
/* If skipping artificial fields, find the first real field
int ii;
j = -1;
- for (ii = 0; ii < TYPE_FN_FIELDLIST_LENGTH (t, i);
- ++ii)
+ for (ii = 0; ii < len; ++ii)
{
/* Skip artificial methods. This is necessary if,
for example, the user wants to "print
subclass::subclass" with only one user-defined
- constructor. There is no ambiguity in this
- case. */
+ constructor. There is no ambiguity in this case.
+ We are careful here to allow artificial methods
+ if they are the unique result. */
if (TYPE_FN_FIELD_ARTIFICIAL (f, ii))
- continue;
+ {
+ if (j == -1)
+ j = ii;
+ continue;
+ }
/* Desired method is ambiguous if more than one
method is defined. */
- if (j != -1)
+ if (j != -1 && !TYPE_FN_FIELD_ARTIFICIAL (f, j))
error (_("non-unique member `%s' requires "
"type instantiation"), name);
j = ii;
}
+
+ if (j == -1)
+ error (_("no matching member function"));
}
if (TYPE_FN_FIELD_STATIC_P (f, j))
inappropriate context. */
struct value *
-value_of_local (const char *name, int complain)
+value_of_this (const struct language_defn *lang, int complain)
{
- struct symbol *func, *sym;
+ struct symbol *sym;
struct block *b;
struct value * ret;
struct frame_info *frame;
+ if (!lang->la_name_of_this)
+ {
+ if (complain)
+ error (_("no `this' in current language"));
+ return 0;
+ }
+
if (complain)
frame = get_selected_frame (_("no frame selected"));
else
return 0;
}
- func = get_frame_function (frame);
- if (!func)
- {
- if (complain)
- error (_("no `%s' in nameless context"), name);
- else
- return 0;
- }
-
- b = SYMBOL_BLOCK_VALUE (func);
- if (dict_empty (BLOCK_DICT (b)))
- {
- if (complain)
- error (_("no args, no `%s'"), name);
- else
- return 0;
- }
+ b = get_frame_block (frame, NULL);
- /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER
- symbol instead of the LOC_ARG one (if both exist). */
- sym = lookup_block_symbol (b, name, VAR_DOMAIN);
+ sym = lookup_language_this (lang, b);
if (sym == NULL)
{
if (complain)
error (_("current stack frame does not contain a variable named `%s'"),
- name);
+ lang->la_name_of_this);
else
return NULL;
}
ret = read_var_value (sym, frame);
if (ret == 0 && complain)
- error (_("`%s' argument unreadable"), name);
+ error (_("`%s' argument unreadable"), lang->la_name_of_this);
return ret;
}
-/* C++/Objective-C: return the value of the class instance variable,
- if one exists. Flag COMPLAIN signals an error if the request is
- made in an inappropriate context. */
-
-struct value *
-value_of_this (int complain)
-{
- if (!current_language->la_name_of_this)
- return 0;
- return value_of_local (current_language->la_name_of_this, complain);
-}
-
/* Create a slice (sub-string, sub-array) of ARRAY, that is LENGTH
elements long, starting at LOWBOUND. The result has the same lower
bound as the original ARRAY. */
else
{
slice = allocate_value (slice_type);
- memcpy (value_contents_writeable (slice),
- value_contents (array) + offset,
- TYPE_LENGTH (slice_type));
+ value_contents_copy (slice, 0, array, offset,
+ TYPE_LENGTH (slice_type));
}
set_value_component_location (slice, array);