Skip to content

Instantly share code, notes, and snippets.

@vprtwn
Created June 6, 2014 23:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vprtwn/3969600f5b74e5c69268 to your computer and use it in GitHub Desktop.
Save vprtwn/3969600f5b74e5c69268 to your computer and use it in GitHub Desktop.
WWDC2014_IntroToLLDBAndTheSwiftREPL

Intro To LLDB and the Swift REPL

Sean Callanan

Basic debugging

  • lldb commands
    • ti/ thread info
      • EXC_BAD_INSTRUCTION = CPU doesn't understand an instruction
        • typically used in assertions -> Assertion failure
    • bt / thread backtrace
      • prints all frames on the stack of the current thread
    • f 1 / frame select 1
    • p foo / expression foo
  • In Xcode, you can also see where blocks get dispatched

Symbolic breakpoints

  • br s -r timestwo.*String
  • methods of a class: -r Account\\.
  • Functions in a module: -r main\\.

Breakpoint commands

  • br co a \ breakpoint command add
    • >p valueInCents
    • >continue
    • >DONE
  • Caveat: You must set separate conditions and actions for Obj-C and Swift locations
  • (lldb) br m --c "a[3]==2"3.1
  • (lldb) br m --c "a[3]==2"3.1

REPL-enabled debugging workflows

  • (lldb) repl when your app is running

    • add code to an existing session(!)
    • : to get back to LLDB
    • :help to issue LLDB commands directly from the repl
  • $ xcrun swift in any shell

  • The REPL adds global code

  • use expression command for investigating stack variables

  • use LLDB REPL for global variables, classes, functions

  • See Advanced Debugging with LLDB 2013 video

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