I want to stop the debugger when a C++ exception is thrown. I start LLDB and run: break set -E c++
. Then run
and the program. It stops and this is my stack. As shown below this is not not the stack at the point of the C++ throw
. Shouldn’t it be?
This is on macOS, so there is a mix of C, Obj-C, and C++ in the stacktrace.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 6.2
* frame #0: 0x00007ff804804e88 libc++abi.dylib`__cxa_rethrow
frame #1: 0x00007ff8044fc90e libobjc.A.dylib`objc_exception_rethrow + 37
frame #2: 0x00007ff805754962 Foundation`-[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 482
frame #3: 0x00007ff805754726 Foundation`_NSAppleEventManagerGenericHandler + 80
frame #4: 0x00007ff80adfed9d AE`___lldb_unnamed_symbol829 + 1848
frame #5: 0x00007ff80adfe608 AE`___lldb_unnamed_symbol828 + 34
frame #6: 0x00007ff80adf7c1d AE`aeProcessAppleEvent + 419
frame #7: 0x00007ff80e281e3f HIToolbox`AEProcessAppleEvent + 54
frame #8: 0x00007ff807a73630 AppKit`_DPSNextEvent + 1738
frame #9: 0x00007ff807a72174 AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
frame #10: 0x00007ff807a647b7 AppKit`-[NSApplication run] + 586
frame #11: 0x00007ff807a387f7 AppKit`NSApplicationMain + 817
frame #12: 0x000000010002e149 buttons`UI::Apple::ApplicationMain(argc=1, argv=0x00007ff7bfeff810, delegate=0x000060000000c000) at Main.mm:60:5
frame #13: 0x0000000100009151 buttons`main(argc=1, argv=0x00007ff7bfeff810) at main.cc:27:9
frame #14: 0x00007ff804516310 dyld`start + 2432
It looks like system library code is throwing the exception. Eventually I found the line of code that throws the exception. Here it is below. (The buttons
binary is my test program.) If I step over that line, the exception gets thrown and I teleport to the shortened (and unhelpful) stacktrace shown above.
(lldb)
Process 85259 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
frame #0: 0x000000010007fc8a buttons`_ZN4objcW12AppleInteropW4objc12ClassBuilder9addMethodEPKcPFvvE(this=0x00007ff7bfefdb38, sel="displayLayer:", imp=(buttons`mcv_displayLayer(objc_object*, objc_selector*, void*) at MetalContentView.cc:290)) at objc_help.cc:140:17
137 if (proto) {
138 auto method = protocol_getMethodDescription(proto, selector, true, true);
139 if (!method.name) {
-> 140 throw std::runtime_error(std::format("Protocol doesn't have method: {}", sel));
141 }
142 class_addMethod(cls, selector, imp, method.types);
143 } else if (baseClass) {
Target 0: (buttons) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
* frame #0: 0x000000010007fc8a buttons`_ZN4objcW12AppleInteropW4objc12ClassBuilder9addMethodEPKcPFvvE(this=0x00007ff7bfefdb38, sel="displayLayer:", imp=(buttons`mcv_displayLayer(objc_object*, objc_selector*, void*) at MetalContentView.cc:290)) at objc_help.cc:140:17
frame #1: 0x000000010004c95f buttons`setupClass() at MetalContentView.cc:846:8
frame #2: 0x000000010004c73a buttons`MetalContentView::create() at MetalContentView.cc:874:9
frame #3: 0x000000010005c131 buttons`UI::Window::Window(this=0x0000600000004840, w=400, h=600) at Window.cc:67:28
frame #4: 0x000000010005c331 buttons`UI::Window::Window(this=0x0000600000004840, w=400, h=600) at Window.cc:55:30
frame #5: 0x000000010000a4d7 buttons`AppDelegate::applicationDidFinishLaunching(this=0x0000600000008060) at main.cc:129:18
frame #6: 0x000000010002e082 buttons`-[AppDelegateAdapter applicationDidFinishLaunching:](self=0x0000600000008070, _cmd="applicationDidFinishLaunching:", aNotification="NSApplicationDidFinishLaunchingNotification") at Main.mm:33:10
frame #7: 0x00007ff80491a3d4 CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 137
frame #8: 0x00007ff8049b441a CoreFoundation`___CFXRegistrationPost_block_invoke + 88
frame #9: 0x00007ff8049b4369 CoreFoundation`_CFXRegistrationPost + 536
frame #10: 0x00007ff8048ed8f9 CoreFoundation`_CFXNotificationPost + 735
frame #11: 0x00007ff805729abc Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 82
frame #12: 0x00007ff807a7b034 AppKit`-[NSApplication _postDidFinishNotification] + 305
frame #13: 0x00007ff807a7ad86 AppKit`-[NSApplication _sendFinishLaunchingNotification] + 208
frame #14: 0x00007ff807a78ab2 AppKit`-[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 541
frame #15: 0x00007ff807a78708 AppKit`-[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665
frame #16: 0x00007ff8057548b4 Foundation`-[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
frame #17: 0x00007ff805754726 Foundation`_NSAppleEventManagerGenericHandler + 80
frame #18: 0x00007ff80adfed9d AE`___lldb_unnamed_symbol829 + 1848
frame #19: 0x00007ff80adfe608 AE`___lldb_unnamed_symbol828 + 34
frame #20: 0x00007ff80adf7c1d AE`aeProcessAppleEvent + 419
frame #21: 0x00007ff80e281e3f HIToolbox`AEProcessAppleEvent + 54
frame #22: 0x00007ff807a73630 AppKit`_DPSNextEvent + 1738
frame #23: 0x00007ff807a72174 AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
frame #24: 0x00007ff807a647b7 AppKit`-[NSApplication run] + 586
frame #25: 0x00007ff807a387f7 AppKit`NSApplicationMain + 817
frame #26: 0x000000010002e149 buttons`UI::Apple::ApplicationMain(argc=1, argv=0x00007ff7bfeff810, delegate=0x0000600000008060) at Main.mm:60:5
frame #27: 0x0000000100009151 buttons`main(argc=1, argv=0x00007ff7bfeff810) at main.cc:27:9
frame #28: 0x00007ff804516310 dyld`start + 2432
(lldb)