Redirect lldb output to file

前端 未结 2 1484
孤城傲影
孤城傲影 2021-02-02 14:49

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

2条回答
  •  别那么骄傲
    2021-02-02 15:13

    You can use a Python script to do so (and much more), as explained here:

    LLDB Python scripting in Xcode

    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
    

提交回复
热议问题