提交 0ac24abd 编写于 作者: D Derek Parker

Validate args to thread command

上级 707d55d0
......@@ -139,6 +139,9 @@ func threads(p *proctl.DebuggedProcess, ars ...string) error {
}
func thread(p *proctl.DebuggedProcess, ars ...string) error {
if len(ars) == 0 {
return fmt.Errorf("you must specify a thread")
}
oldTid := p.CurrentThread.Id
tid, err := strconv.Atoi(ars[0])
if err != nil {
......
......@@ -51,3 +51,10 @@ func TestCommandReplayWithoutPreviousCommand(t *testing.T) {
t.Error("Null command not returned", err)
}
}
func TestSwitchThread(t *testing.T) {
err := thread(nil, []string{}...)
if err == nil {
t.Fatal("expected error for empty arg slice")
}
}
......@@ -312,3 +312,46 @@ func TestFindReturnAddress(t *testing.T) {
}
})
}
func TestSwitchThread(t *testing.T) {
var testfile, _ = filepath.Abs("../_fixtures/testnextprog")
withTestProcess(testfile, t, func(p *DebuggedProcess) {
// With invalid thread id
err := p.SwitchThread(-1)
if err == nil {
t.Fatal("Expected error for invalid thread id")
}
pc, err := p.FindLocation("main.main")
if err != nil {
t.Fatal(err)
}
_, err = p.Break(pc)
if err != nil {
t.Fatal(err)
}
err = p.Continue()
if err != nil {
t.Fatal(err)
}
var nt int
ct := p.CurrentThread.Id
for tid, _ := range p.Threads {
if tid != ct {
nt = tid
break
}
}
if nt == 0 {
t.Fatal("could not find thread to switch to")
}
// With valid thread id
err = p.SwitchThread(nt)
if err != nil {
t.Fatal(err)
}
if p.CurrentThread.Id != nt {
t.Fatal("Did not switch threads")
}
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册