iOS.mach_msg_trap()

mach_msg_trap()

 

1. mach_msg() mach_msg_trap()

 

"

> The Debugger window shows the calling stack at the top of which is

> 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/

 

转载于:https://www.cnblogs.com/cwgk/p/8543575.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值