Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: fix HwbpManual test #557

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
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
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
Loading