Crash types in iOS

Source: Internet
Author: User

http://blog.csdn.net/womendeaiwoming/article/details/44243571

Types of crashes in the OS

Learn about the terminology used by Xcode to represent various types of crashes, and add some of this knowledge. Crashes are usually signals that the operating system sends to a running program, so when we look at the crash log, we often see the following error summary: Application received signal SIGSEGV. In general, there are several common types of crashes:

1, Exc_bad_access

Exc_bad_access appears when you access an object that has been disposed of or sends a message to it. The most common cause of exc_bad_access is the wrong ownership modifier when initializing a variable in the initialization method, which causes the object to be released prematurely. For example, in the Viewdidload method, a nsarray that contains an element is created for Uiviewcontroller, but the ownership modifier of the array is set to assign instead of strong. Now in Viewwillappear, to access objects that have been disposed of, you get a crash called exc_bad_access.

This crash occurs when you look at the crash log, but often get no useful stack information. Fortunately, there is a way to solve this problem: nszombieenabled.

This is an environment variable that is used to debug memory-related issues and to track the release process of objects. With nszombieenabled enabled, it will use a zombie implementation to come to your default Dealloc implementation, that is, when the reference count drops to 0 o'clock, the zombie implementation converts the object into a Zombie object. The purpose of a zombie object is that when you send a message to it, it displays a log and automatically jumps into the debugger.

So, when Nszombie is enabled in the app instead of having the app crash directly, an erroneous memory access becomes an unrecognized message to the zombie object. The Zombie object displays the received message, and then jumps into the debugger so you can see exactly when something went wrong.

You can set the nszombieenabled environment variable in the Xcode scheme page. Click Product-àedit Scheme to open the page, and then tick the Enable Zombie objects check box:

Zombies have a great effect before RAC appears. But since arc, if you pay more attention to the object's ownership, you usually don't run into memory-related crashes.

2, SIGSEGV

The segment error message (SIGSEGV) is a more serious problem that the operating system produces. This error occurs when hardware errors occur, access to unreadable memory addresses, or write data to a protected memory address.

Hardware errors This is not a common situation. You receive SIGSEGV when you want to read data that is saved in RAM, and the location of the RAM hardware is problematic. SIGSEGV more is present in the latter two cases. By default, the code page does not allow write operations, while data does not allow execution. You receive SIGSEGV when a pointer in the app points to a code page and tries to modify the value pointing to the location. You also receive SIGSEGV when you want to read the value of a pointer and it is initialized to a garbage value that points to an invalid memory address.

SIGSEGV errors are more difficult to debug, and the most common cause of SIGSEGV is incorrect type conversions. To avoid excessive use of pointers or attempt to manually modify pointers to read private data structures. If you do that, and you do not notice the memory alignment and padding problems when you modify the pointer, you receive SIGSEGV.

3, Sigbus

The bus error signal (SIGBUG) represents invalid memory access, which means that the memory accessed is an invalid memory address. In other words, the location that the address points to is not the physical memory address at all (it may be the address of a hardware chip). SIGSEGV and Sigbus are the sub-types of badminton exc_bad_access.

4, SIGTRAP

The sigtrap represents the trap signal. It's not a real crash signal. It will be sent at the processor execution trap instruction. The LLDB debugger typically processes this signal and stops running at the specified breakpoint. If you receive an unknown sigtrap, clearing the last output first and then rebuilding the build will usually solve the problem.

5, Exc_arithetic

When you want to remove zero, the app receives a exc_arithmetic signal. This error should be easily resolved.

6, Sigill

Sigill represents signal illegal instruction (illegal command signal). It occurs when an illegal instruction is executed on the processor. Executing an illegal instruction means that when a function pointer is given to another function, the function pointer is bad for some reason, pointing to an already freed memory or a data segment. Sometimes you get exc_bad_instruction instead of Sigill, although they are one thing, but Exc_* is the same as this signal does not depend on architecture.

7, SIGABRT

SIGABRT represents signal abort (abort signal). When the operating system discovers an unsafe situation, it can take more control of the situation, and if necessary, it can require the process to clean up the work. There is no trick in debugging the underlying error that caused this signal. Frameworks such as cocos2d or Uikit typically invoke the C function abort (which sends this signal) when a particular precondition is not met or some bad conditions occur. When SIGABRT appears, the console usually outputs a large amount of information indicating where something went wrong. Because it is a controllable crash, you can print out backtracking information by typing the BT command on the LLDB console.

8. Watchdog timeout

This crash is usually easier to distinguish because the error code is a fixed 0x8badf00d. (Programmers also have a humorous side, they read it as ate bad food.) On iOS, it often occurs when a synchronous network call is performed to block the main thread. Therefore, you should never make synchronous network calls.

Crash types in iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.