Linux:监听信号而不破坏后续核心转储的寄存器?
当我收到导致核心转储的信号时,我想运行自己的处理程序将 siginfo_t 和 ucontext_t 结构复制到全局变量,以便可以在核心转储中访问它们。目前,在处理程序的末尾,我重新分配默认处理程序并调用 raise(thesig)。这样做的问题是核心转储“信息寄存器”显示我的处理程序中寄存器的状态,而不是原始信号时的状态。我意识到,由于我保存了 ucontext_t,我可以在其中查找原始寄存器值,但是当核心转储在团队中传递时,这些知识可能会丢失/遗忘。
所以我的问题是:有没有办法重新发出信号,并确保核心转储文件保存原始信号的寄存器状态?我想也许我可以使用一些内联asm来手动恢复处理程序末尾的所有regs,然后返回到导致信号的指令而不是调用raise(),但我不确定我们是否可以保证重新-尝试该指令将导致与第一次尝试相同的信号行为。
When I get coredump-causing signal, I want to run my own handler to copy the siginfo_t and ucontext_t structures to global variables, so that they may be accessed in the core dump. Currently at the end of my handler I reassign the default handler and call raise(thesig). The problem with doing that is that the core dump "info registers" shows the state of the registers in my handler, and not at the time of the original signal. I realise that since I've saved ucontext_t, I can look in that for the original register values, but that knowledge is likely to get lost/forgotten when core dumps are passed around the team.
So my question is: is there a way to reraise a signal, and ensure the core dump file holds the register state of the original signal? I thought maybe I could use some inline asm to manually restore all the regs at the end of the handler, then return to the instruction that caused the signal instead of calling raise(), but I'm not sure if we can guarantee that re-attempting the instruction will cause the same signalling behaviour as the first attempt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在处理程序中重新引发信号,则无需复制任何内容 - 这些值将位于堆栈上并可以在核心转储。
只需再次执行
up 5
(或者无论您需要升级多少级才能到达崩溃点)并再次info reg
。是:使用
signal(signum, SIG_DFL);
将信号处置设置为SIG_DFL
并从处理程序返回。导致SIGSEGV
的指令将重新启动,并且现在将导致立即核心转储。If you re-raise the signal in your handler, then there is no need to copy anything -- the values will be on stack and accessible in the core dump.
Just do
up 5
(or however many levels you need to step up to get to the crash point) andinfo reg
again.Yes: set signal disposition to
SIG_DFL
usingsignal(signum, SIG_DFL);
and return from your handler. The instruction that causedSIGSEGV
will be restarted, and will now cause immediate core dump.