/* Perform non-arithmetic operations on values, for GDB.
- Copyright (C) 1986-2013 Free Software Foundation, Inc.
+ Copyright (C) 1986-2014 Free Software Foundation, Inc.
This file is part of GDB.
#include "dictionary.h"
#include "cp-support.h"
#include "dfp.h"
-#include "user-regs.h"
#include "tracepoint.h"
#include <errno.h>
-#include "gdb_string.h"
+#include <string.h>
#include "gdb_assert.h"
-#include "cp-support.h"
#include "observer.h"
#include "objfiles.h"
-#include "symtab.h"
#include "exceptions.h"
extern unsigned int overload_debug;
struct badness_vector **, int *,
const int no_adl);
-static int find_oload_champ (struct value **, int, int, int,
+static int find_oload_champ (struct value **, int, int,
struct fn_field *, struct symbol **,
struct badness_vector **);
}
else
{
- struct minimal_symbol *msymbol =
- lookup_minimal_symbol (name, NULL, NULL);
+ struct bound_minimal_symbol msymbol =
+ lookup_bound_minimal_symbol (name);
- if (msymbol != NULL)
+ if (msymbol.minsym != NULL)
{
- struct objfile *objfile = msymbol_objfile (msymbol);
+ struct objfile *objfile = msymbol.objfile;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
struct type *type;
type = lookup_pointer_type (builtin_type (gdbarch)->builtin_char);
type = lookup_function_type (type);
type = lookup_pointer_type (type);
- maddr = SYMBOL_VALUE_ADDRESS (msymbol);
+ maddr = BMSYMBOL_VALUE_ADDRESS (msymbol);
if (objf_p)
*objf_p = objfile;
return get_value_at (type, addr, 1);
}
-/* Called only from the value_contents and value_contents_all()
- macros, if the current data for a variable needs to be loaded into
- value_contents(VAL). Fetches the 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. */
-
-int
-value_fetch_lazy (struct value *val)
-{
- gdb_assert (value_lazy (val));
- allocate_value_contents (val);
- if (value_bitsize (val))
- {
- /* To read a lazy bitfield, read the entire enclosing value. This
- prevents reading the same block of (possibly volatile) memory once
- per bitfield. It would be even better to read only the containing
- word, but we have no way to record that just specific bits of a
- value have been fetched. */
- struct type *type = check_typedef (value_type (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;
-
- if (!value_bits_valid (val,
- TARGET_CHAR_BIT * offset + value_bitpos (val),
- value_bitsize (val)))
- error (_("value has been optimized out"));
-
- 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),
- TYPE_LENGTH (type));
- else
- store_signed_integer (value_contents_raw (val), TYPE_LENGTH (type),
- byte_order, num);
- }
- else if (VALUE_LVAL (val) == lval_memory)
- {
- CORE_ADDR addr = value_address (val);
- struct type *type = check_typedef (value_enclosing_type (val));
-
- if (TYPE_LENGTH (type))
- read_value_memory (val, 0, value_stack (val),
- addr, value_contents_all_raw (val),
- TYPE_LENGTH (type));
- }
- else if (VALUE_LVAL (val) == lval_register)
- {
- struct frame_info *frame;
- int regnum;
- struct type *type = check_typedef (value_type (val));
- struct value *new_val = val, *mark = value_mark ();
-
- /* Offsets are not supported here; lazy register values must
- refer to the entire register. */
- gdb_assert (value_offset (val) == 0);
-
- while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
- {
- frame = frame_find_by_id (VALUE_FRAME_ID (new_val));
- regnum = VALUE_REGNUM (new_val);
-
- gdb_assert (frame != NULL);
-
- /* Convertible register routines are used for multi-register
- values and for interpretation in different types
- (e.g. float or int from a double register). Lazy
- register values should have the register's natural type,
- so they do not apply. */
- gdb_assert (!gdbarch_convert_register_p (get_frame_arch (frame),
- regnum, type));
-
- new_val = get_frame_register_value (frame, regnum);
- }
-
- /* If it's still lazy (for instance, a saved register on the
- stack), fetch it. */
- if (value_lazy (new_val))
- value_fetch_lazy (new_val);
-
- /* If the register was not saved, mark it optimized out. */
- if (value_optimized_out (new_val))
- set_value_optimized_out (val, 1);
- else
- {
- 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)
- {
- struct gdbarch *gdbarch;
- frame = frame_find_by_id (VALUE_FRAME_ID (val));
- regnum = VALUE_REGNUM (val);
- gdbarch = get_frame_arch (frame);
-
- fprintf_unfiltered (gdb_stdlog,
- "{ value_fetch_lazy "
- "(frame=%d,regnum=%d(%s),...) ",
- frame_relative_level (frame), regnum,
- user_reg_map_regnum_to_name (gdbarch, regnum));
-
- fprintf_unfiltered (gdb_stdlog, "->");
- if (value_optimized_out (new_val))
- fprintf_unfiltered (gdb_stdlog, " optimized out");
- else
- {
- int i;
- const gdb_byte *buf = value_contents (new_val);
-
- if (VALUE_LVAL (new_val) == lval_register)
- fprintf_unfiltered (gdb_stdlog, " register=%d",
- VALUE_REGNUM (new_val));
- else if (VALUE_LVAL (new_val) == lval_memory)
- fprintf_unfiltered (gdb_stdlog, " address=%s",
- paddress (gdbarch,
- value_address (new_val)));
- else
- fprintf_unfiltered (gdb_stdlog, " computed");
-
- fprintf_unfiltered (gdb_stdlog, " bytes=");
- fprintf_unfiltered (gdb_stdlog, "[");
- for (i = 0; i < register_size (gdbarch, regnum); i++)
- fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
- fprintf_unfiltered (gdb_stdlog, "]");
- }
-
- fprintf_unfiltered (gdb_stdlog, " }\n");
- }
-
- /* Dispose of the intermediate values. This prevents
- watchpoints from trying to watch the saved frame pointer. */
- value_free_to_mark (mark);
- }
- else if (VALUE_LVAL (val) == lval_computed
- && value_computed_funcs (val)->read != NULL)
- 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."));
-
- set_value_lazy (val, 0);
- 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);
- }
+ ULONGEST xfered = 0;
+
+ while (xfered < length)
+ {
+ enum target_xfer_status status;
+ ULONGEST xfered_len;
+
+ status = target_xfer_partial (current_target.beneath,
+ TARGET_OBJECT_MEMORY, NULL,
+ buffer + xfered, NULL,
+ memaddr + xfered, length - xfered,
+ &xfered_len);
+
+ if (status == TARGET_XFER_OK)
+ /* nothing */;
+ else if (status == TARGET_XFER_UNAVAILABLE)
+ mark_value_bytes_unavailable (val, embedded_offset + xfered,
+ xfered_len);
+ else if (status == TARGET_XFER_EOF)
+ memory_error (TARGET_XFER_E_IO, memaddr + xfered);
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);
+ memory_error (status, memaddr + xfered);
- /* 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);
- }
+ xfered += xfered_len;
+ QUIT;
}
}
&optim, &unavail))
{
if (optim)
- error (_("value has been optimized out"));
+ throw_error (OPTIMIZED_OUT_ERROR,
+ _("value has been optimized out"));
if (unavail)
throw_error (NOT_AVAILABLE_ERROR,
_("value is not available"));
struct value *v;
if (field_is_static (&TYPE_FIELD (type, i)))
- {
- v = value_static_field (type, i);
- if (v == 0)
- error (_("field %s is nonexistent or "
- "has been optimized out"),
- name);
- }
+ v = value_static_field (type, i);
else
v = value_primitive_field (arg1, offset, i, type);
*result_ptr = v;
{
CORE_ADDR base_addr;
- v2 = allocate_value (basetype);
base_addr = value_address (arg1) + boffset;
+ v2 = value_at_lazy (basetype, base_addr);
if (target_read_memory (base_addr,
value_contents_raw (v2),
- TYPE_LENGTH (basetype)) != 0)
+ TYPE_LENGTH (value_type (v2))) != 0)
error (_("virtual baseclass botch"));
- VALUE_LVAL (v2) = lval_memory;
- set_value_address (v2, base_addr);
}
else
{
{
*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 (TYPE_CODE (check_typedef (value_type (*argp))) != TYPE_CODE_FUNC)
*argp = coerce_array (*argp);
t = check_typedef (value_type (*argp));
}
return v;
}
+/* Given *ARGP, a value of type structure or union, or a pointer/reference
+ to a structure or union, extract and return its component (field) of
+ type FTYPE at the specified BITPOS.
+ Throw an exception on error. */
+
+struct value *
+value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
+ const char *err)
+{
+ struct type *t;
+ struct value *v;
+ int i;
+ int nbases;
+
+ *argp = coerce_array (*argp);
+
+ t = check_typedef (value_type (*argp));
+
+ while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+ {
+ *argp = value_ind (*argp);
+ if (TYPE_CODE (check_typedef (value_type (*argp))) != TYPE_CODE_FUNC)
+ *argp = coerce_array (*argp);
+ t = check_typedef (value_type (*argp));
+ }
+
+ if (TYPE_CODE (t) != TYPE_CODE_STRUCT
+ && TYPE_CODE (t) != TYPE_CODE_UNION)
+ error (_("Attempt to extract a component of a value that is not a %s."),
+ err);
+
+ for (i = TYPE_N_BASECLASSES (t); i < TYPE_NFIELDS (t); i++)
+ {
+ if (!field_is_static (&TYPE_FIELD (t, i))
+ && bitpos == TYPE_FIELD_BITPOS (t, i)
+ && types_equal (ftype, TYPE_FIELD_TYPE (t, i)))
+ return value_primitive_field (*argp, 0, i, t);
+ }
+
+ error (_("No field with matching bitpos and type."));
+
+ /* Never hit. */
+ return NULL;
+}
+
/* Search through the methods of an object (and its bases) to find a
specified method. Return the pointer to the fn_field list of
overloaded instances.
{
*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 (TYPE_CODE (check_typedef (value_type (*argp))) != TYPE_CODE_FUNC)
*argp = coerce_array (*argp);
t = check_typedef (value_type (*argp));
}
if (fns_ptr)
{
gdb_assert (TYPE_DOMAIN_TYPE (fns_ptr[0].type) != NULL);
- method_oload_champ = find_oload_champ (args, nargs, method,
+ method_oload_champ = find_oload_champ (args, nargs,
num_fns, fns_ptr,
- oload_syms, &method_badness);
+ NULL, &method_badness);
method_match_quality =
classify_oload_match (method_badness, nargs,
while (new_oload_syms[num_fns])
++num_fns;
- new_oload_champ = find_oload_champ (args, nargs, 0, num_fns,
+ new_oload_champ = find_oload_champ (args, nargs, num_fns,
NULL, new_oload_syms,
&new_oload_champ_bv);
/* Look for a function to take NARGS args of ARGS. Find
the best match from among the overloaded methods or functions
- (depending on METHOD) given by FNS_PTR or OLOAD_SYMS, respectively.
- The number of methods/functions in the list is given by NUM_FNS.
+ given by FNS_PTR or OLOAD_SYMS, respectively. One, and only one of
+ FNS_PTR and OLOAD_SYMS can be non-NULL. The number of
+ methods/functions in the non-NULL list is given by NUM_FNS.
Return the index of the best match; store an indication of the
quality of the match in OLOAD_CHAMP_BV.
It is the caller's responsibility to free *OLOAD_CHAMP_BV. */
static int
-find_oload_champ (struct value **args, int nargs, int method,
+find_oload_champ (struct value **args, int nargs,
int num_fns, struct fn_field *fns_ptr,
struct symbol **oload_syms,
struct badness_vector **oload_champ_bv)
int oload_ambiguous = 0;
/* 0 => no ambiguity, 1 => two good funcs, 2 => incomparable funcs. */
+ /* A champion can be found among methods alone, or among functions
+ alone, but not both. */
+ gdb_assert ((fns_ptr != NULL) + (oload_syms != NULL) == 1);
+
*oload_champ_bv = NULL;
/* Consider each candidate in turn. */
for (ix = 0; ix < num_fns; ix++)
{
int jj;
- int static_offset = oload_method_static (method, fns_ptr, ix);
+ int static_offset;
int nparms;
struct type **parm_types;
- if (method)
+ if (fns_ptr != NULL)
{
nparms = TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (fns_ptr, ix));
+ static_offset = oload_method_static (1, fns_ptr, ix);
}
else
{
/* If it's not a method, this is the proper place. */
nparms = TYPE_NFIELDS (SYMBOL_TYPE (oload_syms[ix]));
+ static_offset = 0;
}
/* Prepare array of parameter types. */
parm_types = (struct type **)
xmalloc (nparms * (sizeof (struct type *)));
for (jj = 0; jj < nparms; jj++)
- parm_types[jj] = (method
+ parm_types[jj] = (fns_ptr != NULL
? (TYPE_FN_FIELD_ARGS (fns_ptr, ix)[jj].type)
: TYPE_FIELD_TYPE (SYMBOL_TYPE (oload_syms[ix]),
jj));
xfree (parm_types);
if (overload_debug)
{
- if (method)
+ if (fns_ptr)
fprintf_filtered (gdb_stderr,
"Overloaded method instance %s, # of parms %d\n",
fns_ptr[ix].physname, nparms);
if (field_is_static (&TYPE_FIELD (t, i)))
{
v = value_static_field (t, i);
- if (v == NULL)
- error (_("static field %s has been optimized out"),
- name);
if (want_address)
v = value_addr (v);
return v;
return value_from_longest
(lookup_memberptr_type (TYPE_FIELD_TYPE (t, i), domain),
offset + (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
- else if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ else if (noside != EVAL_NORMAL)
return allocate_value (TYPE_FIELD_TYPE (t, i));
else
- error (_("Cannot reference non-static field \"%s\""), name);
+ {
+ /* Try to evaluate NAME as a qualified name with implicit
+ this pointer. In this case, attempt to return the
+ equivalent to `this->*(&TYPE::NAME)'. */
+ v = value_of_this_silent (current_language);
+ if (v != NULL)
+ {
+ struct value *ptr;
+ long mem_offset;
+ struct type *type, *tmp;
+
+ ptr = value_aggregate_elt (domain, name, NULL, 1, noside);
+ type = check_typedef (value_type (ptr));
+ gdb_assert (type != NULL
+ && TYPE_CODE (type) == TYPE_CODE_MEMBERPTR);
+ tmp = lookup_pointer_type (TYPE_DOMAIN_TYPE (type));
+ v = value_cast_pointers (tmp, v, 1);
+ mem_offset = value_as_long (ptr);
+ tmp = lookup_pointer_type (TYPE_TARGET_TYPE (type));
+ result = value_from_pointer (tmp,
+ value_as_long (v) + mem_offset);
+ return value_ind (result);
+ }
+
+ error (_("Cannot reference non-static field \"%s\""), name);
+ }
}
}
done with it. */
slice_range_type = create_range_type ((struct type *) NULL,
TYPE_TARGET_TYPE (range_type),
- lowbound,
+ lowbound,
lowbound + length - 1);
- {
- struct type *element_type = TYPE_TARGET_TYPE (array_type);
- LONGEST offset =
- (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
+ {
+ struct type *element_type = TYPE_TARGET_TYPE (array_type);
+ LONGEST offset
+ = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
- slice_type = create_array_type ((struct type *) NULL,
- element_type,
- slice_range_type);
- TYPE_CODE (slice_type) = TYPE_CODE (array_type);
+ slice_type = create_array_type ((struct type *) NULL,
+ element_type,
+ slice_range_type);
+ TYPE_CODE (slice_type) = TYPE_CODE (array_type);
- if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
- slice = allocate_value_lazy (slice_type);
- else
- {
- slice = allocate_value (slice_type);
- value_contents_copy (slice, 0, array, offset,
- TYPE_LENGTH (slice_type));
- }
+ if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
+ slice = allocate_value_lazy (slice_type);
+ else
+ {
+ slice = allocate_value (slice_type);
+ value_contents_copy (slice, 0, array, offset,
+ TYPE_LENGTH (slice_type));
+ }
+
+ set_value_component_location (slice, array);
+ VALUE_FRAME_ID (slice) = VALUE_FRAME_ID (array);
+ set_value_offset (slice, value_offset (array) + offset);
+ }
- set_value_component_location (slice, array);
- VALUE_FRAME_ID (slice) = VALUE_FRAME_ID (array);
- set_value_offset (slice, value_offset (array) + offset);
- }
return slice;
}