什么导致信号‘ SIGILL’?

我正在使用 NDK 和 GCC 将一些 C + + 代码移植到 Android 上。代码基本上运行。在 Eclipse 中进行调试时,调用

Dabbler::Android::Factory* pFactory = new Dabbler::Android::Factory;

导致了这个错误:

Thread [1] (Suspended: Signal 'SIGILL' received. Description: Illegal instruction.)
1 <symbol is not available> 0x812feb44

那是什么意思?编译器是否由于某种原因生成了非法代码?我在构造函数中有一个断点(它什么也不做) ,它没有被命中。我已经做了一个完整的重建。

我做错了什么会导致这个问题?

153075 次浏览

It means the CPU attempted to execute an instruction it didn't understand. This could be caused by corruption I guess, or maybe it's been compiled for the wrong architecture (in which case I would have thought the O/S would refuse to run the executable). Not entirely sure what the root issue is.

It could be some un-initialized function pointer, in particular if you have corrupted memory (then the bogus vtable of C++ bad pointers to invalid objects might give that).

BTW gdb watchpoints & tracepoints, and also valgrind might be useful (if available) to debug such issues. Or some address sanitizer.

Make sure that all functions with non-void return type have a return statement.

While some compilers automatically provide a default return value, others will send a SIGILL or SIGTRAP at runtime when trying to leave a function without a return value.

LeetCode's online compiler and dev environment generates SIGILL errors for mistakes that do not generate the same error in my desktop IDE.

For example, array access with an out-of-bounds index:

["foo", "bar"][2]

LeetCode's compiler shows only the error:

Runtime Error process exited with signal SIGILL

in a local Xcode playground this same code instead results in the error:

error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x18f2ea5d8).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

Only in a full Xcode project compilation and run does it report the actual error:

Thread 1: Fatal error: Index out of range