is stored at %rax register. */
regcache->cooked_read (AMD64_LINUX_ORIG_RAX_REGNUM, buf);
- ret = extract_signed_integer (buf, 8, byte_order);
+ ret = extract_signed_integer (buf, byte_order);
return ret;
}
#include "gdbsupport/host-defs.h"
#include "gdbsupport/enum-flags.h"
+#include "gdbsupport/array-view.h"
/* Scope types enumerator. List the types of scopes the compiler will
accept. */
/* In findvar.c. */
template<typename T, typename = RequireLongest<T>>
-T extract_integer (const gdb_byte *addr, int len, enum bfd_endian byte_order);
+T extract_integer (gdb::array_view<const gdb_byte>, enum bfd_endian byte_order);
+
+static inline LONGEST
+extract_signed_integer (gdb::array_view<const gdb_byte> buf,
+ enum bfd_endian byte_order)
+{
+ return extract_integer<LONGEST> (buf, byte_order);
+}
static inline LONGEST
extract_signed_integer (const gdb_byte *addr, int len,
enum bfd_endian byte_order)
{
- return extract_integer<LONGEST> (addr, len, byte_order);
+ return extract_signed_integer (gdb::array_view<const gdb_byte> (addr, len),
+ byte_order);
+}
+
+static inline ULONGEST
+extract_unsigned_integer (gdb::array_view<const gdb_byte> buf,
+ enum bfd_endian byte_order)
+{
+ return extract_integer<ULONGEST> (buf, byte_order);
}
static inline ULONGEST
extract_unsigned_integer (const gdb_byte *addr, int len,
enum bfd_endian byte_order)
{
- return extract_integer<ULONGEST> (addr, len, byte_order);
+ return extract_unsigned_integer (gdb::array_view<const gdb_byte> (addr, len),
+ byte_order);
}
extern int extract_long_unsigned_integer (const gdb_byte *, int,
encode address spaces and other things in CORE_ADDR. */
bfd_endian byte_order = gdbarch_byte_order (get_frame_arch (frame));
LONGEST byte_offset
- = extract_signed_integer (value_contents (value).data (),
- TYPE_LENGTH (type), byte_order);
+ = extract_signed_integer (value_contents (value), byte_order);
byte_offset += piece->v.ptr.offset;
return indirect_synthetic_pointer (piece->v.ptr.die_sect_off,
ULONGEST result;
dwarf_require_integral (value_type (result_val));
- result = extract_unsigned_integer (value_contents (result_val).data (),
- TYPE_LENGTH (value_type (result_val)),
- byte_order);
+ result = extract_unsigned_integer (value_contents (result_val), byte_order);
/* For most architectures, calling extract_unsigned_integer() alone
is sufficient for extracting an address. However, some
LWPINFO_OFFSET + LWPINFO_PL_FLAGS, 4))
return -1;
- int pl_flags = extract_signed_integer (buf, 4, gdbarch_byte_order (gdbarch));
+ int pl_flags = extract_signed_integer (buf, gdbarch_byte_order (gdbarch));
if (!(pl_flags & PL_FLAG_SI))
return -1;
if (target_read_memory (BMSYMBOL_VALUE_ADDRESS (ms), buf, sizeof buf) != 0)
error (_("Unable to read value of '%s'"), name);
- return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch));
+ return extract_signed_integer (buf, gdbarch_byte_order (gdbarch));
}
/* Lookup offsets of fields in the runtime linker's 'Obj_Entry'
throw_error (TLS_GENERIC_ERROR,
_("Cannot find thread-local variables on this target"));
- return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch));
+ return extract_signed_integer (buf, gdbarch_byte_order (gdbarch));
}
/* See fbsd-tdep.h. */
template<typename T, typename>
T
-extract_integer (const gdb_byte *addr, int len, enum bfd_endian byte_order)
+extract_integer (gdb::array_view<const gdb_byte> buf, enum bfd_endian byte_order)
{
typename std::make_unsigned<T>::type retval = 0;
- const unsigned char *p;
- const unsigned char *startaddr = addr;
- const unsigned char *endaddr = startaddr + len;
- if (len > (int) sizeof (T))
+ if (buf.size () > (int) sizeof (T))
error (_("\
That operation is not available on integers of more than %d bytes."),
(int) sizeof (T));
the least significant. */
if (byte_order == BFD_ENDIAN_BIG)
{
- p = startaddr;
+ size_t i = 0;
+
if (std::is_signed<T>::value)
{
/* Do the sign extension once at the start. */
- retval = ((LONGEST) * p ^ 0x80) - 0x80;
- ++p;
+ retval = ((LONGEST) buf[i] ^ 0x80) - 0x80;
+ ++i;
}
- for (; p < endaddr; ++p)
- retval = (retval << 8) | *p;
+ for (; i < buf.size (); ++i)
+ retval = (retval << 8) | buf[i];
}
else
{
- p = endaddr - 1;
+ ssize_t i = buf.size () - 1;
+
if (std::is_signed<T>::value)
{
/* Do the sign extension once at the start. */
- retval = ((LONGEST) * p ^ 0x80) - 0x80;
- --p;
+ retval = ((LONGEST) buf[i] ^ 0x80) - 0x80;
+ --i;
}
- for (; p >= startaddr; --p)
- retval = (retval << 8) | *p;
+ for (; i >= 0; --i)
+ retval = (retval << 8) | buf[i];
}
return retval;
}
/* Explicit instantiations. */
-template LONGEST extract_integer<LONGEST> (const gdb_byte *addr, int len,
+template LONGEST extract_integer<LONGEST> (gdb::array_view<const gdb_byte> buf,
enum bfd_endian byte_order);
-template ULONGEST extract_integer<ULONGEST> (const gdb_byte *addr, int len,
- enum bfd_endian byte_order);
+template ULONGEST extract_integer<ULONGEST>
+ (gdb::array_view<const gdb_byte> buf, enum bfd_endian byte_order);
/* Sometimes a long long unsigned integer can be extracted as a
LONGEST value. This is done so that we can print these values
{
struct gdbarch *gdbarch = frame_unwind_arch (next_frame);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
- int size = register_size (gdbarch, regnum);
struct value *value = frame_unwind_register_value (next_frame, regnum);
gdb_assert (value != NULL);
_("Register %d is not available"), regnum);
}
- LONGEST r = extract_signed_integer (value_contents_all (value).data (), size,
- byte_order);
+ LONGEST r = extract_signed_integer (value_contents_all (value), byte_order);
release_value (value);
return r;
if (target_read_memory (pc, buf, sizeof buf) != 0)
break;
- op = extract_signed_integer (buf, sizeof buf, byte_order);
+ op = extract_signed_integer (buf, byte_order);
next_pc = pc + 4;
if (target_read_memory (addr, buf, sizeof buf) != 0)
break;
- tag = extract_signed_integer (buf, sizeof buf, byte_order);
+ tag = extract_signed_integer (buf, byte_order);
if (tag == DT_PLTGOT)
{
CORE_ADDR pltgot;
status = target_read_memory (addr, buf, sizeof (buf));
if (status != 0)
break;
- tag = extract_signed_integer (buf, sizeof (buf), byte_order);
+ tag = extract_signed_integer (buf, byte_order);
if (tag == DT_PLTGOT)
{
is stored at %eax register. */
regcache->cooked_read (I386_LINUX_ORIG_EAX_REGNUM, buf);
- ret = extract_signed_integer (buf, 4, byte_order);
+ ret = extract_signed_integer (buf, byte_order);
return ret;
}
status = target_read_memory (addr, buf, sizeof (buf));
if (status != 0)
break;
- tag = extract_signed_integer (buf, sizeof (buf), byte_order);
+ tag = extract_signed_integer (buf, byte_order);
if (tag == DT_PLTGOT)
{
status = target_read_memory (addr, buf, sizeof (buf));
if (status != 0)
break;
- faddr2 = extract_signed_integer (buf, sizeof (buf), byte_order);
+ faddr2 = extract_signed_integer (buf, byte_order);
if (faddr == faddr2)
return addr;
enum register_status
readable_regcache::raw_read (int regnum, T *val)
{
- gdb_byte *buf;
- enum register_status status;
-
assert_regnum (regnum);
- buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
- status = raw_read (regnum, buf);
+ size_t len = m_descr->sizeof_register[regnum];
+ gdb_byte *buf = (gdb_byte *) alloca (len);
+ register_status status = raw_read (regnum, buf);
if (status == REG_VALID)
- *val = extract_integer<T> (buf,
- m_descr->sizeof_register[regnum],
+ *val = extract_integer<T> ({buf, len},
gdbarch_byte_order (m_descr->gdbarch));
else
*val = 0;
enum register_status
readable_regcache::cooked_read (int regnum, T *val)
{
- enum register_status status;
- gdb_byte *buf;
-
gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
- buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
- status = cooked_read (regnum, buf);
+ size_t len = m_descr->sizeof_register[regnum];
+ gdb_byte *buf = (gdb_byte *) alloca (len);
+ register_status status = cooked_read (regnum, buf);
if (status == REG_VALID)
- *val = extract_integer<T> (buf, m_descr->sizeof_register[regnum],
+ *val = extract_integer<T> ({buf, len},
gdbarch_byte_order (m_descr->gdbarch));
else
*val = 0;
gdb_byte *buf = (gdb_byte *) alloca (buf_len);
v.write ({buf, buf_len}, byte_order, !std::is_signed<T>::value);
- return extract_integer<T> (buf, buf_len, byte_order);
+ return extract_integer<T> ({buf, buf_len}, byte_order);
}
/* Test the gdb_mpz::write method over a reasonable range of values.
bits. */
if (code2 == TYPE_CODE_PTR)
longest = extract_unsigned_integer
- (value_contents (arg2).data (), TYPE_LENGTH (type2),
- type_byte_order (type2));
+ (value_contents (arg2), type_byte_order (type2));
else
longest = value_as_long (arg2);
return value_from_longest (to_type, convert_to_boolean ?