WWDC 2013 - Advanced debugging with LLDB Summary
Finding problems
- Debug-only assertions
- NSAssert
- NS_BLOCK_ASSERTIONS disables assertions in release builds
- Log effectively with ASL (Apple System Log)
- ASL_LEVEL_EMERG
- ASL_LEVEL_DEBUG
- Use hash tags like #web in log messages
- Have switches for the heaviest logging (e.g. NSUserDefaults)
- Validate your program with Xcode
- WWDC 2010 Advanced memory analysis with instruments
- WWDC 2013 What's new in the LLVM compiler
Stopping before problems occur
- Breakpoints
- Stop at a source line:
- b MyView.m:4
- Stop at a method:
- b "-[MyViewA drawRect:]"
- Stop whenever any object receives a selector:
- b drawRect:
- Breakpoint commands run each time a breakpoint is hit (e.g. backtrace and continue)
- br co a
- > bt
- > c
- > DONE
- Can be done also from GUI
- Find when a method is called on a specific instance
- (lldb) p id $myModel = self --> create a persistent variable
- (lldb) b "-[MyModel dealloc]"
- (lldb) br m -c "self == $myModel"
- Focus on memory with watchpoints
- (lldb) watchpoint set variable self->_needSync
- Limitation - 4 on Intel, 2 on ARM
Stepping through problems
- (lldb) thread until 11 (th u 11)
- Calling code by hand
- call the code using Clang!
- (lldb) expression --ignore-breakpoints false -- [self removeDuplicates]
Inspecting data to find causes
- Inspecting data at the command line
- (lldb) frame variable --> show my locals
- (lldb) expression (x + 35) --> Execute arbitrary code
- (lldb) p @"Hello" --> Compact syntax for expression
- (lldb) po @"Hello" --> Execute code, then call the description selector on the result
- Data Formatters
- Built-in formatters for system libraries
- STL, CoreFoundation, Foundation
- Summaries
- Synthetic Children
Extending LLDB
- LLDB Object Model
- Calling SB (Scripting Bridge)
- Python API - full power of LLDB
- SBTarget
- SBProcess
- SBThread
- SBFrame
- Custom LLDB commands
- e.g. Calculate depth of a recursion
- Breakpoint Actions
- Breakpoint action allow full program inspection - code + data + object model
- Breakpoint actions associate a breakpoint with a Python function
- The function can return False to tell LLDB to continue your program
- Example: stop if a recursion is more than n levels deep
- Productizing customizations
- ~/.lldbinit
- ~/.lldbinit-Xcode
References
- LLDB Tutorial
- LLDB Quick Start Guide
- LLDB Debugging Infrastructure (video)
- LLDB help - (lldb) help / apropos
- WWDC 2013 videos - https://developer.apple.com/wwdc/videos/
- Interesting LLDB features and WWDC sessions
댓글
댓글 쓰기