OLD | NEW |
---|---|
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 | 28 |
29 #include "v8.h" | 29 #include "v8.h" |
30 #include "debug.h" | |
30 #include "debug-agent.h" | 31 #include "debug-agent.h" |
31 | 32 |
32 #ifdef ENABLE_DEBUGGER_SUPPORT | 33 #ifdef ENABLE_DEBUGGER_SUPPORT |
34 | |
33 namespace v8 { | 35 namespace v8 { |
34 namespace internal { | 36 namespace internal { |
35 | 37 |
36 // Public V8 debugger API message handler function. This function just delegates | 38 // Public V8 debugger API message handler function. This function just delegates |
37 // to the debugger agent through it's data parameter. | 39 // to the debugger agent through it's data parameter. |
38 void DebuggerAgentMessageHandler(const v8::Debug::Message& message) { | 40 void DebuggerAgentMessageHandler(const v8::Debug::Message& message) { |
39 DebuggerAgent::instance_->DebuggerMessage(message); | 41 DebuggerAgent::instance_->DebuggerMessage(message); |
40 } | 42 } |
41 | 43 |
42 // static | 44 // static |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 | 162 |
161 | 163 |
162 void DebuggerAgentSession::Run() { | 164 void DebuggerAgentSession::Run() { |
163 // Send the hello message. | 165 // Send the hello message. |
164 bool ok = DebuggerAgentUtil::SendConnectMessage(client_, *agent_->name_); | 166 bool ok = DebuggerAgentUtil::SendConnectMessage(client_, *agent_->name_); |
165 if (!ok) return; | 167 if (!ok) return; |
166 | 168 |
167 while (true) { | 169 while (true) { |
168 // Read data from the debugger front end. | 170 // Read data from the debugger front end. |
169 SmartPointer<char> message = DebuggerAgentUtil::ReceiveMessage(client_); | 171 SmartPointer<char> message = DebuggerAgentUtil::ReceiveMessage(client_); |
170 if (*message == NULL) { | 172 |
171 // Session is closed. | 173 const char *msg = *message; |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Please avoid mixed case variables, see http://goog
marklam
2011/01/04 20:12:13
Done.
| |
172 agent_->OnSessionClosed(this); | 174 bool isBreakRequest = false; |
173 return; | 175 bool isClosingSession = (msg == NULL); |
176 | |
177 if (msg == NULL) { | |
178 // If we lost the connection, then simulate a disconnect msg: | |
179 msg = "{\"seq\":1,\"type\":\"request\",\"command\":\"disconnect\"}"; | |
180 | |
181 } else { | |
182 // Check if we're getting a break request: | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
These checks seems pretty fragile, and depends on
marklam
2011/01/04 20:12:13
I see what you mean. But yes, at least as a first
| |
183 const char *breakRequestStr = | |
184 "\"type\":\"request\",\"command\":\"break\"}"; | |
185 const char *result = strstr(msg, breakRequestStr); | |
186 if (result != NULL) { | |
187 isBreakRequest = true; | |
188 } else { | |
189 // Check if we're getting a disconnect request: | |
190 const char *disconnectRequestStr = | |
191 "\"type\":\"request\",\"command\":\"disconnect\"}"; | |
192 result = strstr(msg, disconnectRequestStr); | |
193 if (result != NULL) { | |
194 isClosingSession = true; | |
195 } | |
196 } | |
197 } | |
198 | |
199 if (isBreakRequest && !Debug::InDebugger()) { | |
Søren Thygesen Gjesse
2011/01/03 08:56:07
Is this required? Sending the command using v8::De
marklam
2011/01/04 20:12:13
Hmmm. This used to be needed, but I just re-teste
| |
200 v8::Debug::DebugBreak(); | |
174 } | 201 } |
175 | 202 |
176 // Convert UTF-8 to UTF-16. | 203 // Convert UTF-8 to UTF-16. |
177 unibrow::Utf8InputBuffer<> buf(*message, | 204 unibrow::Utf8InputBuffer<> buf(msg, StrLength(msg)); |
178 StrLength(*message)); | |
179 int len = 0; | 205 int len = 0; |
180 while (buf.has_more()) { | 206 while (buf.has_more()) { |
181 buf.GetNext(); | 207 buf.GetNext(); |
182 len++; | 208 len++; |
183 } | 209 } |
184 ScopedVector<int16_t> temp(len + 1); | 210 ScopedVector<int16_t> temp(len + 1); |
185 buf.Reset(*message, StrLength(*message)); | 211 buf.Reset(msg, StrLength(msg)); |
186 for (int i = 0; i < len; i++) { | 212 for (int i = 0; i < len; i++) { |
187 temp[i] = buf.GetNext(); | 213 temp[i] = buf.GetNext(); |
188 } | 214 } |
189 | 215 |
190 // Send the request received to the debugger. | 216 // Send the request received to the debugger. |
191 v8::Debug::SendCommand(reinterpret_cast<const uint16_t *>(temp.start()), | 217 v8::Debug::SendCommand(reinterpret_cast<const uint16_t *>(temp.start()), |
192 len); | 218 len); |
219 | |
220 if (isClosingSession) { | |
221 // Session is closed. | |
222 agent_->OnSessionClosed(this); | |
223 return; | |
224 } | |
193 } | 225 } |
194 } | 226 } |
195 | 227 |
196 | 228 |
197 void DebuggerAgentSession::DebuggerMessage(Vector<uint16_t> message) { | 229 void DebuggerAgentSession::DebuggerMessage(Vector<uint16_t> message) { |
198 DebuggerAgentUtil::SendMessage(client_, message); | 230 DebuggerAgentUtil::SendMessage(client_, message); |
199 } | 231 } |
200 | 232 |
201 | 233 |
202 void DebuggerAgentSession::Shutdown() { | 234 void DebuggerAgentSession::Shutdown() { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 return total_received; | 450 return total_received; |
419 } | 451 } |
420 total_received += received; | 452 total_received += received; |
421 } | 453 } |
422 return total_received; | 454 return total_received; |
423 } | 455 } |
424 | 456 |
425 } } // namespace v8::internal | 457 } } // namespace v8::internal |
426 | 458 |
427 #endif // ENABLE_DEBUGGER_SUPPORT | 459 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |