Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Last active June 4, 2024 13:36
Show Gist options
  • Save brennanMKE/88ec8d07ddb148456bb3619e2e494cdd to your computer and use it in GitHub Desktop.
Save brennanMKE/88ec8d07ddb148456bb3619e2e494cdd to your computer and use it in GitHub Desktop.
LLDB customization with additional commands

LLDB Custom Commands

LLDB can be customized with ~/.lldbinit to run commands and to load more commands from shell and python scripts. One option is Chisel which provides several commands which can be used to debug an software running in Xcode.

It is critical that LLDB can process the commands in ~/.lldbinit successfully as a failure can cause the debugger to fail or run in an undefined way. The configuration listed in this Gist prints a message at the start and end so that when the debugger is run it is clear if any errors are shown in the Xcode console they are related to LLDB.

The output below is what will appear when starting the debugger. If anything does go wrong it will be clear that something with the LLDB configuration has to be corrected.

Loading ~/.lldbinit
Loaded chisel for lldb
Loaded ~/.lldbinit

These files are placed in a folder which is synced with a cloud storage solution. In this case it is Dropbox. The files can be placed in ~/Dropbox/Root and ~/.lldbinit can be symlinked while lldbinit.py is referenced at the Root directory. These files are then kept current across any computers which sync with this cloud storage system.

ln -s ~/Dropbox/Root/lldbinit ~/.lldbinit

Once you've started the debugger you can pause execution and run help to get a full list of available commands.

Read the LLDB Tutorial for more information on how to use and extend LLDB.


# LLDB Init
# http://lldb.llvm.org/tutorial.html
command script import ~/Dropbox/Root/lldbinit.py
command script add -f lldbinit.printloading loading
command script add -f lldbinit.printloadedchisel loadedchisel
command script add -f lldbinit.printloaded loaded
loading
# https://github.com/facebook/chisel
command script import /usr/local/opt/chisel/libexec/fblldb.py
loadedchisel
loaded
if __name__ == "__main__":
print("Run only as script from LLDB... Not as standalone program!")
try:
import lldb
except:
pass
import sys
import re
import os
import time
import struct
import argparse
import subprocess
import tempfile
def printloading(debugger, command, result, internal_dict):
print ("Loading ~/.lldbinit")
def printloadedchisel(debugger, command, result, internal_dict):
print ("Loaded chisel for lldb")
def printloaded(debugger, command, result, internal_dict):
print ("Loaded ~/.lldbinit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment