Skip to content

Commit

Permalink
misc/ios: run lldb commands much more carefully
Browse files Browse the repository at this point in the history
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/6691
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
crawshaw committed Mar 3, 2015
1 parent 9a420f4 commit 7ff6254
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions misc/ios/go_darwin_arm_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

exec.Command("killall", "ios-deploy").Run()
Expand All @@ -51,7 +64,9 @@ func run(bin string, args []string) error {
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(tmpdir)
if !debug {
defer os.RemoveAll(tmpdir)
}

appdir := filepath.Join(tmpdir, "gotest.app")
if err := os.MkdirAll(appdir, 0755); err != nil {
Expand Down Expand Up @@ -166,6 +181,9 @@ func run(bin string, args []string) error {
}
do := func(cmd string) {
fmt.Fprintln(lldb, cmd)
if err := waitFor(fmt.Sprintf("prompt after %q", cmd), "(lldb)"); err != nil {
panic(waitPanic{err})
}
}

// Wait for installation and connection.
Expand All @@ -179,16 +197,10 @@ func run(bin string, args []string) error {
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 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
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 {
return err
}
Expand All @@ -201,21 +213,16 @@ func run(bin string, args []string) error {
do(`expr char* $mem = (char*)malloc(512)`)
do(`expr $mem = (char*)getwd($mem, 512)`)
do(`expr $mem = (char*)strcat($mem, "/` + pkgpath + `")`)
do(`expr int $res = (int)chdir($mem)`)
do(`print $res`)
if err := waitFor("move working dir", "(int) $res = 0"); err != nil {
return err
}
do(`call (void)chdir($mem)`)

// Watch for SIGSEGV. Ideally lldb would never break on SIGSEGV.
// http://golang.org/issue/10043
go func() {
<-w.find("stop reason = EXC_BAD_ACCESS")
do(`bt`)
// The backtrace has no obvious end, so we invent one.
do(`expr int $dummy = 1`)
do(`print $dummy`)
<-w.find(`(int) $dummy = 1`)
// cannot use do here, as the defer/recover is not available
// on this goroutine.
fmt.Fprintln(lldb, `bt`)
waitFor("finish backtrace", "(lldb)")
w.printBuf()
if p := cmd.Process; p != nil {
p.Kill()
Expand All @@ -224,7 +231,7 @@ func run(bin string, args []string) error {

// Run the tests.
w.trimSuffix("(lldb) ")
do(`process continue`)
fmt.Fprintln(lldb, `process continue`)

// Wait for the test to complete.
select {
Expand Down

0 comments on commit 7ff6254

Please sign in to comment.