是什么导致信号“SIGILL”?

发布于 2024-12-12 03:55:57 字数 522 浏览 0 评论 0原文

我正在使用 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

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

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

I'm porting some C++ code to Android using NDK and GCC. The code basically runs. At one point, when debugging in Eclipse, the call

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

causes this error:

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

What does that mean? Has the compiler generated illegal code for some reason? I have a breakpoint in the constructor (which does nothing), and it's not hit. I have already done a full rebuild.

What could I be doing wrong to cause this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无需解释 2024-12-19 03:55:57

确保所有具有非 void 返回类型的函数都有 return 语句。

虽然某些编译器会自动提供默认返回值,但其他编译器会在运行时尝试让函数不带返回值时发送 SIGILL 或 SIGTRAP。

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.

绾颜 2024-12-19 03:55:57

这意味着 CPU 试图执行它不理解的指令。我猜这可能是由于损坏引起的,或者可能是针对错误的体系结构进行编译的(在这种情况下,我会认为操作系统会拒绝运行可执行文件)。不完全确定根本问题是什么。

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.

原谅我要高飞 2024-12-19 03:55:57

它可能是一些未初始化的函数指针,特别是如果您的内存已损坏(那么指向无效对象的 C++ 错误指针的虚假 vtable 可能会导致这种情况)。

BTW gdb 观察点和跟踪点以及 valgrind 可能对调试此类问题很有用(如果可用)。或者一些地址清理工具

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.

恏ㄋ傷疤忘ㄋ疼 2024-12-19 03:55:57

LeetCode 的在线编译器和开发环境对于不生成相同错误的错误会生成 SIGILL 错误在我的桌面 IDE 中。

例如,具有越界索引的数组访问:

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

LeetCode 的编译器仅显示错误:

运行时错误
进程退出并发出信号 SIGILL

但相同的代码会导致 错误

错误:执行被中断,原因:EXC_BREAKPOINT(代码=1,子代码=0x18f2ea5d8)。
进程已留在中断点,使用“thread return -x”返回到表达式求值之前的状态。

只有在完整的 Xcode 项目编译和运行中才会报告实际错误:

线程 1:致命错误:索引超出范围

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文