• 現 iOS (16.10 ~ )

• : minsone.github.io
• LLDB
• LLDB
• Execution Commands
• Evaluating Expression
• Script - Python REPL
• Chisel
• QA
LLDB
• Apple Xcode LLVM
• LLVM - LLDB
• https://lldb.llvm.org/
LLDB
LLDB
(Execution Commands)
Execution Commands
Execution Commands
# Thread
(lldb) thread list
# Thread 2
(lldb) thread select 2 

(lldb) t 2
# stack backtrace
(lldb) thread backtrace 

(lldb) bt
# stack backtrace
(lldb) thread backtrace all

(lldb) bt all
# stack backtrace frame
(lldb) thread backtrace -c 5 # 0~4 frame

(lldb) bt 5 # 0~4 frame

(lldb) thread backtrace -s 5 -c 10 # 5~14 frame
frame
# frame index
(lldb) frame select 3 # 3 Frame 

(lldb) frame info

(lldb) fr s 0 # 0 Frame 

(lldb) fr info
# frame
(lldb) up # frame select -relative=1

(lldb) up 3 #fr s -r3

(lldb) down # frame select -relative=-1

(lldb) down 4 # fr s -r-4
# frame
(lldb) frame variable [ ] # fr v [ ]

(lldb) frame variable --format x [ ] # fr v -f x [ ]

(lldb) frame variable -o [ ] # fr v -o [ ]
# global
(lldb) target variable

(lldb) target variable [ ]
#
(lldb) thread step-over

(lldb) next

(lldb) n
# frame
(lldb) thread step-in

(lldb) step

(lldb) s
# frame
(lldb) thread step-out

(lldb) finish
# /
(lldb) thread until 23

(lldb) thread until --frame 2 10
# / (1) - Command
(lldb) thread until 21 

(lldb) thread jump --line 19

(lldb) thread jump --by -2
# (2) - Drag
LLDB
(Evaluating Expression)
• LLDB .

• .

• Pause Swift .

• p, po, fr v .
Evaluating Expression
• Expression

• 

• LLDB .
Evaluating Expression
#
# Expression
# Print
# Print Object
Evaluating Expression
Command Alias for Execute
po [expession] expression -Object-description --
Code ,
debugDescription 

description 

LLDB formatter
p [expression] expression --
Code 

LLDB formatter
v / fr v [name] frame variable
Code , LLDB
formatter
Evaluating Expression
Command Alias for Execute
po [expession] expression -Object-description --
Code ,
debugDescription 

description 

LLDB formatter
p [expression] expression --
Code 

LLDB formatter
v / fr v [name] frame variable
Code , LLDB
formatter
“po” Under the Hood
(lldb) po view
: WWDC19 - LLDB: Beyond “po"
“po” Under the Hood
(lldb) po view
Create
compilable code
: WWDC19 - LLDB: Beyond “po"
func __lldb_expr() {

__lldb_res = view

}
“po” Under the Hood
(lldb) po view
Create
compilable code
: WWDC19 - LLDB: Beyond “po"
“po” Under the Hood
(lldb) po view
Create
compilable code
Compile
: WWDC19 - LLDB: Beyond “po"
“po” Under the Hood
(lldb) po view
Create
compilable code
Compile Execute
Get result
: WWDC19 - LLDB: Beyond “po"
func __lldb_expr2 -> String() {

return __lldb_res.description

}
“po” Under the Hood
(lldb) po view
Create
compilable code
Compile Execute
Create code to
access
description
Get result
: WWDC19 - LLDB: Beyond “po"
“po” Under the Hood
(lldb) po view
Create
compilable code
Compile Execute
Create code to
access
description
CompileGet result
: WWDC19 - LLDB: Beyond “po"
“po” Under the Hood
(lldb) po view
Create
compilable code
Compile Execute
Create code to
access
description
Compile ExecuteGet result
: WWDC19 - LLDB: Beyond “po"
“po” Under the Hood
(lldb) po view
Create
compilable code
Compile Execute
Create code to
access
description
Compile ExecuteGet result
“<UIView: 0x12345678>”
: WWDC19 - LLDB: Beyond “po"
“po” Under the Hood
(lldb) po view
Get string result
Create
compilable code
Compile Execute
Create code to
access
description
Compile ExecuteGet result
Display result
string
: WWDC19 - LLDB: Beyond “po"
Evaluating Expression
Command Alias for Execute
po [expession] expression -Object-description --
Code ,
debugDescription 

description 

LLDB formatter
p [expression] expression --
Code 

