Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: panic() is not printed in LogCat on android #9398

Closed
jhleath opened this issue Dec 19, 2014 · 10 comments
Closed

runtime: panic() is not printed in LogCat on android #9398

jhleath opened this issue Dec 19, 2014 · 10 comments
Milestone

Comments

@jhleath
Copy link

jhleath commented Dec 19, 2014

What version of go are you running?

devel, definitely after bee8ae1.

What OS and ARCH?

Compiling for Android/Arm.

What did you do?

Create a go program that looks like this:

func Run(port int) {
  panic("Hello, world.")
}

What did you expect to happen?

The program exits with "Hello, world." printed to the log (viewable in logcat).

What happened?

Logcat reports nothing, as below:

I/Go      ( 3286): app.Run
I/go/Seq  ( 3286): loaded go/Seq
I/Go      ( 3286): Runtime started
I/Zygote  (  196): Process 3286 exited cleanly (2)
I/ActivityManager(  530): Process com.getmelange.melange (pid 3286) has died

Then restarts the application multiple times.

@jhleath jhleath changed the title mobile: Panic is not printed in LogCat mobile: panic() is not printed in LogCat Dec 19, 2014
@hyangah
Copy link
Contributor

hyangah commented Dec 19, 2014

Do you use the Dockerfile in the repo?
Yesterday I had a similar issue, rebuilt my docker image, but still had the
same issue.
Eventually, I deleted my docker image and built a fresh new image, which
fixed the issue.
I guess Docker build uses some cache and maybe it doesn't load the fresh
tip go every time it builds.

2014-12-19 9:50 GMT-05:00 Hunter Leath notifications@github.com:

What version of go are you running?

devel, definitely after bee8ae1
bee8ae1
.

What OS and ARCH?

Compiling for Android/Arm.

What did you do?

Create a go program that looks like this:

func Run(port int) {
panic("Hello, world.")
}

What did you expect to happen?

The program exits with "Hello, world." printed to the log (viewable in
logcat).

What happened?

Logcat reports nothing, as below:

I/Go ( 3286): app.Run
I/go/Seq ( 3286): loaded go/Seq
I/Go ( 3286): Runtime started
I/Zygote ( 196): Process 3286 exited cleanly (2)
I/ActivityManager( 530): Process com.getmelange.melange (pid 3286) has died

Then restarts the application multiple times.


Reply to this email directly or view it on GitHub
#9398.

__

@jhleath
Copy link
Author

jhleath commented Dec 19, 2014

Certainly. I've rebuilt a couple of times with --no-cache to no avail, still nothing in the logcat. Could this have something to do with Lollipop? Although I did not have root, running cat /dev/log/main in adb shell returns No such file or directory..

Additionally, I attempted to work around this issue by adding

defer func() {
    fmt.Println("Hello, world.")
    if r := recover(); r != nil {
        fmt.Println("Golang Panic:", r)
    }
}()

To the top of my function, to no avail. Strangely, still nothing prints out at all.

@crawshaw
Copy link
Member

Quickest way to test that there isn't something wrong with your go installation is to run:

docker run mobile /bin/bash -c 'ls /go/src/runtime/print1*'

If you are synced after the printing CL, you should see

/go/src/runtime/print1.go
/go/src/runtime/print1_write.go
/go/src/runtime/print1_write_android.go

Other than that, you can also try adding

log.Print("test message")

above your panic. The Go log package has an entirely different set of hooks for printing output.

Also, I presume there is more to your Go program than the snippet you pasted. Could you show us the rest of your main function?

@jhleath
Copy link
Author

jhleath commented Dec 19, 2014

So, two interesting developments. The original problem that had me going down this direction was fixed by simply go get -u golang.org/x/mobile since I hadn't done that in a while. Turns out it had to do with returning nil as error.

My main function is something like this with the panic. Since I commented out the other code, I assume this is the important part.

func Run(port int, dataDir string, version string, platform string) error {
   panic("Hello, world.")
   return nil
}

Updating the mobile repository certainly fixed the issue with defer-recover, and it now prints panics to stdout. The bare panic, however, doesn't print to logcat. I have confirmed that print1_write_android.go exists.

Additionally, log and fmt are working normally.

@crawshaw
Copy link
Member

My attempt to replicate this failed. Could you provide a complete small program that demonstrates the problem?

@jhleath
Copy link
Author

jhleath commented Dec 22, 2014

It's very likely that I'm just setup incorrectly somehow. If you are unable to reproduce it using a Lollipop device, then I wouldn't worry about it. The code I was trying it with did, in fact, just have a panic in the Run(.) function.

@hyangah
Copy link
Contributor

hyangah commented Dec 23, 2014

I don't know what's Run(.) function, but based on the log from your first report (triggering go/Seq logs), I guess the following modification to example/libhello/hi/hi.go is something similar to what you have, right? If so, I will test it with a Lollipop device later today.

diff --git a/example/libhello/hi/hi.go b/example/libhello/hi/hi.go
index a1e868b..cf3ec23 100644
--- a/example/libhello/hi/hi.go
+++ b/example/libhello/hi/hi.go
@@ -4,5 +4,6 @@ package hi
import "fmt"

func Hello(name string) {

  •   panic("End of the World...")
    fmt.Printf("Hello, %s!\n", name)
    
    }

FYI adb logcat from 4.4.4 nexus 7: https://gist.github.com/hyangah/0b1225eb3b164096ef87 It includes the panic log.

@jhleath
Copy link
Author

jhleath commented Dec 23, 2014

That would effectively sum up what I was attempting. Do let me know what happens with the Lollipop device, and feel free to close if everything works correctly.

@hyangah
Copy link
Contributor

hyangah commented Dec 24, 2014

I could reproduce the problem with Nexus 7 running android version 5.0.1.
The same apk still produces the panic log in android 4.4.4.

@hyangah
Copy link
Contributor

hyangah commented Dec 29, 2014

Based on the recent ndk's logging (https://android.googlesource.com/platform/system/core/+/master/liblog/logd_write.c), I guess logs need to be sent through /dev/socket/logdw (unix domain socket).

The runtime at tip directly writes logs or print messages to /dev/log/main (https://go.googlesource.com/go/+/master/src/runtime/print1_write_android.go)
But /dev/log/... are no longer accessible(?) or used in android-L. Is it possible to use ndk's __android_log_write from the runtime package? __android_log_write handles emulator environment too.

Otherwise, we need to make runtime use /dev/socket/logdw. I don't know android enough to know if it's backwards compatible.

@hyangah hyangah closed this as completed in 3a87135 Feb 4, 2015
@mikioh mikioh changed the title mobile: panic() is not printed in LogCat runtime: panic() is not printed in LogCat on android Aug 5, 2015
@mikioh mikioh added this to the Go1.5 milestone Aug 5, 2015
@golang golang locked and limited conversation to collaborators Aug 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants