Debugging in XCode: Exception Breakpoints
Asked Answered
G

1

6

I'm debugging a random SIGTRAP crash right now that just happens in the background. It's probably something that has to do with an NSManagedObjectContext somewhere.

Besides that, I'm trying to debug it using an exception breakpoint to at least find out where it's originating from. The only problem is that the crash/breakpoint occurs in a 0 objc_exception_throw, which is no help to me.

The data I get back looks like this:

libobjc.A.dylib`objc_exception_throw:
0x32a3a960:  push   {r4, r5, r6, r7, lr} // breakpoint stops here
0x32a3a962:  add    r7, sp, #12
0x32a3a964:  mov    r4, r0
0x32a3a966:  movs   r0, #16
0x32a3a968:  blx    0x32a46854                ; symbol stub for: -[NSObject isEqual:]

So my question is, how I can I create an exception breakpoint to initiate itself earlier? I'm trying to make the breakpoint occur in the last bit of actual Objective-C code before the crash.

I have tried editing the breakpoint to be shared, break on throw, then break on catch, and have changed the type of exception between Objective-C, C++, and "all" with no luck.

How can I make the exception breakpoint throw earlier?

Unless there is a way to decipher the code I posted. If that's possible, please give me a brief explanation of what it means, and how you deciphered it so I can learn to do so as well :)

Thanks everyone!

If I let the program run...

It continues to the crash, which looks like this:

libsystem_kernel.dylib`mach_msg_trap:
0x30830ea0:  mov    r12, sp
0x30830ea4:  push   {r4, r5, r6, r8}
0x30830ea8:  ldm    r12, {r4, r5, r6}
0x30830eac:  mvn    r12, #30
0x30830eb0:  svc    #128
0x30830eb4:  pop    {r4, r5, r6, r8} // SIGTRAP throws here
0x30830eb8:  bx     lr

Stack trace when running command "bt" as a debugger command

* thread #13: tid = 0x2337, 0x32a3a960 libobjc.A.dylib`objc_exception_throw, stop reason = breakpoint 1.1
    frame #0: 0x32a3a960 libobjc.A.dylib`objc_exception_throw
    frame #1: 0x340f9fee CoreData`-[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 298
    frame #2: 0x341522d2 CoreData`-[NSManagedObjectContext save:] + 730
    frame #3: 0x32054b02 UIKit`__84-[UIManagedDocument writeContents:toURL:forSaveOperation:originalContentsURL:error:]_block_invoke_0 + 30
    frame #4: 0x34155bc0 CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 88
    frame #5: 0x36e3d4b6 libdispatch.dylib`_dispatch_client_callout + 22
    frame #6: 0x36e419f6 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 30
    frame #7: 0x34155d42 CoreData`-[NSManagedObjectContext performBlockAndWait:] + 174
    frame #8: 0x32054862 UIKit`-[UIManagedDocument writeContents:toURL:forSaveOperation:originalContentsURL:error:] + 986
    frame #9: 0x3205418a UIKit`-[UIManagedDocument writeContents:andAttributes:safelyToURL:forSaveOperation:error:] + 698
    frame #10: 0x32017ce4 UIKit`__block_global_4 + 68
    frame #11: 0x32017c80 UIKit`__block_global_3 + 156
    frame #12: 0x339c767c Foundation`-[NSFileCoordinator _invokeAccessor:thenCompletionHandler:] + 144
    frame #13: 0x339c791e Foundation`__73-[NSFileCoordinator coordinateWritingItemAtURL:options:error:byAccessor:]_block_invoke_0 + 90
    frame #14: 0x339c894e Foundation`-[NSFileCoordinator(NSPrivate) _invokeAccessor:orDont:thenRelinquishAccessClaimForID:] + 202
    frame #15: 0x339c926c Foundation`-[NSFileCoordinator(NSPrivate) _coordinateWritingItemAtURL:options:error:byAccessor:] + 548
    frame #16: 0x339c78be Foundation`-[NSFileCoordinator coordinateWritingItemAtURL:options:error:byAccessor:] + 90
    frame #17: 0x32017254 UIKit`-[UIDocument _coordinateWritingItemAtURL:error:byAccessor:] + 720
    frame #18: 0x320179a0 UIKit`__59-[UIDocument saveToURL:forSaveOperation:completionHandler:]_block_invoke_0 + 284
    frame #19: 0x36e3e11e libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #20: 0x36e41ece libdispatch.dylib`_dispatch_queue_drain$VARIANT$mp + 142
    frame #21: 0x36e41dc0 libdispatch.dylib`_dispatch_queue_invoke$VARIANT$mp + 40
    frame #22: 0x36e4291c libdispatch.dylib`_dispatch_root_queue_drain + 184
    frame #23: 0x36e42ac0 libdispatch.dylib`_dispatch_worker_thread2 + 84
    frame #24: 0x33ba7a10 libsystem_c.dylib`_pthread_wqthread + 360
    frame #25: 0x33ba78a4 libsystem_c.dylib`start_wqthread + 8

Check out the link that Matt Wilding posted in the comments of his answer!

Godoy answered 11/1, 2013 at 0:17 Comment(5)
The debug navigator in Xcode doesn't help? Even at the highest 'resolution'?Degrease
Unfortunately, no. It's the most bizarre crash I've ever seen.Godoy
Weird. Sometimes one can hit the 'play' button in the debugger and the frameworks writes a more useful error message. But I assume, that you tried that and the debugger just sticks to the crash line...?Degrease
I added some code to show where it crashes.Godoy
@jsksma2 were to able to resolve what was causing this? I am having the same issue.Wares
F
1

You don't have much control over where that breakpoint triggers. Once you've hit the breakpoint though, you can use the bt command to print the current stack trace.


EDIT: With the backtrace...

It looks like UIDocument's -saveToURL:forSaveOperation:completionHandler: method is the culprit. I've never used the class before, so I can't help too much. If you're calling that method anywhere in your code (like from a block?), you could also put a breakpoint there, in anticipation of the failure.

Fabron answered 11/1, 2013 at 0:31 Comment(7)
Is that command what I would enter in for a "debugger command"?Godoy
You could certainly do that if you don't want to type it by hand.Fabron
I add the stack trace in my question.Godoy
Ummm here's the thing; I'm not using that anywhere within my code. However, I'm afraid that that method is called automatically when working with Core Data. I know you said that you're unfamiliar with that method, but do you have any ideas? Also, how did you figure out that that was the culprit? Thanks!Godoy
It was an educated guess based on the trace. It's at the bottom of the callstack that results in [NSManagedObjectContext save:] throwing an exception. Since it's public API, it's something that you could be calling yourself.Fabron
As for next steps, see this question for info on the exception itself.Fabron
That link is amazing! Thank you so much.Godoy

© 2022 - 2024 — McMap. All rights reserved.