Skip to content

Instantly share code, notes, and snippets.

@9bany
Last active June 24, 2021 03:07
Show Gist options
  • Save 9bany/e6c370f7a359b2198c9b35956ba6ff4d to your computer and use it in GitHub Desktop.
Save 9bany/e6c370f7a359b2198c9b35956ba6ff4d to your computer and use it in GitHub Desktop.
LLDB

Explore variables value and state

expression, e, print, p, po

(lldb) print ... = (lldb) p ... = (lldb) expression -- ... = (lldb) e -- ...

Evaluate an expression on the current thread. Display any returned value with LLDB defalt formating.

  1. Usage
  • (lldb) e
  • (lldb) expression
  1. Flags
  • -D (--depth ) — Set the max recurse depth when dumping aggregate types (default is infinity).
  • -O (--object-description) — Display using a language-specific description API, if possible.
  • -T (--show-types) — Show variable types when dumping values.
  • -f (--format ) –– Specify a format to be used for display.
  • -i (--ignore-breakpoints ) — Ignore breakpoint hits while running expressions
  1. Help
  - (lldb) help # To explore all available commands
  - (lldb) help expression # To explore all expressions related sub-commands
  1. Example
  • (lldb) e -D 1 -- self
  • (lldb) e -D 1 -i false -- someMethod()

Get overall app’s state + language specific commands

  1. bugreport
  • Report full current app's state
  1. frame
  • Quick overview stack frame in current thread.

Control app's Execution follow

process, breakpoint, thread

  • process: control debug process
  The following subcommands are supported:

    attach    -- Attach to a process.
    connect   -- Connect to a remote debug service.
    continue  -- Continue execution of all threads in the current process.
    detach    -- Detach from the current target process.
    handle    -- Manage LLDB handling of OS signals for the current target
                 process.  Defaults to showing current policy.
    interrupt -- Interrupt the current target process.
    kill      -- Terminate the current target process.
    launch    -- Launch the executable in the debugger.
    load      -- Load a shared library into the current process.
    plugin    -- Send a custom command to the current target process plug-in.
    save-core -- Save the current process as a core file using an appropriate
                 file type.
    signal    -- Send a UNIX signal to the current target process.
    status    -- Show status and stop location for the current target process.
    unload    -- Unload a shared library from the current process using the
                 index returned by a previous call to "process load".
  • breakpoint
- breakpoint list
- breakpoint set -f ViewController.swift -l 96
- b ViewController.swift:96 // Short version of the command above
- breakpoint set --func-regex valueOfLifeWithoutSumOf
- b -r valueOfLifeWithoutSumOf // Short version of the command above
- breakpoint set --one-shot -f ViewController.swift -l 90
- br s -o -f ViewController.swift -l 91 // Shorter version of the command above
- breakpoint command list 2
  • thread
- (lldb) thread step-over
- (lldb) next // The same as "thread step-over" command
- (lldb) n // The same as "next" command
- (lldb) thread step-in
- (lldb) step // The same as "thread step-in"
- (lldb) s // The same as "step"

Honorable mentions

command, platform, gui

  • command import ~/Desktop/script.py
import lldb

def print_hello(debugger, command, result, internal_dict):
  print "Hello Debugger!"

def __lldb_init_module(debugger, internal_dict):
  debugger.HandleCommand('command script add -f script.print_hello print_hello') // Handle script initialization and add command from this module
  print 'The "print_hello" python command has been installed and is ready for use.' // Print confirmation that everything works
  • platform status
  • gui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment