public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Sandra Loosemore <sandra@codesourcery.com>
To: <gdb-patches@sourceware.org>, Yao Qi <qiyaoltc@gmail.com>
Subject: [patch v2 4/5, nios2] work around issues with unwritable signal handler trampoline code
Date: Thu, 30 Apr 2015 09:08:00 -0000	[thread overview]
Message-ID: <554178D2.7070508@codesourcery.com> (raw)
In-Reply-To: <554172F8.2020108@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 367 bytes --]

It was requested that I split the patch previously posted here:

https://sourceware.org/ml/gdb-patches/2015-04/msg00907.html

into two parts.  This is the second part.  There are no changes from v1 
other than separating it from the part of the original patch that dealt 
with adjusting the register save area offset for the trampoline.  OK to 
commit now?

-Sandra


[-- Attachment #2: gdb-sigtramp-breakpoint.log --]
[-- Type: text/x-log, Size: 430 bytes --]

2015-04-29  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* nios2-tdep.c (nios2_get_next_pc): Make non-static.
	* nios2-tdep.h (nios2_get_next_pc): Declare as extern.
	* nios2-linux-tdep.c: Include breakpoint.h.
	(nios2_linux_software_single_step): New target hook function.
	(nios2_linux_init_abi): Install it.

	gdb/testsuite/
	* gdb.base/sigaltstack.exp: Add kfails for nios2-*-linux*.
	* gdb.base/sigstep.exp: Likewise.

[-- Attachment #3: gdb-sigtramp-breakpoint.patch --]
[-- Type: text/x-patch, Size: 4477 bytes --]

diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
index 0a837b0..c73d8af 100644
--- a/gdb/nios2-linux-tdep.c
+++ b/gdb/nios2-linux-tdep.c
@@ -29,6 +29,7 @@
 #include "linux-tdep.h"
 #include "glibc-tdep.h"
 #include "nios2-tdep.h"
+#include "breakpoint.h"
 
 #include "features/nios2-linux.c"
 
@@ -185,6 +186,32 @@ nios2_linux_syscall_next_pc (struct frame_info *frame)
   return pc + NIOS2_OPCODE_SIZE;
 }
 
+/* Override the bare-metal software_single_step gdbarch method.
+   If the PC where we'd ordinarily want to set the breakpoint is
+   the signal trampoline at 0x1044, the kernel will not let us set a
+   breakpoint at that location.  So, treat it as if it were a function call
+   and set the breakpoint on its return address instead.  */
+
+static int
+nios2_linux_software_single_step (struct frame_info *frame)
+{
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  struct address_space *aspace;
+  CORE_ADDR next_pc = nios2_get_next_pc (frame, get_frame_pc (frame));
+
+  if (next_pc == NIOS2_SIGRETURN_TRAMP_ADDR)
+    {
+      frame = get_prev_frame (frame);
+      next_pc = frame_unwind_caller_pc (frame);
+    }
+
+  aspace = get_frame_address_space (frame);
+  insert_single_step_breakpoint (gdbarch, aspace, next_pc);
+
+  return 1;
+}
+
+
 /* Hook function for gdbarch_register_osabi.  */
 
 static void
@@ -210,6 +237,8 @@ nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tramp_frame_prepend_unwinder (gdbarch,
                                 &nios2_linux_rt_sigreturn_tramp_frame);
 
+  /* Single stepping.  */
+  set_gdbarch_software_single_step (gdbarch, nios2_linux_software_single_step);
   tdep->syscall_next_pc = nios2_linux_syscall_next_pc;
 
   /* Index of target address word in glibc jmp_buf.  */
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 988b9fc..4d9c415 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -1576,7 +1576,7 @@ static const struct frame_unwind nios2_stub_frame_unwind =
 /* Determine where to set a single step breakpoint while considering
    branch prediction.  */
 
-static CORE_ADDR
+CORE_ADDR
 nios2_get_next_pc (struct frame_info *frame, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
diff --git a/gdb/nios2-tdep.h b/gdb/nios2-tdep.h
index af36c41..46eb3e2 100644
--- a/gdb/nios2-tdep.h
+++ b/gdb/nios2-tdep.h
@@ -77,4 +77,6 @@ struct gdbarch_tdep
 extern struct target_desc *tdesc_nios2_linux;
 extern struct target_desc *tdesc_nios2;
 
+extern CORE_ADDR nios2_get_next_pc (struct frame_info *, CORE_ADDR);
+
 #endif /* NIOS2_TDEP_H */
diff --git a/gdb/testsuite/gdb.base/sigaltstack.exp b/gdb/testsuite/gdb.base/sigaltstack.exp
index b65ea48..59a6c17 100644
--- a/gdb/testsuite/gdb.base/sigaltstack.exp
+++ b/gdb/testsuite/gdb.base/sigaltstack.exp
@@ -76,6 +76,7 @@ proc finish_test { pattern msg } {
 	    # don't gracefully fall back to single-stepping.
 	    setup_kfail gdb/8841 "i?86-*-linux*"
 	    setup_kfail gdb/8841 "*-*-openbsd*"
+	    setup_kfail gdb/8841 "nios2-*-linux*"
 	    fail "$msg (could not set breakpoint)"
 	}
 	-re "$pattern.*${gdb_prompt} $" {
diff --git a/gdb/testsuite/gdb.base/sigstep.exp b/gdb/testsuite/gdb.base/sigstep.exp
index 3c9454c..800fa08 100644
--- a/gdb/testsuite/gdb.base/sigstep.exp
+++ b/gdb/testsuite/gdb.base/sigstep.exp
@@ -161,6 +161,14 @@ set in_handler_map {
 		fail "$test (spurious SIGTRAP)"
 		return
 	    }
+	    -re "Cannot insert breakpoint 0.*${gdb_prompt} $" {
+		# Some platforms use a special read-only page for signal
+		# trampolines.  We can't set a breakpoint there, and we
+		# don't gracefully fall back to single-stepping.
+		setup_kfail gdb/8841 "nios2-*-linux*"
+		fail "$test (could not set breakpoint)"
+		return
+	    }
 	    -re "other handler location.*$gdb_prompt $" {
 		pass $test
 	    }
@@ -203,6 +211,7 @@ proc advancei { cmd } {
 		# don't gracefully fall back to single-stepping.
 		setup_kfail gdb/8841 "i?86-*-linux*"
 		setup_kfail gdb/8841 "*-*-openbsd*"
+		setup_kfail gdb/8841 "nios2-*-linux*"
 		fail "$test (could not set breakpoint)"
 		return
 	    }
@@ -225,6 +234,10 @@ proc advancei { cmd } {
 		pass "$test"
 	    }
 	    -re "main .*${gdb_prompt} $" {
+	    # Some targets cannot set single-step breakpoints on a
+	    # signal trampoline and step over the trampoline
+	    # instead of through it.
+	    setup_kfail gdb/8841 "nios2-*-linux*"
 		fail "$test (in main)"
 	    }
 	    -re "$inferior_exited_re normally.*${gdb_prompt} $" {

  parent reply	other threads:[~2015-04-30  0:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30  0:33 [patch v2 0/5, nios2] unbreak nios2-linux-gnu GDB Sandra Loosemore
2015-04-30  0:36 ` [patch v2 1/5, nios2] revert to using "trap 31" for breakpoints Sandra Loosemore
2015-05-08  9:21   ` Yao Qi
2015-04-30  0:39 ` [patch v2 2/5, nios2] use PTRACE_GETREGSET/SETREGSET in gdbserver Sandra Loosemore
2015-05-08  9:23   ` Yao Qi
2015-04-30  9:03 ` [patch v2 3/5, nios2] fix register save offset for signal handler trampolines Sandra Loosemore
2015-05-08  9:31   ` Yao Qi
2015-04-30  9:08 ` Sandra Loosemore [this message]
2015-05-08 11:08   ` [patch v2 4/5, nios2] work around issues with unwritable signal handler trampoline code Yao Qi
2015-04-30 12:05 ` [patch v2 5/5, nios2] add NEWS entry for ABI change Sandra Loosemore

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=554178D2.7070508@codesourcery.com \
    --to=sandra@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    /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).