Commit 7ff6254c authored by David Crawshaw's avatar David Crawshaw

misc/ios: run lldb commands much more carefully

We now wait until we see the completed prompt from a command before
proceeding. This seems to cut down on a spurious error I have seen
this afternoon.

Change-Id: Ic0a3481d8c265c3c3b4449ec7ac1c2752b85b0b6
Reviewed-on: https://go-review.googlesource.com/6691Reviewed-by: default avatarHyang-Ah Hana Kim <hyangah@gmail.com>
parent 9a420f4c
...@@ -42,7 +42,20 @@ func main() { ...@@ -42,7 +42,20 @@ func main() {
} }
} }
func run(bin string, args []string) error { func run(bin string, args []string) (err error) {
type waitPanic struct {
err error
}
defer func() {
if r := recover(); r != nil {
if w, ok := r.(waitPanic); ok {
err = w.err
return
}
panic(r)
}
}()
defer exec.Command("killall", "ios-deploy").Run() // cleanup defer exec.Command("killall", "ios-deploy").Run() // cleanup
exec.Command("killall", "ios-deploy").Run() exec.Command("killall", "ios-deploy").Run()
...@@ -51,7 +64,9 @@ func run(bin string, args []string) error { ...@@ -51,7 +64,9 @@ func run(bin string, args []string) error {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
if !debug {
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
}
appdir := filepath.Join(tmpdir, "gotest.app") appdir := filepath.Join(tmpdir, "gotest.app")
if err := os.MkdirAll(appdir, 0755); err != nil { if err := os.MkdirAll(appdir, 0755); err != nil {
...@@ -166,6 +181,9 @@ func run(bin string, args []string) error { ...@@ -166,6 +181,9 @@ func run(bin string, args []string) error {
} }
do := func(cmd string) { do := func(cmd string) {
fmt.Fprintln(lldb, cmd) fmt.Fprintln(lldb, cmd)
if err := waitFor(fmt.Sprintf("prompt after %q", cmd), "(lldb)"); err != nil {
panic(waitPanic{err})
}
} }
// Wait for installation and connection. // Wait for installation and connection.
...@@ -179,16 +197,10 @@ func run(bin string, args []string) error { ...@@ -179,16 +197,10 @@ func run(bin string, args []string) error {
do(`process handle SIGUSR1 --stop false --pass true --notify false`) do(`process handle SIGUSR1 --stop false --pass true --notify false`)
do(`process handle SIGSEGV --stop false --pass true --notify false`) // does not work do(`process handle SIGSEGV --stop false --pass true --notify false`) // does not work
do(`process handle SIGBUS --stop false --pass true --notify false`) // does not work do(`process handle SIGBUS --stop false --pass true --notify false`) // does not work
if err := waitFor("handlers set", "(lldb)"); err != nil {
return err
}
do(`breakpoint set -n getwd`) // in runtime/cgo/gcc_darwin_arm.go do(`breakpoint set -n getwd`) // in runtime/cgo/gcc_darwin_arm.go
if err := waitFor("breakpoint set", "(lldb)"); err != nil {
return err
}
do(`run`) fmt.Fprintln(lldb, `run`)
if err := waitFor("br getwd", "stop reason = breakpoint"); err != nil { if err := waitFor("br getwd", "stop reason = breakpoint"); err != nil {
return err return err
} }
...@@ -201,21 +213,16 @@ func run(bin string, args []string) error { ...@@ -201,21 +213,16 @@ func run(bin string, args []string) error {
do(`expr char* $mem = (char*)malloc(512)`) do(`expr char* $mem = (char*)malloc(512)`)
do(`expr $mem = (char*)getwd($mem, 512)`) do(`expr $mem = (char*)getwd($mem, 512)`)
do(`expr $mem = (char*)strcat($mem, "/` + pkgpath + `")`) do(`expr $mem = (char*)strcat($mem, "/` + pkgpath + `")`)
do(`expr int $res = (int)chdir($mem)`) do(`call (void)chdir($mem)`)
do(`print $res`)
if err := waitFor("move working dir", "(int) $res = 0"); err != nil {
return err
}
// Watch for SIGSEGV. Ideally lldb would never break on SIGSEGV. // Watch for SIGSEGV. Ideally lldb would never break on SIGSEGV.
// http://golang.org/issue/10043 // http://golang.org/issue/10043
go func() { go func() {
<-w.find("stop reason = EXC_BAD_ACCESS") <-w.find("stop reason = EXC_BAD_ACCESS")
do(`bt`) // cannot use do here, as the defer/recover is not available
// The backtrace has no obvious end, so we invent one. // on this goroutine.
do(`expr int $dummy = 1`) fmt.Fprintln(lldb, `bt`)
do(`print $dummy`) waitFor("finish backtrace", "(lldb)")
<-w.find(`(int) $dummy = 1`)
w.printBuf() w.printBuf()
if p := cmd.Process; p != nil { if p := cmd.Process; p != nil {
p.Kill() p.Kill()
...@@ -224,7 +231,7 @@ func run(bin string, args []string) error { ...@@ -224,7 +231,7 @@ func run(bin string, args []string) error {
// Run the tests. // Run the tests.
w.trimSuffix("(lldb) ") w.trimSuffix("(lldb) ")
do(`process continue`) fmt.Fprintln(lldb, `process continue`)
// Wait for the test to complete. // Wait for the test to complete.
select { select {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment