受到rwestberg
's answer 的启发,我能够编写一个不消耗 100% CPU 的类似脚本。在rwestberg
的脚本中,这是必要的,因为脚本试图在 lldb 本身将事件从侦听器中永久删除之前从侦听器中读取事件。
这是改进的脚本:
import lldb
import threading
import time
class UnixSignalDisabler(threading.Thread):
def __init__(self, debugger):
super(UnixSignalDisabler, self).__init__()
self._debugger = debugger
self._handled = set()
def _suppress_signals(self, process):
print("UnixSignalDisabler: disabling SIGBUS, SIGSEGV in process #" + str(process.GetUniqueID()))
signals = process.GetUnixSignals()
signals.SetShouldStop(10, False) # SIGBUS
signals.SetShouldStop(11, False) # SIGSEGV
def run(self):
while True:
for target in self._debugger:
if target:
process = target.GetProcess()
if process and not process.GetUniqueID() in self._handled:
self._suppress_signals(process)
self._handled.add(process.GetUniqueID())
# Don't hog CPU
time.sleep(0.03)
def __lldb_init_module(debugger, *rest):
# Can't use 'debugger' reference directly because it gets deleted after calling '__lldb_init_module'
debugger = lldb.SBDebugger.FindDebuggerWithID(debugger.GetID())
listener_thread = UnixSignalDisabler(debugger)
listener_thread.start()
要使用,请将其放在类似的位置ignore_signals.py
并从以下位置引用它.lldbinit
:
command script import ~/ignore_signals.py