Handle attempt to set break on nonexistent func
This commit is contained in:
parent
03fab9c26e
commit
251abd2c21
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user