你如何创建一个 LLDB 脚本来忽略 SIGSEGV 和 SIGBUS
How do you create a LLDB script to ignore SIGSEGV and SIGBUS
我经常 运行 lldb 中的 matlab 来调试一些共享库,并且想制作一个 lldb 脚本,而不是输入以下两行。
process handle --pass true --stop false --notify true SIGSEGV
process handle --pass true --stop false --notify true SIGBUS
我可以在 ~/.lldb/ignore_sigs 创建一个文件
但我不确定该文件中要放什么。
"process handle" 的工作方式,您必须有一个 运行 进程来附加信号行为;它不符合目标。所以一旦你有了一个过程,你就需要这样做。最简单的方法是在 .lldbinit 文件中的 main 上设置一个断点,并将命令添加到该断点:
break set -n main -C "process handle..." -C "process handle..."
.lldbinit 文件中设置的断点被所有 lldb 调试会话继承。如果您只希望将其应用于您的 matlab 调试会话,您可以创建一个 Python 命令来检查目标可执行文件的名称,如果它是 matlab,则只执行 process handle
,然后运行该过程处理命令。然后,您可以从断点调用该 Python 命令,如上所示。
我最终在 ~/.lldb/ignoreSigs.py
中创建了一个文件
内容如下
import lldb
def ignoreSigs(debugger, command, result, dict):
debugger.HandleCommand("process handle --pass true --stop false --notify true SIGSEGV")
debugger.HandleCommand("process handle --pass true --stop false --notify true SIGBUS")
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f ignoreSigs.ignoreSigs ignoreSigs')
然后我在 ~/.lldbinit
中添加了以下行
comma script import ~/.lldb/ignoreSigs.py
启动 matlab 后,我可以通过
禁用信号
matlab -Dlldb
run
#Wait for first signal to occur.
ignoreSigs
Jim Ingham 的方法对我有用,唯一的缺点是 main
中的断点在不同的函数中被多次击中,例如当 iOS 应用进入后台时。我添加了 -o true
现在它只命中一次:
break set -n main -o true -C "process handle --stop false --notify false SIGUSR1 SIGUSR2"
从 lldb 的帮助中获得:
lldb
help breakpoint set
-o <boolean> ( --one-shot <boolean> )
The breakpoint is deleted the first time it stop causes a stop.
可以使用脚本配置 lldb,这样就不需要手动输入任何命令。
在另一个问题中找到脚本:
我经常 运行 lldb 中的 matlab 来调试一些共享库,并且想制作一个 lldb 脚本,而不是输入以下两行。
process handle --pass true --stop false --notify true SIGSEGV
process handle --pass true --stop false --notify true SIGBUS
我可以在 ~/.lldb/ignore_sigs 创建一个文件 但我不确定该文件中要放什么。
"process handle" 的工作方式,您必须有一个 运行 进程来附加信号行为;它不符合目标。所以一旦你有了一个过程,你就需要这样做。最简单的方法是在 .lldbinit 文件中的 main 上设置一个断点,并将命令添加到该断点:
break set -n main -C "process handle..." -C "process handle..."
.lldbinit 文件中设置的断点被所有 lldb 调试会话继承。如果您只希望将其应用于您的 matlab 调试会话,您可以创建一个 Python 命令来检查目标可执行文件的名称,如果它是 matlab,则只执行 process handle
,然后运行该过程处理命令。然后,您可以从断点调用该 Python 命令,如上所示。
我最终在 ~/.lldb/ignoreSigs.py
中创建了一个文件内容如下
import lldb
def ignoreSigs(debugger, command, result, dict):
debugger.HandleCommand("process handle --pass true --stop false --notify true SIGSEGV")
debugger.HandleCommand("process handle --pass true --stop false --notify true SIGBUS")
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f ignoreSigs.ignoreSigs ignoreSigs')
然后我在 ~/.lldbinit
中添加了以下行comma script import ~/.lldb/ignoreSigs.py
启动 matlab 后,我可以通过
禁用信号matlab -Dlldb
run
#Wait for first signal to occur.
ignoreSigs
Jim Ingham 的方法对我有用,唯一的缺点是 main
中的断点在不同的函数中被多次击中,例如当 iOS 应用进入后台时。我添加了 -o true
现在它只命中一次:
break set -n main -o true -C "process handle --stop false --notify false SIGUSR1 SIGUSR2"
从 lldb 的帮助中获得:
lldb
help breakpoint set
-o <boolean> ( --one-shot <boolean> )
The breakpoint is deleted the first time it stop causes a stop.
可以使用脚本配置 lldb,这样就不需要手动输入任何命令。
在另一个问题中找到脚本: