Reputation: 1636
I have a weird error and I can't find where it comes from. The only thing that appears in the logcat is :
01-10 17:07:10.665: A/libc(20449): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
I don't get this error right away when I run my app, I get it after a random amount of time (something between 1 min to 5 min). I'm unable to reproduce this error, it seems random and since there are no other informations it's hard to debug. I tried to add some log informations to my library but I still can't say where the crash occurs.
I ran the same app x times and I got different SIGSEGV address (sometimes it was the same address as before :
01-10 17:29:04.650: A/libc(21588): Fatal signal 11 (SIGSEGV) at 0x6c707063 (code=1)
01-10 17:25:55.165: A/libc(21473): Fatal signal 11 (SIGSEGV) at 0x0069004c (code=1)
01-10 17:11:58.780: A/libc(20742): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
01-10 17:00:02.010: A/libc(20160): Fatal signal 11 (SIGSEGV) at 0x00000018 (code=1)
My app is using a c++ library that has a NetworkThread that receives updates from a server. On the Java side there's a WorkerThread that check is there's new updates from the NetworkThread and if there's new updates it notifies all the listeners. I also have a LocationSpotter (on the Java side) that makes some JNI calls when the location is updated.
Is there a way to debug this or to use the addresses I got from the SIGSEGV to debug the app ? Also I'm using a shared JavaVM object for some methods to retrieve the current JNIEnv (and call AttachCurrentThread). Is that thread safe ?
I noticed that I still receive updates from the NetworkThread after I got the SIGSEGV error (before the app actually crashes). That means the NetworkThread is probably working.
I also noticed a line that could be the source of my problem (in the notifyAll method) because the last message printed before SIGSEGV is "notifyAll1" :
for (unsigned i = 0; i < listeners.size(); i++) {
try {
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "notifyAll1");
if (listeners.at(i) == NULL)
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "LISTENER NULL");
listeners.at(i)->update(u); // <- This line is a potential suspect
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "notifyAll2");
The logcat :
01-10 17:07:10.665: I/FROM C++(20449): notifyAll1
01-10 17:07:10.665: A/libc(20449): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
I tried then to print a log in the first line of each listener's update
method but none of them is printed (which is really weird I think).
Any help will be greatly appreciated
Upvotes: 5
Views: 17023
Reputation: 57203
I believe that you should rewrite the notifyAll loop like this:
for (unsigned i = 0; i < listeners.size(); i++) {
try {
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "notifyAll1 i=%u", i);
auto listener = *listeners.at(i);
if (&listener == NULL) {
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "LISTENER NULL");
}
else {
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "notifyAll2 : listener[%u] at %p", i, &listener);
listener.update(u);
}
But it's possible that the crash happens because of exception handling. You did not reveal the catch(...) code, so I cannot speak about this.
Upvotes: 1
Reputation: 10368
It seems to be obvious
if (listeners.at(i) == NULL)
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "LISTENER NULL");
listeners.at(i)->update(u); // <- This line is a potential suspect
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "notifyAll2");
should be
if (listeners.at(i) == NULL) {
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "LISTENER NULL");
} else {
listeners.at(i)->update(u); // <- This line is a potential suspect
__android_log_print(ANDROID_LOG_INFO, "FROM C++", "notifyAll2");
}
Upvotes: 0
Reputation: 8906
Most of time Fatal signal error occur when you are trying to access any object which is not created at that time. So check them properly.
Upvotes: 5