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

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

Issue 25909002: Sampling profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "platform/utils.h"
6 #include "vm/simulator.h"
7 #include "vm/signal_handler.h"
8
9 namespace dart {
10
11 uintptr_t SignalHandler::GetProgramCounter(const mcontext_t& mcontext) {
12 uintptr_t pc = 0;
13
14 #if defined(TARGET_OS_MACOS)
15 #if defined(TARGET_ARCH_IA32)
16 pc = static_cast<uintptr_t>(mcontext->__ss.__eip);
17 #elif defined(TARGET_ARCH_X64)
18 pc = static_cast<uintptr_t>(mcontext->__ss.__rip);
19 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
20 pc = static_cast<uintptr_t>(mcontext->__ss.__eip);
21 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
22 pc = static_cast<uintptr_t>(mcontext->__ss.__eip);
23 #else
24 UNIMPLEMENTED()
25 #endif // TARGET_ARCH_...
26 #endif // TARGET_OS_MACOS
27
28 #if defined(TARGET_OS_LINUX)
29 #if defined(TARGET_ARCH_IA32)
30 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]);
31 #elif defined(TARGET_ARCH_X64)
32 pc = static_cast<uintptr_t>(mcontext.gregs[REG_RIP]);
33 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
34 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]);
35 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
36 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]);
37 #else
38 UNIMPLEMENTED()
39 #endif // TARGET_ARCH_...
40 #endif // TARGET_OS_LINUX
41
42 #if defined(TARGET_OS_ANDROID)
43 UNIMPLEMENTED();
44 #endif // TARGET_OS_ANDROID
45
46 #if defined(TARGET_OS_WINDOWS)
47 UNIMPLEMENTED();
48 #endif // TARGET_OS_WINDOWS
49
50 return pc;
51 }
52
53
54 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) {
55 uintptr_t fp = 0;
56
57 #if defined(TARGET_OS_MACOS)
58 #if defined(TARGET_ARCH_IA32)
59 fp = static_cast<uintptr_t>(mcontext->__ss.__ebp);
60 #elif defined(TARGET_ARCH_X64)
61 fp = static_cast<uintptr_t>(mcontext->__ss.__rbp);
62 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
63 fp = static_cast<uintptr_t>(mcontext->__ss.__ebp);
64 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
65 fp = static_cast<uintptr_t>(mcontext->__ss.__ebp);
66 #else
67 UNIMPLEMENTED()
68 #endif // TARGET_ARCH_...
69 #endif // TARGET_OS_MACOS
70
71 #if defined(TARGET_OS_LINUX)
72 #if defined(TARGET_ARCH_IA32)
73 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]);
74 #elif defined(TARGET_ARCH_X64)
75 fp = static_cast<uintptr_t>(mcontext.gregs[REG_RBP]);
76 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
77 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]);
78 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
79 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]);
80 #else
81 UNIMPLEMENTED()
82 #endif // TARGET_ARCH_...
83 #endif // TARGET_OS_LINUX
84
85 #if defined(TARGET_OS_ANDROID)
86 UNIMPLEMENTED();
87 #endif // TARGET_OS_ANDROID
88
89 #if defined(TARGET_OS_WINDOWS)
90 UNIMPLEMENTED();
91 #endif // TARGET_OS_WINDOWS
92
93 return fp;
94 }
95
siva 2013/10/28 05:19:21 Ditto comment about using individual files for eac
Cutch 2013/11/04 20:36:05 Done.
96
97 uintptr_t SignalHandler::GetStackPointer(const mcontext_t& mcontext) {
98 uintptr_t sp = 0;
99
100 #if defined(TARGET_OS_MACOS)
101 #if defined(TARGET_ARCH_IA32)
102 sp = static_cast<uintptr_t>(mcontext->__ss.__esp);
103 #elif defined(TARGET_ARCH_X64)
104 sp = static_cast<uintptr_t>(mcontext->__ss.__rsp);
105 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
106 sp = static_cast<uintptr_t>(mcontext->__ss.__esp);
107 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
108 sp = static_cast<uintptr_t>(mcontext->__ss.__esp);
109 #else
110 UNIMPLEMENTED()
111 #endif // TARGET_ARCH_...
112 #endif // TARGET_OS_MACOS
113
114 #if defined(TARGET_OS_LINUX)
115 #if defined(TARGET_ARCH_IA32)
116 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]);
117 #elif defined(TARGET_ARCH_X64)
118 sp = static_cast<uintptr_t>(mcontext.gregs[REG_RSP]);
119 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
120 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]);
121 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
122 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]);
123 #else
124 UNIMPLEMENTED()
125 #endif // TARGET_ARCH_...
126 #endif // TARGET_OS_LINUX
127
128 #if defined(TARGET_OS_WINDOWS)
129 UNIMPLEMENTED();
130 #endif // TARGET_OS_WINDOWS
131
132 #if defined(TARGET_OS_ANDROID)
133 UNIMPLEMENTED();
134 #endif // TARGET_OS_ANDROID
135 return sp;
136 }
137
138
139 void SignalHandler::Install(SignalAction action) {
140 #if defined(TARGET_OS_WINDOWS)
141 UNIMPLEMENTED();
142 #else
143 struct sigaction act;
144 act.sa_handler = NULL;
145 act.sa_sigaction = action;
146 sigemptyset(&act.sa_mask);
147 act.sa_flags = SA_RESTART | SA_SIGINFO;
148 // TODO(johnmccutchan): Do we care about restoring the signal handler?
149 struct sigaction old_act;
150 int r = sigaction(SIGPROF, &act, &old_act);
151 ASSERT(r == 0);
152 #endif
153 }
154
155
156 ScopedSignalBlocker::ScopedSignalBlocker() {
157 #if defined(TARGET_OS_WINDOWS)
158 // NOOP.
159 #else
160 sigset_t set;
161 sigemptyset(&set);
162 sigaddset(&set, SIGPROF);
163 pthread_sigmask(SIG_SETMASK, &set, &old_);
164 #endif
165 }
166
167
168 ScopedSignalBlocker::~ScopedSignalBlocker() {
169 #if defined(TARGET_OS_WINDOWS)
170 // NOOP.
171 #else
172 pthread_sigmask(SIG_SETMASK, &old_, NULL);
173 #endif
174 }
175
176
177 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698