LLDB formatter
v / fr v [name] frame variable
Code , LLDB
formatter
“p” Under the Hood
(lldb) p cruise
: WWDC19 - LLDB: Beyond “po"
“p” Under the Hood
Create
compilable code
Compile Execute
Get result
(lldb) p cruise
: WWDC19 - LLDB: Beyond “po"
“p” Under the Hood
Dynamic type
resolution
Create
compilable code
Compile Execute
Get result
(lldb) p cruise
: WWDC19 - LLDB: Beyond “po"
“p” Under the Hood
(lldb) p cruise
Create
compilable code
Compile Execute
Get result Formatter
Dynamic type
resolution
: WWDC19 - LLDB: Beyond “po"
Evaluating Expression
Command Alias for Execute
po [expession] expression -Object-description --
Code ,
debugDescription 

description 

LLDB formatter
p [expression] expression --
Code 

LLDB formatter
v / fr v [name] frame variable
Code , LLDB
formatter
“v” Under the Hood
(lldb) v variable
: WWDC19 - LLDB: Beyond “po"
“v” Under the Hood
(lldb) v variable
(lldb) v variable
: WWDC19 - LLDB: Beyond “po"
“v” Under the Hood
Examine
program state
(lldb) v variable
(lldb) v variable
: WWDC19 - LLDB: Beyond “po"
“v” Under the Hood
Examine
program state
Read value from
memory
(lldb) v variable
(lldb) v variable
: WWDC19 - LLDB: Beyond “po"
“v” Under the Hood
Examine
program state
Read value from
memory
Dynamic type
resolution
(lldb) v variable
(lldb) v variable
: WWDC19 - LLDB: Beyond “po"
“v” Under the Hood
Examine
program state
Read value from
memory
Dynamic type
resolution
(lldb) v variable.field1
(lldb) v variable
: WWDC19 - LLDB: Beyond “po"
“v” Under the Hood
Examine
program state
Read value from
memory
Dynamic type
resolution
(lldb) v variable.field1 .field2
(lldb) v variable
: WWDC19 - LLDB: Beyond “po"
“v” Under the Hood
Examine
program state
Read value from
memory
Dynamic type
resolution
(lldb) v variable.field1 .field2
Formatter(lldb) v variable
: WWDC19 - LLDB: Beyond “po"
• 

• .

• .
Evaluating Expression
# Evaluating Expression -
# Evaluating Expression - Push
#
LLDB
(Script - Python REPL)
• Python LLDB Script .
Script - Python REPL
# Execute Script
# Import
# Default import
Chisel
• Facebook (https://github.com/facebook/
chisel)

• .

• iOS LLDB
Chisel
 Advanced Apple Debugging
and Reverse Engineering



from. Raywenderlich
LLDB: Beyond "po" - https://developer.apple.com/videos/play/wwdc2019/429/

