Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Xcode で快適なデバッグライフを追い求める

Xcode で快適なデバッグライフを追い求める

iOSDC https://iosdc.jp/2016/c/node/116

僕は怠惰な人間です。プログラミングの大半はデバッグに時間を費やすと思っているので、なるべく早く原因に辿りついたり効率のよいデバッグライフを送りたいと常々思っています。
プリントデバッグもいいのですが Xcode には便利な機能が色々とあります。それらを使うことで簡単に原因を特定できるケースがあります。
visualize されるのは分かりやすいですよね。
それらを tips で紹介できたらなと思います。

Toshihiro Morimoto

August 20, 2016
Tweet

More Decks by Toshihiro Morimoto

Other Decks in Technology

Transcript

  1. • Ϋϥογϡͨ͠Β AppDelegate ͩͬͨ໰୊ • Ͳͷ ViewController ͔Θ͔Βͳ͍໰୊ • ىಈ࣌ʹಛఆͷ

    ViewController ʹ͍ͨ͠໰୊ • ࣮ػͷϩά΍ϑΝΠϧΛऔಘ͍ͨ͠໰୊ ຊ೔ͷ͓͠ͳ͕͖
  2. (lldb) po self <ViewController: 0x61800000e080> (lldb) memory history 0x61800000e080 thread

    ... name = 'Memory allocated at' frame #0: 0x00000001051bba97 libclang_rt.asan_iossim_dynamic.dylib`wrap_calloc + 199 frame #1: 0x00000001064362fd libobjc.A.dylib`class_createInstance + 84 frame #2: 0x0000000106440dc7 libobjc.A.dylib`_objc_rootAlloc + 41 frame #3: 0x00000001072d6d25 UIKit`-[UIClassSwapper initWithCoder:] + 175 frame #4: 0x00000001074c731b UIKit`UINibDecoderDecodeObjectForValue + 683 ... Enable Address Sanitizer Λ༗ޮʹ͍ͯ͠Δͱ…
  3. (lldb) bt 0 // suggest * thread #1: tid =

    0x10503c9, 0x00000001088569f4 dealforest`ViewController.viewWillAppear(animated=false, self=0x000061800000e080) -> () + 20 at ViewController.swift:19, queue = 'com.apple.main-thread', stop reason = breakpoint 6.1 (lldb) po "[viewWillAppear] - \(self)”// custom format "[viewWillAppear] - <dealforest.ViewController: 0x61800000e080>" Action - Debugger Command
  4. (lldb) bt 0 * thread #1: tid = 0x10503c9, 0x00000001088569f4

    dealforest`ViewController.viewWillAppear(animated=false, self=0x000061800000e080) -> () + 20 at ViewController.swift:19, queue = 'com.apple.main-thread', stop reason = breakpoint 6.1 Action - Debugger Command ϦϯΫʹͳΓλοϓ͢Δͱ։͚Δ
  5. දࣔ͢ΔॲཧΛdidFinishLaunchingWithOptions ʹ௥Ճ if let env = NSProcessInfo().environment["DF_STORYBOARD_NAME"] { let names

    = env.componentsSeparatedByString(":") if let storyboardName = names.first { let storyboard = UIStoryboard(name: storyboardName, bundle: nil) let controller: UIViewController if let identifier = names.last where identifier != storyboardName { controller = storyboard .instantiateViewControllerWithIdentifier(identifier) } else { controller = storyboard.instantiateInitialViewController()! } window?.rootViewController = controller } }
  6. • ڧ੍తʹ logout • API ͷϦΫΤετઌΛมߋ • localhost:3000 • proxy

    • ϩάϨϕϧͷ੾Γସ͑ Environment Variables ͷ࢖͍ॴ
  7. • iExproler Λ࢖͍ iPhone ΛϚ΢ϯτ͠औಘ • PC ʹܨ͗ Xcode Ͱ

    Container Λऔಘɹɹɹɹ (͜ͷ৔߹ɺࣗ෼͕Ճೖ͍ͯ͠ΔνʔϜͷΞϓϦͷΈͰ͢) ࣮ػͷϩά΍ϑΝΠϧΛऔಘ͍ͨ͠໰୊
  8. • Xcode Functions • memory visualizer • Xcode Plugin •

    LLDB • p, po, frame variable • watchpoint • facebook/chisel And more
  9. • Xcode Settings - Diagonostics - Environment Variables • Breakpoint

    - Exception Breakpoint - Symbolic Breakpoint • LLDB Recap