objective-c - Xcode5 如何调试 快速定位出错行
怪我咯
怪我咯 2017-04-22 09:00:08
0
3
712

、、、objectivec
2014-07-21 18:02:38.259 Sections[2962:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'must pass a class of kind UITableViewCell'
*** First throw call stack:
(
0 CoreFoundation 0x017375e4 exceptionPreprocess + 180
1 libobjc.A.dylib 0x014ba8b6 objc_exception_throw + 44
2 CoreFoundation 0x017373bb +[NSException raise:format:] + 139
3 UIKit 0x00314e08 -[UITableView registerClass:forCellReuseIdentifier:] + 247
4 Sections 0x000030eb -[BIDViewController searchDisplayController:didLoadSearchResultsTableView:] + 171
5 UIKit 0x005cc0b4 -[UISearchDisplayController searchResultsTableView] + 446
6 UIKit 0x005cd5f4 -[UISearchDisplayController _containerView] + 1031
7 UIKit 0x005c7563 -[UISearchDisplayController setActive:animated:] + 9462
8 UIKit 0x005cad4f -[UISearchDisplayController searchBarTextDidBeginEditing:] + 298
9 UIKit 0x004f52c9 -[UISearchBar(UISearchBarStatic) _searchFieldBeginEditing] + 113
10 libobjc.A.dylib 0x014cc81f -[NSObject performSelector:withObject:] + 70
11 UIKit 0x0022ec8c -[UIApplication sendAction:to:from:forEvent:] + 108
12 UIKit 0x0022ec18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
13 UIKit 0x003266d9 -[UIControl sendAction:to:forEvent:] + 66
14 UIKit 0x00326a9c -[UIControl _sendActionsForEvents:withEvent:] + 577
15 UIKit 0x0091254e -[UITextField willAttachFieldEditor:] + 685
16 UIKit 0x0032c4d5 -[UIFieldEditor becomeFieldEditorForView:] + 927
17 UIKit 0x00909643 -[UITextField _becomeFirstResponder] + 160
18 UIKit 0x004f841a -[UISearchBarTextField _becomeFirstResponder] + 98
19 UIKit 0x00386585 -[UIResponder becomeFirstResponder] + 400
20 UIKit 0x00289d0b -[UIView(Hierarchy) becomeFirstResponder] + 114
21 UIKit 0x009090e3 -[UITextField becomeFirstResponder] + 51
22 UIKit 0x005ae651 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 135
23 UIKit 0x005b0ba2 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2640
24 UIKit 0x005a4f8c _UIGestureRecognizerSendActions + 230
25 UIKit 0x005a3c00 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
26 UIKit 0x005a566d -[UIGestureRecognizer _delayedUpdateGesture] + 60
27 UIKit 0x005a8bcd ___UIGestureRecognizerUpdate_block_invoke + 57
28 UIKit 0x005a8b4e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
29 UIKit 0x0059f248 _UIGestureRecognizerUpdate + 199
30 UIKit 0x0026bd4a -[UIWindow _sendGesturesForEvent:] + 1291
31 UIKit 0x0026cc6a -[UIWindow sendEvent:] + 1030
32 UIKit 0x00240a36 -[UIApplication sendEvent:] + 242
33 UIKit 0x0022ad9f _UIApplicationHandleEventQueue + 11421
34 CoreFoundation 0x016c08af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
+ 15
35 CoreFoundation 0x016c023b __CFRunLoopDoSources0 + 235
36 CoreFoundation 0x016dd30e __CFRunLoopRun + 910
37 CoreFoundation 0x016dcb33 CFRunLoopRunSpecific + 467
38 CoreFoundation 0x016dc94b CFRunLoopRunInMode + 123
39 GraphicsServices 0x036d89d7 GSEventRunModal + 192
40 GraphicsServices 0x036d87fe GSEventRun + 104
41 UIKit 0x0022d94b UIApplicationMain + 1225
42 Sections 0x0000399d main + 141
43 libdyld.dylib 0x01d75701 start + 1
44 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
、、、
如上所示,错误提示,使用的是XCODE5 无法根据错误提示找到出错行,网上有的方法试过不可以。希望知道的同学告知下。谢谢!

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回覆(3)
Ty80

在 Xcode 的 Breakpoint Navigator 裡面加入一個異常斷點(Add Exception Breakpoint),然後將斷點條件設定成 Exception: Object-C,這樣就能在異常拋出之前斷下來,你就可以查看當時的呼叫堆疊。

注意最好在快要執行到出問題代碼的時候才打開這個斷點,否則會不斷被各種異常乾擾。

洪涛

你的工程是叫Sections吧?
這就是你的拋異常的地方:
4 Sections 0x000030eb -[BIDViewController searchDisplayController:didLoadSearchResultsTableView:] + 171
BIDViewController類別的searchDisplayController方法的程式碼偏移量171處(差不多就是這個方法的170字元的地方,差不多是第2、3行吧,切記,171不是行號什麼的哦)。

關於ios異常分析,在一開始確實是非常頭痛的問題,因為它沒有直接告訴開發者拋異常的位置,甚至有時還沒有異常堆棧,而即使有異常堆棧也不容易看懂是什麼意思,特別還有那個代碼偏移量的數字,極具誤導性。通常調試的方法比較多,講完一整晚。 Huan Du回答的異常斷點是一種,當然還有日誌斷言打印查看法、符號斷點設定、LLDB調試工具。而我個人還是比較喜歡你題目中發的堆疊分析方法。基本上根據類別名稱、方法名稱和程式碼偏移量就能判斷出問題了。

關於堆疊報告,簡單介紹它裡面的內容是什麼意思:
如:
4 Sections 0x000030eb -[BIDViewController searchDisplayController:didLoadSearchResultsTableView:] + 171
總共包含了5部分:分別是4/Sections/0x000030eb/-[BIDVi...ew:]/171
第1部分:堆疊輸出序號,序號越大表示程式碼越早被呼叫;
第2部分:呼叫的方法所屬框架(函式庫/工程),例如Sections就是樓主您的工程;
第3部分:呼叫方法的記憶體位址,即0x000030eb
第4部分:呼叫方法名,這個非常重要,即-[BIDViewController searchDisplayController:didLoadSearchResultsTableView:]
第5部分:呼叫方法編譯之後的程式碼偏移量,這裡再次強調不是行號,只是編譯後的程式碼偏移量,但是基本上和字元數差不多,你可以透過一些文字工具,透過統計你的方法的字元偏移量大致的估計出錯的行,一般誤差在3~5行內。

這裡推薦一個小技巧,防止xcode不列印堆疊日誌:
在main.m中的main方法上加入@try@catch,就像下面這樣:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char* argv[])
{
    @try {
        @autoreleasepool
        {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
    }
    @catch (NSException* exception)
    {
        Log(@"Exception=%@\nStack Trace:%@", exception, [exception callStackSymbols]);
    }
}

不過記得發佈app前刪除try catch包裹哦,親~~~

大家讲道理

[UITableView registerClass:forCellReuseIdentifier:] 這裡出錯!

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!