Running externals with asan / ubsan on macOS
Hello !
I'm trying to debug a memory issue in an external. My go-to tool for this in normal C++ code is using the compiler's -fsanitize=address / -fsanitize=undefined feature.
If I just compile my external with asan, when I load it I immediately get the error message:
==81381==ERROR: Interceptors are not working. This may be because AddressSanitizer is loaded too late (e.g. via dlopen). Please launch the executable with:
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
So I do what the error message asks me to, but now Max itself crashes as soon as it starts up... is there any way to get things to work?
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Process: Max [81446]
Path: /Applications/Max.app/Contents/MacOS/Max
Identifier: com.cycling74.Max
Version: 8.3.3 (6f7f6680766) (8.3.3)
Code Type: X86-64 (Native)
Parent Process: zsh [63572]
Responsible: iTerm2 [514]
User ID: 501
Date/Time: 2022-10-19 11:40:04.3980 -0400
OS Version: macOS 12.5.1 (21G83)
Report Version: 12
Bridge OS Version: 6.6 (19P6066)
Anonymous UUID: B54FFD31-C3CA-FD9C-6D55-A99EF72D6C93
Time Awake Since Boot: 930000 seconds
System Integrity Protection: disabled
Crashed Thread: 0 CrBrowserMain Dispatch queue: com.apple.main-thread
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process: exc handler [81446]
Thread 0 Crashed:: CrBrowserMain Dispatch queue: com.apple.main-thread
0 Chromium Embedded Framework 0x12c153c28 base::mac::CxxPersonalityRoutine(int, _Unwind_Action, unsigned long long, _Unwind_Exception*, _Unwind_Context*) + 47880
1 Chromium Embedded Framework 0x12c153965 base::mac::CxxPersonalityRoutine(int, _Unwind_Action, unsigned long long, _Unwind_Exception*, _Unwind_Context*) + 47173
2 libsystem_malloc.dylib 0x7ff801a12abb _malloc_zone_malloc + 125
3 libsystem_malloc.dylib 0x7ff801a014e8 malloc_set_zone_name + 334
4 libclang_rt.asan_osx_dynamic.dylib 0x106d16dea wrap_malloc_set_zone_name + 218
5 libdispatch.dylib 0x7ff801a24317 _dispatch_client_callout + 8
6 libdispatch.dylib 0x7ff801a254fa _dispatch_once_callout + 20
7 QuartzCore 0x7ff808ec669f get_malloc_zone() + 44
8 QuartzCore 0x7ff808d51803 CA::Transaction::push(bool) + 53
9 AppKit 0x7ff804728c12 NSPerformVisuallyAtomicChange + 95
10 AppKit 0x7ff804825d67 -[NSPersistentUIRestorer resumeNormalWindowOrderingAndDrawing] + 66
11 AppKit 0x7ff804825c53 -[NSPersistentUIRestorer tearDownStateRestorationApparatusAndResumeWindowOrdering] + 54
12 AppKit 0x7ff80481af09 -[NSPersistentUIRestorer finishedRestoringWindowsWithZOrder:completionHandler:] + 1514
13 AppKit 0x7ff8051dd28f -[NSPersistentUIRestorer restoreStateFromRecords:usingDelegate:requireSecureCoding:completionHandler:] + 1910
14 AppKit 0x7ff8046e0fd1 -[NSPersistentUIManager restoreAllPersistentStateWithCompletionHandler:] + 303
15 AppKit 0x7ff8046e03e5 -[NSApplication _reopenWindowsAsNecessaryIncludingRestorableState:completionHandler:] + 358
16 AppKit 0x7ff8046e016f -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 528
17 AppKit 0x7ff8046dfdd0 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665
18 Foundation 0x7ff802ad26d4 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
19 Foundation 0x7ff802ad2546 _NSAppleEventManagerGenericHandler + 80
20 AE 0x7ff808359480 0x7ff80834e000 + 46208
21 AE 0x7ff808358cea 0x7ff80834e000 + 44266
22 AE 0x7ff80835232f aeProcessAppleEvent + 419
23 HIToolbox 0x7ff80a95fce2 AEProcessAppleEvent + 54
24 AppKit 0x7ff8046da402 _DPSNextEvent + 2036
25 AppKit 0x7ff8046d866a -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1394
26 AppKit 0x7ff8046cad19 -[NSApplication run] + 586
27 Chromium Embedded Framework 0x12c1493bc base::mac::CxxPersonalityRoutine(int, _Unwind_Action, unsigned long long, _Unwind_Exception*, _Unwind_Context*) + 4764
28 Chromium Embedded Framework 0x12c1481d3 base::mac::CxxPersonalityRoutine(int, _Unwind_Action, unsigned long long, _Unwind_Exception*, _Unwind_Context*) + 179
29 Chromium Embedded Framework 0x12c1073bd uhash_compareUnicodeString_69 + 754989
30 Chromium Embedded Framework 0x12c0d33fd uhash_compareUnicodeString_69 + 542061
31 Chromium Embedded Framework 0x12bdb7d3b __gxx_personality_v0 + 401403
32 Max 0x1056b8282 MaxCefEventLoopHandler::runMessageLoop() + 18
33 Max 0x105b31e10 juce::JUCEApplicationBase::main() + 144
34 Max 0x105b31d63 juce::JUCEApplicationBase::main(int, char const**) + 83
35 dyld 0x112c4752e start + 462
For anyone finding this post: the solution is to simply remove CEF from Max's embedded packages.