Blame SOURCES/gdb-rhbz1093259-aarch64-single-step-atomic-seq.patch

7ab123
All attempts:
7ab123
7ab123
 - <https://sourceware.org/ml/gdb-patches/2014-03/msg00576.html>
7ab123
   Message-ID: <20140324161056.GB23291@redacted.bos.redhat.com>
7ab123
7ab123
 - <https://sourceware.org/ml/gdb-patches/2014-03/msg00624.html>
7ab123
   Message-ID: <20140327015125.GE3075@redacted.bos.redhat.com>
7ab123
   (see below)
7ab123
7ab123
 - <https://sourceware.org/ml/gdb-patches/2014-04/msg00433.html>
7ab123
   Message-ID: <20140422165542.GA748@redacted.bos.redhat.com>
7ab123
7ab123
 - <https://sourceware.org/ml/gdb-patches/2014-04/msg00505.html>
7ab123
   Message-ID: <20140424183510.GI7588@redacted.bos.redhat.com>
7ab123
7ab123
 - <https://sourceware.org/ml/gdb-patches/2014-04/msg00642.html>
7ab123
   Message-ID: <20140430160450.GE2148@redacted.bos.redhat.com>
7ab123
   (last version, applied)
7ab123
7ab123
7ab123
Second message from Kyle, which seems complete enough.
7ab123
7ab123
  Date: Wed, 26 Mar 2014 21:51:26 -0400
7ab123
  From: Kyle McMartin <kmcmarti at redhat dot com>
7ab123
  To: gdb-patches at sourceware dot org
7ab123
  Subject: [PATCHv2] aarch64: detect atomic sequences like other ll/sc architectures
7ab123
  Message-ID: <20140327015125.GE3075@redacted.bos.redhat.com>
7ab123
7ab123
  Add similar single-stepping over atomic sequences support like other
7ab123
  load-locked/store-conditional architectures (alpha, powerpc, arm, etc.)
7ab123
  do. Verified the decode_masked_match, and decode_bcond works against the
7ab123
  atomic sequences used in the Linux kernel atomic.h, and also gcc
7ab123
  libatomic. Thanks to Richard Henderson for feedback on my initial
7ab123
  attempt at this patch, and for the feedback from gdb-patches, which I
7ab123
  hope I've addressed...
7ab123
7ab123
7ab123
7ab123
commit 9404b58f46328b3b171b0d5eeb0691bd685bc4f5
7ab123
Author: Kyle McMartin <kmcmarti@redhat.com>
7ab123
Date:   Wed Apr 30 12:04:50 2014 -0400
7ab123
7ab123
    aarch64: detect atomic sequences like other ll/sc architectures
7ab123
    
7ab123
    gdb/Changelog:
7ab123
    
7ab123
            * aarch64-tdep.c (aarch64_software_single_step): New function.
7ab123
            (aarch64_gdbarch_init): Handle single stepping of atomic sequences
7ab123
            with aarch64_software_single_step.
7ab123
    
7ab123
    gdb/testsuite/ChangeLog:
7ab123
    
7ab123
            * gdb.arch/aarch64-atomic-inst.c: New file.
7ab123
            * gdb.arch/aarch64-atomic-inst.exp: New file.
7ab123
7ab123
Index: gdb-7.6.1/gdb/aarch64-tdep.c
7ab123
===================================================================
7ab123
--- gdb-7.6.1.orig/gdb/aarch64-tdep.c
7ab123
+++ gdb-7.6.1/gdb/aarch64-tdep.c
7ab123
@@ -2518,6 +2518,84 @@ value_of_aarch64_user_reg (struct frame_
7ab123
 }
7ab123
 
7ab123
 
