From af9e97b69720e009340c18f76562b0f915bbc394 Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Sat, 5 Sep 2015 17:23:59 -0500 Subject: [PATCH] service/debugger: Use PC instead of scope in Location.Find --- service/debugger/debugger.go | 4 ++-- service/debugger/locations.go | 23 ++++++++--------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 2c15e1bc..4e52041b 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -502,12 +502,12 @@ func (d *Debugger) FindLocation(scope api.EvalScope, locStr string) ([]api.Locat return nil, err } - s, err := d.process.ConvertEvalScope(scope.GoroutineID, scope.Frame) + pc, err := d.process.PC() if err != nil { return nil, err } - locs, err := loc.Find(d, s, locStr) + locs, err := loc.Find(d, pc, locStr) for i := range locs { file, line, fn := d.process.PCToLine(locs[i].PC) locs[i].File = file diff --git a/service/debugger/locations.go b/service/debugger/locations.go index 5afa2731..d1d56f17 100644 --- a/service/debugger/locations.go +++ b/service/debugger/locations.go @@ -7,14 +7,13 @@ import ( "strconv" "strings" - "github.com/derekparker/delve/proc" "github.com/derekparker/delve/service/api" ) const maxFindLocationCandidates = 5 type LocationSpec interface { - Find(d *Debugger, scope *proc.EvalScope, locStr string) ([]api.Location, error) + Find(d *Debugger, pc uint64, locStr string) ([]api.Location, error) } type NormalLocationSpec struct { @@ -205,7 +204,7 @@ func (spec *FuncLocationSpec) Match(sym *gosym.Sym) bool { return true } -func (loc *RegexLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr string) ([]api.Location, error) { +func (loc *RegexLocationSpec) Find(d *Debugger, pc uint64, locStr string) ([]api.Location, error) { funcs := d.process.Funcs() matches, err := regexFilterFuncs(loc.FuncRegex, funcs) if err != nil { @@ -221,7 +220,7 @@ func (loc *RegexLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr st return r, nil } -func (loc *AddrLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr string) ([]api.Location, error) { +func (loc *AddrLocationSpec) Find(d *Debugger, pc uint64, locStr string) ([]api.Location, error) { return []api.Location{{PC: loc.Addr}}, nil } @@ -248,7 +247,7 @@ func (ale AmbiguousLocationError) Error() string { return fmt.Sprintf("Location \"%s\" ambiguous: %s…", ale.Location, strings.Join(candidates, ", ")) } -func (loc *NormalLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr string) ([]api.Location, error) { +func (loc *NormalLocationSpec) Find(d *Debugger, pc uint64, locStr string) ([]api.Location, error) { funcs := d.process.Funcs() files := d.process.Sources() @@ -304,11 +303,8 @@ func (loc *NormalLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s } } -func (loc *OffsetLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr string) ([]api.Location, error) { - if scope == nil { - return nil, fmt.Errorf("could not determine current location (scope is nil)") - } - file, line, fn := d.process.PCToLine(scope.PC) +func (loc *OffsetLocationSpec) Find(d *Debugger, pc uint64, locStr string) ([]api.Location, error) { + file, line, fn := d.process.PCToLine(pc) if fn == nil { return nil, fmt.Errorf("could not determine current location") } @@ -316,11 +312,8 @@ func (loc *OffsetLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s return []api.Location{{PC: addr}}, err } -func (loc *LineLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr string) ([]api.Location, error) { - if scope == nil { - return nil, fmt.Errorf("could not determine current location (scope is nil)") - } - file, _, fn := d.process.PCToLine(scope.PC) +func (loc *LineLocationSpec) Find(d *Debugger, pc uint64, locStr string) ([]api.Location, error) { + file, _, fn := d.process.PCToLine(pc) if fn == nil { return nil, fmt.Errorf("could not determine current location") }