Handle attempt to set break on nonexistent func

This commit is contained in:
Derek Parker 2014-05-24 11:36:18 -05:00
parent 03fab9c26e
commit 251abd2c21
2 changed files with 23 additions and 1 deletions

@ -91,14 +91,18 @@ func (dbp *DebuggedProcess) Break(fname string) (*BreakPoint, error) {
var (
int3 = []byte{'0', 'x', 'C', 'C'}
fn = dbp.GoSymTable.LookupFunc(fname)
addr = uintptr(fn.LineTable.PC)
)
if fn == nil {
return nil, fmt.Errorf("No function named %s\n", fname)
}
_, ok := dbp.BreakPoints[fname]
if ok {
return nil, fmt.Errorf("Breakpoint already set")
}
addr := uintptr(fn.LineTable.PC)
_, err := syscall.PtracePokeData(dbp.Pid, addr, int3)
if err != nil {
return nil, err

@ -158,3 +158,21 @@ func TestBreakPointIsSetOnlyOnce(t *testing.T) {
t.Fatal("Should not be able to add breakpoint twice")
}
}
func TestBreakPointWithNonExistantFunction(t *testing.T) {
cmd, err := StartTestProcess("testprog")
if err != nil {
t.Fatal("Starting test process:", err)
}
pid := cmd.Process.Pid
p, err := NewDebugProcess(pid)
if err != nil {
t.Fatal("NewDebugProcess():", err)
}
_, err = p.Break("foo")
if err == nil {
t.Fatal("Should not be able to break at non existant function")
}
}