如何告诉LLDB将信号传递到程序 [英] How to tell LLDB to pass signal onto program

查看:59
本文介绍了如何告诉LLDB将信号传递到程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在lldb中为MacOS上安装的基于C语言的应用程序设置了很多断点.断点大多在应用程序的同一功能中设置.但是,第二天我回到应用程序继续进行处理,然后又开始在同一函数中设置断点,出现了一个问题,即断点不在应用程序函数内部发生,而是在其中一个中断发生.应用程序的底层库,并且每次我尝试中断该功能(即它在底层库中停止)时,它都会一遍又一遍地执行此操作,而我无法通过单步执行(每次执行时,都会达到所需的功能) ,它只是在基础库中向前迈进).

I set a lot of breakpoints in lldb for a C language based application I installed on my MacOS. The breakpoints were mostly set in the same function in the application. However, the next day that I went back to the application to continue working on it, and I started setting breakpoints again in the same function, a problem arose in that the break didn't occur inside the application function, but rather in one of the underlying libraries of the application and it keeps doing this over and over again everytime I try to break in the function (i.e. it's stopping in the underlying library) and I'm not able to reach the desired function by stepping (every time I step, it just steps forward in the underlying library).

更新:

我在其中设置断点的函数是从信号处理程序中调用的.例如,当我发送SIGINT信号时,信号处理程序将调用某些函数以在应用程序中进行清理,而我在要清理的那些函数之一上设置了断点.有时,LLDB停止在我设置断点的函数中(使用stop reason = breakpoint 1.1),有时它停止在使用stop reason = signal SIGSTOP的基础/包含的事件处理库中;如果是后者,则停止在我按下"c"的情况下(继续进入希望的应用程序中的断点并从事件处理库中移出),只是有时候它让我继续到所需的断点,有时它只是说"Process 41524 resuming",而我再也无法到达所需的断点.

The function I am setting the breakpoint in is called from within a signal handler. For example when I send a SIGINT signal, the signal handler calls some functions to cleanup in the application, and I am setting the breakpoint on one of those functions that cleanup. Sometimes, LLDB stops in the function that I set the breakpoint in (with stop reason = breakpoint 1.1) , sometimes it stops in the underlying/included event handling library with stop reason = signal SIGSTOP and, if the latter, if I press "c" (to continue onto the breakpoint in the application hopefully and out of the event handling library), only sometimes does it let me continue onto the desired breakpoint, othertimes it just says "Process 41524 resuming" and I can never get to the desired breakpoint.

推荐答案

嗯,那我不认为问题出在断点上,而是问题在于您的信号处理程序是否真正被调用了.

Ah, then I don't think the problem was with breakpoints, but with whether your signal handler was actually getting called.

大多数调试器都有某种方法来控制接收到信号时发生的情况.在lldb中,这是通过process handle命令完成的.例如:

Most debuggers have some way to control what happens when a signal is received. In lldb this is done through the process handle command. For instance:

(lldb) process handle SIGSTOP
NAME         PASS   STOP   NOTIFY
===========  =====  =====  ======
SIGSTOP      false  true   true 

这意味着当为您的进程提供SIGSTOP时,lldb将停止,并会通知您有关SIGSTOP的信息,但不会将SIGSTOP传递给您正在调试的程序(因此,不会为SIGSTOP调用处理程序.)不带任何参数的process handle将为您提供所有信号的行为列表.

That means lldb will stop when your process is given a SIGSTOP, and will notify you about the SIGSTOP, but will NOT pass the SIGSTOP on to the program you are debugging (and thus your handler will not get called for SIGSTOP.) process handle with no arguments will give you the list of behaviors for all signals.

默认情况下,我们不传递SIGSTOP,因为调试器出于自身目的使用了SIGSTOP,因此您可能会收到对您的处理程序的调用,这些调用并非来自真实的" SIGSTOP.出于相同的原因,SIGINT也是如此:

We don't pass SIGSTOP by default because it is used by the debugger for its own purposes, and so you might get calls to your handler that didn't come from "real" SIGSTOP's. The same is true, for the same reason, of SIGINT:

(lldb) process handle SIGINT
NAME         PASS   STOP   NOTIFY
===========  =====  =====  ======
SIGINT       false  true   true 

您可以轻松更改此行为,例如SIGINT:

You can easily change this behavior, for instance for SIGINT:

(lldb) process handle SIGINT -p true
NAME         PASS   STOP   NOTIFY
===========  =====  =====  ======
SIGINT       true   true   true 

然后,调试器会将SIGINT传递给该进程,并在您的处理程序中停止.

Then the debugger will pass the SIGINT on to the process, and it will stop in your handler.

这篇关于如何告诉LLDB将信号传递到程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