|
|
8f6b9e |
commit 7f03bd92e389a32da490bb55037881cf374d0f69
|
|
|
8f6b9e |
Author: Pedro Alves <palves@redhat.com>
|
|
|
8f6b9e |
Date: Thu Aug 6 18:23:00 2015 +0100
|
|
|
8f6b9e |
|
|
|
8f6b9e |
PPC64: Fix gdb.arch/ppc64-atomic-inst.exp with displaced stepping
|
|
|
8f6b9e |
|
|
|
8f6b9e |
The ppc64 displaced step code can't handle atomic sequences. Fallback
|
|
|
8f6b9e |
to stepping over the breakpoint in-line if we detect one.
|
|
|
8f6b9e |
|
|
|
8f6b9e |
gdb/ChangeLog:
|
|
|
8f6b9e |
2015-08-07 Pedro Alves <palves@redhat.com>
|
|
|
8f6b9e |
|
|
|
8f6b9e |
* infrun.c (displaced_step_prepare_throw): Return -1 if
|
|
|
8f6b9e |
gdbarch_displaced_step_copy_insn returns NULL. Update intro
|
|
|
8f6b9e |
comment.
|
|
|
8f6b9e |
* rs6000-tdep.c (LWARX_MASK, LWARX_INSTRUCTION, LDARX_INSTRUCTION)
|
|
|
8f6b9e |
(STWCX_MASK, STWCX_INSTRUCTION, STDCX_INSTRUCTION): Move higher up
|
|
|
8f6b9e |
in file.
|
|
|
8f6b9e |
(ppc_displaced_step_copy_insn): New function.
|
|
|
8f6b9e |
(ppc_displaced_step_fixup): Update comment.
|
|
|
8f6b9e |
(rs6000_gdbarch_init): Install ppc_displaced_step_copy_insn as
|
|
|
8f6b9e |
gdbarch_displaced_step_copy_insn hook.
|
|
|
8f6b9e |
* gdbarch.sh (displaced_step_copy_insn): Document what happens on
|
|
|
8f6b9e |
NULL return.
|
|
|
8f6b9e |
* gdbarch.h: Regenerate.
|
|
|
8f6b9e |
|
|
|
8f6b9e |
gdb/testsuite/ChangeLog:
|
|
|
8f6b9e |
2015-08-07 Pedro Alves <palves@redhat.com>
|
|
|
8f6b9e |
|
|
|
8f6b9e |
* gdb.arch/ppc64-atomic-inst.exp (do_test): New procedure, move
|
|
|
8f6b9e |
tests here.
|
|
|
8f6b9e |
(top level): Run do_test with and without displaced stepping.
|
|
|
8f6b9e |
|
|
|
8f6b9e |
### a/gdb/ChangeLog
|
|
|
8f6b9e |
### b/gdb/ChangeLog
|
|
|
8f6b9e |
## -1,5 +1,21 @@
|
|
|
8f6b9e |
2015-08-07 Pedro Alves <palves@redhat.com>
|
|
|
8f6b9e |
|
|
|
8f6b9e |
+ * infrun.c (displaced_step_prepare_throw): Return -1 if
|
|
|
8f6b9e |
+ gdbarch_displaced_step_copy_insn returns NULL. Update intro
|
|
|
8f6b9e |
+ comment.
|
|
|
8f6b9e |
+ * rs6000-tdep.c (LWARX_MASK, LWARX_INSTRUCTION, LDARX_INSTRUCTION)
|
|
|
8f6b9e |
+ (STWCX_MASK, STWCX_INSTRUCTION, STDCX_INSTRUCTION): Move higher up
|
|
|
8f6b9e |
+ in file.
|
|
|
8f6b9e |
+ (ppc_displaced_step_copy_insn): New function.
|
|
|
8f6b9e |
+ (ppc_displaced_step_fixup): Update comment.
|
|
|
8f6b9e |
+ (rs6000_gdbarch_init): Install ppc_displaced_step_copy_insn as
|
|
|
8f6b9e |
+ gdbarch_displaced_step_copy_insn hook.
|
|
|
8f6b9e |
+ * gdbarch.sh (displaced_step_copy_insn): Document what happens on
|
|
|
8f6b9e |
+ NULL return.
|
|
|
8f6b9e |
+ * gdbarch.h: Regenerate.
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+2015-08-07 Pedro Alves <palves@redhat.com>
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
* inferior.h (struct inferior) <displaced_stepping_failed>: New
|
|
|
8f6b9e |
field.
|
|
|
8f6b9e |
* infrun.c (use_displaced_stepping_now_p): New parameter 'inf'.
|
|
|
8f6b9e |
Index: gdb-7.6.1/gdb/gdbarch.h
|
|
|
8f6b9e |
===================================================================
|
|
|
8f6b9e |
--- gdb-7.6.1.orig/gdb/gdbarch.h 2017-08-29 21:41:21.400218851 +0200
|
|
|
8f6b9e |
+++ gdb-7.6.1/gdb/gdbarch.h 2017-08-29 21:41:29.832299833 +0200
|
|
|
8f6b9e |
@@ -870,7 +870,11 @@
|
|
|
8f6b9e |
|
|
|
8f6b9e |
If your architecture doesn't need to adjust instructions before
|
|
|
8f6b9e |
single-stepping them, consider using simple_displaced_step_copy_insn
|
|
|
8f6b9e |
- here. */
|
|
|
8f6b9e |
+ here.
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ If the instruction cannot execute out of line, return NULL. The
|
|
|
8f6b9e |
+ core falls back to stepping past the instruction in-line instead in
|
|
|
8f6b9e |
+ that case. */
|
|
|
8f6b9e |
|
|
|
8f6b9e |
extern int gdbarch_displaced_step_copy_insn_p (struct gdbarch *gdbarch);
|
|
|
8f6b9e |
|
|
|
8f6b9e |
Index: gdb-7.6.1/gdb/gdbarch.sh
|
|
|
8f6b9e |
===================================================================
|
|
|
8f6b9e |
--- gdb-7.6.1.orig/gdb/gdbarch.sh 2017-08-29 21:41:21.401218861 +0200
|
|
|
8f6b9e |
+++ gdb-7.6.1/gdb/gdbarch.sh 2017-08-29 21:41:29.833299843 +0200
|
|
|
8f6b9e |
@@ -724,6 +724,10 @@
|
|
|
8f6b9e |
# If your architecture doesn't need to adjust instructions before
|
|
|
8f6b9e |
# single-stepping them, consider using simple_displaced_step_copy_insn
|
|
|
8f6b9e |
# here.
|
|
|
8f6b9e |
+#
|
|
|
8f6b9e |
+# If the instruction cannot execute out of line, return NULL. The
|
|
|
8f6b9e |
+# core falls back to stepping past the instruction in-line instead in
|
|
|
8f6b9e |
+# that case.
|
|
|
8f6b9e |
M:struct displaced_step_closure *:displaced_step_copy_insn:CORE_ADDR from, CORE_ADDR to, struct regcache *regs:from, to, regs
|
|
|
8f6b9e |
|
|
|
8f6b9e |
# Return true if GDB should use hardware single-stepping to execute
|
|
|
8f6b9e |
Index: gdb-7.6.1/gdb/infrun.c
|
|
|
8f6b9e |
===================================================================
|
|
|
8f6b9e |
--- gdb-7.6.1.orig/gdb/infrun.c 2017-08-29 21:41:21.404218890 +0200
|
|
|
8f6b9e |
+++ gdb-7.6.1/gdb/infrun.c 2017-08-29 21:41:29.835299862 +0200
|
|
|
8f6b9e |
@@ -1323,7 +1323,9 @@
|
|
|
8f6b9e |
explain how we handle this case instead.
|
|
|
8f6b9e |
|
|
|
8f6b9e |
Returns 1 if preparing was successful -- this thread is going to be
|
|
|
8f6b9e |
- stepped now; or 0 if displaced stepping this thread got queued. */
|
|
|
8f6b9e |
+ stepped now; 0 if displaced stepping this thread got queued; or -1
|
|
|
8f6b9e |
+ if this instruction can't be displaced stepped. */
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
static int
|
|
|
8f6b9e |
displaced_step_prepare (ptid_t ptid)
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
@@ -1412,9 +1414,14 @@
|
|
|
8f6b9e |
|
|
|
8f6b9e |
closure = gdbarch_displaced_step_copy_insn (gdbarch,
|
|
|
8f6b9e |
original, copy, regcache);
|
|
|
8f6b9e |
-
|
|
|
8f6b9e |
- /* We don't support the fully-simulated case at present. */
|
|
|
8f6b9e |
- gdb_assert (closure);
|
|
|
8f6b9e |
+ if (closure == NULL)
|
|
|
8f6b9e |
+ {
|
|
|
8f6b9e |
+ /* The architecture doesn't know how or want to displaced step
|
|
|
8f6b9e |
+ this instruction or instruction sequence. Fallback to
|
|
|
8f6b9e |
+ stepping over the breakpoint in-line. */
|
|
|
8f6b9e |
+ do_cleanups (old_cleanups);
|
|
|
8f6b9e |
+ return -1;
|
|
|
8f6b9e |
+ }
|
|
|
8f6b9e |
|
|
|
8f6b9e |
/* Save the information we need to fix things up if the step
|
|
|
8f6b9e |
succeeds. */
|
|
|
8f6b9e |
Index: gdb-7.6.1/gdb/rs6000-tdep.c
|
|
|
8f6b9e |
===================================================================
|
|
|
8f6b9e |
--- gdb-7.6.1.orig/gdb/rs6000-tdep.c 2017-08-29 21:41:21.407218918 +0200
|
|
|
8f6b9e |
+++ gdb-7.6.1/gdb/rs6000-tdep.c 2017-08-29 21:41:29.837299881 +0200
|
|
|
8f6b9e |
@@ -975,6 +975,61 @@
|
|
|
8f6b9e |
#define BXL_INSN 0x4c000000
|
|
|
8f6b9e |
#define BP_INSN 0x7C000008
|
|
|
8f6b9e |
|
|
|
8f6b9e |
+/* Instruction masks used during single-stepping of atomic
|
|
|
8f6b9e |
+ sequences. */
|
|
|
8f6b9e |
+#define LWARX_MASK 0xfc0007fe
|
|
|
8f6b9e |
+#define LWARX_INSTRUCTION 0x7c000028
|
|
|
8f6b9e |
+#define LDARX_INSTRUCTION 0x7c0000A8
|
|
|
8f6b9e |
+#define STWCX_MASK 0xfc0007ff
|
|
|
8f6b9e |
+#define STWCX_INSTRUCTION 0x7c00012d
|
|
|
8f6b9e |
+#define STDCX_INSTRUCTION 0x7c0001ad
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+/* We can't displaced step atomic sequences. Otherwise this is just
|
|
|
8f6b9e |
+ like simple_displaced_step_copy_insn. */
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+static struct displaced_step_closure *
|
|
|
8f6b9e |
+ppc_displaced_step_copy_insn (struct gdbarch *gdbarch,
|
|
|
8f6b9e |
+ CORE_ADDR from, CORE_ADDR to,
|
|
|
8f6b9e |
+ struct regcache *regs)
|
|
|
8f6b9e |
+{
|
|
|
8f6b9e |
+ size_t len = gdbarch_max_insn_length (gdbarch);
|
|
|
8f6b9e |
+ gdb_byte *buf = xmalloc (len);
|
|
|
8f6b9e |
+ struct cleanup *old_chain = make_cleanup (xfree, buf);
|
|
|
8f6b9e |
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
|
8f6b9e |
+ int insn;
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ read_memory (from, buf, len);
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ insn = extract_signed_integer (buf, PPC_INSN_SIZE, byte_order);
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ /* Assume all atomic sequences start with a lwarx/ldarx instruction. */
|
|
|
8f6b9e |
+ if ((insn & LWARX_MASK) == LWARX_INSTRUCTION
|
|
|
8f6b9e |
+ || (insn & LWARX_MASK) == LDARX_INSTRUCTION)
|
|
|
8f6b9e |
+ {
|
|
|
8f6b9e |
+ if (debug_displaced)
|
|
|
8f6b9e |
+ {
|
|
|
8f6b9e |
+ fprintf_unfiltered (gdb_stdlog,
|
|
|
8f6b9e |
+ "displaced: can't displaced step "
|
|
|
8f6b9e |
+ "atomic sequence at %s\n",
|
|
|
8f6b9e |
+ paddress (gdbarch, from));
|
|
|
8f6b9e |
+ }
|
|
|
8f6b9e |
+ do_cleanups (old_chain);
|
|
|
8f6b9e |
+ return NULL;
|
|
|
8f6b9e |
+ }
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ write_memory (to, buf, len);
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ if (debug_displaced)
|
|
|
8f6b9e |
+ {
|
|
|
8f6b9e |
+ fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
|
|
|
8f6b9e |
+ paddress (gdbarch, from), paddress (gdbarch, to));
|
|
|
8f6b9e |
+ displaced_step_dump_bytes (gdb_stdlog, buf, len);
|
|
|
8f6b9e |
+ }
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ discard_cleanups (old_chain);
|
|
|
8f6b9e |
+ return (struct displaced_step_closure *) buf;
|
|
|
8f6b9e |
+}
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
/* Fix up the state of registers and memory after having single-stepped
|
|
|
8f6b9e |
a displaced instruction. */
|
|
|
8f6b9e |
static void
|
|
|
8f6b9e |
@@ -984,8 +1039,7 @@
|
|
|
8f6b9e |
struct regcache *regs)
|
|
|
8f6b9e |
{
|
|
|
8f6b9e |
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
|
8f6b9e |
- /* Since we use simple_displaced_step_copy_insn, our closure is a
|
|
|
8f6b9e |
- copy of the instruction. */
|
|
|
8f6b9e |
+ /* Our closure is a copy of the instruction. */
|
|
|
8f6b9e |
ULONGEST insn = extract_unsigned_integer ((gdb_byte *) closure,
|
|
|
8f6b9e |
PPC_INSN_SIZE, byte_order);
|
|
|
8f6b9e |
ULONGEST opcode = 0;
|
|
|
8f6b9e |
@@ -1078,14 +1132,6 @@
|
|
|
8f6b9e |
return 1;
|
|
|
8f6b9e |
}
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-/* Instruction masks used during single-stepping of atomic sequences. */
|
|
|
8f6b9e |
-#define LWARX_MASK 0xfc0007fe
|
|
|
8f6b9e |
-#define LWARX_INSTRUCTION 0x7c000028
|
|
|
8f6b9e |
-#define LDARX_INSTRUCTION 0x7c0000A8
|
|
|
8f6b9e |
-#define STWCX_MASK 0xfc0007ff
|
|
|
8f6b9e |
-#define STWCX_INSTRUCTION 0x7c00012d
|
|
|
8f6b9e |
-#define STDCX_INSTRUCTION 0x7c0001ad
|
|
|
8f6b9e |
-
|
|
|
8f6b9e |
/* Checks for an atomic sequence of instructions beginning with a LWARX/LDARX
|
|
|
8f6b9e |
instruction and ending with a STWCX/STDCX instruction. If such a sequence
|
|
|
8f6b9e |
is found, attempt to step through it. A breakpoint is placed at the end of
|
|
|
8f6b9e |
@@ -6427,7 +6473,7 @@
|
|
|
8f6b9e |
|
|
|
8f6b9e |
/* Setup displaced stepping. */
|
|
|
8f6b9e |
set_gdbarch_displaced_step_copy_insn (gdbarch,
|
|
|
8f6b9e |
- simple_displaced_step_copy_insn);
|
|
|
8f6b9e |
+ ppc_displaced_step_copy_insn);
|
|
|
8f6b9e |
set_gdbarch_displaced_step_hw_singlestep (gdbarch,
|
|
|
8f6b9e |
ppc_displaced_step_hw_singlestep);
|
|
|
8f6b9e |
set_gdbarch_displaced_step_fixup (gdbarch, ppc_displaced_step_fixup);
|
|
|
8f6b9e |
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-atomic-inst.exp
|
|
|
8f6b9e |
===================================================================
|
|
|
8f6b9e |
--- gdb-7.6.1.orig/gdb/testsuite/gdb.arch/ppc64-atomic-inst.exp 2017-08-29 21:41:21.408218928 +0200
|
|
|
8f6b9e |
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-atomic-inst.exp 2017-08-29 21:41:29.837299881 +0200
|
|
|
8f6b9e |
@@ -32,27 +32,41 @@
|
|
|
8f6b9e |
return -1
|
|
|
8f6b9e |
}
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-if ![runto_main] then {
|
|
|
8f6b9e |
- untested "could not run to main"
|
|
|
8f6b9e |
- return -1
|
|
|
8f6b9e |
-}
|
|
|
8f6b9e |
+# The test proper. DISPLACED is true if we should try with displaced
|
|
|
8f6b9e |
+# stepping.
|
|
|
8f6b9e |
+proc do_test { displaced } {
|
|
|
8f6b9e |
+ global decimal hex
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ if ![runto_main] then {
|
|
|
8f6b9e |
+ untested "could not run to main"
|
|
|
8f6b9e |
+ return -1
|
|
|
8f6b9e |
+ }
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+ gdb_test_no_output "set displaced-stepping $displaced"
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-set bp1 [gdb_get_line_number "lwarx"]
|
|
|
8f6b9e |
-gdb_breakpoint "$bp1" "Breakpoint $decimal at $hex" \
|
|
|
8f6b9e |
- "Set the breakpoint at the start of the lwarx/stwcx sequence"
|
|
|
8f6b9e |
+ set bp1 [gdb_get_line_number "lwarx"]
|
|
|
8f6b9e |
+ gdb_breakpoint "$bp1" "Breakpoint $decimal at $hex" \
|
|
|
8f6b9e |
+ "Set the breakpoint at the start of the lwarx/stwcx sequence"
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-set bp2 [gdb_get_line_number "ldarx"]
|
|
|
8f6b9e |
-gdb_breakpoint "$bp2" "Breakpoint $decimal at $hex" \
|
|
|
8f6b9e |
- "Set the breakpoint at the start of the ldarx/stdcx sequence"
|
|
|
8f6b9e |
+ set bp2 [gdb_get_line_number "ldarx"]
|
|
|
8f6b9e |
+ gdb_breakpoint "$bp2" "Breakpoint $decimal at $hex" \
|
|
|
8f6b9e |
+ "Set the breakpoint at the start of the ldarx/stdcx sequence"
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-gdb_test continue "Continuing.*Breakpoint $decimal.*" \
|
|
|
8f6b9e |
- "Continue until lwarx/stwcx start breakpoint"
|
|
|
8f6b9e |
+ gdb_test continue "Continuing.*Breakpoint $decimal.*" \
|
|
|
8f6b9e |
+ "Continue until lwarx/stwcx start breakpoint"
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-gdb_test nexti "bne.*1b" \
|
|
|
8f6b9e |
- "Step through the lwarx/stwcx sequence"
|
|
|
8f6b9e |
+ gdb_test nexti "bne.*1b" \
|
|
|
8f6b9e |
+ "Step through the lwarx/stwcx sequence"
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-gdb_test continue "Continuing.*Breakpoint $decimal.*" \
|
|
|
8f6b9e |
- "Continue until ldarx/stdcx start breakpoint"
|
|
|
8f6b9e |
+ gdb_test continue "Continuing.*Breakpoint $decimal.*" \
|
|
|
8f6b9e |
+ "Continue until ldarx/stdcx start breakpoint"
|
|
|
8f6b9e |
|
|
|
8f6b9e |
-gdb_test nexti "bne.*1b" \
|
|
|
8f6b9e |
- "Step through the ldarx/stdcx sequence"
|
|
|
8f6b9e |
+ gdb_test nexti "bne.*1b" \
|
|
|
8f6b9e |
+ "Step through the ldarx/stdcx sequence"
|
|
|
8f6b9e |
+}
|
|
|
8f6b9e |
+
|
|
|
8f6b9e |
+foreach displaced { "off" "on" } {
|
|
|
8f6b9e |
+ with_test_prefix "displaced=$displaced" {
|
|
|
8f6b9e |
+ do_test $displaced
|
|
|
8f6b9e |
+ }
|
|
|
8f6b9e |
+}
|