MainThreadMonitor: don't monitor thread if debugger is attached#2502
Conversation
See #2463. If you're actively debugging and interrupt the main thread, it'll end up asserting, which isn't very convenient. Copied the logic from https://stackoverflow.com/a/33177600/401024. It's not the safest code, but this only runs in tests.
Codecov Report
@@ Coverage Diff @@
## main #2502 +/- ##
==========================================
+ Coverage 87.66% 87.72% +0.05%
==========================================
Files 197 197
Lines 13347 13347
==========================================
+ Hits 11700 11708 +8
+ Misses 1647 1639 -8 |
| // Counts buffer's size in bytes (like C/C++'s `sizeof`). | ||
| var size = MemoryLayout.stride(ofValue: info) | ||
| // Tells we want info about own process. | ||
| var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()] |
There was a problem hiding this comment.
Not sure but since this info isn't supposed to change, could mib be a let?
There was a problem hiding this comment.
It's passed as a reference in the next line so it can be modified. Swift would actually suggest this needs to be immutable otherwise :)
| guard !Self.debuggerIsAttached else { | ||
| Logger.verbose("\(type(of: self)): debugger is attached, ignoring") | ||
| return | ||
| } |
There was a problem hiding this comment.
So when you run tests through Xcode, the debugger will be attached by default I think. I guess that means this monitor will only run when executing tests through the command line tool correct? We should just be aware that tests results may vary between executing them through xcode and through command line.
There was a problem hiding this comment.
Yeah or in CI. But you can also run them in Xcode without the debugger attached.
) See #2463. If you're actively debugging and interrupt the main thread, it'll end up asserting, which isn't very convenient. Copied the logic from https://stackoverflow.com/a/33177600/401024. It's not the safest code, but this only runs in tests.
See #2463.
If you're actively debugging and interrupt the main thread, it'll end up asserting, which isn't very convenient.
Copied the logic from https://stackoverflow.com/a/33177600/401024. It's not the safest code, but this only runs in tests.