调试基础

Debugging basics

我是编程新手,我正在尝试在 swift 中编写我的第一个应用程序。 我的应用程序在运行时崩溃了,但我无法理解 Xcode 调试导航器中的一个词。 我无法 post 截图,因为这是我在 Whosebug 的第一个 post。

你能帮我解释一下 XCode6 (Swift) 崩溃控制台。 我如何指出崩溃的原因? 我需要关注什么?

对于这个一般性问题,我深表歉意,但我无法在 XCode 6.

中找到有关调试的明确文档

感谢您的帮助

这是控制台显示的内容(删除断点后):

(Entrée dans la fonction, numberOfSectionsInTableView) (Entrée dans la fonction, tableView(:numberOfRowsInSection:)) (Entrée dans la fonction, numberOfSectionsInTableView) (Entrée dans la fonction, tableView(:numberOfRowsInSection:)) (Entrée dans la fonction, numberOfSectionsInTableView) (Entrée dans la fonction, tableView(:numberOfRowsInSection:)) (Entrée dans la fonction, numberOfSectionsInTableView) (Entrée dans la fonction, tableView(:numberOfRowsInSection:)) 2015-04-14 12:05:12.659 ListeDeCourses[20984:2203737] -[ListeDeCourses.AjoutViewController ButtonAdd:]: unrecognized selector sent to instance 0x7fe178739770 2015-04-14 12:05:12.663 ListeDeCourses[20984:2203737] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ListeDeCourses.AjoutViewController ButtonAdd:]: unrecognized selector sent to instance 0x7fe178739770' * First throw call stack: ( 0 CoreFoundation 0x0000000106ecff35 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000108a13bb7 objc_exception_throw + 45 2 CoreFoundation
0x0000000106ed704d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x0000000106e2f27c ___forwarding_
+ 988 4 CoreFoundation 0x0000000106e2ee18 _CF_forwarding_prep_0 + 120 5 UIKit
0x000000010775c8be -[UIApplication sendAction:to:from:forEvent:] + 75 6 UIKit 0x0000000107863410 -[UIControl _sendActionsForEvents:withEvent:] + 467 7 UIKit 0x00000001078627df -[UIControl touchesEnded:withEvent:] + 522 8
UIKit 0x00000001077a2308 -[UIWindow _sendTouchesForEvent:] + 735 9 UIKit 0x00000001077a2c33 -[UIWindow sendEvent:] + 683 10 UIKit
0x000000010776f9b1 -[UIApplication sendEvent:] + 246 11 UIKit
0x000000010777ca7d _UIApplicationHandleEventFromQueueEvent + 17370 12 UIKit 0x0000000107758103 _UIApplicationHandleEventQueue + 1961 13 CoreFoundation 0x0000000106e05551 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 14 CoreFoundation 0x0000000106dfb41d __CFRunLoopDoSources0 + 269 15 CoreFoundation 0x0000000106dfaa54 __CFRunLoopRun + 868 16 CoreFoundation
0x0000000106dfa486 CFRunLoopRunSpecific + 470 17 GraphicsServices
0x000000010afc69f0 GSEventRunModal + 161 18 UIKit
0x000000010775b420 UIApplicationMain + 1282 19 ListeDeCourses
0x0000000106ce243e top_level_code + 78 20 ListeDeCourses
0x0000000106ce247a main + 42 21 libdyld.dylib
0x00000001091ed145 start + 1 22 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

这是带有异常断点的显示内容:

(Entrée dans la fonction, numberOfSectionsInTableView) (Entrée dans la fonction, tableView(:numberOfRowsInSection:)) (Entrée dans la fonction, numberOfSectionsInTableView) (Entrée dans la fonction, tableView(:numberOfRowsInSection:)) (Entrée dans la fonction, numberOfSectionsInTableView) (Entrée dans la fonction, tableView(:numberOfRowsInSection:)) (Entrée dans la fonction, numberOfSectionsInTableView) (Entrée dans la fonction, tableView(:numberOfRowsInSection:)) 2015-04-14 12:10:28.285 ListeDeCourses[21044:2208020] -[ListeDeCourses.AjoutViewController ButtonAdd:]: unrecognized selector sent to instance 0x7fcf5a748630 (lldb)

最后一张截图:

通常,当您使用 Xcode 调试应用程序时,如果应用程序崩溃,XCode 将在崩溃的那一行停止。你可以看到 "Debug navigator"

中发生了什么

和控制台:

如果未出现控制台,请按此图像中蓝色按钮左侧的按钮以显示它。此栏按钮位于 XCode.

的底部

如果XCode没有在异常点停止,尝试在断点菜单中添加Exception断点:

罪魁祸首是

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ListeDeCourses.AjoutViewController ButtonAdd:]: unrecognized selector sent to instance 0x7fe178739770

意味着您向控制器发送了一条未知消息 ButtonAdd:。设置断点后,您的代码将停在相关位置,您应该能够找出原因。

我终于在 Whosebug 中发现我需要取消选中一个选项:Debug > Debug > Always show disassembly。 感谢大家帮助我在搜索中找到好的关键字。