refactor(debug): move watchpoint slot state into the session

This commit is contained in:
2026-09-14 18:22:00 +02:00
parent 909f874797
commit 4f190ee1a2
7 changed files with 38 additions and 51 deletions
+7 -10
View File
@@ -22,9 +22,6 @@ const (
WatchRead WatchpointType = 3
)
// wpSlots tracks watchpoint slot occupancy.
var wpSlots [16]bool // arm64 supports up to 16 watchpoints
const maxWatchpoints = 16
// hwBreakState mirrors the kernel's struct user_hwdebug_state.
@@ -45,7 +42,7 @@ const (
func (s *Session) FindFreeWatchpointSlot() int {
for i := range maxWatchpoints {
if !wpSlots[i] {
if !s.wpSlots[i] {
return i
}
}
@@ -56,7 +53,7 @@ func (s *Session) IsWatchpointSlotUsed(slot int) bool {
if slot < 0 || slot >= maxWatchpoints {
return false
}
return wpSlots[slot]
return s.wpSlots[slot]
}
// SetWatchpoint installs a hardware watchpoint on the given address.
@@ -64,7 +61,7 @@ func (s *Session) SetWatchpoint(slot int, addr uint64, typ WatchpointType, size
if slot < 0 || slot >= maxWatchpoints {
return fmt.Errorf("debug: watchpoint slot must be 0-%d", maxWatchpoints-1)
}
if wpSlots[slot] {
if s.wpSlots[slot] {
return fmt.Errorf("debug: watchpoint slot %d already in use", slot)
}
@@ -105,7 +102,7 @@ func (s *Session) SetWatchpoint(slot int, addr uint64, typ WatchpointType, size
return fmt.Errorf("debug: set watchpoint: %w", err)
}
wpSlots[slot] = true
s.wpSlots[slot] = true
return nil
}
@@ -113,7 +110,7 @@ func (s *Session) ClearWatchpoint(slot int) error {
if slot < 0 || slot >= maxWatchpoints {
return fmt.Errorf("debug: watchpoint slot must be 0-%d", maxWatchpoints-1)
}
if !wpSlots[slot] {
if !s.wpSlots[slot] {
return fmt.Errorf("debug: watchpoint slot %d is not in use", slot)
}
@@ -126,13 +123,13 @@ func (s *Session) ClearWatchpoint(slot int) error {
if err := s.setHWBreakState(state); err != nil {
return err
}
wpSlots[slot] = false
s.wpSlots[slot] = false
return nil
}
func (s *Session) ClearAllWatchpoints() error {
for slot := 0; slot < maxWatchpoints; slot++ {
if wpSlots[slot] {
if s.wpSlots[slot] {
if err := s.ClearWatchpoint(slot); err != nil {
return err
}