fix(debug): handle mapping edges, stray traps and dying debuggees
Assisted-by: GLM 5.3
This commit is contained in:
@@ -14,17 +14,25 @@ import (
|
||||
)
|
||||
|
||||
// Disassemble decodes the instruction at the given address in the debuggee's
|
||||
// memory and returns its text representation and length in bytes.
|
||||
// memory and returns its text representation and length in bytes. The read
|
||||
// shrinks from 4 to 2 bytes when the full word crosses into unmapped memory:
|
||||
// a compressed instruction at the mapping's end still fits the shorter
|
||||
// window, and an instruction can never extend past the mapping that holds it.
|
||||
func (s *Session) Disassemble(addr uint64) (string, int, error) {
|
||||
mem, err := s.ReadMemory(addr, 4)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
var lastErr error
|
||||
for _, n := range []int{4, 2} {
|
||||
mem, err := s.ReadMemory(addr, n)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
}
|
||||
ins, derr := disasm.Decode(arch.RISCV, mem, addr)
|
||||
if derr != nil {
|
||||
return "", 0, derr
|
||||
}
|
||||
return ins.Text, ins.Len, nil
|
||||
}
|
||||
ins, err := disasm.Decode(arch.RISCV, mem, addr)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
return ins.Text, ins.Len, nil
|
||||
return "", 0, lastErr
|
||||
}
|
||||
|
||||
// DisassembleN decodes up to n instructions starting at addr.
|
||||
|
||||
Reference in New Issue
Block a user