Skip to content

Instantly share code, notes, and snippets.

@bricklife
Created January 13, 2017 08:12
Show Gist options
  • Save bricklife/1f6bff179cf5bda5b99638afc25b248a to your computer and use it in GitHub Desktop.
Save bricklife/1f6bff179cf5bda5b99638afc25b248a to your computer and use it in GitHub Desktop.
LLDB Plugin - json
#!/usr/bin/env python
import lldb
def process(debugger, command, result, internal_dict):
lldb.debugger.HandleCommand("""
expr -l swift --
func $process(object: AnyObject) {
func json(object: AnyObject) -> String {
if let data = try? NSJSONSerialization.dataWithJSONObject(object, options: .PrettyPrinted) {
return String(data: data, encoding: NSUTF8StringEncoding) ?? ""
}
else {
return String(object)
}
}
Swift.print(json(object))
}
""".strip())
lldb.debugger.HandleCommand('expr -l swift -- $process(' + command + ')')
def __lldb_init_module(debugger,internal_dict):
debugger.HandleCommand("command script add -f json.process json")
print "json command enabled."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment