Xcode Sanitizers and Runtime Issues

RSS for tag

Xcode Runtime Issues are reports of programming errors found at run time. Issues can be found by variety of tools, including Address Sanitizer (ASan), Main Thread Checker (MTC), Thread Sanitizer (TSan), and Undefined Behavior Sanitizer (UBSan).

Posts under Xcode Sanitizers and Runtime Issues tag

32 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

[Bug] std::variant in containers triggers UBSan error in Xcode 16.x
I've discovered a bug in Xcode 16.0/16.1 where using std::variant in containers across compilation units triggers UBSan errors. This is a regression as it works correctly in Xcode 15.4. Here's a minimal reproduction case: [base.h] #pragma once #include <string> #include <variant> #include <forward_list> class Item { public: std::variant<std::monostate, std::string> value; }; typedef std::forward_list<Item> ItemList; class Test { public: void addItem(const Item& item); ItemList items; }; [base.cpp] #include "base.h" void Test::addItem(const Item& item) { items.push_front(item); } [main.cpp] #include "base.h" int main() { Test t; Item item; t.addItem(item); return 0; } To reproduce: Compile with UBSan enabled (-fsanitize=undefined) Occurs on both arm64 and x86_64 Occurs in both Xcode 16.0 and 16.1 Works correctly in Xcode 15.4 I've filed a Feedback Assistant report: FB15710420 Workaround: The issue can be avoided by implementing the addItem method in the header file instead of a separate compilation unit. Has anyone else encountered this issue? Are there other workarounds besides moving the implementation to the header?
2
0
43
4h
Debugging a macOS IPS dump
I have a macOS application built via command line (xcodebuild) using Xcode 16.1. Developed on ARM but end user is on Intel (same macOS 15.1). App crashed and they sent me a .IPS dump. From what MacGPT tells me: Reading an IPS (Incident Processing System) file from a macOS crash report in Xcode isn’t as straightforward as with iOS device logs. I can open the dump using Console. I see the IPS dump is partially symbolicated. Line in the dump says: Meteorologist 0x103e0348f 0x103d88000 + 504975 Referencing this article: Adding identifiable symbol names to a crash report | Apple Developer Documentation I run this command and see the same UUID for x86_64 as in the dump. dwarfdump --uuid /Users/ed/meteorologist/trunk/Build/Meteorologist.xcarchive/dSYMs/Meteorologist.app.dSYM/Contents/Resources/DWARF/Meteorologist I run this command: atos -arch x86_64 -o /Users/ed/meteorologist/trunk/Build/Meteorologist.xcarchive/dSYMs/Meteorologist.app.dSYM/Contents/Resources/DWARF/Meteorologist -l 0x103d88000 0x103e0348f And it says: fg: no current job Suggestions for what I’m missing?
1
0
60
2d
New phone and new xcode version fail
I recently bought a new phone and update xcode version to the latest. An app that I have been developing and worked perfectly fine would not be runned. I kept getting errors similar to below. Is that anything wrong with my setting or something? Class _TtC6SQLite6Backup is implemented in both /System/Library/PrivateFrameworks/LinkServices.framework/LinkServices (0x1f16db218) and /private/var/containers/Bundle/Application/E2xxxx2xxA-DF7B-xx-***-xxxxxxxx/xxxx.app/xxxxx.debug.dylib (0xxxxxx3d0). One of the two will be used. Which one is undefined.
1
0
165
1w
'Segmentation fault: 11' error after upgrading to the latest macOS version
Today I updated my macbook pro to macOS sequoia. with this I also downloaded the latest Xcode and visionOS 2 packages. I had a working project. Which did work with my vision pro which is updated to the latest visionOS 2. But now whenever I try to click on preview in xcode while editing a swift file I am receiving the following error: (lot of lines here) Library/Developer/Xcode/DerivedData/test2-fznbrpphddkqdaddrzamkayoajjm/Build/Intermediates.noindex/RealityKitContent.build/Debug-xrsimulator/RealityKitContent_RealityKitContent.build/DerivedSources/RealityAssetsGenerated/CustomComponentUSDInitializers.usda error: Tool terminated by signal 'Segmentation fault: 11' I tried exiting and restarting my mac but the problem is not going away. Can someone help me with this? Thank you!
4
0
329
Oct ’24
SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<Presents_2024.Item> from [:]
I'm still getting this error (SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData._KKMDBackingData<Presents_2024.Item> from [:]) in Xcode 16.1 Beta (16B5001e). The app works for a limited amount of time and then crashes with this error. It looks like the SwiftData model isn't being created properly and when a context is saved it crashes. Can you tell me if this error will be fixed in the next beta?
8
4
650
3w
Peculiar EXC_BAD_ACCESS, involving sparse matrices
Helo all, Currently, I'm working on an iOS app that performs measurement and shows the results to the user in a graph. I use a Savitzky-Golay filter to filter out noise, so that the graph is nice and smooth. However, the code that calculates the Savitzky-Golay coefficients using sparse matrices crashes sometimes, throwing an EXC_BAD_ACCESS. I tried to find out what the problem is by turning on Address Sanitizer and Thread Sanitizer, but, for some reason, the bad access exception isn't thrown when either of these is on. What else could I try to trace back the problem? Thanks in advance, CaS To reproduce the error, run the following: import SwiftUI import Accelerate struct ContentView: View { var body: some View { VStack { Button("Try", action: test) } .padding() } func test() { for windowLength in 3...100 { let coeffs = SavitzkyGolay.coefficients(windowLength: windowLength, polynomialOrder: 2) print(coeffs) } } } class SavitzkyGolay { static func coefficients(windowLength: Int, polynomialOrder: Int, derivativeOrder: Int = 0, delta: Int = 1) -> [Double] { let (halfWindow, remainder) = windowLength.quotientAndRemainder(dividingBy: 2) var pos = Double(halfWindow) if remainder == 0 { pos -= 0.5 } let X = [Double](stride(from: Double(windowLength) - pos - 1, through: -pos, by: -1)) let P = [Double](stride(from: 0, through: Double(polynomialOrder), by: 1)) let A = P.map { exponent in X.map { pow($0, exponent) } } var B = [Double](repeating: 0, count: polynomialOrder + 1) B[derivativeOrder] = Double(factorial(derivativeOrder)) / pow(Double(delta), Double(derivativeOrder)) return leastSquaresSolution(A: A, B: B) } static func leastSquaresSolution(A: [[Double]], B: [Double]) -> [Double] { let sparseA = A.sparseMatrix() var sparseAValuesCopy = sparseA.values var xValues = [Double](repeating: 0, count: A.transpose().count) var bValues = B sparseAValuesCopy.withUnsafeMutableBufferPointer { valuesPtr in let a = SparseMatrix_Double( structure: sparseA.structure, data: valuesPtr.baseAddress! ) bValues.withUnsafeMutableBufferPointer { bPtr in xValues.withUnsafeMutableBufferPointer { xPtr in let b = DenseVector_Double( count: Int32(B.count), data: bPtr.baseAddress! ) let x = DenseVector_Double( count: Int32(A.transpose().count), data: xPtr.baseAddress! ) #warning("EXC_BAD_ACCESS is thrown below") print("This code is executed...") let status = SparseSolve(SparseLSMR(), a, b, x, SparsePreconditionerDiagScaling) print("...but, if an EXC_BAD_ACCESS is thrown, this code isn't") if status != SparseIterativeConverged { fatalError("Failed to converge. Returned with error \(status).") } } } } return xValues } } func factorial(_ n: Int) -> Int { n < 2 ? 1 : n * factorial(n - 1) } extension Array where Element == [Double] { func sparseMatrix() -> (structure: SparseMatrixStructure, values: [Double]) { let columns = self.transpose() var rowIndices: [Int32] = columns.map { column in column.indices.compactMap { indexInColumn in if column[indexInColumn] != 0 { return Int32(indexInColumn) } return nil } }.reduce([], +) let sparseColumns = columns.map { column in column.compactMap { if $0 != 0 { return $0 } return nil } } var counter = 0 var columnStarts = [Int]() for sparseColumn in sparseColumns { columnStarts.append(counter) counter += sparseColumn.count } let reducedSparseColumns = sparseColumns.reduce([], +) columnStarts.append(reducedSparseColumns.count) let structure: SparseMatrixStructure = rowIndices.withUnsafeMutableBufferPointer { rowIndicesPtr in columnStarts.withUnsafeMutableBufferPointer { columnStartsPtr in let attributes = SparseAttributes_t() return SparseMatrixStructure( rowCount: Int32(self.count), columnCount: Int32(columns.count), columnStarts: columnStartsPtr.baseAddress!, rowIndices: rowIndicesPtr.baseAddress!, attributes: attributes, blockSize: 1 ) } } return (structure, reducedSparseColumns) } func transpose() -> Self { let columns = self.count let rows = self.reduce(0) { Swift.max($0, $1.count) } return (0 ..< rows).reduce(into: []) { result, row in result.append((0 ..< columns).reduce(into: []) { result, column in result.append(row < self[column].count ? self[column][row] : 0) }) } } }
11
0
806
Jul ’24
Issue running app when SIP disabled.
I've been developing an MacOS app for a while and everything was going smoothly until one of the testers reported that the app was crashing on launch. After investigation, we discovered that he had System Integrity Protection disabled. I could reproduce the error by disabling SIP: Library not loaded: @rpath/myframework.framework/myframework Referenced from: <4C129258-1BF8-3D30-9AFE-BF4206D0A767> /Applications/MyApp.app/Contents/MacOS/MyApp Reason: , (security policy does not allow @ path expansion) (terminated at launch; ignore backtrace) The app launches normally if I reenable SIP. I can't find information about "security policy does not allow @ path expansion". I'll appreciate if someone can point me in the right direction.
2
0
564
Jun ’24
Suppressing "Known Hang" warnings with PERFC_SUPPRESSION_FILE
Recently we have started refactoring some code to use Swift concurrency in Xcode 15.3. As we have added some new async methods and Tasks, new runtime warnings have emerged titled "Known Hang" and several are listed. None of the stack traces listed with these warnings are in areas directly modified but some of the same types/methods called are also called from the modified areas. So I can sort of understand why they are coming up...but they had to have been there before we added the Swift concurrency. Example of a tooltip with the warnings: My first query is: Are these warnings only issued when Swift concurrency is added/applied (as they were not there when using closures and mostly just off the main thread to network calls)? The documentation indicates these can all be suppressed by turning off the Thread Performance Checker BUT I would rather just suppress the few places as we refactor our codebase (as it is quite large). In that way, any new ones may be documented and we can decide to fix them now or later. I have tried to follow the instructions and added an environment variable PERFC_SUPPRESSION_FILE (in the Scheme) with a full path to a file formatted similarly to the example in the documentation. class:NSManagedObjectContext method:-[NSManagedObjectContext save:] My second query is: I have verified that the variable is set by reading it from the ProcessInfo. However, regardless of my settings, the runtime warnings are still presented. I could not find any examples or even any mention of others using this environment variable. I am reaching out with any advice or ideas to try. Has anyone successfully tried this or found an issue/alternative? Help me Mr. Wizard!
3
0
712
May ’24
Memory corruption crash
Hello! We are experiencing crashes on iOS both in debug and release builds in a game made in Godot 3.5.1. The main problem is that we don’t know where exactly the problem is and cannot understand how could we find a way to fix it. We don't expect that someone here will know how to fix this on Godot's side, but we would appreciate some help on how to get more info about the problem and potentially fix it. Debug builds: It is way more frequent in debug builds when we make a build, open it in Xcode, and install it directly on an iOS device. The first type of the crash in debug build is occurring like 70% of the time when the game is loading and trying to get into its main menu. The thing we are getting in Xcode looks like on first image below. Another type of crash happens when we open some save files and start the actual playable part of the game. It happens just after moving the character a few steps and it looks like on second image below. We are aware that the log recommends using breakpoints to find where exactly the problem is, but the thing is that we don’t know where we could do that in Xcode. We are not sure if we are missing something in Xcode or if we cannot do that when opening a project made in Godot. We tried many different builds with removed shader files, and scenes and changed different kinds of settings. We would get the same crash every time. When we made a new build, we cleared the build’s folder. Also, we occasionally deleted the .import folder of the project during development and reimported it. The problem occurred on many different iOS devices with more than 4GB of RAM. Release builds: These builds are uploaded on TestFlight. In release builds crashes wouldn’t occur like in debug builds. They would happen like totally randomly. In some testing sessions, it would happen like 10 minutes in the game, and in others in a few hours. Some testers couldn’t get the crash and altogether and we couldn’t find some repro steps to produce these crashes. In the attached files, you can find logs that we managed to collect from TestFlight. The most frequent type of the crash that we got, is following: Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS Additional info: From reading Apple’s documentation Investigating memory access crashes, we got it that the problem is in “Invalid memory fetch”, but we couldn’t find how this could help us with further investigation. When we used Address Sanitizer tool and made a build, suddently the game stopped crashing in debug builds like it did before. Also we then didn't receive logs in Xcode that would hint us that something is going on. Tried to build our project in newer version of Godot, but the problem still persisted. Used software and hardware: Godot 3.5.1 macOS, Ventura, 13.5 Xcode, 15.2 iPad Air (5th generation), 17.4.1 MacBook Pro, Apple M1 If you have some clues or ideas on how to fix this problem, please write it, it would mean us a lot. Don’t hesitate to ask questions if something is unclear. Thank you very much in advance!
2
0
834
May ’24
xcode build error: Could not find path to clang binary to locate Address Sanitizer library
When I have the Address Sanitizer option turned off in Xcode(version 15.3), the project builds successfully. However, as soon as I enable the option, the build fails with the error message: 'Could not find path to clang binary to locate Address Sanitizer library.' I found libclang_rt.asan_ios_dynamic.dylib in the Xcode directory and added it to the build Phases -> Link Library with Libraries. However, I still get the same error. But when I create a new project and enable the Address Sanitizer option, it builds successfully.
1
0
551
Apr ’24
Callstack of a std::exception does not include the location of the throw
We have an C++ app which runs on multiple platforms and is build using the Qt framework. For a while we had issues with unexplainable stack traces reported by testflight users. Now I found out that if I just put throw std::runtime_error("something"); at the start of my main method the resulting crash call stack would not point to my main method. Is there something I can do (compiler flags/variables/code etc) to have the call stack from the actual throw show up in XCode and testflight?
3
0
479
Apr ’24
Lag on a complicated SwiftUI view on devices different than iPhone 13 mini
The problem, that I am currently facing is related to an electronic program guide screen. I will add a simplified example of what my initial implementation was. ScrollViewReader { ScrollView(axis: [.horizontal, .vertical]) { LazyVStack(pinnedViews: .sectionHeaders) { Section(header: TimelineView()) { ForEach(channels) { channel in LazyHStack(pinnedViews: .sectionHeaders) { Section(header: ChannelLogoView()) { ForEach(channel.programs) { program in ProgramCell(program) } } } } } } } The actual implementation included a lot more modifiers and code, but I never got it to work and gave up because most of the problems happening were so weird that there was no code explaining what is going on. Examples are cells appearing out of the view bounds or just disappearing when you scroll around. I thought those are happening because of the nested Lazy stack both with pinned views and I gave up on that approach. So next I decided to use PreferenceKey for updating the scroll position and offset both the views that need to be pinned based on that. The code looks something like that: GeometryReader { geoProxy in ScrollViewReader { scrollProxy in ScrollView([.vertical, .horizontal], showsIndicators: false) { ProgramGuideView() .background( GeometryReader { geometry in theme.primaryColor.preference( key: ScrollOffsetPreferenceKey.self, value: geometry.frame(in: .named(X)).origin ) } ) .onPreferenceChange(ScrollOffsetPreferenceKey.self) { point in self.position = point //Position is a @State held in the view } } } } On top of the grometry reader I have 2 overlays with offsets for the Channel headers and timeline view. In the program guide view I removed the Lazy stacks and used the normal ones and what was very crucial for this whole combination not to lag was using the drawingGroup() modifier. And it worked like a charm when testing on my iPhone 13 mini, but on all other devices that I have tested (14 Pro Max, 14 Pro, 13, Xs) it lags. The only difference that I am seeing is that on those phones when ran from Xcode an error gets logged - Bound preference key tried updating multiple times per frame. So my questions here are: What is the difference between the iPhone 13 mini and the rest of the deices, for this error to occur, and is there a way to overcome it? Do you have any suggestions on implementing a view like that using SwiftUI, or just improvement/optimisation ideas on the approaches described above? I am sorry if I have made any mistakes writing and copy-pasting the code in the snippets above. Also that I am not including the source code directly but I can definitely add more specifics if someone has interest in the problem. Thanks!
0
0
558
Mar ’24
Branch coverage data with UBSAN enable (UndefinedBehaviorSanitizer) in Xcode
Hi, On enabling UBSAN(UndefinedBehaviorSanitizer) on Xcode a dip in branch coverage is observed. Is this behaviour expected? If the answer is yes, is there a way to enable UBSAN without affecting branch coverage data? Below is the reference of same code base, branch coverage data with enable and disable UBSAN Xcode version: 14.3.1 With UBSAN enable: Total branches: 250733 No of branches hit: 47945 With UBSAN disable: Total branches: 38673 No of branches hit: 11220
0
0
438
Mar ’24
Branch coverage data with UBSAN enable (UndefinedBehaviorSanitizer) in Xcode
Hi, On enabling UBSAN(UndefinedBehaviorSanitizer) on Xcode a dip in branch coverage is observed. Is this behaviour expected? If the answer is yes, is there a way to enable UBSAN without affecting branch coverage data? Below is the reference of same code base, branch coverage data with enable and disable UBSAN Xcode version: 14.3.1 With UBSAN enable: Total branches: 250733 No of branches hit: 47945 With UBSAN disable: Total branches: 38673 No of branches hit: 11220
1
0
416
Mar ’24
Crash on [WKWebView initWithFrame: configuration:]
Crash condition: when I update the Xcode version to 15.3 and run the iPhone to load the app on debug mode with the following diagnosing setting: Hardware Model: iPhone 14 pro Role: Foreground Date/Time: 2024-03-08 11:30 -0800 Launch Time: 2024-03-08 11:30 -0800 OS Version: iPhone OS 17.4(21E219) Exception Type: EXC_BREAKPOINT Exception Codes: (code=1, subcode=0x19b1eba48) Exception Note: EXC_BREAKPOINT Triggered by Thread: 1 Thread 1 Queue : com.apple.main-thread (serial) #0 0x000000019b1eba48 in xzm_malloc_zone_free_slow.cold.1 () #1 0x000000019b1e28d0 in xzm_malloc_zone_free_slow () #2 0x00000001a25ef1c8 in pas_try_deallocate_slow_no_cache () #3 0x00000001a10d32f8 in ***::String::String(__CFString const*) () #4 0x00000001a0494ab8 in WebKit::isFullWebBrowserOrRunningTest() () #5 0x00000001a09e1520 in WebKit::WebsiteDataStoreConfiguration::WebsiteDataStoreConfiguration(WebKit::IsPersistent, WebKit::WebsiteDataStoreConfiguration::ShouldInitializePaths) () #6 0x00000001a09d3ae0 in WebKit::WebsiteDataStore::defaultDataStore() () #7 0x00000001a05bc5e8 in +[WKWebsiteDataStore defaultDataStore] () #8 0x00000001a05b6624 in -[WKWebViewConfiguration websiteDataStore] () #9 0x00000001a0576850 in -[WKWebView _initializeWithConfiguration:] () #10 0x00000001a0577e04 in -[WKWebView initWithFrame:configuration:] () #11 0x0000000104cbf724 in -[AAChartView initConfigurationWithFrame:] at /Users/quinn/Documents/objcio/AAChartKit-master/AAChartKitLib/AAChartCreator/AAChartView.m:133 #12 0x0000000104cbf4e8 in -[AAChartView initWithFrame:] at /Users/quinn/Documents/objcio/AAChartKit-master/AAChartKitLib/AAChartCreator/AAChartView.m:115 #13 0x0000000104c133a4 in -[BasicChartVC setupAAChartView] at /Users/quinn/Documents/objcio/AAChartKit-master/AAChartKitDemo/ChartsDemo/BasicChartVC.m:99 #14 0x0000000104c13208 in -[BasicChartVC drawChart] at /Users/quinn/Documents/objcio/AAChartKit-master/AAChartKitDemo/ChartsDemo/BasicChartVC.m:86 #15 0x0000000104c12f9c in -[BasicChartVC viewDidLoad] at /Users/quinn/Documents/objcio/AAChartKit-master/AAChartKitDemo/ChartsDemo/BasicChartVC.m:66 #16 0x000000018d4e530c in -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] () #17 0x000000018d29bfb4 in -[UIViewController loadViewIfRequired] () #18 0x000000018d29a7a8 in -[UIViewController view] () #19 0x000000018d98a384 in -[UINavigationController _startCustomTransition:] () #20 0x000000018d39dca4 in -[UINavigationController _startDeferredTransitionIfNeeded:] () #21 0x000000018d39d3a0 in -[UINavigationController __viewWillLayoutSubviews] () #22 0x000000018d39d304 in -[UILayoutContainerView layoutSubviews] () #23 0x000000018d2b90f8 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] () #24 0x000000018c6e3e30 in CA::Layer::layout_if_needed(CA::Transaction*) () #25 0x000000018c6e39b4 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) () #26 0x000000018c6e9bb4 in CA::Context::commit_transaction(CA::Transaction*, double, double*) () #27 0x000000018c6e31bc in CA::Transaction::commit() () #28 0x000000018d331280 in _UIApplicationFlushCATransaction () #29 0x000000018d330d78 in _UIUpdateSequenceRun () #30 0x000000018d330468 in schedulerStepScheduledMainSection () #31 0x000000018d330524 in runloopSourceCallback () #32 0x000000018b04162c in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ () #33 0x000000018b0408a8 in __CFRunLoopDoSource0 () #34 0x000000018b03f058 in __CFRunLoopDoSources0 () #35 0x000000018b03dd88 in __CFRunLoopRun () #36 0x000000018b03d968 in CFRunLoopRunSpecific () #37 0x00000001cf33b4e0 in GSEventRunModal () #38 0x000000018d4b0edc in -[UIApplication _run] () #39 0x000000018d4b0518 in UIApplicationMain () #40 0x0000000104d42ba8 in main at /Users/quinn/Documents/objcio/AAChartKit-master/AAChartKitDemo/main.m:38 #41 0x00000001ae55ed84 in start ()
6
0
2.2k
May ’24