aboutsummaryrefslogtreecommitdiff
path: root/gdb/i386-tdep.c
diff options
context:
space:
mode:
authorMarkus Metzger <markus.t.metzger@intel.com>2013-03-22 15:56:56 +0100
committerMarkus Metzger <markus.t.metzger@intel.com>2014-01-16 12:45:11 +0100
commitc2170eeffa616c51ca4c7ab7142523c04b762603 (patch)
tree8275515276a5b0591073db7cf182e45545f12471 /gdb/i386-tdep.c
parent864089d2f64c6624aac3f52ece2c31dff6a8f59f (diff)
downloadgdb-c2170eeffa616c51ca4c7ab7142523c04b762603.zip
gdb-c2170eeffa616c51ca4c7ab7142523c04b762603.tar.gz
gdb-c2170eeffa616c51ca4c7ab7142523c04b762603.tar.bz2
gdbarch: add instruction predicate methods
Add new methods to gdbarch for analyzing the instruction at a given address. Implement those methods for i386 and amd64 architectures. This is needed by "record btrace" to detect function calls in the execution trace. 2014-01-16 Markus Metzger <markus.t.metzger@intel.com> * amd64-tdep.c (amd64_classify_insn_at, amd64_insn_is_call) (amd64_insn_is_ret, amd64_insn_is_jump, amd64_jmp_p): New. (amd64_init_abi): Add insn_is_call, insn_is_ret, and insn_is_jump to gdbarch. * i386-tdep.c (i386_insn_is_call, i386_insn_is_ret) (i386_insn_is_jump, i386_jmp_p): New. (i386_gdbarch_init): Add insn_is_call, insn_is_ret, and insn_is_jump to gdbarch. * gdbarch.sh (insn_is_call, insn_is_ret, insn_is_jump): New. * gdbarch.h: Regenerated. * gdbarch.c: Regenerated. * arch-utils.h (default_insn_is_call, default_insn_is_ret) (default_insn_is_jump): New. * arch-utils.c (default_insn_is_call, default_insn_is_ret) (default_insn_is_jump): New.
Diffstat (limited to 'gdb/i386-tdep.c')
-rw-r--r--gdb/i386-tdep.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 4a5f652..57f18cb 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -530,6 +530,22 @@ i386_absolute_jmp_p (const gdb_byte *insn)
return 0;
}
+/* Return non-zero if INSN is a jump, zero otherwise. */
+
+static int
+i386_jmp_p (const gdb_byte *insn)
+{
+ /* jump short, relative. */
+ if (insn[0] == 0xeb)
+ return 1;
+
+ /* jump near, relative. */
+ if (insn[0] == 0xe9)
+ return 1;
+
+ return i386_absolute_jmp_p (insn);
+}
+
static int
i386_absolute_call_p (const gdb_byte *insn)
{
@@ -601,6 +617,45 @@ i386_syscall_p (const gdb_byte *insn, int *lengthp)
return 0;
}
+/* The gdbarch insn_is_call method. */
+
+static int
+i386_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
+{
+ gdb_byte buf[I386_MAX_INSN_LEN], *insn;
+
+ read_code (addr, buf, I386_MAX_INSN_LEN);
+ insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
+
+ return i386_call_p (insn);
+}
+
+/* The gdbarch insn_is_ret method. */
+
+static int
+i386_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
+{
+ gdb_byte buf[I386_MAX_INSN_LEN], *insn;
+
+ read_code (addr, buf, I386_MAX_INSN_LEN);
+ insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
+
+ return i386_ret_p (insn);
+}
+
+/* The gdbarch insn_is_jump method. */
+
+static int
+i386_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
+{
+ gdb_byte buf[I386_MAX_INSN_LEN], *insn;
+
+ read_code (addr, buf, I386_MAX_INSN_LEN);
+ insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
+
+ return i386_jmp_p (insn);
+}
+
/* Some kernels may run one past a syscall insn, so we have to cope.
Otherwise this is just simple_displaced_step_copy_insn. */
@@ -8017,6 +8072,10 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_gen_return_address (gdbarch, i386_gen_return_address);
+ set_gdbarch_insn_is_call (gdbarch, i386_insn_is_call);
+ set_gdbarch_insn_is_ret (gdbarch, i386_insn_is_ret);
+ set_gdbarch_insn_is_jump (gdbarch, i386_insn_is_jump);
+
/* Hook in ABI-specific overrides, if they have been registered. */
info.tdep_info = (void *) tdesc_data;
gdbarch_init_osabi (info, gdbarch);