aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2025-03-07 09:25:33 +0100
committerTom de Vries <tdevries@suse.de>2025-03-07 09:25:33 +0100
commita7769415cb4a3207de4c18baf46794344ab220d1 (patch)
tree4eb1f0d6c23d429f95254e2978597eb149d5d52b
parentbbb04932e6cab8aac83b3ab8d0d4aa5fae3356f9 (diff)
downloadbinutils-a7769415cb4a3207de4c18baf46794344ab220d1.zip
binutils-a7769415cb4a3207de4c18baf46794344ab220d1.tar.gz
binutils-a7769415cb4a3207de4c18baf46794344ab220d1.tar.bz2
[gdb/tdep] Factor out rip_relative_p
Factor out rip_relative_p, and rewrite it to use MODRM_MOD_FIELD and MODRM_RM_FIELD. No functional changes. Tested on x86_64-linux.
-rw-r--r--gdb/amd64-tdep.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 8471ca6..a2da139 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -1207,6 +1207,18 @@ amd64_skip_prefixes (gdb_byte *insn)
return insn;
}
+/* Return true if the MODRM byte of an insn indicates that the insn is
+ rip-relative. */
+
+static bool
+rip_relative_p (gdb_byte modrm)
+{
+ gdb_byte mod = MODRM_MOD_FIELD (modrm);
+ gdb_byte rm = MODRM_RM_FIELD (modrm);
+
+ return mod == 0 && rm == 0x05;
+}
+
/* Return a register mask for the integer registers that are used as an input
operand in INSN. If !ASSUMPTIONS, only return the registers we actually
found, for the benefit of self tests. */
@@ -1455,7 +1467,7 @@ fixup_displaced_copy (struct gdbarch *gdbarch,
{
gdb_byte modrm = details->raw_insn[details->modrm_offset];
- if ((modrm & 0xc7) == 0x05)
+ if (rip_relative_p (modrm))
{
/* The insn uses rip-relative addressing.
Deal with it. */
@@ -1789,7 +1801,7 @@ rip_relative_offset (struct amd64_insn *insn)
{
gdb_byte modrm = insn->raw_insn[insn->modrm_offset];
- if ((modrm & 0xc7) == 0x05)
+ if (rip_relative_p (modrm))
{
/* The displacement is found right after the ModRM byte. */
return insn->modrm_offset + 1;