将lldb输出重定向到文件 [英] Redirect lldb output to file
问题描述
我在Xcode中使用lldb,我的一个变量包含了很大一部分的JSON数据.使用po myVar
来分析这些数据并没有多大帮助,因为它将在微小的Xcode调试控制台中输出.
I'm using lldb inside Xcode, and one of my variables contains a huge chunk of JSON data. Using po myVar
isn't much helpful to analyse this data, as it will output in the tiny Xcode debug console.
是否可以将lldb输出重定向到文件?
我在此处看到,这样的功能似乎可以在gdb上使用:
I saw here that such a feature seems to be available on gdb as :
(gdb) set logging on
(gdb) set logging file /tmp/mem.txt
(gdb) x/512bx 0xbffff3c0
(gdb) set logging off
,并且在lldb中被翻译"为:
and is "translated" in lldb as :
(lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0
(lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0
(lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0
但是,对于我来说memory read
命令无济于事,并且--outfile
似乎不适用于print
命令.
However, the memory read
command will not help in my case, and --outfile
do not seems to be available for the print
command.
推荐答案
您可以使用Python脚本(以及更多)来这样做,如此处所述:
You can use a Python script to do so (and much more), as explained here:
在您选择的目录中创建一个名为po.py的文件(例如〜/.lldb"):
Create a file named po.py in a directory of your choice (for example "~/.lldb"):
import lldb
def print_to_file(debugger, command, result, dict):
#Change the output file to a path/name of your choice
f=open("/Users/user/temp.txt","w")
debugger.SetOutputFileHandle(f,True);
#Change command to the command you want the output of
command = "po self"
debugger.HandleCommand(command)
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f po.print_to_file print_to_file ')
然后在调试控制台中编写:
Then in the debug console write:
comma script import ~/.lldb/po.py
print_to_file
这篇关于将lldb输出重定向到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!