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

Side by Side Diff: src/debug-agent.cc

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 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
« no previous file with comments | « src/debug-agent.h ('k') | src/debug-debugger.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 20 matching lines...) Expand all
31 #include "debug-agent.h" 31 #include "debug-agent.h"
32 32
33 #ifdef ENABLE_DEBUGGER_SUPPORT 33 #ifdef ENABLE_DEBUGGER_SUPPORT
34 34
35 namespace v8 { 35 namespace v8 {
36 namespace internal { 36 namespace internal {
37 37
38 // Public V8 debugger API message handler function. This function just delegates 38 // Public V8 debugger API message handler function. This function just delegates
39 // to the debugger agent through it's data parameter. 39 // to the debugger agent through it's data parameter.
40 void DebuggerAgentMessageHandler(const v8::Debug::Message& message) { 40 void DebuggerAgentMessageHandler(const v8::Debug::Message& message) {
41 DebuggerAgent::instance_->DebuggerMessage(message); 41 DebuggerAgent* agent = Isolate::Current()->debugger_agent_instance();
42 ASSERT(agent != NULL);
43 agent->DebuggerMessage(message);
42 } 44 }
43 45
44 // static
45 DebuggerAgent* DebuggerAgent::instance_ = NULL;
46 46
47 // Debugger agent main thread. 47 // Debugger agent main thread.
48 void DebuggerAgent::Run() { 48 void DebuggerAgent::Run() {
49 const int kOneSecondInMicros = 1000000; 49 const int kOneSecondInMicros = 1000000;
50 50
51 // Allow this socket to reuse port even if still in TIME_WAIT. 51 // Allow this socket to reuse port even if still in TIME_WAIT.
52 server_->SetReuseAddress(true); 52 server_->SetReuseAddress(true);
53 53
54 // First bind the socket to the requested port. 54 // First bind the socket to the requested port.
55 bool bound = false; 55 bool bound = false;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 // Close existing session if any. 96 // Close existing session if any.
97 CloseSession(); 97 CloseSession();
98 } 98 }
99 99
100 100
101 void DebuggerAgent::WaitUntilListening() { 101 void DebuggerAgent::WaitUntilListening() {
102 listening_->Wait(); 102 listening_->Wait();
103 } 103 }
104 104
105 static const char* kCreateSessionMessage =
106 "Remote debugging session already active\r\n";
107
105 void DebuggerAgent::CreateSession(Socket* client) { 108 void DebuggerAgent::CreateSession(Socket* client) {
106 ScopedLock with(session_access_); 109 ScopedLock with(session_access_);
107 110
108 // If another session is already established terminate this one. 111 // If another session is already established terminate this one.
109 if (session_ != NULL) { 112 if (session_ != NULL) {
110 static const char* message = "Remote debugging session already active\r\n"; 113 client->Send(kCreateSessionMessage, StrLength(kCreateSessionMessage));
111
112 client->Send(message, StrLength(message));
113 delete client; 114 delete client;
114 return; 115 return;
115 } 116 }
116 117
117 // Create a new session and hook up the debug message handler. 118 // Create a new session and hook up the debug message handler.
118 session_ = new DebuggerAgentSession(this, client); 119 session_ = new DebuggerAgentSession(isolate(), this, client);
119 v8::Debug::SetMessageHandler2(DebuggerAgentMessageHandler); 120 v8::Debug::SetMessageHandler2(DebuggerAgentMessageHandler);
120 session_->Start(); 121 session_->Start();
121 } 122 }
122 123
123 124
124 void DebuggerAgent::CloseSession() { 125 void DebuggerAgent::CloseSession() {
125 ScopedLock with(session_access_); 126 ScopedLock with(session_access_);
126 127
127 // Terminate the session. 128 // Terminate the session.
128 if (session_ != NULL) { 129 if (session_ != NULL) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 DebuggerAgentUtil::SendMessage(client_, message); 218 DebuggerAgentUtil::SendMessage(client_, message);
218 } 219 }
219 220
220 221
221 void DebuggerAgentSession::Shutdown() { 222 void DebuggerAgentSession::Shutdown() {
222 // Shutdown the socket to end the blocking receive. 223 // Shutdown the socket to end the blocking receive.
223 client_->Shutdown(); 224 client_->Shutdown();
224 } 225 }
225 226
226 227
227 const char* DebuggerAgentUtil::kContentLength = "Content-Length"; 228 const char* const DebuggerAgentUtil::kContentLength = "Content-Length";
228 int DebuggerAgentUtil::kContentLengthSize = 229 const int DebuggerAgentUtil::kContentLengthSize =
229 StrLength(kContentLength); 230 StrLength(kContentLength);
230 231
231 232
232 SmartPointer<char> DebuggerAgentUtil::ReceiveMessage(const Socket* conn) { 233 SmartPointer<char> DebuggerAgentUtil::ReceiveMessage(const Socket* conn) {
233 int received; 234 int received;
234 235
235 // Read header. 236 // Read header.
236 int content_length = 0; 237 int content_length = 0;
237 while (true) { 238 while (true) {
238 const int kHeaderBufferSize = 80; 239 const int kHeaderBufferSize = 80;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return total_received; 438 return total_received;
438 } 439 }
439 total_received += received; 440 total_received += received;
440 } 441 }
441 return total_received; 442 return total_received;
442 } 443 }
443 444
444 } } // namespace v8::internal 445 } } // namespace v8::internal
445 446
446 #endif // ENABLE_DEBUGGER_SUPPORT 447 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW
« no previous file with comments | « src/debug-agent.h ('k') | src/debug-debugger.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698