What can cause this SIGSEGV error?

2019-03-03 09:59发布

问题:

I received a crash log that I cannot explain. I have searched around and it appears that the SIGSEGV has something to do with memory. But in my case there is nothing of my own code except for the main.m in the stacktrace. Also it doesn't seem to symbolicate any of the system libraries.

The crash so far only happened on one iPhone. On other phones I haven't been able to reproduce it. Right now I'm completely stuck and don't know where to continue so if anyone has seen something like this before it would be good to hear their problem and resolution.

The crash log:

Incident Identifier: TODO
CrashReporter Key:   TODO
Hardware Model:      iPhone4,1
OS Version:      iPhone OS 6.1.3 (10B329)
Report Version:  104
Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0x41fd5903
Crashed Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib                     0x3b0b9564 0x3b0b6000 + 13668
1   libobjc.A.dylib                     0x3b0bb1d7 0x3b0b6000 + 20951
2   CoreFoundation                      0x33396605 0x332d4000 + 796165
3   CoreFoundation                      0x3339635d 0x332d4000 + 795485
4   libobjc.A.dylib                     0x3b0bea65 0x3b0b6000 + 35429
5   libc++abi.dylib                     0x3ab0b07b 0x3ab0a000 + 4219
6   libc++abi.dylib                     0x3ab0b114 0x3ab0a000 + 4372
7   libc++abi.dylib                     0x3ab0c599 0x3ab0a000 + 9625
8   libobjc.A.dylib                     0x3b0be9d1 0x3b0b6000 + 35281
9   CoreFoundation                      0x332dcf21 0x332d4000 + 36641
10  CoreFoundation                      0x332dcd49 0x332d4000 + 36169
11  GraphicsServices                    0x36eb52eb 0x36eb0000 + 21227
12  UIKit                               0x351f2301 0x3519b000 + 357121
13  Stylbar                             0x0007109f main (main.m:21)

Edit 3th of May:

The crash log is sent by a user. I haven't been able to reproduce the issue myself unfortunately, which is why it's so difficult for me to figure out what went wrong with just this crash log.

It appeared to have happened about 15 times in a row for the same user when opening a certain view controller. The view controller does several calls to a server to load a post, comments and images and profile pictures. All the code that's executed when this view controller is opened is probably over 2000 lines of code (excluding the RestKit and SBWebImage libraries that are used within this code). Posting that code here wouldn't help anyone I'm afraid.

回答1:

The most simple and useful way to spend your time hunting for the cause of the crash is to look at your code and focus on places where UIKit has a delegate that points back into your code. For example, I found that the most common place this sort of thing would show up was in UITableView. The reason these problems are so hard to track down is that they might only happen in a low memory situation or in some uncommon UI condition that is very hard to reproduce. It is better to just do a code review and make sure that delegate that are set to point to your classes are set back to nil in your own object destructors. If you have many developers, it is often better to work on some higher level abstractions like a generic table and cell class that is used throughout the project than to have every developer coding up a UITableView and making mistakes like forgetting to nil out the delegate that are very difficult to find.



回答2:

SIGSEGV is a problem the occurs when your application tries to access an address of memory that doesn't exists or some address where is already reserved to another program. I have the same issue with an application right now but I have to review my code to figure it out better. One clue for this kind of problem could be something equivalent to this (found in wikipedia):

#include <stdlib.h>  

int main(void)
{
char p = NULL; / p is a pointer to char that initializes poiting to "nowhere"*/
* p = 'x'; /* Tries to save the char 'x' in 'no address'*/
return 0;
}

I hope this can help someone.