Skip to content

Instantly share code, notes, and snippets.

@Bunn
Last active Sep 5, 2021
Embed
What would you like to do?
import lldb
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add -f SwiftPrinter.printer pjson')
def printer(debugger, command, result, internal_dict):
debugger.HandleCommand('p print(String(data: try! JSONSerialization.data(withJSONObject:' + command + ', options: .prettyPrinted), encoding: .utf8 )!)')
@Bunn

This comment has been minimized.

Copy link
Owner Author

@Bunn Bunn commented Jun 25, 2021

To use the script you'll need to import it first:
command script import $PATH_TO_YOUR_PYTHON_FILE

For example:

(lldb) pjson a
error: 'pjson' is not a valid command.
(lldb) command script import ~/lldb/SwiftPrinter.py
(lldb) pjson a
{
  "bar" : 123,
  "foo" : "banana",
  "wow" : [
    1,
    2,
    3,
    4
  ],
  "bleh" : {
    "bla" : 333
  }
}

Or set it up in your .lldbinit file

@eneko

This comment has been minimized.

Copy link

@eneko eneko commented Jun 25, 2021

Nice! Never done this before, where is/should be .lldbinit located? In the home directory?

@Bunn

This comment has been minimized.

Copy link
Owner Author

@Bunn Bunn commented Jun 25, 2021

Nice! Never done this before, where is/should be .lldbinit located? In the home directory?

Yes, @eneko home directory, for example:

cat ~/.lldbinit 
command script import ~/lldb/SwiftPrinter.py
@eneko

This comment has been minimized.

Copy link

@eneko eneko commented Jun 25, 2021

Great, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment