Skip to content

Commit

Permalink
Merge pull request #557 from en-sc/en-sc/manual-hwbp
Browse files Browse the repository at this point in the history
debug: fix HwbpManual test
  • Loading branch information
en-sc authored May 31, 2024
2 parents 0eb7121 + 4193bb2 commit 8f9c68e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions debug/gdbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ def test(self):
self.gdb.command("delete")
#self.gdb.hbreak("rot13")
tdata1 = MCONTROL_DMODE(self.hart.xlen)
tdata1 = set_field(tdata1, MCONTROL_TYPE(self.hart.xlen),
MCONTROL_TYPE_MATCH)
tdata1 = set_field(tdata1, MCONTROL_ACTION, MCONTROL_ACTION_DEBUG_MODE)
tdata1 = set_field(tdata1, MCONTROL_MATCH, MCONTROL_MATCH_EQUAL)
tdata1 |= MCONTROL_M | MCONTROL_S | MCONTROL_U | MCONTROL_EXECUTE
Expand All @@ -697,20 +699,30 @@ def test(self):
value = self.gdb.p("$tselect")
if value != tselect:
raise TestNotApplicable
# Need to disable the trigger before writing tdata2
self.gdb.p("$tdata1=0")
# Need to write a valid value to tdata2 before writing tdata1
self.gdb.p("$tdata2=&rot13")
self.gdb.p(f"$tdata1=0x{tdata1:x}")
value = self.gdb.p("$tselect")
value = self.gdb.p("$tdata1")
if value == tdata1:
break
if value & MCONTROL_TYPE(self.hart.xlen) == MCONTROL_TYPE_NONE:
raise TestNotApplicable
self.gdb.p("$tdata1=0")
tselect += 1

self.gdb.p("$tdata2=&rot13")
# The breakpoint should be hit exactly 2 times.
for _ in range(2):
output = self.gdb.c(ops=2)
self.gdb.p("$pc")
assertEqual(self.gdb.p("$pc"), self.gdb.p("&rot13"))
assertRegex(output, r"[bB]reakpoint")
assertIn("rot13 ", output)

# Hardware breakpoint are removed by the binary in handle_reset.
# This changes tselect. Therefore GDB needs to restore it.
self.gdb.p(f"$tselect={tselect}")

self.gdb.p("$tdata2=&crc32a")
self.gdb.c()
before = self.gdb.p("$pc")
Expand All @@ -719,6 +731,10 @@ def test(self):
after = self.gdb.p("$pc")
assertNotEqual(before, after)

# Remove the manual HW breakpoint.
assertEqual(tselect, self.gdb.p("$tselect"))
self.gdb.p("$tdata1=0")

self.gdb.b("_exit")
self.exit()

Expand Down

0 comments on commit 8f9c68e

Please sign in to comment.