提交 3f2335f2 编写于 作者: A aarzilli 提交者: Derek Parker

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.
上级 26df58af
......@@ -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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册