Skip to content

Instantly share code, notes, and snippets.

@catlan
Forked from zrxq/.lldbinit
Last active May 10, 2024 15:04
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catlan/a29608e8cbe493dd671e7c1b03760c50 to your computer and use it in GitHub Desktop.
Save catlan/a29608e8cbe493dd671e7c1b03760c50 to your computer and use it in GitHub Desktop.
Execute lldb command and open its output in Kaleidoscope diff

Diff output of two lldb commands

Setup

  1. Copy the contents of the last snippet (lldbinit) from the gist page, and paste into your .lldbinit file. This makes the ksdiff macro known inside lldb.
  2. Put file ksdiff.py in ~/.lldb/
  3. sudo pip install temp
  4. Restart Xcode debug session

Example

(lldb) ksdiff <any lldb command>; <any lldb command>

e.g.

(lldb) ksdiff po myArray1; po myArray2

If it doesn't work, make sure you have ksdiff installed and the path (see below) is correct

#
# See README.md for install details.
#
# (lldb) ksdiff <any lldb command>; <any lldb command>
#
# e.g.
#
# (lldb) ksdiff po myArray1; po myArray2
#
import lldb
import subprocess
import tempfile
diff_tool_path = '/usr/local/bin/ksdiff'
def ksdiff(debugger, command, result, dict):
res = lldb.SBCommandReturnObject()
comminter = debugger.GetCommandInterpreter()
commands = command.split(';')
comminter.HandleCommand(commands[0], res)
if not res.Succeeded():
print('error: ' + commands[0])
return
lhs_output = res.GetOutput()
lhs_file = tempfile.NamedTemporaryFile(delete=False)
lhs_file.write(lhs_output)
lhs_file.close()
comminter.HandleCommand(commands[1], res)
if not res.Succeeded():
print('error:' + commands[1])
return
rhs_output = res.GetOutput()
rhs_file = tempfile.NamedTemporaryFile(delete=False)
rhs_file.write(rhs_output)
rhs_file.close()
subl = subprocess.Popen([diff_tool_path, lhs_file.name, rhs_file.name])
### Kaleidoscope LLDB commands support - DO NOT MODIFY
command script import ~/.lldb/ksdiff.py
command script add -f ksdiff.ksdiff ksdiff
###
@catlan
Copy link
Author

catlan commented Oct 29, 2018

Screenshot

Screenshot

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