简体   繁体   English

防止特定线程上的断点 - LLDB

[英]Prevent breakpoint on specific thread - LLDB

I know how to create/modify a breakpoint to stop only on a specific thread using breakpoint modify <breakpoint-id> -T <thread-name> , but can I do it the other way around, preventing the breakpoint to stop on a specific thread?我知道如何使用breakpoint modify <breakpoint-id> -T <thread-name>创建/修改断点以仅在特定线程上停止,但我可以反过来做,防止断点在特定线程上停止线?

I have a log thread that use the same function I'm trying to debug on other threads and it's annoying to have to let it continue every time it hits.我有一个日志线程,它使用我试图在其他线程上调试的相同功能,每次触发时都必须让它继续运行,这很烦人。

You can do this sort of thing using the lldb Python API and Python breakpoint callbacks.您可以使用 lldb Python API 和 Python 断点回调来执行此类操作。 The callback returns a "should stop" value, ie if it returns True, you stop at the breakpoint, and False you continue.回调返回一个“应该停止”值,即如果它返回 True,则在断点处停止,而 False 则继续。

So for instance:例如:

(lldb) breakpoint command add -s python -o 'return frame.thread.name != "MyThread"'

is what you wanted.是你想要的。 Note, in this example, I didn't provide a breakpoint ID.请注意,在此示例中,我没有提供断点 ID。 In lldb that means "act on the last set breakpoint".在 lldb 中,这意味着“在最后设置的断点上操作”。 But you can also supply the breakpoint ID if the one you want to add the command to doesn't happen to be the last breakpoint you set.但是,如果您想要添加命令的那个不是您设置的最后一个断点,您也可以提供断点 ID。 And if you want to add it to multiple breakpoints, you can specify a breakpoint ID list.并且如果你想将它添加到多个断点,你可以指定一个断点ID列表。

There's more on the API's and the callback format here:这里有更多关于 API 和回调格式的信息:

https://lldb.llvm.org/python_api.html https://lldb.llvm.org/python_api.html

https://lldb.llvm.org/use/python-reference.html#running-a-python-script-when-a-breakpoint-gets-hit https://lldb.llvm.org/use/python-reference.html#running-a-python-script-when-a-breakpoint-gets-hit

Note, however, that breakpoints with should-stop callbacks will force a stop every time the breakpoint is hit.但是请注意,带有应该停止回调的断点将在每次遇到断点时强制停止。 lldb auto-continues pretty quickly, so for many applications this isn't a problem. lldb 自动继续非常快,因此对于许多应用程序来说这不是问题。 But just getting from the stop over to the debugger and back is not cheap, so if your breakpoint is in a work loop and getting hit hundreds of thousands of times a second, this is going to slow down the run.但是仅仅从停止到调试器并返回并不便宜,所以如果你的断点在一个工作循环中并且每秒被命中数十万次,这会减慢运行速度。 If that ends up being a problem and you control your source code, tricks like the one Eljay suggested in the comments can be really handy.如果这最终成为一个问题并且您控制了您的源代码,那么像 Eljay 在评论中建议的技巧会非常方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM