开发者

Is there a way to see exactly what line a program crashes on in XCode?

开发者 https://www.devze.com 2023-02-13 12:17 出处:网络
I remember using a compiler (i think JCreator or Eclipse) that would tell you what line of code it crashed on.I can\'t find this info in XCode.Does it have this feature?

I remember using a compiler (i think JCreator or Eclipse) that would tell you what line of code it crashed on. I can't find this info in XCode. Does it have this feature?

EDIT:

Here's a sample stack throw

2011-02-26 18:07:24.859 NumbersFlashCards[8803:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString size]: unrecognized selector sent to instance 0x531b580'

* Call stack at first throw:

(

0   CoreFoundation                      0x00ebabe9 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x0100f5c2 objc_exception_throw + 47
2   CoreFoundation                      0x00ebc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3   CoreFoundation                      0x00e2c366 ___forwarding___ + 966
4   CoreFoundation                      0x00e2bf22 _CF_forwarding_prep_0 + 50
5   UIKit                               0x0039ab68 -[UIImageView initWithImage:] + 51
6   NumbersFlashCards                   0x00003373 -[LettersFlashCardsViewController viewDidLoad] + 3311
7   UIKit                               0x0037d65e -[UIViewController view] + 179
8   UIKit                               0x0037f012 -[UIViewController viewControllerForRotation] + 63
9   UIKit                               0x0037af76 -[UIViewController _visibleView] + 90
10  UIKit                               0x00614a97 -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 354
11  UIKit                               0x002f6ba8 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 954
12  UIKit                               0x00576948 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1053
13  UIKit                               0x00381982 -[UIViewController presentModalViewController:withTransition:] + 3151
14  NumbersFlashCards                   0x00005d83 -[StartPage start] + 103
15  UIKit                        开发者_StackOverflow社区       0x002cfa6e -[UIApplication sendAction:to:from:forEvent:] + 119
16  UIKit                               0x0035e1b5 -[UIControl sendAction:to:forEvent:] + 67
17  UIKit                               0x00360647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
18  UIKit                               0x0035f438 -[UIControl touchesBegan:withEvent:] + 277
19  UIKit                               0x002f4025 -[UIWindow _sendTouchesForEvent:] + 395
20  UIKit                               0x002d537a -[UIApplication sendEvent:] + 447
21  UIKit                               0x002da732 _UIApplicationHandleEvent + 7576
22  GraphicsServices                    0x017f0a36 PurpleEventCallback + 1550
23  CoreFoundation                      0x00e9c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
24  CoreFoundation                      0x00dfc6f7 __CFRunLoopDoSource1 + 215
25  CoreFoundation                      0x00df9983 __CFRunLoopRun + 979
26  CoreFoundation                      0x00df9240 CFRunLoopRunSpecific + 208
27  CoreFoundation                      0x00df9161 CFRunLoopRunInMode + 97
28  GraphicsServices                    0x017ef268 GSEventRunModal + 217
29  GraphicsServices                    0x017ef32d GSEventRun + 115
30  UIKit                               0x002de42e UIApplicationMain + 1160
31  NumbersFlashCards                   0x00002320 main + 102
32  NumbersFlashCards                   0x000022b1 start + 53
33  ???                                 0x00000001 0x0 + 1

)

and I know the crash was caused at line 112 of my code (i surrounded it with nslogs to narrow it down). But I don't see 112 anywhere here? I just don't want to have to track it down with nslogs every time.


Xcode uses the GNU Debugger GDB. At the (gdb) prompt type 'where' or 'backtrace' or 'bt' and you will see a backtrace. This shows you the call stack leading up to the crash. You will see a file path and line number in your backtrace. Sometimes this points directly to the culprit.

terminate called after throwing an instance of 'NSException'
(gdb) where
#0  0x3105ba1c in __pthread_kill ()
#1  0x34e0a3ba in pthread_kill ()
#2  0x34e02bfe in abort ()
#3  0x32c29a6a in __gnu_cxx::__verbose_terminate_handler ()
#4  0x35d66072 in _objc_terminate ()
#5  0x32c27e3c in __cxxabiv1::__terminate ()
#6  0x32c27e90 in std::terminate ()
#7  0x32c27f60 in __cxa_throw ()
#8  0x35d64c8a in objc_exception_throw ()
#9  0x34d8f3cc in -[NSException raise] ()
#10 0x3159ceda in -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] ()
#11 0x315559ca in _NSSetUsingKeyValueSetter ()
#12 0x31555216 in -[NSObject(NSKeyValueCoding) setValue:forKey:] ()
#13 0x3153742e in -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] ()
#14 0x3568c8de in -[UIRuntimeOutletConnection connect] ()
#15 0x34d27d7a in -[NSObject(NSObject) performSelector:] ()
#16 0x34d2799c in -[NSArray makeObjectsPerformSelector:] ()
#17 0x3568b846 in -[UINib instantiateWithOwner:options:] ()
#18 0x3568ce08 in -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] ()
#19 0x354b74cc in -[UIApplication _loadMainNibFile] ()
#20 0x354b1b08 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] ()
#21 0x354867d6 in -[UIApplication handleEvent:withNewEvent:] ()
#22 0x35486214 in -[UIApplication sendEvent:] ()
#23 0x35485c52 in _UIApplicationHandleEvent ()
#24 0x32199e76 in PurpleEventCallback ()
#25 0x34d66a96 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#26 0x34d6883e in __CFRunLoopDoSource1 ()
#27 0x34d6960c in __CFRunLoopRun ()
#28 0x34cf9ec2 in CFRunLoopRunSpecific ()
#29 0x34cf9dca in CFRunLoopRunInMode ()
#30 0x354b0d48 in -[UIApplication _run] ()
#31 0x354ae806 in UIApplicationMain ()
#32 0x00002ce2 in main (argc=1, argv=0x2fdff544) at /Users/dogbert/Documents/myNoobProject/main.m:13


You use "run and debug" in Xcode. If it crashes, the call stack is in the top left of the debugger window. Click the top item to see the location of the crash. Click any other line to see that call.

0

精彩评论

暂无评论...
验证码 换一张
取 消