首页 > 解决方案 > 如何使用 LLDB python API `debugger.CreateTarget` 指定 dsym 文件

问题描述

我可以在 lldb 命令行应用程序中指定 myapp.dsym:

target create --no-dependents -arch arm64 --symfile myapp.dsym myapp

但是在使用 python API 时如何指定 dsym 文件?

target = debugger.CreateTarget(

    "myapp", triple, platform_name, add_dependents, lldb.SBError())

我在https://github.com/llvm/llvm-project/https://lldb.llvm.org/python_reference/index.html中进行了搜索。但无法解决。

标签: pythondebugginglldbdsym

解决方案


如果您的二进制文件是/tmp/a.out并且您的 dSYM 是/tmp/hide.noindex/a.out.dSYM,这将是一种方法:

(lldb) scri
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> dbg = lldb.SBDebugger().Create()
>>> dbg.SetAsync(False)
>>> target = dbg.CreateTarget('')
>>> modspec = lldb.SBModuleSpec()
>>> modspec.SetFileSpec(lldb.SBFileSpec("/tmp/a.out"))
>>> modspec.SetSymbolFileSpec(lldb.SBFileSpec("/tmp/hide.noindex/a.out.dSYM"))
>>> target.AddModule(modspec)
<lldb.SBModule; proxy of <Swig Object of type 'lldb::SBModule *' at 0x1077e2ea0> >
>>> target.BreakpointCreateByName("main")
<lldb.SBBreakpoint; proxy of <Swig Object of type 'lldb::SBBreakpoint *' at 0x1077e2f60> >
>>> process = target.LaunchSimple(None, None, "/tmp/")
>>> print (process)
SBProcess: pid = 87848, state = stopped, threads = 1, executable = a.out
>>> print (process.GetThreadAtIndex(0))
thread #1: tid = 0xeacb2f, 0x000000010a548fb0 a.out`main, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

推荐阅读