iOS 崩溃日志中的异常类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7446655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:33:17  来源:igfitidea点击:

Exception Types in iOS crash logs

iphoneobjective-ciosexceptioncrash-reports

提问by Tuyen Nguyen

I've seen a few different types of crash logs since I begin learning iOS development.

自从我开始学习 iOS 开发以来,我已经看到了几种不同类型的崩溃日志。

I know that: Exception Type: EXC_BAD_ACCESS (SIGSEGV)mean we are accessing a released object.

我知道: 异常类型:EXC_BAD_ACCESS (SIGSEGV)意味着我们正在访问一个已发布的对象。

but don't know about:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Type: EXC_CRASH (SIGABRT)
Exception Type: EXC_BREAKPOINT (SIGTRAP)

但不知道:
异常类型:EXC_BAD_ACCESS (SIGBUS)
异常类型:EXC_CRASH (SIGABRT)
异常类型:EXC_BREAKPOINT (SIGTRAP)

Do you know how many Exception Types in iOS crash logs and what do they mean?

你知道iOS崩溃日志中有多少异常类型以及它们是什么意思吗?

回答by Macmade

I know that: Exception Type: EXC_BAD_ACCESS (SIGSEGV) mean we are accessing a released object.

我知道:异常类型:EXC_BAD_ACCESS (SIGSEGV) 意味着我们正在访问一个已发布的对象。

No.

不。

A SIGSEGV is a segmentation fault, meaning you are trying to access an invalid memory address.

SIGSEGV 是分段错误,这意味着您正在尝试访问无效的内存地址。

Those exceptions (in fact, they are signals) are not related to Objective-C, but C. So you can get such an exception without Objective-C objects.

那些异常(实际上,它们是信号)与Objective-C无关,而是与C相关。所以你可以在没有Objective-C对象的情况下得到这样的异常。

Note that a signal is not an exception, meaning you can't catch them with @tryand @catchblocks.

请注意,信号不是例外,这意味着您不能使用@try@catch块来捕获它们。

You may set a signal handler with the signaland sigactionfunctions. Keep in mind some signals, like SIGABRT cannot be blocked.

您可以使用signalsigaction函数设置信号处理程序。请记住某些信号,例如 SIGABRT 不能被阻止。

You can check the Wikipediapage about signals, if you want more informations.

如果您需要更多信息,您可以查看有关信号的维基百科页面。

That said, to resume:

也就是说,要继续:

SIGSEGV(Segmentation fault)

SIGSEGV(分段错误)

Access to an invalid memory address. The address exist, but your program does not have access to it.

访问无效的内存地址。地址存在,但您的程序无权访问它。

SIGBUS(Bus error)

SIGBUS(总线错误)

Access to an invalid memory address. The address does not exist, or the alignment is invalid.

访问无效的内存地址。地址不存在,或对齐无效。

SIGFPE(Floating point exception)

SIGFPE(浮点异常)

Invalid arithmetic operation. Can be related to integer operations, despite the name.

无效的算术运算。尽管名称如此,但可能与整数运算有关。

SIGPIPE

SIGPIPE

Broken pipe.

破管子。

SIGILL

信号

Illegal processor instruction.

非法的处理器指令。

SIGTRAP

信号陷阱

Debugger related

调试器相关

SIGABRT

SIGABRT

Program crash, not related to one of the preceding signal.

程序崩溃,与前面的信号之一无关。

回答by Tommy

SIGSEGV literally means you're accessing an address you don't own. So it's not necessarily that you're accessing a released object; you could be accessing an object that never existed, as in:

SIGSEGV 字面意思是您正在访问不属于您的地址。因此,您不一定要访问已发布的对象;您可能正在访问一个从未存在过的对象,例如:

UIView *view; // uninitialised, could point to anything
[view setFrame:someFrame];

Or even just making an error in C-level non-object stuff, such as:

或者甚至只是在 C 级非对象内容中出错,例如:

int array[100];
array[1000] = 23; // out-of-bounds access

