Minor post-refactoring cleanup (#808)

* proc/native: remove unused utility methods

* proc: turn FindFileLocation, FindFunctionLocation, FirstPCAfterPrologue methods into function
This commit is contained in:
Alessandro Arzilli 2017-04-28 19:15:39 +02:00 committed by Derek Parker
parent 24b20099aa
commit a731eb661f
11 changed files with 48 additions and 162 deletions

@ -1,7 +1,6 @@
package core package core
import ( import (
"debug/gosym"
"errors" "errors"
"fmt" "fmt"
"go/ast" "go/ast"
@ -277,18 +276,6 @@ func (p *Process) Exited() bool {
return false return false
} }
func (p *Process) FindFileLocation(fileName string, lineNumber int) (uint64, error) {
return proc.FindFileLocation(p.CurrentThread(), p.breakpoints, &p.bi, fileName, lineNumber)
}
func (p *Process) FirstPCAfterPrologue(fn *gosym.Func, sameline bool) (uint64, error) {
return proc.FirstPCAfterPrologue(p.CurrentThread(), p.breakpoints, &p.bi, fn, sameline)
}
func (p *Process) FindFunctionLocation(funcName string, firstLine bool, lineOffset int) (uint64, error) {
return proc.FindFunctionLocation(p.CurrentThread(), p.breakpoints, &p.bi, funcName, firstLine, lineOffset)
}
func (p *Process) AllGCache() *[]*proc.G { func (p *Process) AllGCache() *[]*proc.G {
return &p.allGCache return &p.allGCache
} }

@ -142,7 +142,10 @@ func init() {
// FirstPCAfterPrologue returns the address of the first instruction after the prologue for function fn // FirstPCAfterPrologue returns the address of the first instruction after the prologue for function fn
// If sameline is set FirstPCAfterPrologue will always return an address associated with the same line as fn.Entry // If sameline is set FirstPCAfterPrologue will always return an address associated with the same line as fn.Entry
func FirstPCAfterPrologue(mem MemoryReadWriter, breakpoints map[uint64]*Breakpoint, bi *BinaryInfo, fn *gosym.Func, sameline bool) (uint64, error) { func FirstPCAfterPrologue(p Process, fn *gosym.Func, sameline bool) (uint64, error) {
var mem MemoryReadWriter = p.CurrentThread()
breakpoints := p.Breakpoints()
bi := p.BinInfo()
text, err := disassemble(mem, nil, breakpoints, bi, fn.Entry, fn.End) text, err := disassemble(mem, nil, breakpoints, bi, fn.Entry, fn.End)
if err != nil { if err != nil {
return fn.Entry, err return fn.Entry, err

@ -62,7 +62,6 @@
package gdbserial package gdbserial
import ( import (
"debug/gosym"
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
@ -259,7 +258,7 @@ func Connect(addr string, path string, pid int, attempts int) (*Process, error)
p.bi.Arch.SetGStructOffset(ver, isextld) p.bi.Arch.SetGStructOffset(ver, isextld)
p.selectedGoroutine, _ = proc.GetG(p.CurrentThread()) p.selectedGoroutine, _ = proc.GetG(p.CurrentThread())
panicpc, err := p.FindFunctionLocation("runtime.startpanic", true, 0) panicpc, err := proc.FindFunctionLocation(p, "runtime.startpanic", true, 0)
if err == nil { if err == nil {
bp, err := p.SetBreakpoint(panicpc, proc.UserBreakpoint, nil) bp, err := p.SetBreakpoint(panicpc, proc.UserBreakpoint, nil)
if err == nil { if err == nil {
@ -417,18 +416,6 @@ func (p *Process) Running() bool {
return p.conn.running return p.conn.running
} }
func (p *Process) FindFileLocation(fileName string, lineNumber int) (uint64, error) {
return proc.FindFileLocation(p.CurrentThread(), p.breakpoints, &p.bi, fileName, lineNumber)
}
func (p *Process) FirstPCAfterPrologue(fn *gosym.Func, sameline bool) (uint64, error) {
return proc.FirstPCAfterPrologue(p.CurrentThread(), p.breakpoints, &p.bi, fn, sameline)
}
func (p *Process) FindFunctionLocation(funcName string, firstLine bool, lineOffset int) (uint64, error) {
return proc.FindFunctionLocation(p.CurrentThread(), p.breakpoints, &p.bi, funcName, firstLine, lineOffset)
}
func (p *Process) FindThread(threadID int) (proc.Thread, bool) { func (p *Process) FindThread(threadID int) (proc.Thread, bool) {
thread, ok := p.threads[threadID] thread, ok := p.threads[threadID]
return thread, ok return thread, ok

@ -1,7 +1,6 @@
package proc package proc
import ( import (
"debug/gosym"
"go/ast" "go/ast"
) )
@ -22,30 +21,6 @@ type Info interface {
ThreadInfo ThreadInfo
GoroutineInfo GoroutineInfo
// FindFileLocation returns the address of the first instruction belonging
// to line lineNumber in file fileName.
FindFileLocation(fileName string, lineNumber int) (uint64, error)
// FirstPCAfterPrologue returns the first instruction address after fn's
// prologue.
// If sameline is true and the first instruction after the prologue belongs
// to a different source line the entry point will be returned instead.
FirstPCAfterPrologue(fn *gosym.Func, sameline bool) (uint64, error)
// FindFunctionLocation finds address of a function's line
//
// If firstLine == true is passed FindFunctionLocation will attempt to find
// the first line of the function.
//
// If lineOffset is passed FindFunctionLocation will return the address of
// that line.
//
// Pass lineOffset == 0 and firstLine == false if you want the address for
// the function's entry point. Note that setting breakpoints at that
// address will cause surprising behavior:
// https://github.com/derekparker/delve/issues/170
FindFunctionLocation(funcName string, firstLine bool, lineOffset int) (uint64, error)
} }
// ThreadInfo is an interface for getting information on active threads // ThreadInfo is an interface for getting information on active threads

@ -1,7 +1,6 @@
package native package native
import ( import (
"debug/gosym"
"errors" "errors"
"fmt" "fmt"
"go/ast" "go/ast"
@ -165,23 +164,6 @@ func (dbp *Process) LoadInformation(path string) error {
return nil return nil
} }
func (dbp *Process) FindFunctionLocation(funcName string, firstLine bool, lineOffset int) (uint64, error) {
return proc.FindFunctionLocation(dbp.currentThread, dbp.breakpoints, &dbp.bi, funcName, firstLine, lineOffset)
}
func (dbp *Process) FindFileLocation(fileName string, lineno int) (uint64, error) {
return proc.FindFileLocation(dbp.currentThread, dbp.breakpoints, &dbp.bi, fileName, lineno)
}
func (dbp *Process) FirstPCAfterPrologue(fn *gosym.Func, sameline bool) (uint64, error) {
return proc.FirstPCAfterPrologue(dbp.currentThread, dbp.breakpoints, &dbp.bi, fn, sameline)
}
// CurrentLocation returns the location of the current thread.
func (dbp *Process) CurrentLocation() (*proc.Location, error) {
return dbp.currentThread.Location()
}
// RequestManualStop sets the `halt` flag and // RequestManualStop sets the `halt` flag and
// sends SIGSTOP to all threads. // sends SIGSTOP to all threads.
func (dbp *Process) RequestManualStop() error { func (dbp *Process) RequestManualStop() error {
@ -259,11 +241,6 @@ func (dbp *Process) ClearBreakpoint(addr uint64) (*proc.Breakpoint, error) {
return bp, nil return bp, nil
} }
// Status returns the status of the current main thread context.
func (dbp *Process) Status() *WaitStatus {
return dbp.currentThread.Status
}
func (dbp *Process) ContinueOnce() (proc.Thread, error) { func (dbp *Process) ContinueOnce() (proc.Thread, error) {
if dbp.exited { if dbp.exited {
return nil, &proc.ProcessExitedError{} return nil, &proc.ProcessExitedError{}
@ -365,33 +342,6 @@ func (dbp *Process) Halt() (err error) {
return nil return nil
} }
// Registers obtains register values from the
// "current" thread of the traced process.
func (dbp *Process) Registers() (proc.Registers, error) {
return dbp.currentThread.Registers(false)
}
// PC returns the PC of the current thread.
func (dbp *Process) PC() (uint64, error) {
return dbp.currentThread.PC()
}
// CurrentBreakpoint returns the breakpoint the current thread
// is stopped at.
func (dbp *Process) CurrentBreakpoint() *proc.Breakpoint {
return dbp.currentThread.CurrentBreakpoint
}
// FindBreakpointByID finds the breakpoint for the given ID.
func (dbp *Process) FindBreakpointByID(id int) (*proc.Breakpoint, bool) {
for _, bp := range dbp.breakpoints {
if bp.ID == id {
return bp, true
}
}
return nil, false
}
// FindBreakpoint finds the breakpoint for the given pc. // FindBreakpoint finds the breakpoint for the given pc.
func (dbp *Process) FindBreakpoint(pc uint64) (*proc.Breakpoint, bool) { func (dbp *Process) FindBreakpoint(pc uint64) (*proc.Breakpoint, bool) {
// Check to see if address is past the breakpoint, (i.e. breakpoint was hit). // Check to see if address is past the breakpoint, (i.e. breakpoint was hit).
@ -446,7 +396,7 @@ func initializeDebugProcess(dbp *Process, path string, attach bool) (*Process, e
// the offset of g struct inside TLS // the offset of g struct inside TLS
dbp.selectedGoroutine, _ = proc.GetG(dbp.currentThread) dbp.selectedGoroutine, _ = proc.GetG(dbp.currentThread)
panicpc, err := dbp.FindFunctionLocation("runtime.startpanic", true, 0) panicpc, err := proc.FindFunctionLocation(dbp, "runtime.startpanic", true, 0)
if err == nil { if err == nil {
bp, err := dbp.SetBreakpoint(panicpc, proc.UserBreakpoint, nil) bp, err := dbp.SetBreakpoint(panicpc, proc.UserBreakpoint, nil)
if err == nil { if err == nil {
@ -507,19 +457,3 @@ func (dbp *Process) writeSoftwareBreakpoint(thread *Thread, addr uint64) error {
func (dbp *Process) AllGCache() *[]*proc.G { func (dbp *Process) AllGCache() *[]*proc.G {
return &dbp.allGCache return &dbp.allGCache
} }
/*
// EvalPackageVariable will evaluate the package level variable
// specified by 'name'.
func (dbp *Process) EvalPackageVariable(name string, cfg proc.LoadConfig) (*proc.Variable, error) {
scope := &proc.EvalScope{0, 0, dbp.currentThread, nil, dbp.BinInfo()}
v, err := scope.packageVarAddr(name)
if err != nil {
return nil, err
}
v.loadValue(cfg)
return v, nil
}
*/

@ -189,7 +189,6 @@ func (t *Thread) Registers(floatingPoint bool) (proc.Registers, error) {
return registers(t, floatingPoint) return registers(t, floatingPoint)
} }
// PC returns the current PC for this thread.
func (t *Thread) PC() (uint64, error) { func (t *Thread) PC() (uint64, error) {
regs, err := t.Registers(false) regs, err := t.Registers(false)
if err != nil { if err != nil {

@ -34,13 +34,13 @@ func (pe ProcessExitedError) Error() string {
// FindFileLocation returns the PC for a given file:line. // FindFileLocation returns the PC for a given file:line.
// Assumes that `file` is normailzed to lower case and '/' on Windows. // Assumes that `file` is normailzed to lower case and '/' on Windows.
func FindFileLocation(mem MemoryReadWriter, breakpoints map[uint64]*Breakpoint, bi *BinaryInfo, fileName string, lineno int) (uint64, error) { func FindFileLocation(p Process, fileName string, lineno int) (uint64, error) {
pc, fn, err := bi.goSymTable.LineToPC(fileName, lineno) pc, fn, err := p.BinInfo().goSymTable.LineToPC(fileName, lineno)
if err != nil { if err != nil {
return 0, err return 0, err
} }
if fn.Entry == pc { if fn.Entry == pc {
pc, _ = FirstPCAfterPrologue(mem, breakpoints, bi, fn, true) pc, _ = FirstPCAfterPrologue(p, fn, true)
} }
return pc, nil return pc, nil
} }
@ -51,14 +51,15 @@ func FindFileLocation(mem MemoryReadWriter, breakpoints map[uint64]*Breakpoint,
// Pass lineOffset == 0 and firstLine == false if you want the address for the function's entry point // Pass lineOffset == 0 and firstLine == false if you want the address for the function's entry point
// Note that setting breakpoints at that address will cause surprising behavior: // Note that setting breakpoints at that address will cause surprising behavior:
// https://github.com/derekparker/delve/issues/170 // https://github.com/derekparker/delve/issues/170
func FindFunctionLocation(mem MemoryReadWriter, breakpoints map[uint64]*Breakpoint, bi *BinaryInfo, funcName string, firstLine bool, lineOffset int) (uint64, error) { func FindFunctionLocation(p Process, funcName string, firstLine bool, lineOffset int) (uint64, error) {
bi := p.BinInfo()
origfn := bi.goSymTable.LookupFunc(funcName) origfn := bi.goSymTable.LookupFunc(funcName)
if origfn == nil { if origfn == nil {
return 0, fmt.Errorf("Could not find function %s\n", funcName) return 0, fmt.Errorf("Could not find function %s\n", funcName)
} }
if firstLine { if firstLine {
return FirstPCAfterPrologue(mem, breakpoints, bi, origfn, false) return FirstPCAfterPrologue(p, origfn, false)
} else if lineOffset > 0 { } else if lineOffset > 0 {
filename, lineno, _ := bi.goSymTable.PCToLine(origfn.Entry) filename, lineno, _ := bi.goSymTable.PCToLine(origfn.Entry)
breakAddr, _, err := bi.goSymTable.LineToPC(filename, lineno+lineOffset) breakAddr, _, err := bi.goSymTable.LineToPC(filename, lineno+lineOffset)
@ -272,7 +273,7 @@ func StepOut(dbp Process) error {
deferPCEntry := selg.DeferPC() deferPCEntry := selg.DeferPC()
if deferPCEntry != 0 { if deferPCEntry != 0 {
_, _, deferfn := dbp.BinInfo().PCToLine(deferPCEntry) _, _, deferfn := dbp.BinInfo().PCToLine(deferPCEntry)
deferpc, err = dbp.FirstPCAfterPrologue(deferfn, false) deferpc, err = FirstPCAfterPrologue(dbp, deferfn, false)
if err != nil { if err != nil {
return err return err
} }

@ -168,7 +168,7 @@ func TestExitAfterContinue(t *testing.T) {
} }
func setFunctionBreakpoint(p proc.Process, fname string) (*proc.Breakpoint, error) { func setFunctionBreakpoint(p proc.Process, fname string) (*proc.Breakpoint, error) {
addr, err := p.FindFunctionLocation(fname, true, 0) addr, err := proc.FindFunctionLocation(p, fname, true, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -176,7 +176,7 @@ func setFunctionBreakpoint(p proc.Process, fname string) (*proc.Breakpoint, erro
} }
func setFileBreakpoint(p proc.Process, t *testing.T, fixture protest.Fixture, lineno int) *proc.Breakpoint { func setFileBreakpoint(p proc.Process, t *testing.T, fixture protest.Fixture, lineno int) *proc.Breakpoint {
addr, err := p.FindFileLocation(fixture.Source, lineno) addr, err := proc.FindFileLocation(p, fixture.Source, lineno)
if err != nil { if err != nil {
t.Fatalf("FindFileLocation: %v", err) t.Fatalf("FindFileLocation: %v", err)
} }
@ -235,7 +235,7 @@ func TestHalt(t *testing.T) {
func TestStep(t *testing.T) { func TestStep(t *testing.T) {
withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) {
helloworldaddr, err := p.FindFunctionLocation("main.helloworld", false, 0) helloworldaddr, err := proc.FindFunctionLocation(p, "main.helloworld", false, 0)
assertNoError(err, t, "FindFunctionLocation") assertNoError(err, t, "FindFunctionLocation")
_, err = p.SetBreakpoint(helloworldaddr, proc.UserBreakpoint, nil) _, err = p.SetBreakpoint(helloworldaddr, proc.UserBreakpoint, nil)
@ -257,7 +257,7 @@ func TestStep(t *testing.T) {
func TestBreakpoint(t *testing.T) { func TestBreakpoint(t *testing.T) {
withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) {
helloworldaddr, err := p.FindFunctionLocation("main.helloworld", false, 0) helloworldaddr, err := proc.FindFunctionLocation(p, "main.helloworld", false, 0)
assertNoError(err, t, "FindFunctionLocation") assertNoError(err, t, "FindFunctionLocation")
bp, err := p.SetBreakpoint(helloworldaddr, proc.UserBreakpoint, nil) bp, err := p.SetBreakpoint(helloworldaddr, proc.UserBreakpoint, nil)
@ -281,7 +281,7 @@ func TestBreakpoint(t *testing.T) {
func TestBreakpointInSeperateGoRoutine(t *testing.T) { func TestBreakpointInSeperateGoRoutine(t *testing.T) {
withTestProcess("testthreads", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("testthreads", t, func(p proc.Process, fixture protest.Fixture) {
fnentry, err := p.FindFunctionLocation("main.anotherthread", false, 0) fnentry, err := proc.FindFunctionLocation(p, "main.anotherthread", false, 0)
assertNoError(err, t, "FindFunctionLocation") assertNoError(err, t, "FindFunctionLocation")
_, err = p.SetBreakpoint(fnentry, proc.UserBreakpoint, nil) _, err = p.SetBreakpoint(fnentry, proc.UserBreakpoint, nil)
@ -311,7 +311,7 @@ func TestBreakpointWithNonExistantFunction(t *testing.T) {
func TestClearBreakpointBreakpoint(t *testing.T) { func TestClearBreakpointBreakpoint(t *testing.T) {
withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) {
fnentry, err := p.FindFunctionLocation("main.sleepytime", false, 0) fnentry, err := proc.FindFunctionLocation(p, "main.sleepytime", false, 0)
assertNoError(err, t, "FindFunctionLocation") assertNoError(err, t, "FindFunctionLocation")
bp, err := p.SetBreakpoint(fnentry, proc.UserBreakpoint, nil) bp, err := p.SetBreakpoint(fnentry, proc.UserBreakpoint, nil)
assertNoError(err, t, "SetBreakpoint()") assertNoError(err, t, "SetBreakpoint()")
@ -362,7 +362,7 @@ func testseq(program string, contFunc contFunc, testcases []nextTest, initialLoc
bp, err = setFunctionBreakpoint(p, initialLocation) bp, err = setFunctionBreakpoint(p, initialLocation)
} else { } else {
var pc uint64 var pc uint64
pc, err = p.FindFileLocation(fixture.Source, testcases[0].begin) pc, err = proc.FindFileLocation(p, fixture.Source, testcases[0].begin)
assertNoError(err, t, "FindFileLocation()") assertNoError(err, t, "FindFileLocation()")
bp, err = p.SetBreakpoint(pc, proc.UserBreakpoint, nil) bp, err = p.SetBreakpoint(pc, proc.UserBreakpoint, nil)
} }
@ -655,7 +655,7 @@ func TestFindReturnAddress(t *testing.T) {
func TestFindReturnAddressTopOfStackFn(t *testing.T) { func TestFindReturnAddressTopOfStackFn(t *testing.T) {
withTestProcess("testreturnaddress", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("testreturnaddress", t, func(p proc.Process, fixture protest.Fixture) {
fnName := "runtime.rt0_go" fnName := "runtime.rt0_go"
fnentry, err := p.FindFunctionLocation(fnName, false, 0) fnentry, err := proc.FindFunctionLocation(p, fnName, false, 0)
assertNoError(err, t, "FindFunctionLocation") assertNoError(err, t, "FindFunctionLocation")
if _, err := p.SetBreakpoint(fnentry, proc.UserBreakpoint, nil); err != nil { if _, err := p.SetBreakpoint(fnentry, proc.UserBreakpoint, nil); err != nil {
t.Fatal(err) t.Fatal(err)
@ -676,7 +676,7 @@ func TestSwitchThread(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("Expected error for invalid thread id") t.Fatal("Expected error for invalid thread id")
} }
pc, err := p.FindFunctionLocation("main.main", true, 0) pc, err := proc.FindFunctionLocation(p, "main.main", true, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -721,7 +721,7 @@ func TestCGONext(t *testing.T) {
} }
withTestProcess("cgotest", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("cgotest", t, func(p proc.Process, fixture protest.Fixture) {
pc, err := p.FindFunctionLocation("main.main", true, 0) pc, err := proc.FindFunctionLocation(p, "main.main", true, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1022,7 +1022,7 @@ func TestParseVersionString(t *testing.T) {
func TestBreakpointOnFunctionEntry(t *testing.T) { func TestBreakpointOnFunctionEntry(t *testing.T) {
withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) {
addr, err := p.FindFunctionLocation("main.main", false, 0) addr, err := proc.FindFunctionLocation(p, "main.main", false, 0)
assertNoError(err, t, "FindFunctionLocation()") assertNoError(err, t, "FindFunctionLocation()")
_, err = p.SetBreakpoint(addr, proc.UserBreakpoint, nil) _, err = p.SetBreakpoint(addr, proc.UserBreakpoint, nil)
assertNoError(err, t, "SetBreakpoint()") assertNoError(err, t, "SetBreakpoint()")
@ -1690,9 +1690,9 @@ func TestIssue332_Part2(t *testing.T) {
regs, err := p.CurrentThread().Registers(false) regs, err := p.CurrentThread().Registers(false)
assertNoError(err, t, "Registers()") assertNoError(err, t, "Registers()")
pc := regs.PC() pc := regs.PC()
pcAfterPrologue, err := p.FindFunctionLocation("main.changeMe", true, -1) pcAfterPrologue, err := proc.FindFunctionLocation(p, "main.changeMe", true, -1)
assertNoError(err, t, "FindFunctionLocation()") assertNoError(err, t, "FindFunctionLocation()")
pcEntry, err := p.FindFunctionLocation("main.changeMe", false, 0) pcEntry, err := proc.FindFunctionLocation(p, "main.changeMe", false, 0)
if pcAfterPrologue == pcEntry { if pcAfterPrologue == pcEntry {
t.Fatalf("main.changeMe and main.changeMe:0 are the same (%x)", pcAfterPrologue) t.Fatalf("main.changeMe and main.changeMe:0 are the same (%x)", pcAfterPrologue)
} }
@ -1712,7 +1712,7 @@ func TestIssue332_Part2(t *testing.T) {
func TestIssue396(t *testing.T) { func TestIssue396(t *testing.T) {
withTestProcess("callme", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("callme", t, func(p proc.Process, fixture protest.Fixture) {
_, err := p.FindFunctionLocation("main.init", true, -1) _, err := proc.FindFunctionLocation(p, "main.init", true, -1)
assertNoError(err, t, "FindFunctionLocation()") assertNoError(err, t, "FindFunctionLocation()")
}) })
} }
@ -1765,7 +1765,7 @@ func TestIssue149(t *testing.T) {
} }
// setting breakpoint on break statement // setting breakpoint on break statement
withTestProcess("break", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("break", t, func(p proc.Process, fixture protest.Fixture) {
_, err := p.FindFileLocation(fixture.Source, 8) _, err := proc.FindFileLocation(p, fixture.Source, 8)
assertNoError(err, t, "FindFileLocation()") assertNoError(err, t, "FindFileLocation()")
}) })
} }
@ -1991,7 +1991,7 @@ func TestIssue573(t *testing.T) {
// calls to runtime.duffzero and runtime.duffcopy jump directly into the middle // calls to runtime.duffzero and runtime.duffcopy jump directly into the middle
// of the function and the internal breakpoint set by StepInto may be missed. // of the function and the internal breakpoint set by StepInto may be missed.
withTestProcess("issue573", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("issue573", t, func(p proc.Process, fixture protest.Fixture) {
fentry, _ := p.FindFunctionLocation("main.foo", false, 0) fentry, _ := proc.FindFunctionLocation(p, "main.foo", false, 0)
_, err := p.SetBreakpoint(fentry, proc.UserBreakpoint, nil) _, err := p.SetBreakpoint(fentry, proc.UserBreakpoint, nil)
assertNoError(err, t, "SetBreakpoint()") assertNoError(err, t, "SetBreakpoint()")
assertNoError(proc.Continue(p), t, "Continue()") assertNoError(proc.Continue(p), t, "Continue()")
@ -2003,9 +2003,9 @@ func TestIssue573(t *testing.T) {
func TestTestvariables2Prologue(t *testing.T) { func TestTestvariables2Prologue(t *testing.T) {
withTestProcess("testvariables2", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("testvariables2", t, func(p proc.Process, fixture protest.Fixture) {
addrEntry, err := p.FindFunctionLocation("main.main", false, 0) addrEntry, err := proc.FindFunctionLocation(p, "main.main", false, 0)
assertNoError(err, t, "FindFunctionLocation - entrypoint") assertNoError(err, t, "FindFunctionLocation - entrypoint")
addrPrologue, err := p.FindFunctionLocation("main.main", true, 0) addrPrologue, err := proc.FindFunctionLocation(p, "main.main", true, 0)
assertNoError(err, t, "FindFunctionLocation - postprologue") assertNoError(err, t, "FindFunctionLocation - postprologue")
if addrEntry == addrPrologue { if addrEntry == addrPrologue {
t.Fatalf("Prologue detection failed on testvariables2.go/main.main") t.Fatalf("Prologue detection failed on testvariables2.go/main.main")
@ -2146,7 +2146,7 @@ func TestStepOut(t *testing.T) {
func TestStepConcurrentDirect(t *testing.T) { func TestStepConcurrentDirect(t *testing.T) {
withTestProcess("teststepconcurrent", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("teststepconcurrent", t, func(p proc.Process, fixture protest.Fixture) {
pc, err := p.FindFileLocation(fixture.Source, 37) pc, err := proc.FindFileLocation(p, fixture.Source, 37)
assertNoError(err, t, "FindFileLocation()") assertNoError(err, t, "FindFileLocation()")
bp, err := p.SetBreakpoint(pc, proc.UserBreakpoint, nil) bp, err := p.SetBreakpoint(pc, proc.UserBreakpoint, nil)
assertNoError(err, t, "SetBreakpoint()") assertNoError(err, t, "SetBreakpoint()")
@ -2220,7 +2220,7 @@ func nextInProgress(p proc.Process) bool {
func TestStepConcurrentPtr(t *testing.T) { func TestStepConcurrentPtr(t *testing.T) {
withTestProcess("teststepconcurrent", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("teststepconcurrent", t, func(p proc.Process, fixture protest.Fixture) {
pc, err := p.FindFileLocation(fixture.Source, 24) pc, err := proc.FindFileLocation(p, fixture.Source, 24)
assertNoError(err, t, "FindFileLocation()") assertNoError(err, t, "FindFileLocation()")
_, err = p.SetBreakpoint(pc, proc.UserBreakpoint, nil) _, err = p.SetBreakpoint(pc, proc.UserBreakpoint, nil)
assertNoError(err, t, "SetBreakpoint()") assertNoError(err, t, "SetBreakpoint()")
@ -2299,7 +2299,7 @@ func TestStepConcurrentPtr(t *testing.T) {
func TestStepOutDefer(t *testing.T) { func TestStepOutDefer(t *testing.T) {
withTestProcess("testnextdefer", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("testnextdefer", t, func(p proc.Process, fixture protest.Fixture) {
pc, err := p.FindFileLocation(fixture.Source, 9) pc, err := proc.FindFileLocation(p, fixture.Source, 9)
assertNoError(err, t, "FindFileLocation()") assertNoError(err, t, "FindFileLocation()")
bp, err := p.SetBreakpoint(pc, proc.UserBreakpoint, nil) bp, err := p.SetBreakpoint(pc, proc.UserBreakpoint, nil)
assertNoError(err, t, "SetBreakpoint()") assertNoError(err, t, "SetBreakpoint()")
@ -2342,7 +2342,7 @@ const maxInstructionLength uint64 = 15
func TestStepOnCallPtrInstr(t *testing.T) { func TestStepOnCallPtrInstr(t *testing.T) {
withTestProcess("teststepprog", t, func(p proc.Process, fixture protest.Fixture) { withTestProcess("teststepprog", t, func(p proc.Process, fixture protest.Fixture) {
pc, err := p.FindFileLocation(fixture.Source, 10) pc, err := proc.FindFileLocation(p, fixture.Source, 10)
assertNoError(err, t, "FindFileLocation()") assertNoError(err, t, "FindFileLocation()")
_, err = p.SetBreakpoint(pc, proc.UserBreakpoint, nil) _, err = p.SetBreakpoint(pc, proc.UserBreakpoint, nil)
assertNoError(err, t, "SetBreakpoint()") assertNoError(err, t, "SetBreakpoint()")

@ -158,7 +158,7 @@ func next(dbp Process, stepInto bool) error {
if deferPCEntry != 0 { if deferPCEntry != 0 {
_, _, deferfn := dbp.BinInfo().PCToLine(deferPCEntry) _, _, deferfn := dbp.BinInfo().PCToLine(deferPCEntry)
var err error var err error
deferpc, err = dbp.FirstPCAfterPrologue(deferfn, false) deferpc, err = FirstPCAfterPrologue(dbp, deferfn, false)
if err != nil { if err != nil {
return err return err
} }
@ -236,7 +236,7 @@ func setStepIntoBreakpoint(dbp Process, text []AsmInstruction, cond ast.Expr) er
// those extra checks should be done here. // those extra checks should be done here.
// Set a breakpoint after the function's prologue // Set a breakpoint after the function's prologue
pc, _ := dbp.FirstPCAfterPrologue(fn, false) pc, _ := FirstPCAfterPrologue(dbp, fn, false)
if _, err := dbp.SetBreakpoint(pc, NextBreakpoint, cond); err != nil { if _, err := dbp.SetBreakpoint(pc, NextBreakpoint, cond); err != nil {
if _, ok := err.(BreakpointExistsError); !ok { if _, ok := err.(BreakpointExistsError); !ok {
return err return err

@ -203,7 +203,7 @@ func (d *Debugger) Restart() ([]api.DiscardedBreakpoint, error) {
continue continue
} }
if len(oldBp.File) > 0 { if len(oldBp.File) > 0 {
oldBp.Addr, err = p.FindFileLocation(oldBp.File, oldBp.Line) oldBp.Addr, err = proc.FindFileLocation(p, oldBp.File, oldBp.Line)
if err != nil { if err != nil {
discarded = append(discarded, api.DiscardedBreakpoint{oldBp, err.Error()}) discarded = append(discarded, api.DiscardedBreakpoint{oldBp, err.Error()})
continue continue
@ -298,12 +298,12 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoin
} }
} }
} }
addr, err = d.target.FindFileLocation(fileName, requestedBp.Line) addr, err = proc.FindFileLocation(d.target, fileName, requestedBp.Line)
case len(requestedBp.FunctionName) > 0: case len(requestedBp.FunctionName) > 0:
if requestedBp.Line >= 0 { if requestedBp.Line >= 0 {
addr, err = d.target.FindFunctionLocation(requestedBp.FunctionName, false, requestedBp.Line) addr, err = proc.FindFunctionLocation(d.target, requestedBp.FunctionName, false, requestedBp.Line)
} else { } else {
addr, err = d.target.FindFunctionLocation(requestedBp.FunctionName, true, 0) addr, err = proc.FindFunctionLocation(d.target, requestedBp.FunctionName, true, 0)
} }
default: default:
addr = requestedBp.Addr addr = requestedBp.Addr

@ -250,7 +250,7 @@ func (loc *RegexLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr st
} }
r := make([]api.Location, 0, len(matches)) r := make([]api.Location, 0, len(matches))
for i := range matches { for i := range matches {
addr, err := d.target.FindFunctionLocation(matches[i], true, 0) addr, err := proc.FindFunctionLocation(d.target, matches[i], true, 0)
if err == nil { if err == nil {
r = append(r, api.Location{PC: addr}) r = append(r, api.Location{PC: addr})
} }
@ -279,7 +279,7 @@ func (loc *AddrLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr str
return []api.Location{{PC: addr}}, nil return []api.Location{{PC: addr}}, nil
case reflect.Func: case reflect.Func:
_, _, fn := d.target.BinInfo().PCToLine(uint64(v.Base)) _, _, fn := d.target.BinInfo().PCToLine(uint64(v.Base))
pc, err := d.target.FirstPCAfterPrologue(fn, false) pc, err := proc.FirstPCAfterPrologue(d.target, fn, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -366,12 +366,12 @@ func (loc *NormalLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s
if loc.LineOffset < 0 { if loc.LineOffset < 0 {
return nil, fmt.Errorf("Malformed breakpoint location, no line offset specified") return nil, fmt.Errorf("Malformed breakpoint location, no line offset specified")
} }
addr, err = d.target.FindFileLocation(candidates[0], loc.LineOffset) addr, err = proc.FindFileLocation(d.target, candidates[0], loc.LineOffset)
} else { } else {
if loc.LineOffset < 0 { if loc.LineOffset < 0 {
addr, err = d.target.FindFunctionLocation(candidates[0], true, 0) addr, err = proc.FindFunctionLocation(d.target, candidates[0], true, 0)
} else { } else {
addr, err = d.target.FindFunctionLocation(candidates[0], false, loc.LineOffset) addr, err = proc.FindFunctionLocation(d.target, candidates[0], false, loc.LineOffset)
} }
} }
if err != nil { if err != nil {
@ -394,7 +394,7 @@ func (loc *OffsetLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr s
if fn == nil { if fn == nil {
return nil, fmt.Errorf("could not determine current location") return nil, fmt.Errorf("could not determine current location")
} }
addr, err := d.target.FindFileLocation(file, line+loc.Offset) addr, err := proc.FindFileLocation(d.target, file, line+loc.Offset)
return []api.Location{{PC: addr}}, err return []api.Location{{PC: addr}}, err
} }
@ -406,6 +406,6 @@ func (loc *LineLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr str
if fn == nil { if fn == nil {
return nil, fmt.Errorf("could not determine current location") return nil, fmt.Errorf("could not determine current location")
} }
addr, err := d.target.FindFileLocation(file, loc.Line) addr, err := proc.FindFileLocation(d.target, file, loc.Line)
return []api.Location{{PC: addr}}, err return []api.Location{{PC: addr}}, err
} }