iOS.mach_msg_trap()
mach_msg_trap()
1. mach_msg() mach_msg_trap()
"
>
> 0 mach_msg_trap
> 1 mach_msg
> 2 CFRunLoopRunSpecific
> etc.
This is showing the main thread, which is just paused waiting for events. The crash is on a different thread,
but Xcode 3.1 often doesn't switch to the thread that crashed. You'll need to use the thread pop-up to
switch between the different threads to see which one actually has a crash. (Any other threads that are in
mach_msg_trap or in various functions having to do with locks or semaphores are also just idling.) " Ref[10]
2. What's trap?
"Mach system calls are commonly known as "traps", and are maintained in a Mach Trap table. " Ref[9]
3. System Trace
System Trace Profile vs. Time Profiler
"
You can use the System Trace tool in Instruments by running your App in profile mode.
Then you will get a detailed run down of all the threads in the system along with stack traces at each scheduling event the thread goes through.
There is a great video from the 2016 WWDC System Trace in Depth which will walk you through debugging a blocked thread issue.
This is much better than the Time Profiler instrument since, that tool works based off of taking samples of what is running on the CPU at intervals.
However, if your thread is blocked, it isn't running on the CPU, so - it will not be sampled. You might have your main thread blocked for
a whole second but it won't show up in Time Profiler.
" Ref[6]
"
System Trace Profiling Template
Instruments Included in Template
-
Points of Interest
-
System Load
-
Thread State Trace
-
Virtual memory Trace
-
System Call Trace
" Ref[7]
Reference
1. How can main thread be blocked in mach_msg_trap?
http://www.cocoabuilder.com/archive/cocoa/232843-how-can-main-thread-be-blocked-in-mach-msg-trap.html
2. kDebug
2.1 https://www.theiphonewiki.com/wiki/Kdebug
2.2 http://newosxbook.com/tools/kdv.html
2.3 https://www.slideshare.net/JohnPetrucci4/check-point-advanced-kernel-debug
3. Reaching the MACH layer
http://blog.wuntee.sexy/reaching-the-mach-layer
https://github.com/opensource-apple/xnu/
- Mach messages are sent via kernel traps.
4. mach_msg_trap
https://github.com/apple/darwin-xnu/blob/master/osfmk/mach/mach_traps.h
5. Mach Overview
https://developer.apple.com/library/content/documentation/Darwin/Conceptual/KernelProgramming/Mach/Mach.html#//apple_ref/doc/uid/TP30000905-CH209-TPXREF101
6. iOS How to determine what is blocking the UI
https://stackoverflow.com/questions/15928035/ios-how-to-determine-what-is-blocking-the-ui
7. System Trace Profiling Template
https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/ProfilingTemplates.html#//apple_ref/doc/uid/TP40004652-CH19-SW1
8. macOS MACH Traps
https://sigsegv.pl/osx-mach-traps/
9. Kernel Syscalls
https://www.theiphonewiki.com/wiki/Kernel_Syscalls
10. help-with-debugger-mach-msg-trap-message
http://www.cocoabuilder.com/archive/xcode/279565-help-with-debugger-mach-msg-trap-message.html
11. Core Data Concurrency Debugging
https://oleb.net/blog/2014/06/core-data-concurrency-debugging/
You enable the assertions by passing -com.apple.CoreData.ConcurrencyDebug 1
to your app on the command line via Xcode’s Scheme Editor.
12. Technical Q&A QA1693 Synchronous Networking On The Main Thread
https://developer.apple.com/library/content/qa/qa1693/_index.html
13. System Trace in Depth
https://developer.apple.com/videos/play/wwdc2016/411/