From: Uros Bizjak <ubizjak@gmail.com>
To: Ulrich Weigand <uweigand@de.ibm.com>
Cc: gdb-patches@sourceware.org, Alan Modra <amodra@gmail.com>,
Richard Henderson <rth@redhat.com>,
Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Subject: [PATCH v3, alpha]: Handle single-stepping of atomic sequences
Date: Thu, 24 Nov 2011 13:29:00 -0000 [thread overview]
Message-ID: <CAFULd4a6B0mP9wK74+DOaczfYA3iRA_Cn023+ps60LwPh1gpDA@mail.gmail.com> (raw)
In-Reply-To: <201111241237.pAOCbFIK019798@d06av02.portsmouth.uk.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 724 bytes --]
On Thu, Nov 24, 2011 at 1:37 PM, Ulrich Weigand <uweigand@de.ibm.com> wrote:
>> 2011-11-24 Uros Bizjak <ubizjak@gmail.com>
>>
>> * alpha-tdep.c (br_opcode): New.
>> (ldl_l_opcode, ldq_l_opcode, stl_c_opcode, stq_c_opcode): Ditto.
>> (alpha_deal_with_atomic_sequence): New function.
>> (alpha_gdbarch_init): Handle single stepping of atomic sequences
>> with alpha_deal_with_atomic_sequence.
>>
>> [v3]: As suggested by Ulrich, handle all branch instructions inside
>> compare and exchange loop.
>>
>> Re-tested on alphaev68-pc-linux-gnu, also with simulate-thread.exp
>> from GCC testsuite.
>
> Patch seems to be missing ...
Eh, sorry... attached now.
Uros.
[-- Attachment #2: gdb-7.3.50.20111114.diff --]
[-- Type: text/x-patch, Size: 4032 bytes --]
--- alpha-tdep.c 2011-11-24 10:09:34.000000000 +0100
+++ alpha-tdep.c.ub 2011-11-24 10:08:26.000000000 +0100
@@ -65,6 +65,7 @@ static const int stq_opcode = 0x2d;
/* Branch instruction format */
#define BR_RA(insn) MEM_RA(insn)
+static const int br_opcode = 0x30;
static const int bne_opcode = 0x3d;
/* Operate instruction format */
@@ -762,6 +763,94 @@ alpha_skip_prologue (struct gdbarch *gdb
}
\f
+static const int ldl_l_opcode = 0x2a;
+static const int ldq_l_opcode = 0x2b;
+static const int stl_c_opcode = 0x2e;
+static const int stq_c_opcode = 0x2f;
+
+/* Checks for an atomic sequence of instructions beginning with a LDL_L/LDQ_L
+ instruction and ending with a STL_C/STQ_C instruction. If such a sequence
+ is found, attempt to step through it. A breakpoint is placed at the end of
+ the sequence. */
+
+int
+alpha_deal_with_atomic_sequence (struct frame_info *frame)
+{
+ struct gdbarch *gdbarch = get_frame_arch (frame);
+ struct address_space *aspace = get_frame_address_space (frame);
+ CORE_ADDR pc = get_frame_pc (frame);
+ CORE_ADDR breaks[2] = {-1, -1};
+ CORE_ADDR loc = pc;
+ CORE_ADDR closing_insn; /* Instruction that closes the atomic sequence. */
+ unsigned int insn = alpha_read_insn (gdbarch, loc);
+ int insn_count;
+ int index;
+ int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
+ const int atomic_sequence_length = 16; /* Instruction sequence length. */
+ int bc_insn_count = 0; /* Conditional branch instruction count. */
+
+ /* Assume all atomic sequences start with a LDL_L/LDQ_L instruction. */
+ if (INSN_OPCODE (insn) != ldl_l_opcode
+ && INSN_OPCODE (insn) != ldq_l_opcode)
+ return 0;
+
+ /* Assume that no atomic sequence is longer than "atomic_sequence_length"
+ instructions. */
+ for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
+ {
+ loc += ALPHA_INSN_SIZE;
+ insn = alpha_read_insn (gdbarch, loc);
+
+ /* Assume that there is at most one branch in the atomic
+ sequence. If a branch is found, put a breakpoint in
+ its destination address. */
+ if (INSN_OPCODE (insn) >= br_opcode)
+ {
+ int immediate = (insn & 0x001fffff) << 2;
+
+ immediate = (immediate ^ 0x400000) - 0x400000;
+
+ if (bc_insn_count >= 1)
+ return 0; /* More than one branch found, fallback
+ to the standard single-step code. */
+
+ breaks[1] = loc + ALPHA_INSN_SIZE + immediate;
+
+ bc_insn_count++;
+ last_breakpoint++;
+ }
+
+ if (INSN_OPCODE (insn) == stl_c_opcode
+ || INSN_OPCODE (insn) == stq_c_opcode)
+ break;
+ }
+
+ /* Assume that the atomic sequence ends with a STL_C/STQ_C instruction. */
+ if (INSN_OPCODE (insn) != stl_c_opcode
+ && INSN_OPCODE (insn) != stq_c_opcode)
+ return 0;
+
+ closing_insn = loc;
+ loc += ALPHA_INSN_SIZE;
+
+ /* Insert a breakpoint right after the end of the atomic sequence. */
+ breaks[0] = loc;
+
+ /* Check for duplicated breakpoints. Check also for a breakpoint
+ placed (branch instruction's destination) anywhere in sequence. */
+ if (last_breakpoint
+ && (breaks[1] == breaks[0]
+ || (breaks[1] >= pc && breaks[1] <= closing_insn)))
+ last_breakpoint = 0;
+
+ /* Effectively inserts the breakpoints. */
+ for (index = 0; index <= last_breakpoint; index++)
+ insert_single_step_breakpoint (gdbarch, aspace, breaks[index]);
+
+ return 1;
+}
+
+\f
/* Figure out where the longjmp will land.
We expect the first arg to be a pointer to the jmp_buf structure from
which we extract the PC (JB_PC) that we will land at. The PC is copied
@@ -1749,6 +1838,9 @@ alpha_gdbarch_init (struct gdbarch_info
set_gdbarch_decr_pc_after_break (gdbarch, ALPHA_INSN_SIZE);
set_gdbarch_cannot_step_breakpoint (gdbarch, 1);
+ /* Handles single stepping of atomic sequences. */
+ set_gdbarch_software_single_step (gdbarch, alpha_deal_with_atomic_sequence);
+
/* Hook in ABI-specific overrides, if they have been registered. */
gdbarch_init_osabi (info, gdbarch);
next prev parent reply other threads:[~2011-11-24 13:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-16 22:47 [PATCH, " Uros Bizjak
2011-11-18 12:19 ` [PATCH v2, " Uros Bizjak
2011-11-24 9:21 ` Uros Bizjak
2011-11-24 12:37 ` Ulrich Weigand
2011-11-24 13:29 ` Uros Bizjak [this message]
2011-11-25 17:09 ` [PATCH v3, " Ulrich Weigand
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=CAFULd4a6B0mP9wK74+DOaczfYA3iRA_Cn023+ps60LwPh1gpDA@mail.gmail.com \
--to=ubizjak@gmail.com \
--cc=Ulrich.Weigand@de.ibm.com \
--cc=amodra@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=rth@redhat.com \
--cc=uweigand@de.ibm.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