7ab123
+/* Implement the "software_single_step" gdbarch method, needed to
7ab123
+   single step through atomic sequences on AArch64.  */
7ab123
+
7ab123
+static int
7ab123
+aarch64_software_single_step (struct frame_info *frame)
7ab123
+{
7ab123
+  struct gdbarch *gdbarch = get_frame_arch (frame);
7ab123
+  struct address_space *aspace = get_frame_address_space (frame);
7ab123
+  enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
7ab123
+  const int insn_size = 4;
7ab123
+  const int atomic_sequence_length = 16; /* Instruction sequence length.  */
7ab123
+  CORE_ADDR pc = get_frame_pc (frame);
7ab123
+  CORE_ADDR breaks[2] = { -1, -1 };
7ab123
+  CORE_ADDR loc = pc;
7ab123
+  CORE_ADDR closing_insn = 0;
7ab123
+  uint32_t insn = read_memory_unsigned_integer (loc, insn_size,
7ab123
+						byte_order_for_code);
7ab123
+  int index;
7ab123
+  int insn_count;
7ab123
+  int bc_insn_count = 0; /* Conditional branch instruction count.  */
7ab123
+  int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed).  */
7ab123
+
7ab123
+  /* Look for a Load Exclusive instruction which begins the sequence.  */
7ab123
+  if (!decode_masked_match (insn, 0x3fc00000, 0x08400000))
7ab123
+    return 0;
7ab123
+
7ab123
+  for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
7ab123
+    {
7ab123
+      int32_t offset;
7ab123
+      unsigned cond;
7ab123
+
7ab123
+      loc += insn_size;
7ab123
+      insn = read_memory_unsigned_integer (loc, insn_size,
7ab123
+					   byte_order_for_code);
7ab123
+
7ab123
+      /* Check if the instruction is a conditional branch.  */
7ab123
+      if (decode_bcond (loc, insn, &cond, &offset))
7ab123
+	{
7ab123
+	  if (bc_insn_count >= 1)
7ab123
+	    return 0;
7ab123
+
7ab123
+	  /* It is, so we'll try to set a breakpoint at the destination.  */
7ab123
+	  breaks[1] = loc + offset;
7ab123
+
7ab123
+	  bc_insn_count++;
7ab123
+	  last_breakpoint++;
7ab123
+	}
7ab123
+
7ab123
+      /* Look for the Store Exclusive which closes the atomic sequence.  */
7ab123
+      if (decode_masked_match (insn, 0x3fc00000, 0x08000000))
7ab123
+	{
7ab123
+	  closing_insn = loc;
7ab123
+	  break;
7ab123
+	}
7ab123
+    }
7ab123
+
7ab123
+  /* We didn't find a closing Store Exclusive instruction, fall back.  */
7ab123
+  if (!closing_insn)
7ab123
+    return 0;
7ab123
+
7ab123
+  /* Insert breakpoint after the end of the atomic sequence.  */
7ab123
+  breaks[0] = loc + insn_size;
7ab123
+
7ab123
+  /* Check for duplicated breakpoints, and also check that the second
7ab123
+     breakpoint is not within the atomic sequence.  */
7ab123
+  if (last_breakpoint
7ab123
+      && (breaks[1] == breaks[0]
7ab123
+	  || (breaks[1] >= pc && breaks[1] <= closing_insn)))
7ab123
+    last_breakpoint = 0;
7ab123
+
7ab123
+  /* Insert the breakpoint at the end of the sequence, and one at the
7ab123
+     destination of the conditional branch, if it exists.  */
7ab123
+  for (index = 0; index <= last_breakpoint; index++)
7ab123
+    insert_single_step_breakpoint (gdbarch, aspace, breaks[index]);
7ab123
+
7ab123
+  return 1;
7ab123
+}
7ab123
+
7ab123
 /* Initialize the current architecture based on INFO.  If possible,
7ab123
    re-use an architecture from ARCHES, which is a list of
7ab123
    architectures already created during this debugging session.
7ab123
@@ -2635,6 +2713,7 @@ aarch64_gdbarch_init (struct gdbarch_inf
7ab123
   set_gdbarch_breakpoint_from_pc (gdbarch, aarch64_breakpoint_from_pc);
7ab123
   set_gdbarch_cannot_step_breakpoint (gdbarch, 1);
7ab123
   set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
7ab123
+  set_gdbarch_software_single_step (gdbarch, aarch64_software_single_step);
7ab123
 
7ab123
   /* Information about registers, etc.  */
7ab123
   set_gdbarch_sp_regnum (gdbarch, AARCH64_SP_REGNUM);
