fix(debug): handle mapping edges, stray traps and dying debuggees

Assisted-by: GLM 5.3
This commit is contained in:
2026-10-02 00:40:54 +02:00
parent dd1782c538
commit f57377abb9
19 changed files with 726 additions and 97 deletions
+44
View File
@@ -10,6 +10,8 @@ package debug
// build on every supported linux architecture.
import (
"fmt"
"slices"
"strings"
"testing"
)
@@ -263,3 +265,45 @@ func TestConditionString(t *testing.T) {
}
}
}
// TestBreakpointsInfoOrdered proves the listing is ordered by address: the
// numbers it prints are map keys rendered in iteration order otherwise, so
// the same set of breakpoints would renumber itself between calls.
func TestBreakpointsInfoOrdered(t *testing.T) {
tr := newMockTracer()
bm := NewBreakpoints(tr)
addrs := []uint64{0x9000, 0x1000, 0x7000, 0x3000, 0x8000, 0x2000,
0x6000, 0x4000, 0x5000, 0xa000}
for i, a := range addrs {
if _, err := bm.Set(a, fmt.Sprintf("bp%d", i)); err != nil {
t.Fatalf("Set(%#x): %v", a, err)
}
}
sorted := append([]uint64(nil), addrs...)
slices.Sort(sorted)
info := bm.Info()
for i, a := range sorted {
want := fmt.Sprintf(" %d: bp%d at %#x", i+1, indexOf(addrs, a), a)
if !strings.Contains(info, want) {
t.Errorf("Info() missing %q; listing:\n%s", want, info)
}
}
// The numbers themselves must ascend: "1:" before "2" ... "10".
pos := 0
for i := range len(addrs) {
next := strings.Index(info[pos:], fmt.Sprintf(" %d: ", i+1))
if next < 0 {
t.Fatalf("Info() has no entry %d; listing:\n%s", i+1, info)
}
pos += next
}
}
func indexOf(addrs []uint64, a uint64) int {
for i, v := range addrs {
if v == a {
return i
}
}
return -1
}