SIGBUS is very similar to SIGSEGV, the difference being at the hardware level (usually the difference between trying to access an address that does exist but which you don't own and trying to access an address that doesn't have anything behind it, but that's not a strict definition), but is usually associated with the same sort of errors, though a SIGBUS is much more likely to be to do with an uninitialised variable than a SIGSEGV.

SIGBUS 与 SIGSEGV 非常相似,区别在于硬件级别(通常是尝试访问确实存在但您不拥有的地址与尝试访问后面没有任何内容的地址之间的区别,但是这不是一个严格的定义),但通常与相同类型的错误相关联,尽管 SIGBUS 比 SIGSEGV 更有可能与未初始化的变量有关。

If you're trying to map to errors you probably made in Objective-C, you probably just want to read SIGSEGV and SIGBUS together as meaning "a memory access I didn't have the right to make".

如果您试图映射到您可能在 Objective-C 中犯的错误,您可能只想将 SIGSEGV 和 SIGBUS 一起读作“我无权进行的内存访问”。

SIGABRT is a program attempting to abort itself, so it usually means that some sort of internal consistency check has failed. For example, SIGABRT is raised if you try to free the same memory twice, or — at the Cocoa level — if you raisean NSExceptionthat isn't caught. If you get a SIGABRT, you've done something wrong that is detected by the system software (in contrast to SEGV and BUS, which arise in hardware).

SIGABRT 是一个试图中止自身的程序,所以它通常意味着某种内部一致性检查失败了。在可可的水平- -如果您例如,SIGABRT是,如果你尝试释放相同的内存的两倍,或者提出raise一个NSException没有被抓到。如果您收到 SIGABRT,则系统软件会检测到您做错了什么(与硬件中出现的 SEGV 和 BUS 形成对比)。

SIGTRAP is a call out from the program to a debugger. Anecdotally, Apple seem to use these when you do something wrong that can be detected in software but relates to the environment rather than your specific code. So, for example, you call a C function that exists in the SDK you built with but not on the device you are running on (such as when you build against the latest SDK with a lower deployment target), or do a similar thing with an object.

SIGTRAP 是从程序到调试器的调用。有趣的是,当你做错了一些可以在软件中检测到但与环境而不是你的特定代码有关的错误时,Apple 似乎会使用这些。因此,例如,您调用一个 C 函数,该函数存在于您构建的 SDK 中,但不在您运行的设备上(例如,当您针对部署目标较低的最新 SDK 进行构建时),或执行类似的操作一个东西。

回答by Youssef

These messages are from gdb, and they are not exclusive for objective-C. To get info about the signals all you have to do is enter info signalsat the debugger console, this is an example output. Sorry for no posting it here, but the format of the console output is awful.

这些消息来自 gdb,它们不是 Objective-C 独有的。要获取有关信号的信息,您只需info signals在调试器控制台输入,这是一个示例输出。很抱歉没有在这里发布它,但控制台输出的格式很糟糕。

Source and more info about signals

关于信号的来源和更多信息

回答by Faisal Memon

I've recently studied this topic area and here is my summary:

我最近研究了这个主题领域,这是我的总结:

EXC_BAD_ACCESS (SIGSEGV)or EXC_BAD_ACCESS (SIGBUS)

EXC_BAD_ACCESS (SIGSEGV)或者 EXC_BAD_ACCESS (SIGBUS)

Our program most likely tried to access a bad memory location or the address was good but we did not have the privilege to access it. The memory might have been deallocated due to memory pressure.

我们的程序很可能试图访问错误的内存位置或地址是好的,但我们没有访问它的权限。由于内存压力,内存可能已被释放。

EXC_BREAKPOINT (SIGTRAP)

EXC_BREAKPOINT (SIGTRAP)

This is due to an NSExceptionbeing raised (possibly by a library on our behalf) or _NSLockErroror objc_exception_throwbeing called. For example, this can be the Swift environment detecting an anomaly such as force unwrapping a nil optional.

这是由于NSException所提出的(可能是由图书馆代表我们)或_NSLockErrorobjc_exception_throw被调用。例如,这可以是 Swift 环境检测到异常情况,例如强制解包 nil 可选。

EXC_BAD_INSTRUCTION (SIGILL)

EXC_BAD_INSTRUCTION (SIGILL)

This is when the program code itself is faulty, not the memory it might be accessing. This should be rare on iOS devices; perhaps a compiler or optimizer bug, or faulty hand written assembly code. On Simulator, it is a different story as using an undefined opcode is a technique used by the Swift runtime to stop on access to zombie objects (deallocated objects).

这是程序代码本身有问题的时候,而不是它可能正在访问的内存。这在 iOS 设备上应该很少见;可能是编译器或优化器错误,或错误的手写汇编代码。在模拟器上,情况就不同了,因为使用未定义的操作码是 Swift 运行时用来停止访问僵尸对象(解除分配的对象)的技术。

EXC_GUARD

EXC_GUARD

This is when the program closed a file descriptor that was guarded. An example is the SQLite database used by the system.

这是程序关闭受保护的文件描述符的时间。一个例子是系统使用的 SQLite 数据库。