2013年4月9日 星期二

Exception

教學文章 邊寫邊看

-於Breakpoint Navigator新增例外處理的斷點

-記憶體搜尋 (這應該不太會用到)

-LLDB Debuger
這東西太有趣了, 教學給指令
($eax用在simulator, $r0用在device, $rax用在OS X)
po $eax
po [$eax class]
po [$eax name]
po [$eax reason]

以下是實作碰到的問題:
找不到$eax這個暫存器, 上網找文章
register read //可以列出General Purpose Registers
但是還是沒有找到$eax, 最後這邊找到解法
檢查stack, 最上層的是否為objc_exception_throw
將發生錯誤時自動選擇到的[MainViewController buttonTapped:]
改選擇到objc_exception_throw
然後再使用register read, 就可以看到有$eax

第一篇結束


教學文章第二篇重點兩個

-Zombie 殭屍模式

-Run Static Analyzer

其他我看大多都程式邏輯錯誤





最後 引用該篇教學文章最後提到的Tips
  • If the app crashes on main.m, then set the Exception Breakpoint.
  • With the Exception Breakpoint enabled, you may no longer get a useful error message. In that case, either resume the app until you do, or type the “po $eax” command after the debug prompt.
  • If you get an EXC_BAD_ACCESS, enable Zombie Objects and try again.
  • The most common reason for crashes and other bugs are missing or bad connections in your nibs or storyboards. These usually don’t result in compiler errors and may therefore be hidden from sight.
  • Don’t ignore compiler warnings. If you have them, they’re often the reason why things go wrong. If you don’t understand why you get a certain compiler warning, then figure that out first. These are life savers!
  • Debugging on the device can be slightly different from debugging on the simulator. These two environments are not exactly the same and you’ll get different results.

沒有留言:

張貼留言