我根据sigaction / sa_handler机制在Mac OSX上编写程序。运行用户的代码段,并随时准备捕获信号/异常。该程序工作正常,但问题是我无法使用lldb对其进行调试。lldb似乎无法忽略任何异常,即使我设置了
proc hand -p true -s false SIGSEGV
proc hand -p true -s false SIGBUS
Run Code Online (Sandbox Code Playgroud)
控制流在触发异常的指令处停止,即使我尝试使用command,也不会跳转到我先前安装的sa_handler c。输出为:
Process 764 stopped
* thread #2: tid = 0xf140, 0x00000001000b8000, stop reason = EXC_BAD_ACCESS (code=2, address=0x1000b8000)
Run Code Online (Sandbox Code Playgroud)
如何使lldb忽略异常/信号,并让程序的sa_handler执行其工作?
编辑:示例代码
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <pthread.h>
#include <unistd.h>
static void handler(int signo, siginfo_t *sigaction, void *context)
{
printf("in handler.\n");
signal(signo, SIG_DFL);
}
static void gen_exception()
{
printf("gen_exception in.\n");
*(int *)0 = 0;
printf("gen_exception out.\n");
}
void *gen_exception_thread(void *parg)
{ …Run Code Online (Sandbox Code Playgroud)