IOS
Debugging

Copy result from LLDB to clipboard

9min

Did you need to copy the result of po command to clipboard? Well, I needed, and it was a JSON of 1000+ lines. It was so painful to select everything from the LLDB console.

Thankfully, there's an option to create a custom LLDB command using Swift!

Using Swift code in LLDB

Shell


expr -l Swift -O -- will tell LLDB to interpret everything after -- as Swift code.

Shell


Creating LLDB copy command

First, we need to create a custom LLDB command that can be used from the debug session.

To create custom command execute following in LLDB console

LLDB


Doing it this way will make this command available for the current running LLDB session. As soon as the session is terminated, command won't be available.

To make the command available for all LLDB sessions, we need to add it to ~/.lldbinit file. To create LLDB copy command, execute the following in terminal.

Shell


If we try to run a copy command in LLDB session that is already running, it will show the following error.

Document image


We can re-run application from Xcode. Or, we can reload it by executing following from LLDB console.

LLDB


Using copy command

copy command will use String representation from what is passed.

Examples

Copying value from UserDefaults

LLDB



Copy object description

Swift

LLDB


And we will have the following text in our clipboard

Text


Autocomplete is not working with custom LLDB commands. Simple workaround is to use po and then change it with copy.

References