Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: runtime/vm/thread_interrupter_macos.cc

Issue 2682343002: Disable the profiler when a debugger is attached (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include <errno.h> // NOLINT 8 #include <errno.h> // NOLINT
9 #include <assert.h> // NOLINT
10 #include <stdbool.h> // NOLINT
11 #include <sys/types.h> // NOLINT
12 #include <unistd.h> // NOLINT
13 #include <sys/sysctl.h> // NOLINT
9 14
10 #include "vm/flags.h" 15 #include "vm/flags.h"
11 #include "vm/os.h" 16 #include "vm/os.h"
12 #include "vm/profiler.h" 17 #include "vm/profiler.h"
13 #include "vm/signal_handler.h" 18 #include "vm/signal_handler.h"
14 #include "vm/thread_interrupter.h" 19 #include "vm/thread_interrupter.h"
15 20
16 namespace dart { 21 namespace dart {
17 22
18 #ifndef PRODUCT 23 #ifndef PRODUCT
19 24
20 DECLARE_FLAG(bool, thread_interrupter); 25 DECLARE_FLAG(bool, thread_interrupter);
21 DECLARE_FLAG(bool, trace_thread_interrupter); 26 DECLARE_FLAG(bool, trace_thread_interrupter);
22 27
28 // Returns true if the current process is being debugged (either
29 // running under the debugger or has a debugger attached post facto).
30 // Code from https://developer.apple.com/library/content/qa/qa1361/_index.html
31 bool ThreadInterrupter::IsDebuggerAttached() {
32 int junk;
33 int mib[4];
34 struct kinfo_proc info;
35 size_t size;
36
37 // Initialize the flags so that, if sysctl fails for some bizarre
38 // reason, we get a predictable result.
39 info.kp_proc.p_flag = 0;
40
41 // Initialize mib, which tells sysctl the info we want, in this case
42 // we're looking for information about a specific process ID.
43 mib[0] = CTL_KERN;
44 mib[1] = KERN_PROC;
45 mib[2] = KERN_PROC_PID;
46 mib[3] = getpid();
47
48 // Call sysctl.
49 size = sizeof(info);
Vyacheslav Egorov (Google) 2017/02/09 17:14:05 Maybe better structure this code like this: struc
Cutch 2017/02/09 18:34:07 Done.
50 junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
51 ASSERT(junk == 0);
52 // We're being debugged if the P_TRACED flag is set.
53 return ((info.kp_proc.p_flag & P_TRACED) != 0);
54 }
55
23 class ThreadInterrupterMacOS : public AllStatic { 56 class ThreadInterrupterMacOS : public AllStatic {
24 public: 57 public:
25 static void ThreadInterruptSignalHandler(int signal, 58 static void ThreadInterruptSignalHandler(int signal,
26 siginfo_t* info, 59 siginfo_t* info,
27 void* context_) { 60 void* context_) {
28 if (signal != SIGPROF) { 61 if (signal != SIGPROF) {
29 return; 62 return;
30 } 63 }
31 Thread* thread = Thread::Current(); 64 Thread* thread = Thread::Current();
32 if (thread == NULL) { 65 if (thread == NULL) {
(...skipping 30 matching lines...) Expand all
63 96
64 void ThreadInterrupter::RemoveSignalHandler() { 97 void ThreadInterrupter::RemoveSignalHandler() {
65 SignalHandler::Remove(); 98 SignalHandler::Remove();
66 } 99 }
67 100
68 #endif // !PRODUCT 101 #endif // !PRODUCT
69 102
70 } // namespace dart 103 } // namespace dart
71 104
72 #endif // defined(TARGET_OS_MACOS) 105 #endif // defined(TARGET_OS_MACOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698