IOS
Debugging
Copy result from LLDB to clipboard
9 min
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 expr l swift o \[swift code] expr l swift o will tell lldb to interpret everything after as swift code expr l swift o print("hello from lldb") 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 command regex copy 's/( +)/expr l swift o uipasteboard general string = "\\(%1)"/' 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 echo "command regex copy 's/( +)/expr l swift o uipasteboard general string = \\"\\(%1)\\"; print(\\"result is copied to clipboard\\")/'" >> / lldbinit if we try to run a copy command in lldb session that is already running, it will show the following error we can re run application from xcode or, we can reload it by executing following from lldb console lldb command source / lldbinit using copy command copy command will use string representation from what is passed examples copying value from userdefaults lldb copy string(data userdefaults standard data(forkey "key")!, encoding utf8)! copy object description struct person { let name string let email string } let person = person(name "test person", email "test person\@email com") lldb copy person and we will have the following text in our clipboard person(name "test person", email "test person\@email com") autocomplete is not working with custom lldb commands simple workaround is to use po and then change it with copy references https //swiftsenpai com/testing/add custom lldb/ https //swiftsenpai com/testing/add custom lldb/