Skip to content

Commit 3b90f2c

Browse files
Use disassemble instead of calling DynamicCallReg field to get the destination function address in CALL Reg instruction
1 parent 121dc1b commit 3b90f2c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

service/debugger/debugger.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,8 +1481,21 @@ func (d *Debugger) traverse(t proc.ValidTargets, f *proc.Function, depth int, fo
14811481
return false, fmt.Errorf("registers inside callback returned err")
14821482

14831483
}
1484-
dregs := tgt.BinInfo().Arch.RegistersToDwarfRegisters(0, regs)
1485-
addr := dregs.Uint64Val(tgt.BinInfo().Arch.DynamicCallReg)
1484+
// Disassemble the instruction at the current PC to get the call destination
1485+
pc := instr.Loc.PC
1486+
maxInstLen := uint64(tgt.BinInfo().Arch.MaxInstructionLength())
1487+
disasm, err := proc.Disassemble(t.Memory(), regs, t.Breakpoints(), tgt.BinInfo(), pc, pc+maxInstLen)
1488+
if err != nil {
1489+
return false, fmt.Errorf("failed to disassemble instruction: %w", err)
1490+
}
1491+
1492+
// Extract address from the decoded instruction's destination location
1493+
var addr uint64
1494+
if len(disasm) > 0 && disasm[0].DestLoc != nil {
1495+
addr = disasm[0].DestLoc.PC
1496+
} else {
1497+
return false, fmt.Errorf("failed to extract call destination from instruction at PC %#x", pc)
1498+
}
14861499
fn := tgt.BinInfo().PCToFunc(addr)
14871500
if fn == nil {
14881501
return false, fmt.Errorf("PCToFunc returned nil")

0 commit comments

Comments
 (0)