[Apple - LLDB Quick Start Guide](https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/
gdb_to_lldb_transition_guide/document/Introduction.html#//apple_ref/doc/uid/TP40012917-CH1-SW1)

[UIKonf18 – Day 1 – Carola Nitz – Advanced Debugging Techniques](https://www.youtube.com/watch?v=578YdS2sNqk)

[Advanced Debugging with Xcode and LLDB](https://developer.apple.com/videos/play/wwdc2018/412)

[Chisel](https://github.com/facebook/chisel)

[LLDB Chisel Commands](https://kapeli.com/cheat_sheets/LLDB_Chisel_Commands.docset/Contents/Resources/Documents/
index)

[More than `po`: Debugging in lldb](https://www.slideshare.net/micheletitolo/more-than-po-debugging-in-lldb)

[Debugging RubyMotion applications](http://ruby-korea.github.io/RubyMotionDocumentation/articles/debugging/)

[Xcode LLDB ](https://www.letmecompile.com/xcode-lldb-%EB%94%94%EB%B2%84%EA%B9%85-
%ED%85%8C%ED%81%AC%EB%8B%89/)

[LLDB Debugging Cheat Sheet](https://gist.github.com/alanzeino/82713016fd6229ea43a8)

[Debugging a Debugger](http://idrisr.com/2015/10/12/debugging-a-debugger.html)

https://kapeli.com/cheat_sheets/LLDB_Chisel_Commands.docset/Contents/Resources/Documents/index

http://ios.137422.xyz/83589/

https://jayeshkawli.ghost.io/advanced-debugging-in-ios/

https://www.slideshare.net/YiyingTseng/debug-lldb-86558535

https://medium.com/flawless-app-stories/debugging-swift-code-with-lldb-b30c5cf2fd49

https://dailyhotel.io/advanced-debugging-with-xcode-and-lldb-8e8dc5326167

https://pspdfkit.com/blog/2018/how-to-extend-lldb-to-provide-a-better-debugging-experience/
QnA

[TECHCON 2019: MOBILE - iOS]3.쉽고 재미있는 iOS 디버깅 - LLDB Command

  • 3.
    • 現 iOS(16.10 ~ ) • : minsone.github.io
  • 4.
    • LLDB • LLDB •Execution Commands • Evaluating Expression • Script - Python REPL • Chisel • QA
  • 5.
  • 6.
    • Apple XcodeLLVM • LLVM - LLDB • https://lldb.llvm.org/ LLDB
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
    # Thread 2 (lldb)thread select 2 (lldb) t 2
  • 12.
    # stack backtrace (lldb)thread backtrace (lldb) bt
  • 13.
    # stack backtrace (lldb)thread backtrace all (lldb) bt all
  • 14.
    # stack backtraceframe (lldb) thread backtrace -c 5 # 0~4 frame (lldb) bt 5 # 0~4 frame (lldb) thread backtrace -s 5 -c 10 # 5~14 frame
  • 15.
  • 16.
    # frame index (lldb)frame select 3 # 3 Frame (lldb) frame info (lldb) fr s 0 # 0 Frame (lldb) fr info
  • 17.
    # frame (lldb) up# frame select -relative=1 (lldb) up 3 #fr s -r3 (lldb) down # frame select -relative=-1 (lldb) down 4 # fr s -r-4
  • 18.
    # frame (lldb) framevariable [ ] # fr v [ ] (lldb) frame variable --format x [ ] # fr v -f x [ ] (lldb) frame variable -o [ ] # fr v -o [ ]
  • 19.
    # global (lldb) targetvariable (lldb) target variable [ ]
  • 20.
  • 21.
    # frame (lldb) threadstep-in (lldb) step (lldb) s
  • 22.
    # frame (lldb) threadstep-out (lldb) finish
  • 23.
    # / (lldb) threaduntil 23 (lldb) thread until --frame 2 10
  • 24.
    # / (1)- Command (lldb) thread until 21 (lldb) thread jump --line 19 (lldb) thread jump --by -2
  • 25.
    # (2) -Drag
  • 26.
  • 27.
    • LLDB . •. • Pause Swift . • p, po, fr v . Evaluating Expression
  • 28.
    • Expression • •LLDB . Evaluating Expression
  • 29.
  • 30.
  • 31.
    Evaluating Expression Command Aliasfor Execute po [expession] expression -Object-description -- Code , debugDescription description LLDB formatter p [expression] expression -- Code LLDB formatter v / fr v [name] frame variable Code , LLDB formatter
  • 32.
    Evaluating Expression Command Aliasfor Execute po [expession] expression -Object-description -- Code , debugDescription description LLDB formatter p [expression] expression -- Code LLDB formatter v / fr v [name] frame variable Code , LLDB formatter
  • 33.
    “po” Under theHood (lldb) po view : WWDC19 - LLDB: Beyond “po"
  • 34.
    “po” Under theHood (lldb) po view Create compilable code : WWDC19 - LLDB: Beyond “po"
  • 35.
    func __lldb_expr() {
 __lldb_res= view
 } “po” Under the Hood (lldb) po view Create compilable code : WWDC19 - LLDB: Beyond “po"
  • 36.
    “po” Under theHood (lldb) po view Create compilable code Compile : WWDC19 - LLDB: Beyond “po"
  • 37.
    “po” Under theHood (lldb) po view Create compilable code Compile Execute Get result : WWDC19 - LLDB: Beyond “po"
  • 38.
    func __lldb_expr2 ->String() {
 return __lldb_res.description
 } “po” Under the Hood (lldb) po view Create compilable code Compile Execute Create code to access description Get result : WWDC19 - LLDB: Beyond “po"
  • 39.
    “po” Under theHood (lldb) po view Create compilable code Compile Execute Create code to access description CompileGet result : WWDC19 - LLDB: Beyond “po"
  • 40.
    “po” Under theHood (lldb) po view Create compilable code Compile Execute Create code to access description Compile ExecuteGet result : WWDC19 - LLDB: Beyond “po"
  • 41.
    “po” Under theHood (lldb) po view Create compilable code Compile Execute Create code to access description Compile ExecuteGet result “<UIView: 0x12345678>” : WWDC19 - LLDB: Beyond “po"
  • 42.
    “po” Under theHood (lldb) po view Get string result Create compilable code Compile Execute Create code to access description Compile ExecuteGet result Display result string : WWDC19 - LLDB: Beyond “po"
  • 43.
    Evaluating Expression Command Aliasfor Execute po [expession] expression -Object-description -- Code , debugDescription description LLDB formatter p [expression] expression -- Code LLDB formatter v / fr v [name] frame variable Code , LLDB formatter
  • 44.
    “p” Under theHood (lldb) p cruise : WWDC19 - LLDB: Beyond “po"
  • 45.
    “p” Under theHood Create compilable code Compile Execute Get result (lldb) p cruise : WWDC19 - LLDB: Beyond “po"
  • 46.
    “p” Under theHood Dynamic type resolution Create compilable code Compile Execute Get result (lldb) p cruise : WWDC19 - LLDB: Beyond “po"
  • 47.
    “p” Under theHood (lldb) p cruise Create compilable code Compile Execute Get result Formatter Dynamic type resolution : WWDC19 - LLDB: Beyond “po"
  • 48.
    Evaluating Expression Command Aliasfor Execute po [expession] expression -Object-description -- Code , debugDescription description LLDB formatter p [expression] expression -- Code LLDB formatter v / fr v [name] frame variable Code , LLDB formatter
  • 49.
    “v” Under theHood (lldb) v variable : WWDC19 - LLDB: Beyond “po"
  • 50.
    “v” Under theHood (lldb) v variable (lldb) v variable : WWDC19 - LLDB: Beyond “po"
  • 51.
    “v” Under theHood Examine program state (lldb) v variable (lldb) v variable : WWDC19 - LLDB: Beyond “po"
  • 52.
    “v” Under theHood Examine program state Read value from memory (lldb) v variable (lldb) v variable : WWDC19 - LLDB: Beyond “po"
  • 53.
    “v” Under theHood Examine program state Read value from memory Dynamic type resolution (lldb) v variable (lldb) v variable : WWDC19 - LLDB: Beyond “po"
  • 54.
    “v” Under theHood Examine program state Read value from memory Dynamic type resolution (lldb) v variable.field1 (lldb) v variable : WWDC19 - LLDB: Beyond “po"
  • 55.
    “v” Under theHood Examine program state Read value from memory Dynamic type resolution (lldb) v variable.field1 .field2 (lldb) v variable : WWDC19 - LLDB: Beyond “po"
  • 56.
    “v” Under theHood Examine program state Read value from memory Dynamic type resolution (lldb) v variable.field1 .field2 Formatter(lldb) v variable : WWDC19 - LLDB: Beyond “po"
  • 57.
    • • . •. Evaluating Expression
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
    • Python LLDBScript . Script - Python REPL # Execute Script # Import # Default import
  • 63.
  • 64.
  • 66.
     Advanced Apple Debugging andReverse Engineering
 
 from. Raywenderlich
  • 67.
    LLDB: Beyond "po"- https://developer.apple.com/videos/play/wwdc2019/429/ [Apple - LLDB Quick Start Guide](https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/ gdb_to_lldb_transition_guide/document/Introduction.html#//apple_ref/doc/uid/TP40012917-CH1-SW1) [UIKonf18 – Day 1 – Carola Nitz – Advanced Debugging Techniques](https://www.youtube.com/watch?v=578YdS2sNqk) [Advanced Debugging with Xcode and LLDB](https://developer.apple.com/videos/play/wwdc2018/412) [Chisel](https://github.com/facebook/chisel) [LLDB Chisel Commands](https://kapeli.com/cheat_sheets/LLDB_Chisel_Commands.docset/Contents/Resources/Documents/ index) [More than `po`: Debugging in lldb](https://www.slideshare.net/micheletitolo/more-than-po-debugging-in-lldb) [Debugging RubyMotion applications](http://ruby-korea.github.io/RubyMotionDocumentation/articles/debugging/) [Xcode LLDB ](https://www.letmecompile.com/xcode-lldb-%EB%94%94%EB%B2%84%EA%B9%85- %ED%85%8C%ED%81%AC%EB%8B%89/) [LLDB Debugging Cheat Sheet](https://gist.github.com/alanzeino/82713016fd6229ea43a8) [Debugging a Debugger](http://idrisr.com/2015/10/12/debugging-a-debugger.html) https://kapeli.com/cheat_sheets/LLDB_Chisel_Commands.docset/Contents/Resources/Documents/index http://ios.137422.xyz/83589/ https://jayeshkawli.ghost.io/advanced-debugging-in-ios/ https://www.slideshare.net/YiyingTseng/debug-lldb-86558535 https://medium.com/flawless-app-stories/debugging-swift-code-with-lldb-b30c5cf2fd49 https://dailyhotel.io/advanced-debugging-with-xcode-and-lldb-8e8dc5326167 https://pspdfkit.com/blog/2018/how-to-extend-lldb-to-provide-a-better-debugging-experience/
  • 68.