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; |
172 agent_->OnSessionClosed(this); | 174 bool is_closing_session = (msg == NULL); |
173 return; | 175 |
| 176 if (msg == NULL) { |
| 177 // If we lost the connection, then simulate a disconnect msg: |
| 178 msg = "{\"seq\":1,\"type\":\"request\",\"command\":\"disconnect\"}"; |
| 179 |
| 180 } else { |
| 181 // Check if we're getting a disconnect request: |
| 182 const char* disconnectRequestStr = |
| 183 "\"type\":\"request\",\"command\":\"disconnect\"}"; |
| 184 const char* result = strstr(msg, disconnectRequestStr); |
| 185 if (result != NULL) { |
| 186 is_closing_session = true; |
| 187 } |
174 } | 188 } |
175 | 189 |
176 // Convert UTF-8 to UTF-16. | 190 // Convert UTF-8 to UTF-16. |
177 unibrow::Utf8InputBuffer<> buf(*message, | 191 unibrow::Utf8InputBuffer<> buf(msg, StrLength(msg)); |
178 StrLength(*message)); | |
179 int len = 0; | 192 int len = 0; |
180 while (buf.has_more()) { | 193 while (buf.has_more()) { |
181 buf.GetNext(); | 194 buf.GetNext(); |
182 len++; | 195 len++; |
183 } | 196 } |
184 ScopedVector<int16_t> temp(len + 1); | 197 ScopedVector<int16_t> temp(len + 1); |
185 buf.Reset(*message, StrLength(*message)); | 198 buf.Reset(msg, StrLength(msg)); |
186 for (int i = 0; i < len; i++) { | 199 for (int i = 0; i < len; i++) { |
187 temp[i] = buf.GetNext(); | 200 temp[i] = buf.GetNext(); |
188 } | 201 } |
189 | 202 |
190 // Send the request received to the debugger. | 203 // Send the request received to the debugger. |
191 v8::Debug::SendCommand(reinterpret_cast<const uint16_t *>(temp.start()), | 204 v8::Debug::SendCommand(reinterpret_cast<const uint16_t *>(temp.start()), |
192 len); | 205 len); |
| 206 |
| 207 if (is_closing_session) { |
| 208 // Session is closed. |
| 209 agent_->OnSessionClosed(this); |
| 210 return; |
| 211 } |
193 } | 212 } |
194 } | 213 } |
195 | 214 |
196 | 215 |
197 void DebuggerAgentSession::DebuggerMessage(Vector<uint16_t> message) { | 216 void DebuggerAgentSession::DebuggerMessage(Vector<uint16_t> message) { |
198 DebuggerAgentUtil::SendMessage(client_, message); | 217 DebuggerAgentUtil::SendMessage(client_, message); |
199 } | 218 } |
200 | 219 |
201 | 220 |
202 void DebuggerAgentSession::Shutdown() { | 221 void DebuggerAgentSession::Shutdown() { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 return total_received; | 437 return total_received; |
419 } | 438 } |
420 total_received += received; | 439 total_received += received; |
421 } | 440 } |
422 return total_received; | 441 return total_received; |
423 } | 442 } |
424 | 443 |
425 } } // namespace v8::internal | 444 } } // namespace v8::internal |
426 | 445 |
427 #endif // ENABLE_DEBUGGER_SUPPORT | 446 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |