fix(debug): make ptrace sessions reliable on Go tracees

This commit is contained in:
2026-08-30 22:35:22 +02:00
parent 96cc70731f
commit 9cb1666b35
6 changed files with 232 additions and 39 deletions
+21 -12
View File
@@ -223,29 +223,38 @@ REPL commands:
return 1
}
}
hits := map[uint64]int{}
traps := 0
fmt.Printf("gasm debug: coverage run over %d instructions\n", len(instrs))
for {
for _, bp := range bm.All() {
bm.Reinsert(bp.Addr)
}
// Remove the breakpoint the run is parked on, count the hit,
// then continue.
regs, rerr := sess.GetRegs()
if rerr == nil {
if bp := bm.At(regs.GetPC()); bp != nil {
bm.Clear(bp.Addr)
traps++
hits[regs.GetPC()-base]++
}
}
if err := sess.Continue(); err != nil {
break // debuggee finished or died
}
if sess.Exited() {
break
}
regs, rerr := sess.GetRegs()
if rerr != nil {
break
}
// HandleTrap restores the original byte, rewinds PC and counts
// the hit on the breakpoint itself. Single-step over the
// restored instruction so the reinsertion at the top of the
// loop cannot re-trap on the same breakpoint.
if bp := bm.HandleTrap(&regs); bp != nil {
if err := sess.Step(); err != nil {
break
}
}
}
hits := map[uint64]int{}
traps := 0
for _, bp := range bm.All() {
if n := bp.Hits(); n > 0 {
hits[bp.Addr-base] = n
traps += n
}
}
var hit []string
var missed []string