将lldb输出重定向到文件

时间:2013-10-04 08:29:21

标签: lldb io-redirection

我在Xcode中使用lldb,我的一个变量包含大量的JSON数据。使用po myVar对分析这些数据没有多大帮助,因为它将在微小的Xcode调试控制台中输出。

有没有办法将lldb输出重定向到文件?

我看到here这样的功能似乎在gdb上可用:

(gdb) set logging on
(gdb) set logging file /tmp/mem.txt
(gdb) x/512bx 0xbffff3c0
(gdb) set logging off

并在lldb中“翻译”为:

(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

3 个答案:

答案 0 :(得分:13)

您可以使用Python脚本(以及更多),如下所述:

LLDB Python scripting in Xcode

在您选择的目录中创建一个名为po.py的文件(例如“〜/ .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 ')

然后在调试控制台中写:

comma script import ~/.lldb/po.py
print_to_file

答案 1 :(得分:1)

以下是对上述一些评论的轻微修改:

C:\Users> assoc .jar  
.jar=jarfile
C:\Users> ftype jarfile
jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*  

这允许命令作为参数提供,并在运行命令后将输出文件句柄恢复为stdout。

答案 2 :(得分:0)

我创建了一个使用memory read的Python脚本,然后处理输出以将其转换为我需要的格式(在我的情况下,每行一个值):https://gist.github.com/aleph7/96ec9b3c5df60a07b216

相关问题