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
  • How Python summaries work
    • Summaries match a type to a Python function
    • LLDB passes an SBValue to it. The function returns a string to be shown
    • e.g.
    • (lldb) type summary add MyAddress --python-function MyAddress_Summary
  • Expression for data analysis

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

댓글

이 블로그의 인기 게시물

Wireless: HotSpot 2.0 이란?

Apple M1 Mac Mini에서 이더리움 (Ethereum) 채굴하기

Java: Java for Game? Java가 Game 개발에 어울릴까?