swift_slowAlloc Crash 分析
一、Crash详情
Crash类型
1 2 | exception EXC_BREAKPOINT (SIGTRAP) reason EXC_BREAKPOINT EXC_ARM_BREAKPOINT fault_address:0x0000000185ba6824 |
Crash堆栈
1 2 3 4 5 6 | 0 libswiftCore.dylib 0x0000000185ba6824 swift_slowAlloc.cold.1 ( in libswiftCore.dylib) + 16 1 libswiftCore.dylib 0x0000000185b2c9d8 _swift_slowAlloc ( in libswiftCore.dylib) + 208 2 libswiftCore.dylib 0x0000000185b2cb48 _swift_allocObject ( in libswiftCore.dylib) + 60 3 libswiftCore.dylib 0x0000000185abe67c specialized static _DictionaryStorage.resize(original: __RawDictionaryStorage, capacity: Int, move: Bool) ( in libswiftCore.dylib) + 328 4 libswiftCore.dylib 0x000000018591fbf8 _NativeDictionary._copyOrMoveAndResize(capacity: Int, moveElements: Bool) ( in libswiftCore.dylib) + 324 5 libswiftCore.dylib 0x0000000185920034 _NativeDictionary.ensureUnique(isUnique: Bool, capacity: Int) ( in libswiftCore.dylib) + 52 |
二、分析过程
经过排查, 该对象不存在多线程访问的问题
通过 异常类型 EXC_BREAKPOINT, 猜测是Swift Runtime中的异常触发, 参考SwiftAlloc的源代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // When alignMask == ~(size_t(0)), allocation uses the "default" // _swift_MinAllocationAlignment. This is different than calling swift_slowAlloc // with `alignMask == _swift_MinAllocationAlignment - 1` because it forces // the use of AlignedAlloc. This allows manually allocated to memory to always // be deallocated with AlignedFree without knowledge of its original allocation // alignment. // // For alignMask > (_minAllocationAlignment-1) // i.e. alignment == 0 || alignment > _minAllocationAlignment: // The runtime must use AlignedAlloc, and the standard library must // deallocate using an alignment that meets the same condition. // // For alignMask <= (_minAllocationAlignment-1) // i.e. 0 < alignment <= _minAllocationAlignment: // The runtime may use either malloc or AlignedAlloc, and the standard library // must deallocate using an identical alignment. void *swift::swift_slowAlloc(size_t size, size_t alignMask) { void *p; // This check also forces "default" alignment to use AlignedAlloc. if (alignMask <= MALLOC_ALIGN_MASK) { #if defined(__APPLE__) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC p = malloc_zone_malloc(DEFAULT_ZONE(), size); #else p = malloc(size); #endif } else { size_t alignment = (alignMask == ~(size_t(0))) ? _swift_MinAllocationAlignment : alignMask + 1; p = AlignedAlloc(size, alignment); } if (!p) swift::crash( "Could not allocate memory." ); return p; } |
关于 EXC_BREAKPOINT
The breakpoint exception type indicates a trace trap interrupted the process. A trace trap gives an attached debugger the chance to interrupt the process at a specific point in its execution. On ARM processors, this appears as EXC_BREAKPOINT (SIGTRAP). On x86_64 processors, this appears as EXC_BAD_INSTRUCTION (SIGILL). The Swift runtime uses trace traps for specific types of unrecoverable errors—see Addressing Crashes from Swift Runtime Errors for information on those errors. Some lower-level libraries, such as Dispatch, trap the process with this exception upon encountering an unrecoverable error, and log additional information about the error in the Additional Diagnostic Information section of the crash report. See Diagnostic Messages for information about those messages. If you want to use the same technique in your own code for unrecoverable errors, call the __builtin_trap() function. This allows the system to generate a crash report with thread backtraces that show how you reached the unrecoverable error.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2017-09-22 音视频学习--H264解析渲染
2017-09-22 iOS11 ReplayKit2 问题总结