Skip to content

Instantly share code, notes, and snippets.

@LemonSpike
Last active February 14, 2023 15:29
Show Gist options
  • Save LemonSpike/7b63534052ca4d48bd79f77eccce3569 to your computer and use it in GitHub Desktop.
Save LemonSpike/7b63534052ca4d48bd79f77eccce3569 to your computer and use it in GitHub Desktop.
Xcode LLDB Snippets
command alias 🚽 expression -l objc -- (void)[CATransaction flush]
command alias porvc e -l swift -- UIApplication.shared.keyWindow?.rootViewController?.value(forKey: "_printHierarchy")

Xcode LLDB Snippets

here are some of my favourite LLDB shortcuts for the console junkies out there

Help

(lldb) help <command>

get help for a command like expression or break set

(lldb) help

get complete help docs

(lldb) type lookup Equatable

shows information about a type

Breakpoints

(lldb) run
(lldb) kill
... hit breakpoints...
(lldb) continue
(lldb) expr -i 0 -- functionWithBreakpoint()

calls the function that contains the breakpoint and stops at the breakpoint.

(lldb) break set -r "\.Circle\..*"

breaks on all calls from a specified class.

Expressions

(lldb) po let $array = [321,1241,44]

creates a variable that you can use later on. ensure that $ is added to the variable name.

(lldb) expression
struct $Person {
let name: String
}
po let $pranav = $Person.init(name: "pranav")
po $pranav
$Person
- name : "pranav"

define a struct in lldb and create new vars

(lldb) expr -l objc++ —- (Class)(variableName class)

tells lldb to fetch an expression using a particular language

(lldb) expr -O --language objc -- [SomeClass returnAnObject]

print the memory address of the result of an expression

(lldb) expr -O --language objc —- 0x100001c74

print the dynamic type of the result of a memory address

(lldb) e -l swift -- UIApplication.shared.keyWindow?.rootViewController?.value(forKey: "_printHierarchy")

get a printout of your entire view hierarchy during pause

(lldb) expression
extension Collection where Self.Element == Int {
var $elementsOver30: [Self.Element]? {
return self.filter { $0 > 30 }
}
}
(lldb) po [32,31,4].$elementsOver30

swift extensions in lldb

Reading memory addresses

(lldb) po 0x100001c74

4294974580

Frames

(lldb) next
(lldb) step
(lldb) finish
(lldb) up
(lldb) down

move around the frame

(lldb) fr v

shows all local variables

(lldb) register read

show the general-purpose registers for the current thread

(lldb) fr v variableName

shows all information about a variable

(lldb) f

shows where you are in the frame

(lldb) thread info

shows extended information about the threads at a breakpoint

(lldb) bt

shows thread backtrace

(lldb) image list ModuleName

lists targets for module

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