Disassemble command

Implements #368
This commit is contained in:
aarzilli
2016-02-06 07:00:48 +01:00
committed by Derek Parker
parent b370e20cd5
commit e7a9a3ea9a
26 changed files with 14830 additions and 3 deletions

View File

@ -575,3 +575,41 @@ func (d *Debugger) FindLocation(scope api.EvalScope, locStr string) ([]api.Locat
}
return locs, err
}
// Disassembles code between startPC and endPC
// if endPC == 0 it will find the function containing startPC and disassemble the whole function
func (d *Debugger) Disassemble(scope api.EvalScope, startPC, endPC uint64, flavour api.AssemblyFlavour) (api.AsmInstructions, error) {
if endPC == 0 {
_, _, fn := d.process.PCToLine(startPC)
if fn == nil {
return nil, fmt.Errorf("Address 0x%x does not belong to any function", startPC)
}
startPC = fn.Entry
endPC = fn.End
}
s, err := d.process.ConvertEvalScope(scope.GoroutineID, scope.Frame)
if err != nil {
return nil, err
}
currentGoroutine := true
if scope.GoroutineID != -1 {
g, _ := s.Thread.GetG()
if g == nil || g.ID != scope.GoroutineID {
currentGoroutine = false
}
}
insts, err := s.Thread.Disassemble(startPC, endPC, currentGoroutine)
if err != nil {
return nil, err
}
disass := make(api.AsmInstructions, len(insts))
for i := range insts {
disass[i] = api.ConvertAsmInstruction(insts[i], insts[i].Text(proc.AssemblyFlavour(flavour)))
}
return disass, nil
}