7ab123
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/aarch64-atomic-inst.c
7ab123
===================================================================
7ab123
--- /dev/null
7ab123
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/aarch64-atomic-inst.c
7ab123
@@ -0,0 +1,48 @@
7ab123
+/* This file is part of GDB, the GNU debugger.
7ab123
+
7ab123
+   Copyright 2008-2014 Free Software Foundation, Inc.
7ab123
+
7ab123
+   This program is free software; you can redistribute it and/or modify
7ab123
+   it under the terms of the GNU General Public License as published by
7ab123
+   the Free Software Foundation; either version 3 of the License, or
7ab123
+   (at your option) any later version.
7ab123
+
7ab123
+   This program is distributed in the hope that it will be useful,
7ab123
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
7ab123
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7ab123
+   GNU General Public License for more details.
7ab123
+
7ab123
+   You should have received a copy of the GNU General Public License
7ab123
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
7ab123
+
7ab123
+int main(void)
7ab123
+{
7ab123
+  unsigned long tmp, cond;
7ab123
+  unsigned long dword = 0;
7ab123
+
7ab123
+  /* Test that we can step over ldxr/stxr. This sequence should step from
7ab123
+     ldxr to the following __asm __volatile.  */
7ab123
+  __asm __volatile ("1:     ldxr    %0,%2\n"                             \
7ab123
+                    "       cmp     %0,#1\n"                             \
7ab123
+                    "       b.eq    out\n"                               \
7ab123
+                    "       add     %0,%0,1\n"                           \
7ab123
+                    "       stxr    %w1,%0,%2\n"                         \
7ab123
+                    "       cbnz    %w1,1b"                              \
7ab123
+                    : "=&r" (tmp), "=&r" (cond), "+Q" (dword)            \
7ab123
+                    : : "memory");
7ab123
+
7ab123
+  /* This sequence should take the conditional branch and step from ldxr
7ab123
+     to the return dword line.  */
7ab123
+  __asm __volatile ("1:     ldxr    %0,%2\n"                             \
7ab123
+                    "       cmp     %0,#1\n"                             \
7ab123
+                    "       b.eq    out\n"                               \
7ab123
+                    "       add     %0,%0,1\n"                           \
7ab123
+                    "       stxr    %w1,%0,%2\n"                         \
7ab123
+                    "       cbnz    %w1,1b\n"                            \
7ab123
+                    : "=&r" (tmp), "=&r" (cond), "+Q" (dword)            \
7ab123
+                    : : "memory");
7ab123
+
7ab123
+  dword = -1;
7ab123
+__asm __volatile ("out:\n");
7ab123
+  return dword;
7ab123
+}
7ab123
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/aarch64-atomic-inst.exp
7ab123
===================================================================
7ab123
--- /dev/null
7ab123
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/aarch64-atomic-inst.exp
7ab123
@@ -0,0 +1,48 @@
7ab123
+# Copyright 2008-2014 Free Software Foundation, Inc.
7ab123
+#
7ab123
+# This program is free software; you can redistribute it and/or modify
7ab123
+# it under the terms of the GNU General Public License as published by
7ab123
+# the Free Software Foundation; either version 3 of the License, or
7ab123
+# (at your option) any later version.
7ab123
+#
7ab123
+# This program is distributed in the hope that it will be useful,
7ab123
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7ab123
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7ab123
+# GNU General Public License for more details.
7ab123
+#
7ab123
+# You should have received a copy of the GNU General Public License
7ab123
+# along with this program; if not, write to the Free Software
7ab123
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7ab123
+#
7ab123
+# This file is part of the gdb testsuite.
7ab123
+
7ab123
+# Test single stepping through atomic sequences beginning with
7ab123
+# a ldxr instruction and ending with a stxr instruction.
7ab123
+
7ab123
+if {![istarget "aarch64*"]} {
7ab123
+    verbose "Skipping ${gdb_test_file_name}."
7ab123
+    return
7ab123
+}
7ab123
+
7ab123
+standard_testfile
7ab123
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
7ab123
+    return -1
7ab123
+}
7ab123
+
7ab123
+if ![runto_main] {
7ab123
+    untested "could not run to main"
7ab123
+    return -1
7ab123
+}
7ab123
+
7ab123
+gdb_breakpoint "[gdb_get_line_number "ldxr"]" \
7ab123
+  "Breakpoint $decimal at $hex" \
7ab123
+  "Set the breakpoint at the start of the sequence"
7ab123
+
7ab123
+gdb_test "continue" "Continuing.*Breakpoint $decimal.*" \
7ab123
+  "Continue until breakpoint"
7ab123
+
7ab123
+gdb_test "next" ".*__asm __volatile.*" \
7ab123
+  "Step through the ldxr/stxr sequence"
7ab123
+
7ab123
+gdb_test "next" ".*return dword.*" \
7ab123
+  "Stepped through sequence through conditional branch"