Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions lldb/test/API/riscv/step/TestSoftwareStep.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,26 @@ def do_sequence_test(self, filename, bkpt_name):
substrs=["stopped", "stop reason = instruction step into"],
)

pc = cur_thread.GetFrameAtIndex(0).GetPC()
# Get the instruction we stopped at
pc = cur_thread.GetFrameAtIndex(0).GetPCAddress()
inst = target.ReadInstructions(pc, 1).GetInstructionAtIndex(0)

return pc - entry_pc
inst_mnemonic = inst.GetMnemonic(target)
inst_operands = inst.GetOperands(target)
if not inst_operands:
return inst_mnemonic

@skipIf(archs=no_match("^rv.*"))
return f"{inst_mnemonic} {inst_operands}"

@skipIf(archs=no_match("^riscv.*"))
def test_cas(self):
"""
This test verifies LLDB instruction step handling of a proper lr/sc pair.
"""
difference = self.do_sequence_test("main", "cas")
self.assertEqual(difference, 0x1A)
instruction = self.do_sequence_test("main", "cas")
self.assertEqual(instruction, "nop")

@skipIf(archs=no_match("^rv.*"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this regex was never matching and so the test was always skipped, probably also skipped on RISC-V until you fixed it here?

Istr updating this riscv regex in another test in the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't notice that we actually changed the regex for RISCV in #130034. Maybe ^rv.* works somehow too, because I was able to run the tests. Or maybe I didn't have the patch on my branch.

Anyway, after #130034, we can use riscv32 and riscv64. For any RISCV target, I use ^riscv.* - for example, in the software watchpoints tests.

I noticed that lldb/test/API/riscv/break-undecoded/TestBreakpointIllegal.py has the old regex, we should change it at some point.

@skipIf(archs=no_match("^riscv.*"))
def test_branch_cas(self):
"""
LLDB cannot predict the actual state of registers within a critical section (i.e., inside an atomic
Expand All @@ -51,29 +58,29 @@ def test_branch_cas(self):
test is nearly identical to the previous one, except for the branch condition, which is inverted and
will result in a taken jump.
"""
difference = self.do_sequence_test("branch", "branch_cas")
self.assertEqual(difference, 0x1A)
instruction = self.do_sequence_test("branch", "branch_cas")
self.assertEqual(instruction, "ret")

@skipIf(archs=no_match("^rv.*"))
@skipIf(archs=no_match("^riscv.*"))
def test_incomplete_sequence_without_lr(self):
"""
This test verifies the behavior of a standalone sc instruction without a preceding lr. Since the sc
lacks the required lr pairing, LLDB should treat it as a non-atomic store rather than part of an
atomic sequence.
"""
difference = self.do_sequence_test(
instruction = self.do_sequence_test(
"incomplete_sequence_without_lr", "incomplete_cas"
)
self.assertEqual(difference, 0x4)
self.assertEqual(instruction, "and a5, a2, a4")

@skipIf(archs=no_match("^rv.*"))
@skipIf(archs=no_match("^riscv.*"))
def test_incomplete_sequence_without_sc(self):
"""
This test checks the behavior of a standalone lr instruction without a subsequent sc. Since the lr
lacks its required sc counterpart, LLDB should treat it as a non-atomic load rather than part of an
atomic sequence.
"""
difference = self.do_sequence_test(
instruction = self.do_sequence_test(
"incomplete_sequence_without_sc", "incomplete_cas"
)
self.assertEqual(difference, 0x4)
self.assertEqual(instruction, "and a5, a2, a4")
1 change: 1 addition & 0 deletions lldb/test/API/riscv/step/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void __attribute__((naked)) branch_cas(int *a, int *b) {
"xor a5, a2, a5\n\t"
"sc.w a5, a1, (a3)\n\t"
"beqz a5, 1b\n\t"
"nop\n\t"
"2:\n\t"
"ret\n\t");
}
Expand Down
1 change: 1 addition & 0 deletions lldb/test/API/riscv/step/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void __attribute__((naked)) cas(int *a, int *b) {
"xor a5, a2, a5\n\t"
"sc.w a5, a1, (a3)\n\t"
"beqz a5, 1b\n\t"
"nop\n\t"
"2:\n\t"
"ret\n\t");
}
Expand Down
Loading