1 问题描述
开发APP进行GBD调试,程序自己运行时无问题,调试则遇到
GDB:Program received signal SIGILL, Illegal instruction. 0x46096268 in ?? () from /lib/libcrypto.so.1.0.
(gdb) start
Temporary breakpoint 1 at 0x183e0: file
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
warning: Unable to find libthread_db matching inferior’s thread library, thread debugging will not be available.
Program received signal SIGILL, Illegal instruction.
0x46096268 in ?? () from /lib/libcrypto.so.1.0.0
2 SIGILL介绍
进程在运行过程中会收到SIGILL信号,此类错误是由操作系统发送给进程的。
SIGILL是某个进程中的某一句不能被CPU识别指令,这些指令可能是一些形式错误、未知或者特权指令。
详细见:https://www.cnblogs.com/arnoldlu/p/10815908.html
3 解决办法
(gdb) handle SIGILL nostop noprint
4根本原因
When debugging I observe SIGILL during OpenSSL initialization?
OpenSSL adapts to processor it executes on and for this reason has to
query its capabilities. Unfortunately on some processors the only way
to achieve this for non-privileged code is to attempt instructions
that can cause Illegal Instruction exceptions. The initialization
procedure is coded to handle these exceptions to manipulate
corresponding bits in capabilities vector. This normally appears
transparent, except when you execute it under debugger, which stops
prior delivering signal to handler. Simply resuming execution does the
trick, but when debugging a lot it might feel counterproductive. Two
options. Either set explicit capability environment variable in order
to bypass the capability query (see corresponding crypto/*cap.c for
details). Or configure debugger not to stop upon SIGILL exception,
e.g. in gdb case add ‘handle SIGILL nostop’ to your .gdbinit.
官方原文地址:https://www.openssl.org/docs/faq.html#PROG17
OpenSSL为了适应处理器,因此必须查询它的能力。不幸的是,在某些处理器上,实现非特权代码的唯一方法是尝试可能导致非法指令异常的指令。初始化过程被编码来处理这些异常。这通常是透明的,除非你在调试器下执行它,它会在向处理程序传递信号之前停止。简单地恢复执行就可以了,但是当大量调试时可能会适得其反。两个选择。
1、设置显式的能力环境变量以绕过能力查询(参见相应的crypto/*cap.c了解详细信息)。
2、或者配置调试器在SIGILL异常时不停止,例如在gdb的情况下,在.gdbinit中添加’ handle SIGILL nostop '。
这里我使用第二种,成功进行调试