我怎么知道
SBThread
是否退出或完成运行代码?
我编写了一个 LLDB 脚本来跟踪程序自启动以来进行的所有 fn 调用。循环应该在最后一次
exit
调用后结束,但实际上,它永远不会结束,并且线程使用无效的程序计数器连续执行。这是我的脚本:
import lldb
def run_program(debugger, command, result, internal_dict):
target = debugger.GetSelectedTarget()
print("target is %s"%(target,))
debugger.SetAsync(False)
l = lldb.SBLaunchInfo(argv=[])
error = lldb.SBError()
l.SetLaunchFlags(lldb.eLaunchFlagStopAtEntry)
process = target.Launch(l, error)
thread = process.GetThreadAtIndex(0)
start_fp = None
while not thread.is_stopped:
thread.StepOver()
frame = thread.get_thread_frames()[-1]
if not start_fp or start_fp != frame:
print("%s::"%(frame,))
start_fp = frame
return
def __lldb_init_module (debugger, dict):
#adds a command `rp` (type rp in the lldb prompt)
#this will execute a python function that keeps stepping until the frame is switched and then print info about the frame
debugger.HandleCommand('command script add -f %s.run_program rp' % __name__)
lldb --file vector
(lldb) target create "vector"
Current executable set to '/Users/draklor40/gowind-whisper/vector' (arm64).
(lldb) command script import run_program.py
(lldb)
在
exit()
之后我的循环继续运行:
frame #0: 0x00000001006990f0 vector`main(c_argc=0, c_argv=0x0000000000000000, c_envp=0x0000000000000000) at start.zig:501::
frame #1: 0x000000018c51be50 dyld`start + 2544::
{ 79, 79, 79, 79, 79, 79, 79, 79 }
1
frame #0: 0x000000018c56a058 dyld`dyld3::MachOFile::isSimulatorPlatform(dyld3::Platform, dyld3::Platform*)::
frame #0: 0x000000018c51be64 dyld`start + 2564::
frame #0: 0x000000018c85df68 libdyld.dylib`dyld4::LibSystemHelpers::exit(int) const::
frame #1: 0x000000018c51be9c dyld`start + 2620::
::
::
::
::
::
::
::
::
从documentation,它说,
is_stopped
只有在线程停止但没有退出时才为真。我怎么知道线程是否退出?