From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 16/17] S/390: displaced stepping and PC-relative RIL-b/RIL-c instructions
Date: Fri, 17 Apr 2015 11:06:00 -0000 [thread overview]
Message-ID: <1429267521-21047-17-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1429267521-21047-1-git-send-email-palves@redhat.com>
This adds displaced stepping support for the General-Instruction
Extension Facility instructions, which have a PC-relative displacement
(RIL-b/RIL-c). We already handle RIL branches, but not others.
Currently, displaced stepping a breakpoint put on any of these
instructions results in the inferior crashing when or after the
instruction is executed out-of-line in the scratch pad.
This patch takes the easy route of patching the displacement in the
copy of the instruction in the scratch pad. As the displacement is a
signed 32-bit field, it's possible that the stratch pad ends too far
that the needed displacement doesn't fit in the adjusted instruction,
as e.g., if stepping over a breakpoint in a shared library (the
scratch pad is around the main program's entry point). That case is
detected and GDB falls back to stepping over the breakpoint in-line
(which involves pausing all threads momentarily).
(We could probably do something smarter, but I don't plan on doing it
myself. This was already sufficient to get "maint set target-non-stop
on" working regression free on S/390.)
Tested on S/390 RHEL 7.1, where it fixes a few hundred FAILs when
testing with displaced stepping force-enabled, with the end result
being no regressions compared to a test run that doesn't force
displaced stepping. Fixes the non-stop tests compared to mainline
too; most are crashing due to this on the machine I run tests on.
gdb/ChangeLog:
2015-04-17 Pedro Alves <palves@redhat.com>
* s390-linux-tdep.c (is_non_branch_ril)
(s390_displaced_step_copy_insn): New functions.
(s390_displaced_step_fixup): Update comment.
(s390_gdbarch_init): Install s390_displaced_step_copy_insn as
gdbarch_displaced_step_copy_insn hook.
v3:
- No changes.
---
gdb/s390-linux-tdep.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 112 insertions(+), 3 deletions(-)
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index b83a264..41790a4 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -1529,6 +1529,116 @@ s390_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
/* Displaced stepping. */
+/* Return true if INSN is a non-branch RIL-b or RIL-c format
+ instruction. */
+
+static int
+is_non_branch_ril (gdb_byte *insn)
+{
+ gdb_byte op1 = insn[0];
+
+ if (op1 == 0xc4)
+ {
+ gdb_byte op2 = insn[1] & 0x0f;
+
+ switch (op2)
+ {
+ case 0x02: /* llhrl */
+ case 0x04: /* lghrl */
+ case 0x05: /* lhrl */
+ case 0x06: /* llghrl */
+ case 0x07: /* sthrl */
+ case 0x08: /* lgrl */
+ case 0x0b: /* stgrl */
+ case 0x0c: /* lgfrl */
+ case 0x0d: /* lrl */
+ case 0x0e: /* llgfrl */
+ case 0x0f: /* strl */
+ return 1;
+ }
+ }
+ else if (op1 == 0xc6)
+ {
+ gdb_byte op2 = insn[1] & 0x0f;
+
+ switch (op2)
+ {
+ case 0x00: /* exrl */
+ case 0x02: /* pfdrl */
+ case 0x04: /* cghrl */
+ case 0x05: /* chrl */
+ case 0x06: /* clghrl */
+ case 0x07: /* clhrl */
+ case 0x08: /* cgrl */
+ case 0x0a: /* clgrl */
+ case 0x0c: /* cgfrl */
+ case 0x0d: /* crl */
+ case 0x0e: /* clgfrl */
+ case 0x0f: /* clrl */
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/* Implementation of gdbarch_displaced_step_copy_insn. */
+
+static struct displaced_step_closure *
+s390_displaced_step_copy_insn (struct gdbarch *gdbarch,
+ CORE_ADDR from, CORE_ADDR to,
+ struct regcache *regs)
+{
+ size_t len = gdbarch_max_insn_length (gdbarch);
+ gdb_byte *buf = xmalloc (len);
+ struct cleanup *old_chain = make_cleanup (xfree, buf);
+
+ read_memory (from, buf, len);
+
+ /* Adjust the displacement field of PC-relative RIL instructions,
+ except branches. The latter are handled in the fixup hook. */
+ if (is_non_branch_ril (buf))
+ {
+ LONGEST offset;
+
+ offset = extract_signed_integer (buf + 2, 4, BFD_ENDIAN_BIG);
+ offset = (from - to + offset * 2) / 2;
+
+ /* If the instruction is too far from the jump pad, punt. This
+ will usually happen with instructions in shared libraries.
+ We could probably support these by rewriting them to be
+ absolute or fully emulating them. */
+ if (offset < INT32_MIN || offset > INT32_MAX)
+ {
+ /* Let the core fall back to stepping over the breakpoint
+ in-line. */
+ if (debug_displaced)
+ {
+ fprintf_unfiltered (gdb_stdlog,
+ "displaced: can't displaced step "
+ "RIL instruction: offset %s out of range\n",
+ plongest (offset));
+ }
+ do_cleanups (old_chain);
+ return NULL;
+ }
+
+ store_signed_integer (buf + 2, 4, BFD_ENDIAN_BIG, offset);
+ }
+
+ write_memory (to, buf, len);
+
+ if (debug_displaced)
+ {
+ fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
+ paddress (gdbarch, from), paddress (gdbarch, to));
+ displaced_step_dump_bytes (gdb_stdlog, buf, len);
+ }
+
+ discard_cleanups (old_chain);
+ return (struct displaced_step_closure *) buf;
+}
+
/* Fix up the state of registers and memory after having single-stepped
a displaced instruction. */
static void
@@ -1537,8 +1647,7 @@ s390_displaced_step_fixup (struct gdbarch *gdbarch,
CORE_ADDR from, CORE_ADDR to,
struct regcache *regs)
{
- /* Since we use simple_displaced_step_copy_insn, our closure is a
- copy of the instruction. */
+ /* Our closure is a copy of the instruction. */
gdb_byte *insn = (gdb_byte *) closure;
static int s390_instrlen[] = { 2, 4, 4, 6 };
int insnlen = s390_instrlen[insn[0] >> 6];
@@ -3291,7 +3400,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
/* Displaced stepping. */
set_gdbarch_displaced_step_copy_insn (gdbarch,
- simple_displaced_step_copy_insn);
+ s390_displaced_step_copy_insn);
set_gdbarch_displaced_step_fixup (gdbarch, s390_displaced_step_fixup);
set_gdbarch_displaced_step_free_closure (gdbarch,
simple_displaced_step_free_closure);
--
1.9.3
next prev parent reply other threads:[~2015-04-17 11:06 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-17 10:47 [PATCH v3 00/23] All-stop on top of non-stop Pedro Alves
2015-04-17 10:45 ` [PATCH v3 15/17] PPC64: Fix gdb.arch/ppc64-atomic-inst.exp with displaced stepping Pedro Alves
2015-04-21 11:21 ` Yao Qi
2015-04-22 20:04 ` Pedro Alves
2015-04-17 10:45 ` [PATCH v3 11/17] Fix signal-while-stepping-over-bp-other-thread.exp on targets always in non-stop Pedro Alves
2015-04-17 10:45 ` [PATCH v3 08/17] Factor out code to re-resume stepped thread Pedro Alves
2015-04-17 10:45 ` [PATCH v3 05/17] Embed the pending step-over chain in thread_info objects Pedro Alves
2015-04-21 8:28 ` Yao Qi
2015-04-22 20:14 ` Pedro Alves
2015-04-21 9:53 ` Yao Qi
2015-04-22 19:07 ` Pedro Alves
2015-04-22 4:25 ` Doug Evans
2015-04-22 22:19 ` Pedro Alves
2015-04-17 10:45 ` [PATCH v3 03/17] remote.c/all-stop: Implement TARGET_WAITKIND_NO_RESUMED and TARGET_WNOHANG Pedro Alves
2015-04-17 10:45 ` [PATCH v3 13/17] Fix step-over-{trips-on-watchpoint|lands-on-breakpoint}.exp race Pedro Alves
2015-04-17 10:45 ` [PATCH v3 04/17] Make thread_still_needs_step_over consider stepping_over_watchpoint too Pedro Alves
2015-04-17 10:45 ` [PATCH v3 06/17] Use keep_going in proceed and start_step_over too Pedro Alves
2015-04-22 5:09 ` Doug Evans
2015-04-22 22:22 ` Pedro Alves
2015-04-17 10:45 ` [PATCH v3 02/17] Change adjust_pc_after_break's prototype Pedro Alves
2015-04-17 10:47 ` [PATCH v3 07/17] Misc switch_back_to_stepped_thread cleanups Pedro Alves
2015-04-21 9:50 ` Yao Qi
2015-04-22 20:04 ` Pedro Alves
2015-04-22 5:23 ` Doug Evans
2015-04-22 20:05 ` Pedro Alves
2015-04-28 20:28 ` Doug Evans
2015-04-17 10:47 ` [PATCH v3 17/17] native Linux: enable always non-stop by default Pedro Alves
2015-04-17 10:47 ` [PATCH v3 01/17] Fix and test "checkpoint" in non-stop mode Pedro Alves
2015-04-21 2:36 ` Doug Evans
2015-04-22 17:48 ` Pedro Alves
2015-04-28 18:18 ` Doug Evans
2015-04-29 4:56 ` Doug Evans
2015-05-19 18:08 ` Pedro Alves
2015-04-17 10:52 ` [PATCH v3 12/17] Fix interrupt-noterm.exp on targets always in non-stop Pedro Alves
2015-04-21 11:40 ` Yao Qi
2015-04-22 20:03 ` Pedro Alves
2015-04-17 10:52 ` [PATCH v3 09/17] Teach non-stop to do in-line step-overs (stop all, step, restart) Pedro Alves
2015-04-17 11:01 ` Pedro Alves
2015-04-21 15:01 ` Yao Qi
2015-04-22 20:03 ` Pedro Alves
2015-04-24 9:06 ` Yao Qi
2015-04-27 20:17 ` Doug Evans
2015-05-19 18:09 ` Pedro Alves
2015-05-19 18:49 ` Pedro Alves
2015-04-17 10:56 ` [PATCH v3 14/17] Disable displaced stepping if trying it fails Pedro Alves
2015-04-17 11:06 ` Pedro Alves [this message]
2015-04-17 11:38 ` [PATCH v3 10/17] Implement all-stop on top of a target running non-stop mode Pedro Alves
2015-04-21 11:09 ` Yao Qi
2015-04-22 20:16 ` Pedro Alves
2015-04-24 7:39 ` Yao Qi
2015-05-19 18:08 ` Pedro Alves
2015-05-21 9:17 ` Yao Qi
2015-04-20 12:02 ` [PATCH v3 00/23] All-stop on top of non-stop Yao Qi
2015-04-20 16:54 ` Sergio Durigan Junior
2015-04-20 16:43 ` Pedro Alves
2015-04-21 7:48 ` Yao Qi
2015-04-21 15:05 ` Yao Qi
2015-04-22 22:27 ` Pedro Alves
2015-04-20 17:35 ` Simon Marchi
2015-05-19 18:14 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429267521-21047-17-git-send-email-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).