/* Intel 386 target-dependent stuff.
- Copyright (C) 1988-2023 Free Software Foundation, Inc.
+ Copyright (C) 1988-2024 Free Software Foundation, Inc.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "defs.h"
+#include "extract-store-integer.h"
#include "opcode/i386.h"
#include "arch-utils.h"
#include "command.h"
#include "frame-unwind.h"
#include "inferior.h"
#include "infrun.h"
-#include "gdbcmd.h"
+#include "cli/cli-cmds.h"
#include "gdbcore.h"
#include "gdbtypes.h"
#include "objfiles.h"
static const char * const i386_byte_names[] =
{
- "al", "cl", "dl", "bl",
+ "al", "cl", "dl", "bl",
"ah", "ch", "dh", "bh"
};
if (I387_ST0_REGNUM (tdep) < 0)
return 0;
- return (I387_FCTRL_REGNUM (tdep) <= regnum
+ return (I387_FCTRL_REGNUM (tdep) <= regnum
&& regnum < I387_XMM0_REGNUM (tdep));
}
displaced_debug_printf ("%s->%s: %s",
paddress (gdbarch, from), paddress (gdbarch, to),
- displaced_step_dump_bytes (buf, len).c_str ());
+ bytes_to_string (buf, len).c_str ());
/* This is a work around for a problem with g++ 4.8. */
return displaced_step_copy_insn_closure_up (closure.release ());
i386_displaced_step_fixup (struct gdbarch *gdbarch,
struct displaced_step_copy_insn_closure *closure_,
CORE_ADDR from, CORE_ADDR to,
- struct regcache *regs)
+ struct regcache *regs, bool completed_p)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
the displaced instruction; make it relative. Well, signal
handler returns don't need relocation either, but we use the
value of %eip to recognize those; see below. */
- if (! i386_absolute_jmp_p (insn)
- && ! i386_absolute_call_p (insn)
- && ! i386_ret_p (insn))
+ if (!completed_p
+ || (!i386_absolute_jmp_p (insn)
+ && !i386_absolute_call_p (insn)
+ && !i386_ret_p (insn)))
{
- ULONGEST orig_eip;
int insn_len;
- regcache_cooked_read_unsigned (regs, I386_EIP_REGNUM, &orig_eip);
+ CORE_ADDR pc = regcache_read_pc (regs);
/* A signal trampoline system call changes the %eip, resuming
execution of the main program after the signal handler has
it unrelocated. Goodness help us if there are PC-relative
system calls. */
if (i386_syscall_p (insn, &insn_len)
- && orig_eip != to + (insn - insn_start) + insn_len
+ && pc != to + (insn - insn_start) + insn_len
/* GDB can get control back after the insn after the syscall.
Presumably this is a kernel bug.
- i386_displaced_step_copy_insn ensures its a nop,
+ i386_displaced_step_copy_insn ensures it's a nop,
we add one to the length for it. */
- && orig_eip != to + (insn - insn_start) + insn_len + 1)
+ && pc != to + (insn - insn_start) + insn_len + 1)
displaced_debug_printf ("syscall changed %%eip; not relocating");
else
{
- ULONGEST eip = (orig_eip - insn_offset) & 0xffffffffUL;
+ ULONGEST eip = (pc - insn_offset) & 0xffffffffUL;
/* If we just stepped over a breakpoint insn, we don't backup
the pc on purpose; this is to match behaviour without
stepping. */
- regcache_cooked_write_unsigned (regs, I386_EIP_REGNUM, eip);
+ regcache_write_pc (regs, eip);
displaced_debug_printf ("relocated %%eip from %s to %s",
- paddress (gdbarch, orig_eip),
+ paddress (gdbarch, pc),
paddress (gdbarch, eip));
}
}
/* If the instruction was a call, the return address now atop the
stack is the address following the copied instruction. We need
to make it the address following the original instruction. */
- if (i386_call_p (insn))
+ if (completed_p && i386_call_p (insn))
{
ULONGEST esp;
ULONGEST retaddr;
cache->pc_in_eax = 1;
return current_pc;
}
-
+
if (buf[1] == proto1[1])
return pc + 4;
else
pushl constant
call _probe
addl $4, %esp
-
+
followed by
pushl %ebp
pushl -4(%reg)
"andl $-XXX, %esp" can be either 3 bytes or 6 bytes:
-
+
0x83 0xe4 0xf0 andl $-16, %esp
0x81 0xe4 0x00 0xff 0xff 0xff andl $-256, %esp
*/
/* MOD must be binary 10 and R/M must be binary 100. */
if ((buf[2] & 0xc7) != 0x44)
return pc;
-
+
/* REG has register number. Registers in pushl and leal have to
be the same. */
if (reg != ((buf[2] >> 3) & 7))
static i386_insn i386_frame_setup_skip_insns[] =
{
/* Check for `movb imm8, r' and `movl imm32, r'.
-
+
??? Should we handle 16-bit operand-sizes here? */
/* `movb imm8, %al' and `movb imm8, %ah' */
if (target_read_code (pc, &op, 1))
return pc;
- while (check)
+ while (check)
{
check = 0;
/* Ignore `nop' instruction. */
- if (op == 0x90)
+ if (op == 0x90)
{
pc += 1;
if (target_read_code (pc, &op, 1))
}
}
}
- return pc;
+ return pc;
}
/* Check whether PC points at a code that sets up a new stack frame.
if (limit <= pc)
return limit;
- /* Check for stack adjustment
+ /* Check for stack adjustment
subl $XXX, %esp
or
%ebx (and sometimes a harmless bug causes it to also save but not
restore %eax); however, the code below is willing to see the pushes
in any order, and will handle up to 8 of them.
-
+
If the setup sequence is at the end of the function, then the next
instruction will be a branch back to the start. */
&& cust->producer () != NULL
&& (producer_is_llvm (cust->producer ())
|| producer_is_icc_ge_19 (cust->producer ()))))
- return std::max (start_pc, post_prologue_pc);
+ return std::max (start_pc, post_prologue_pc);
}
-
+
cache.locals = -1;
pc = i386_analyze_prologue (gdbarch, start_pc, 0xffffffff, &cache);
if (cache.locals < 0)
/* This function is 64-bit safe. */
static CORE_ADDR
-i386_unwind_pc (struct gdbarch *gdbarch, frame_info_ptr next_frame)
+i386_unwind_pc (struct gdbarch *gdbarch, const frame_info_ptr &next_frame)
{
gdb_byte buf[8];
/* Normal frames. */
static void
-i386_frame_cache_1 (frame_info_ptr this_frame,
+i386_frame_cache_1 (const frame_info_ptr &this_frame,
struct i386_frame_cache *cache)
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
}
static struct i386_frame_cache *
-i386_frame_cache (frame_info_ptr this_frame, void **this_cache)
+i386_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
{
struct i386_frame_cache *cache;
}
static void
-i386_frame_this_id (frame_info_ptr this_frame, void **this_cache,
+i386_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
struct frame_id *this_id)
{
struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
}
static enum unwind_stop_reason
-i386_frame_unwind_stop_reason (frame_info_ptr this_frame,
+i386_frame_unwind_stop_reason (const frame_info_ptr &this_frame,
void **this_cache)
{
struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
}
static struct value *
-i386_frame_prev_register (frame_info_ptr this_frame, void **this_cache,
+i386_frame_prev_register (const frame_info_ptr &this_frame, void **this_cache,
int regnum)
{
struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
i386_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
{
gdb_byte insn;
- struct compunit_symtab *cust;
-
- cust = find_pc_compunit_symtab (pc);
- if (cust != NULL && cust->epilogue_unwind_valid ())
- return 0;
-
if (target_read_memory (pc, &insn, 1))
return 0; /* Can't read memory at pc. */
return 1;
}
+static int
+i386_epilogue_frame_sniffer_1 (const struct frame_unwind *self,
+ const frame_info_ptr &this_frame,
+ void **this_prologue_cache, bool override_p)
+{
+ struct gdbarch *gdbarch = get_frame_arch (this_frame);
+ CORE_ADDR pc = get_frame_pc (this_frame);
+
+ if (frame_relative_level (this_frame) != 0)
+ /* We're not in the inner frame, so assume we're not in an epilogue. */
+ return 0;
+
+ bool unwind_valid_p
+ = compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc));
+ if (override_p)
+ {
+ if (unwind_valid_p)
+ /* Don't override the symtab unwinders, skip
+ "i386 epilogue override". */
+ return 0;
+ }
+ else
+ {
+ if (!unwind_valid_p)
+ /* "i386 epilogue override" unwinder already ran, skip
+ "i386 epilogue". */
+ return 0;
+ }
+
+ /* Check whether we're in an epilogue. */
+ return i386_stack_frame_destroyed_p (gdbarch, pc);
+}
+
+static int
+i386_epilogue_override_frame_sniffer (const struct frame_unwind *self,
+ const frame_info_ptr &this_frame,
+ void **this_prologue_cache)
+{
+ return i386_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache,
+ true);
+}
+
static int
i386_epilogue_frame_sniffer (const struct frame_unwind *self,
- frame_info_ptr this_frame,
+ const frame_info_ptr &this_frame,
void **this_prologue_cache)
{
- if (frame_relative_level (this_frame) == 0)
- return i386_stack_frame_destroyed_p (get_frame_arch (this_frame),
- get_frame_pc (this_frame));
- else
- return 0;
+ return i386_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache,
+ false);
}
static struct i386_frame_cache *
-i386_epilogue_frame_cache (frame_info_ptr this_frame, void **this_cache)
+i386_epilogue_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
{
struct i386_frame_cache *cache;
CORE_ADDR sp;
}
static enum unwind_stop_reason
-i386_epilogue_frame_unwind_stop_reason (frame_info_ptr this_frame,
+i386_epilogue_frame_unwind_stop_reason (const frame_info_ptr &this_frame,
void **this_cache)
{
struct i386_frame_cache *cache =
}
static void
-i386_epilogue_frame_this_id (frame_info_ptr this_frame,
+i386_epilogue_frame_this_id (const frame_info_ptr &this_frame,
void **this_cache,
struct frame_id *this_id)
{
}
static struct value *
-i386_epilogue_frame_prev_register (frame_info_ptr this_frame,
+i386_epilogue_frame_prev_register (const frame_info_ptr &this_frame,
void **this_cache, int regnum)
{
/* Make sure we've initialized the cache. */
return i386_frame_prev_register (this_frame, this_cache, regnum);
}
+static const struct frame_unwind i386_epilogue_override_frame_unwind =
+{
+ "i386 epilogue override",
+ NORMAL_FRAME,
+ i386_epilogue_frame_unwind_stop_reason,
+ i386_epilogue_frame_this_id,
+ i386_epilogue_frame_prev_register,
+ NULL,
+ i386_epilogue_override_frame_sniffer
+};
+
static const struct frame_unwind i386_epilogue_frame_unwind =
{
"i386 epilogue",
i386_epilogue_frame_unwind_stop_reason,
i386_epilogue_frame_this_id,
i386_epilogue_frame_prev_register,
- NULL,
+ NULL,
i386_epilogue_frame_sniffer
};
\f
static int
i386_stack_tramp_frame_sniffer (const struct frame_unwind *self,
- frame_info_ptr this_frame,
+ const frame_info_ptr &this_frame,
void **this_cache)
{
if (frame_relative_level (this_frame) == 0)
i386_epilogue_frame_unwind_stop_reason,
i386_epilogue_frame_this_id,
i386_epilogue_frame_prev_register,
- NULL,
+ NULL,
i386_stack_tramp_frame_sniffer
};
\f
/* Signal trampolines. */
static struct i386_frame_cache *
-i386_sigtramp_frame_cache (frame_info_ptr this_frame, void **this_cache)
+i386_sigtramp_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
}
static enum unwind_stop_reason
-i386_sigtramp_frame_unwind_stop_reason (frame_info_ptr this_frame,
+i386_sigtramp_frame_unwind_stop_reason (const frame_info_ptr &this_frame,
void **this_cache)
{
struct i386_frame_cache *cache =
}
static void
-i386_sigtramp_frame_this_id (frame_info_ptr this_frame, void **this_cache,
+i386_sigtramp_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
struct frame_id *this_id)
{
struct i386_frame_cache *cache =
}
static struct value *
-i386_sigtramp_frame_prev_register (frame_info_ptr this_frame,
+i386_sigtramp_frame_prev_register (const frame_info_ptr &this_frame,
void **this_cache, int regnum)
{
/* Make sure we've initialized the cache. */
static int
i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
- frame_info_ptr this_frame,
+ const frame_info_ptr &this_frame,
void **this_prologue_cache)
{
gdbarch *arch = get_frame_arch (this_frame);
\f
static CORE_ADDR
-i386_frame_base_address (frame_info_ptr this_frame, void **this_cache)
+i386_frame_base_address (const frame_info_ptr &this_frame, void **this_cache)
{
struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
};
static struct frame_id
-i386_dummy_id (struct gdbarch *gdbarch, frame_info_ptr this_frame)
+i386_dummy_id (struct gdbarch *gdbarch, const frame_info_ptr &this_frame)
{
CORE_ADDR fp;
success. */
static int
-i386_get_longjmp_target (frame_info_ptr frame, CORE_ADDR *pc)
+i386_get_longjmp_target (const frame_info_ptr &frame, CORE_ADDR *pc)
{
gdb_byte buf[4];
CORE_ADDR sp, jb_addr;
int i;
for (i = 0; i < type->num_fields (); i++)
{
- if (field_is_static (&type->field (i)))
+ if (type->field (i).is_static ())
continue;
if (i386_16_byte_align_p (type->field (i).type ()))
return 1;
args_space_used = align_up (args_space_used, 16);
write_memory (sp + args_space_used,
- value_contents_all (args[i]).data (), len);
+ args[i]->contents_all ().data (), len);
/* The System V ABI says that:
"An argument's size is increased, if necessary, to make it a
/* The 'this' pointer needs to be in ECX. */
if (thiscall)
regcache->cooked_write (I386_ECX_REGNUM,
- value_contents_all (args[0]).data ());
+ args[0]->contents_all ().data ());
/* If the PLT is position-independent, the SYSTEM V ABI requires %ebx to be
set to the address of the GOT when doing a call to a PLT address.
{
*read_value = value::allocate (type);
i386_extract_return_value (gdbarch, type, regcache,
- value_contents_raw (*read_value).data ());
+ (*read_value)->contents_raw ().data ());
}
if (writebuf)
i386_store_return_value (gdbarch, type, regcache, writebuf);
the MMX registers need to be mapped onto floating point registers. */
static int
-i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
+i386_mmx_regnum_to_fp_regnum (const frame_info_ptr &next_frame, int regnum)
{
- gdbarch *arch = regcache->arch ();
+ gdbarch *arch = frame_unwind_arch (next_frame);
i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
- int mmxreg, fpreg;
- ULONGEST fstat;
- int tos;
-
- mmxreg = regnum - tdep->mm0_regnum;
- regcache->raw_read (I387_FSTAT_REGNUM (tdep), &fstat);
- tos = (fstat >> 11) & 0x7;
- fpreg = (mmxreg + tos) % 8;
+ ULONGEST fstat
+ = frame_unwind_register_unsigned (next_frame, I387_FSTAT_REGNUM (tdep));
+ int tos = (fstat >> 11) & 0x7;
+ int mmxreg = regnum - tdep->mm0_regnum;
+ int fpreg = (mmxreg + tos) % 8;
return (I387_ST0_REGNUM (tdep) + fpreg);
}
amd64_pseudo_register_read_value. It does all the work but reads
the data into an already-allocated value. */
-void
-i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
- readable_regcache *regcache,
- int regnum,
- struct value *result_value)
+value *
+i386_pseudo_register_read_value (gdbarch *gdbarch, const frame_info_ptr &next_frame,
+ const int pseudo_reg_num)
{
- gdb_byte raw_buf[I386_MAX_REGISTER_SIZE];
- enum register_status status;
- gdb_byte *buf = value_contents_raw (result_value).data ();
-
- if (i386_mmx_regnum_p (gdbarch, regnum))
+ if (i386_mmx_regnum_p (gdbarch, pseudo_reg_num))
{
- int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum);
+ int fpnum = i386_mmx_regnum_to_fp_regnum (next_frame, pseudo_reg_num);
/* Extract (always little endian). */
- status = regcache->raw_read (fpnum, raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0,
- result_value->type ()->length ());
- else
- memcpy (buf, raw_buf, register_size (gdbarch, regnum));
+ return pseudo_from_raw_part (next_frame, pseudo_reg_num, fpnum, 0);
}
else
{
i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
- if (i386_bnd_regnum_p (gdbarch, regnum))
+ if (i386_bnd_regnum_p (gdbarch, pseudo_reg_num))
{
- regnum -= tdep->bnd0_regnum;
+ int i = pseudo_reg_num - tdep->bnd0_regnum;
/* Extract (always little endian). Read lower 128bits. */
- status = regcache->raw_read (I387_BND0R_REGNUM (tdep) + regnum,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0, 16);
- else
- {
- enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
- LONGEST upper, lower;
- int size = builtin_type (gdbarch)->builtin_data_ptr->length ();
+ value *bndr_value
+ = value_of_register (I387_BND0R_REGNUM (tdep) + i, next_frame);
+ int size = builtin_type (gdbarch)->builtin_data_ptr->length ();
+ value *result
+ = value::allocate_register (next_frame, pseudo_reg_num);
- lower = extract_unsigned_integer (raw_buf, 8, byte_order);
- upper = extract_unsigned_integer (raw_buf + 8, 8, byte_order);
- upper = ~upper;
+ /* Copy the lower. */
+ bndr_value->contents_copy (result, 0, 0, size);
+
+ /* Copy the upper. */
+ bndr_value->contents_copy (result, size, 8, size);
- memcpy (buf, &lower, size);
- memcpy (buf + size, &upper, size);
+ /* If upper bytes are available, compute ones' complement. */
+ if (result->bytes_available (size, size))
+ {
+ bfd_endian byte_order
+ = gdbarch_byte_order (frame_unwind_arch (next_frame));
+ gdb::array_view<gdb_byte> upper_bytes
+ = result->contents_raw ().slice (size, size);
+ ULONGEST upper
+ = extract_unsigned_integer (upper_bytes, byte_order);
+ upper = ~upper;
+ store_unsigned_integer (upper_bytes, byte_order, upper);
}
- }
- else if (i386_k_regnum_p (gdbarch, regnum))
- {
- regnum -= tdep->k0_regnum;
- /* Extract (always little endian). */
- status = regcache->raw_read (tdep->k0_regnum + regnum, raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0, 8);
- else
- memcpy (buf, raw_buf, 8);
+ return result;
}
- else if (i386_zmm_regnum_p (gdbarch, regnum))
+ else if (i386_zmm_regnum_p (gdbarch, pseudo_reg_num))
{
- regnum -= tdep->zmm0_regnum;
+ /* Which register is it, relative to zmm0. */
+ int i_0 = pseudo_reg_num - tdep->zmm0_regnum;
- if (regnum < num_lower_zmm_regs)
- {
- /* Extract (always little endian). Read lower 128bits. */
- status = regcache->raw_read (I387_XMM0_REGNUM (tdep) + regnum,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0, 16);
- else
- memcpy (buf, raw_buf, 16);
-
- /* Extract (always little endian). Read upper 128bits. */
- status = regcache->raw_read (tdep->ymm0h_regnum + regnum,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 16, 16);
- else
- memcpy (buf + 16, raw_buf, 16);
- }
+ if (i_0 < num_lower_zmm_regs)
+ return pseudo_from_concat_raw (next_frame, pseudo_reg_num,
+ I387_XMM0_REGNUM (tdep) + i_0,
+ tdep->ymm0h_regnum + i_0,
+ tdep->zmm0h_regnum + i_0);
else
{
- /* Extract (always little endian). Read lower 128bits. */
- status = regcache->raw_read (I387_XMM16_REGNUM (tdep) + regnum
- - num_lower_zmm_regs,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0, 16);
- else
- memcpy (buf, raw_buf, 16);
-
- /* Extract (always little endian). Read upper 128bits. */
- status = regcache->raw_read (I387_YMM16H_REGNUM (tdep) + regnum
- - num_lower_zmm_regs,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 16, 16);
- else
- memcpy (buf + 16, raw_buf, 16);
- }
+ /* Which register is it, relative to zmm16. */
+ int i_16 = i_0 - num_lower_zmm_regs;
- /* Read upper 256bits. */
- status = regcache->raw_read (tdep->zmm0h_regnum + regnum,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 32, 32);
- else
- memcpy (buf + 32, raw_buf, 32);
+ return pseudo_from_concat_raw (next_frame, pseudo_reg_num,
+ I387_XMM16_REGNUM (tdep) + i_16,
+ I387_YMM16H_REGNUM (tdep) + i_16,
+ tdep->zmm0h_regnum + i_0);
+ }
}
- else if (i386_ymm_regnum_p (gdbarch, regnum))
+ else if (i386_ymm_regnum_p (gdbarch, pseudo_reg_num))
{
- regnum -= tdep->ymm0_regnum;
+ int i = pseudo_reg_num - tdep->ymm0_regnum;
- /* Extract (always little endian). Read lower 128bits. */
- status = regcache->raw_read (I387_XMM0_REGNUM (tdep) + regnum,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0, 16);
- else
- memcpy (buf, raw_buf, 16);
- /* Read upper 128bits. */
- status = regcache->raw_read (tdep->ymm0h_regnum + regnum,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 16, 32);
- else
- memcpy (buf + 16, raw_buf, 16);
+ return pseudo_from_concat_raw (next_frame, pseudo_reg_num,
+ I387_XMM0_REGNUM (tdep) + i,
+ tdep->ymm0h_regnum + i);
}
- else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
+ else if (i386_ymm_avx512_regnum_p (gdbarch, pseudo_reg_num))
{
- regnum -= tdep->ymm16_regnum;
- /* Extract (always little endian). Read lower 128bits. */
- status = regcache->raw_read (I387_XMM16_REGNUM (tdep) + regnum,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0, 16);
- else
- memcpy (buf, raw_buf, 16);
- /* Read upper 128bits. */
- status = regcache->raw_read (tdep->ymm16h_regnum + regnum,
- raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 16, 16);
- else
- memcpy (buf + 16, raw_buf, 16);
+ int i = pseudo_reg_num - tdep->ymm16_regnum;
+
+ return pseudo_from_concat_raw (next_frame, pseudo_reg_num,
+ I387_XMM16_REGNUM (tdep) + i,
+ tdep->ymm16h_regnum + i);
}
- else if (i386_word_regnum_p (gdbarch, regnum))
+ else if (i386_word_regnum_p (gdbarch, pseudo_reg_num))
{
- int gpnum = regnum - tdep->ax_regnum;
+ int gpnum = pseudo_reg_num - tdep->ax_regnum;
/* Extract (always little endian). */
- status = regcache->raw_read (gpnum, raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0,
- result_value->type ()->length ());
- else
- memcpy (buf, raw_buf, 2);
+ return pseudo_from_raw_part (next_frame, pseudo_reg_num, gpnum, 0);
}
- else if (i386_byte_regnum_p (gdbarch, regnum))
+ else if (i386_byte_regnum_p (gdbarch, pseudo_reg_num))
{
- int gpnum = regnum - tdep->al_regnum;
+ int gpnum = pseudo_reg_num - tdep->al_regnum;
/* Extract (always little endian). We read both lower and
upper registers. */
- status = regcache->raw_read (gpnum % 4, raw_buf);
- if (status != REG_VALID)
- mark_value_bytes_unavailable (result_value, 0,
- result_value->type ()->length ());
- else if (gpnum >= 4)
- memcpy (buf, raw_buf + 1, 1);
- else
- memcpy (buf, raw_buf, 1);
+ return pseudo_from_raw_part (next_frame, pseudo_reg_num, gpnum % 4,
+ gpnum >= 4 ? 1 : 0);
}
else
internal_error (_("invalid regnum"));
}
}
-static struct value *
-i386_pseudo_register_read_value (struct gdbarch *gdbarch,
- readable_regcache *regcache,
- int regnum)
-{
- struct value *result;
-
- result = value::allocate (register_type (gdbarch, regnum));
- VALUE_LVAL (result) = lval_register;
- VALUE_REGNUM (result) = regnum;
-
- i386_pseudo_register_read_into_value (gdbarch, regcache, regnum, result);
-
- return result;
-}
-
void
-i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
- int regnum, const gdb_byte *buf)
+i386_pseudo_register_write (gdbarch *gdbarch, const frame_info_ptr &next_frame,
+ const int pseudo_reg_num,
+ gdb::array_view<const gdb_byte> buf)
{
- gdb_byte raw_buf[I386_MAX_REGISTER_SIZE];
-
- if (i386_mmx_regnum_p (gdbarch, regnum))
+ if (i386_mmx_regnum_p (gdbarch, pseudo_reg_num))
{
- int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum);
+ int fpnum = i386_mmx_regnum_to_fp_regnum (next_frame, pseudo_reg_num);
- /* Read ... */
- regcache->raw_read (fpnum, raw_buf);
- /* ... Modify ... (always little endian). */
- memcpy (raw_buf, buf, register_size (gdbarch, regnum));
- /* ... Write. */
- regcache->raw_write (fpnum, raw_buf);
+ pseudo_to_raw_part (next_frame, buf, fpnum, 0);
}
else
{
i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
- if (i386_bnd_regnum_p (gdbarch, regnum))
+ if (i386_bnd_regnum_p (gdbarch, pseudo_reg_num))
{
- ULONGEST upper, lower;
int size = builtin_type (gdbarch)->builtin_data_ptr->length ();
- enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
+ bfd_endian byte_order
+ = gdbarch_byte_order (current_inferior ()->arch ());
/* New values from input value. */
- regnum -= tdep->bnd0_regnum;
- lower = extract_unsigned_integer (buf, size, byte_order);
- upper = extract_unsigned_integer (buf + size, size, byte_order);
+ int reg_index = pseudo_reg_num - tdep->bnd0_regnum;
+ int raw_regnum = I387_BND0R_REGNUM (tdep) + reg_index;
- /* Fetching register buffer. */
- regcache->raw_read (I387_BND0R_REGNUM (tdep) + regnum,
- raw_buf);
+ value *bndr_value = value_of_register (raw_regnum, next_frame);
+ gdb::array_view<gdb_byte> bndr_view
+ = bndr_value->contents_writeable ();
- upper = ~upper;
+ /* Copy lower bytes directly. */
+ copy (buf.slice (0, size), bndr_view.slice (0, size));
- /* Set register bits. */
- memcpy (raw_buf, &lower, 8);
- memcpy (raw_buf + 8, &upper, 8);
-
- regcache->raw_write (I387_BND0R_REGNUM (tdep) + regnum, raw_buf);
- }
- else if (i386_k_regnum_p (gdbarch, regnum))
- {
- regnum -= tdep->k0_regnum;
+ /* Convert and then copy upper bytes. */
+ ULONGEST upper
+ = extract_unsigned_integer (buf.slice (size, size), byte_order);
+ upper = ~upper;
+ store_unsigned_integer (bndr_view.slice (8, size), byte_order,
+ upper);
- regcache->raw_write (tdep->k0_regnum + regnum, buf);
+ put_frame_register (next_frame, raw_regnum, bndr_view);
}
- else if (i386_zmm_regnum_p (gdbarch, regnum))
+ else if (i386_zmm_regnum_p (gdbarch, pseudo_reg_num))
{
- regnum -= tdep->zmm0_regnum;
+ /* Which register is it, relative to zmm0. */
+ int reg_index_0 = pseudo_reg_num - tdep->zmm0_regnum;
- if (regnum < num_lower_zmm_regs)
- {
- /* Write lower 128bits. */
- regcache->raw_write (I387_XMM0_REGNUM (tdep) + regnum, buf);
- /* Write upper 128bits. */
- regcache->raw_write (I387_YMM0_REGNUM (tdep) + regnum, buf + 16);
- }
+ if (reg_index_0 < num_lower_zmm_regs)
+ pseudo_to_concat_raw (next_frame, buf,
+ I387_XMM0_REGNUM (tdep) + reg_index_0,
+ I387_YMM0_REGNUM (tdep) + reg_index_0,
+ tdep->zmm0h_regnum + reg_index_0);
else
{
- /* Write lower 128bits. */
- regcache->raw_write (I387_XMM16_REGNUM (tdep) + regnum
- - num_lower_zmm_regs, buf);
- /* Write upper 128bits. */
- regcache->raw_write (I387_YMM16H_REGNUM (tdep) + regnum
- - num_lower_zmm_regs, buf + 16);
+ /* Which register is it, relative to zmm16. */
+ int reg_index_16 = reg_index_0 - num_lower_zmm_regs;
+
+ pseudo_to_concat_raw (next_frame, buf,
+ I387_XMM16_REGNUM (tdep) + reg_index_16,
+ I387_YMM16H_REGNUM (tdep) + reg_index_16,
+ tdep->zmm0h_regnum + +reg_index_0);
}
- /* Write upper 256bits. */
- regcache->raw_write (tdep->zmm0h_regnum + regnum, buf + 32);
}
- else if (i386_ymm_regnum_p (gdbarch, regnum))
+ else if (i386_ymm_regnum_p (gdbarch, pseudo_reg_num))
{
- regnum -= tdep->ymm0_regnum;
+ int i = pseudo_reg_num - tdep->ymm0_regnum;
- /* ... Write lower 128bits. */
- regcache->raw_write (I387_XMM0_REGNUM (tdep) + regnum, buf);
- /* ... Write upper 128bits. */
- regcache->raw_write (tdep->ymm0h_regnum + regnum, buf + 16);
+ pseudo_to_concat_raw (next_frame, buf, I387_XMM0_REGNUM (tdep) + i,
+ tdep->ymm0h_regnum + i);
}
- else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
+ else if (i386_ymm_avx512_regnum_p (gdbarch, pseudo_reg_num))
{
- regnum -= tdep->ymm16_regnum;
+ int i = pseudo_reg_num - tdep->ymm16_regnum;
- /* ... Write lower 128bits. */
- regcache->raw_write (I387_XMM16_REGNUM (tdep) + regnum, buf);
- /* ... Write upper 128bits. */
- regcache->raw_write (tdep->ymm16h_regnum + regnum, buf + 16);
+ pseudo_to_concat_raw (next_frame, buf, I387_XMM16_REGNUM (tdep) + i,
+ tdep->ymm16h_regnum + i);
}
- else if (i386_word_regnum_p (gdbarch, regnum))
+ else if (i386_word_regnum_p (gdbarch, pseudo_reg_num))
{
- int gpnum = regnum - tdep->ax_regnum;
+ int gpnum = pseudo_reg_num - tdep->ax_regnum;
- /* Read ... */
- regcache->raw_read (gpnum, raw_buf);
- /* ... Modify ... (always little endian). */
- memcpy (raw_buf, buf, 2);
- /* ... Write. */
- regcache->raw_write (gpnum, raw_buf);
+ pseudo_to_raw_part (next_frame, buf, gpnum, 0);
}
- else if (i386_byte_regnum_p (gdbarch, regnum))
+ else if (i386_byte_regnum_p (gdbarch, pseudo_reg_num))
{
- int gpnum = regnum - tdep->al_regnum;
+ int gpnum = pseudo_reg_num - tdep->al_regnum;
- /* Read ... We read both lower and upper registers. */
- regcache->raw_read (gpnum % 4, raw_buf);
- /* ... Modify ... (always little endian). */
- if (gpnum >= 4)
- memcpy (raw_buf + 1, buf, 1);
- else
- memcpy (raw_buf, buf, 1);
- /* ... Write. */
- regcache->raw_write (gpnum % 4, raw_buf);
+ pseudo_to_raw_part (next_frame, buf, gpnum % 4, gpnum >= 4 ? 1 : 0);
}
else
internal_error (_("invalid regnum"));
ax_reg_mask (ax, I387_BND0R_REGNUM (tdep) + regnum);
return 0;
}
- else if (i386_k_regnum_p (gdbarch, regnum))
- {
- regnum -= tdep->k0_regnum;
- ax_reg_mask (ax, tdep->k0_regnum + regnum);
- return 0;
- }
else if (i386_zmm_regnum_p (gdbarch, regnum))
{
regnum -= tdep->zmm0_regnum;
return its contents in TO. */
static int
-i386_register_to_value (frame_info_ptr frame, int regnum,
+i386_register_to_value (const frame_info_ptr &frame, int regnum,
struct type *type, gdb_byte *to,
int *optimizedp, int *unavailablep)
{
gdb_assert (regnum != -1);
gdb_assert (register_size (gdbarch, regnum) == 4);
- if (!get_frame_register_bytes (frame, regnum, 0,
- gdb::make_array_view (to,
- register_size (gdbarch,
- regnum)),
+ auto to_view
+ = gdb::make_array_view (to, register_size (gdbarch, regnum));
+ frame_info_ptr next_frame = get_next_frame_sentinel_okay (frame);
+ if (!get_frame_register_bytes (next_frame, regnum, 0, to_view,
optimizedp, unavailablep))
return 0;
REGNUM in frame FRAME. */
static void
-i386_value_to_register (frame_info_ptr frame, int regnum,
+i386_value_to_register (const frame_info_ptr &frame, int regnum,
struct type *type, const gdb_byte *from)
{
int len = type->length ();
gdb_assert (regnum != -1);
gdb_assert (register_size (get_frame_arch (frame), regnum) == 4);
- put_frame_register (frame, regnum, from);
+ auto from_view = gdb::make_array_view (from, 4);
+ put_frame_register (get_next_frame_sentinel_okay (frame), regnum,
+ from_view);
regnum = i386_next_regnum (regnum);
len -= 4;
from += 4;
/* Stuff for WIN32 PE style DLL's but is pretty generic really. */
CORE_ADDR
-i386_pe_skip_trampoline_code (frame_info_ptr frame,
+i386_pe_skip_trampoline_code (const frame_info_ptr &frame,
CORE_ADDR pc, char *name)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
routine. */
int
-i386_sigtramp_p (frame_info_ptr this_frame)
+i386_sigtramp_p (const frame_info_ptr &this_frame)
{
CORE_ADDR pc = get_frame_pc (this_frame);
const char *name;
routine. */
static int
-i386_svr4_sigtramp_p (frame_info_ptr this_frame)
+i386_svr4_sigtramp_p (const frame_info_ptr &this_frame)
{
CORE_ADDR pc = get_frame_pc (this_frame);
const char *name;
address of the associated sigcontext (ucontext) structure. */
static CORE_ADDR
-i386_svr4_sigcontext_addr (frame_info_ptr this_frame)
+i386_svr4_sigcontext_addr (const frame_info_ptr &this_frame)
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* Get the ARGIth function argument for the current function. */
static CORE_ADDR
-i386_fetch_pointer_argument (frame_info_ptr frame, int argi,
+i386_fetch_pointer_argument (const frame_info_ptr &frame, int argi,
struct type *type)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
ir.addr -= 1;
goto no_support;
}
- for (regnum = X86_RECORD_REAX_REGNUM;
+ for (regnum = X86_RECORD_REAX_REGNUM;
regnum <= X86_RECORD_REDI_REGNUM;
regnum++)
I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
ir.addr -= 1;
goto no_support;
}
- /* FALLTHROUGH */
+ [[fallthrough]];
case 0x0fb2: /* lss Gv */
case 0x0fb4: /* lfs Gv */
case 0x0fb5: /* lgs Gv */
I386_SAVE_FPU_REGS))
return -1;
}
- /* Fall through */
+ [[fallthrough]];
default:
if (record_full_arch_list_add_mem (addr64, 2))
return -1;
ir.addr -= 1;
goto no_support;
}
- /* FALLTHROUGH */
+ [[fallthrough]];
case 0xf5: /* cmc */
case 0xf8: /* clc */
case 0xf9: /* stc */
goto no_support;
break;
+ case 0x0f01f9: /* rdtscp */
+ I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
+ [[fallthrough]];
case 0x0f31: /* rdtsc */
I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
case 0x0f01:
if (i386_record_modrm (&ir))
return -1;
+ if (ir.modrm == 0xf9)
+ {
+ opcode = (opcode << 8) | 0xf9;
+ goto reswitch;
+ }
switch (ir.reg)
{
case 0: /* sgdt */
else if (ir.rm == 1)
break;
}
- /* Fall through. */
+ [[fallthrough]];
case 3: /* lidt */
if (ir.mod == 3)
{
|| strcmp (name, "_Float128") == 0
|| strcmp (name, "complex _Float128") == 0
|| strcmp (name, "complex(kind=16)") == 0
+ || strcmp (name, "COMPLEX(16)") == 0
|| strcmp (name, "complex*32") == 0
|| strcmp (name, "COMPLEX*32") == 0
|| strcmp (name, "quad complex") == 0
|| strcmp (name, "real(kind=16)") == 0
|| strcmp (name, "real*16") == 0
- || strcmp (name, "REAL*16") == 0)
+ || strcmp (name, "REAL*16") == 0
+ || strcmp (name, "REAL(16)") == 0)
return floatformats_ieee_quad;
return default_floatformat_for_type (gdbarch, name, len);
}
+/* Compute an XCR0 mask based on a target description. */
+
+static uint64_t
+i386_xcr0_from_tdesc (const struct target_desc *tdesc)
+{
+ if (! tdesc_has_registers (tdesc))
+ return 0;
+
+ const struct tdesc_feature *feature_core;
+
+ const struct tdesc_feature *feature_sse, *feature_avx, *feature_mpx,
+ *feature_avx512, *feature_pkeys;
+
+ /* Get core registers. */
+ feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.core");
+ if (feature_core == NULL)
+ return 0;
+
+ /* Get SSE registers. */
+ feature_sse = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.sse");
+
+ /* Try AVX registers. */
+ feature_avx = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx");
+
+ /* Try MPX registers. */
+ feature_mpx = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx");
+
+ /* Try AVX512 registers. */
+ feature_avx512 = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx512");
+
+ /* Try PKEYS */
+ feature_pkeys = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.pkeys");
+
+ /* The XCR0 bits. */
+ uint64_t xcr0 = X86_XSTATE_X87;
+
+ if (feature_sse)
+ xcr0 |= X86_XSTATE_SSE;
+
+ if (feature_avx)
+ {
+ /* AVX register description requires SSE register description. */
+ if (!feature_sse)
+ return 0;
+
+ xcr0 |= X86_XSTATE_AVX;
+ }
+
+ if (feature_mpx)
+ xcr0 |= X86_XSTATE_MPX_MASK;
+
+ if (feature_avx512)
+ {
+ /* AVX512 register description requires AVX register description. */
+ if (!feature_avx)
+ return 0;
+
+ xcr0 |= X86_XSTATE_AVX512;
+ }
+
+ if (feature_pkeys)
+ xcr0 |= X86_XSTATE_PKRU;
+
+ return xcr0;
+}
+
static int
i386_validate_tdesc_p (i386_gdbarch_tdep *tdep,
struct tdesc_arch_data *tdesc_data)
int bnd0_regnum;
int num_bnd_cooked;
+ x86_xsave_layout xsave_layout = target_fetch_x86_xsave_layout ();
+
+ /* If the target did not provide an XSAVE layout but the target
+ description includes registers from the XSAVE extended region,
+ use a fallback XSAVE layout. Specifically, this fallback layout
+ is used when writing out a local core dump for a remote
+ target. */
+ if (xsave_layout.sizeof_xsave == 0)
+ xsave_layout
+ = i387_fallback_xsave_layout (i386_xcr0_from_tdesc (info.target_desc));
+
/* If there is already a candidate, use it. */
- arches = gdbarch_list_lookup_by_info (arches, &info);
- if (arches != NULL)
- return arches->gdbarch;
+ for (arches = gdbarch_list_lookup_by_info (arches, &info);
+ arches != NULL;
+ arches = gdbarch_list_lookup_by_info (arches->next, &info))
+ {
+ /* Check that the XSAVE layout of ARCHES matches the layout for
+ the current target. */
+ i386_gdbarch_tdep *other_tdep
+ = gdbarch_tdep<i386_gdbarch_tdep> (arches->gdbarch);
+
+ if (other_tdep->xsave_layout == xsave_layout)
+ return arches->gdbarch;
+ }
/* Allocate space for the new architecture. Assume i386 for now. */
gdbarch *gdbarch
set_gdbarch_fetch_pointer_argument (gdbarch, i386_fetch_pointer_argument);
/* Hook the function epilogue frame unwinder. This unwinder is
- appended to the list first, so that it supercedes the DWARF
+ appended to the list first, so that it supersedes the DWARF
unwinder in function epilogues (where the DWARF unwinder
currently fails). */
if (info.bfd_arch_info->bits_per_word == 32)
- frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind);
+ frame_unwind_append_unwinder (gdbarch, &i386_epilogue_override_frame_unwind);
/* Hook in the DWARF CFI frame unwinder. This unwinder is appended
to the list before the prologue-based unwinders, so that DWARF
CFI info will be used if it is available. */
dwarf2_append_unwinders (gdbarch);
+ if (info.bfd_arch_info->bits_per_word == 32)
+ frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind);
+
frame_base_set_default (gdbarch, &i386_frame_base);
/* Pseudo registers may be changed by amd64_init_abi. */
gdbarch_free (gdbarch);
return NULL;
}
+ tdep->xsave_layout = xsave_layout;
num_bnd_cooked = (tdep->bnd0r_regnum > 0 ? I387_NUM_BND_REGS : 0);
static unsigned long
i386_mpx_bd_base (void)
{
- struct regcache *rcache;
ULONGEST ret;
enum register_status regstatus;
- rcache = get_current_regcache ();
+ regcache *rcache = get_thread_regcache (inferior_thread ());
gdbarch *arch = rcache->arch ();
i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
/* Add "bound" command for the show mpx commands list. */
- add_cmd ("bound", no_class, i386_mpx_info_bounds,
+ cmd_list_element *c = add_cmd ("bound", no_class, i386_mpx_info_bounds,
"Show the memory bounds for a given array/pointer storage\
in the bound table.",
&mpx_show_cmdlist);
+ deprecate_cmd (c, nullptr);
/* Add "bound" command for the set mpx commands list. */
- add_cmd ("bound", no_class, i386_mpx_set_bounds,
+ c = add_cmd ("bound", no_class, i386_mpx_set_bounds,
"Set the memory bounds for a given array/pointer storage\
in the bound table.",
&mpx_set_cmdlist);
+ deprecate_cmd (c, nullptr);
gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SVR4,
i386_svr4_init_abi);