Redirect lldb output to file

前端 未结 2 1483
孤城傲影
孤城傲影 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:03

    Here is a slight modification incorporating some of the comments from above:

    def toFile(debugger, command, result, dict):
        f=open("/Users/user/temp.txt","w")
        debugger.SetOutputFileHandle(f,True);
        debugger.HandleCommand(command)  
        f.close()
        debugger.SetOutputFileHandle(sys.stdout, True)
    

    This allows the command to be supplied as an argument, and reverts the output file handle to stdout after the command is run.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题