mirror of
https://github.com/go-delve/delve.git
synced 2025-11-01 20:20:40 +08:00
Validate args to thread command
This commit is contained in:
@ -139,6 +139,9 @@ func threads(p *proctl.DebuggedProcess, ars ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func thread(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
|
oldTid := p.CurrentThread.Id
|
||||||
tid, err := strconv.Atoi(ars[0])
|
tid, err := strconv.Atoi(ars[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -51,3 +51,10 @@ func TestCommandReplayWithoutPreviousCommand(t *testing.T) {
|
|||||||
t.Error("Null command not returned", err)
|
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")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user