debugger/locations: locspec "+0" should always evaluate to the current PC
So far we have evaluated the locspec "+0" the same way we evaluate all "+n" locspecs, this means that we turn the current PC into a file:line pair, then we turn back the file:line into a PC address. Normally this is harmless, however all autogenerated code returns the source position "<autogenerated>:1" which resolves back to the very first autogenerated instruction in the code. This messes up the behaviour of the "disassemble" command which uses the locspec "+0" to figure out what code to disassemble if no arguments are passed. We should make +0 always resolve to the current PC (of the given scope) so that clients can use +0 as a default locspec.
This commit is contained in:
parent
26df58af7e
commit
3f2335f289
@ -677,3 +677,15 @@ func TestConfig(t *testing.T) {
|
||||
t.Fatalf("new alias found after delete")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisassembleAutogenerated(t *testing.T) {
|
||||
// Executing the 'disassemble' command on autogenerated code should work correctly
|
||||
withTestTerminal("math", t, func(term *FakeTerminal) {
|
||||
term.MustExec("break main.init")
|
||||
term.MustExec("continue")
|
||||
out := term.MustExec("disassemble")
|
||||
if !strings.Contains(out, "TEXT main.init(SB) ") {
|
||||
t.Fatalf("output of disassemble wasn't for the main.init function %q", out)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -397,6 +397,9 @@ func (loc *OffsetLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s
|
||||
if scope == nil {
|
||||
return nil, fmt.Errorf("could not determine current location (scope is nil)")
|
||||
}
|
||||
if loc.Offset == 0 {
|
||||
return []api.Location{{PC: scope.PC}}, nil
|
||||
}
|
||||
file, line, fn := d.target.BinInfo().PCToLine(scope.PC)
|
||||
if fn == nil {
|
||||
return nil, fmt.Errorf("could not determine current location")
|
||||
|
Loading…
Reference in New Issue
Block a user