jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 28 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 29 | |
| 30 | #include "d8.h" |
| 31 | #include "d8-debug.h" |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 32 | #include "debug-agent.h" |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | namespace v8 { |
| 36 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 37 | static bool was_running = true; |
| 38 | |
| 39 | void PrintPrompt(bool is_running) { |
| 40 | const char* prompt = is_running? "> " : "dbg> "; |
| 41 | was_running = is_running; |
| 42 | printf("%s", prompt); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 43 | fflush(stdout); |
| 44 | } |
| 45 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 46 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 47 | void PrintPrompt() { |
| 48 | PrintPrompt(was_running); |
| 49 | } |
| 50 | |
| 51 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 52 | void HandleDebugEvent(const Debug::EventDetails& event_details) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 53 | // TODO(svenpanne) There should be a way to retrieve this in the callback. |
| 54 | Isolate* isolate = Isolate::GetCurrent(); |
| 55 | HandleScope scope(isolate); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 56 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 57 | DebugEvent event = event_details.GetEvent(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 58 | // Check for handled event. |
| 59 | if (event != Break && event != Exception && event != AfterCompile) { |
| 60 | return; |
| 61 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 62 | |
| 63 | TryCatch try_catch; |
| 64 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 65 | // Get the toJSONProtocol function on the event and get the JSON format. |
| 66 | Local<String> to_json_fun_name = String::New("toJSONProtocol"); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 67 | Handle<Object> event_data = event_details.GetEventData(); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 68 | Local<Function> to_json_fun = |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 69 | Local<Function>::Cast(event_data->Get(to_json_fun_name)); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 70 | Local<Value> event_json = to_json_fun->Call(event_data, 0, NULL); |
| 71 | if (try_catch.HasCaught()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 72 | Shell::ReportException(isolate, &try_catch); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 73 | return; |
| 74 | } |
| 75 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 76 | // Print the event details. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 77 | Handle<Object> details = |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 78 | Shell::DebugMessageDetails(isolate, Handle<String>::Cast(event_json)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 79 | if (try_catch.HasCaught()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 80 | Shell::ReportException(isolate, &try_catch); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | String::Utf8Value str(details->Get(String::New("text"))); |
| 84 | if (str.length() == 0) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 85 | // Empty string is used to signal not to process this event. |
| 86 | return; |
| 87 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 88 | printf("%s\n", *str); |
| 89 | |
| 90 | // Get the debug command processor. |
| 91 | Local<String> fun_name = String::New("debugCommandProcessor"); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 92 | Handle<Object> exec_state = event_details.GetExecutionState(); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 93 | Local<Function> fun = Local<Function>::Cast(exec_state->Get(fun_name)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 94 | Local<Object> cmd_processor = |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 95 | Local<Object>::Cast(fun->Call(exec_state, 0, NULL)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 96 | if (try_catch.HasCaught()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 97 | Shell::ReportException(isolate, &try_catch); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 98 | return; |
| 99 | } |
| 100 | |
| 101 | static const int kBufferSize = 256; |
| 102 | bool running = false; |
| 103 | while (!running) { |
| 104 | char command[kBufferSize]; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 105 | PrintPrompt(running); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 106 | char* str = fgets(command, kBufferSize, stdin); |
| 107 | if (str == NULL) break; |
| 108 | |
| 109 | // Ignore empty commands. |
| 110 | if (strlen(command) == 0) continue; |
| 111 | |
| 112 | TryCatch try_catch; |
| 113 | |
| 114 | // Convert the debugger command to a JSON debugger request. |
| 115 | Handle<Value> request = |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 116 | Shell::DebugCommandToJSONRequest(isolate, String::New(command)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 117 | if (try_catch.HasCaught()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 118 | Shell::ReportException(isolate, &try_catch); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 119 | continue; |
| 120 | } |
| 121 | |
| 122 | // If undefined is returned the command was handled internally and there is |
| 123 | // no JSON to send. |
| 124 | if (request->IsUndefined()) { |
| 125 | continue; |
| 126 | } |
| 127 | |
| 128 | Handle<String> fun_name; |
| 129 | Handle<Function> fun; |
| 130 | // All the functions used below take one argument. |
| 131 | static const int kArgc = 1; |
| 132 | Handle<Value> args[kArgc]; |
| 133 | |
| 134 | // Invoke the JavaScript to convert the debug command line to a JSON |
| 135 | // request, invoke the JSON request and convert the JSON respose to a text |
| 136 | // representation. |
| 137 | fun_name = String::New("processDebugRequest"); |
| 138 | fun = Handle<Function>::Cast(cmd_processor->Get(fun_name)); |
| 139 | args[0] = request; |
| 140 | Handle<Value> response_val = fun->Call(cmd_processor, kArgc, args); |
| 141 | if (try_catch.HasCaught()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 142 | Shell::ReportException(isolate, &try_catch); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 143 | continue; |
| 144 | } |
| 145 | Handle<String> response = Handle<String>::Cast(response_val); |
| 146 | |
| 147 | // Convert the debugger response into text details and the running state. |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 148 | Handle<Object> response_details = |
| 149 | Shell::DebugMessageDetails(isolate, response); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 150 | if (try_catch.HasCaught()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 151 | Shell::ReportException(isolate, &try_catch); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 152 | continue; |
| 153 | } |
| 154 | String::Utf8Value text_str(response_details->Get(String::New("text"))); |
| 155 | if (text_str.length() > 0) { |
| 156 | printf("%s\n", *text_str); |
| 157 | } |
| 158 | running = |
| 159 | response_details->Get(String::New("running"))->ToBoolean()->Value(); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 164 | void RunRemoteDebugger(Isolate* isolate, int port) { |
| 165 | RemoteDebugger debugger(isolate, port); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 166 | debugger.Run(); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | void RemoteDebugger::Run() { |
| 171 | bool ok; |
| 172 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 173 | // Connect to the debugger agent. |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 174 | conn_ = new i::Socket; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 175 | static const int kPortStrSize = 6; |
| 176 | char port_str[kPortStrSize]; |
| 177 | i::OS::SNPrintF(i::Vector<char>(port_str, kPortStrSize), "%d", port_); |
| 178 | ok = conn_->Connect("localhost", port_str); |
| 179 | if (!ok) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 180 | printf("Unable to connect to debug agent %d\n", i::Socket::GetLastError()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 181 | return; |
| 182 | } |
| 183 | |
| 184 | // Start the receiver thread. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 185 | ReceiverThread receiver(this); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 186 | receiver.Start(); |
| 187 | |
| 188 | // Start the keyboard thread. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 189 | KeyboardThread keyboard(this); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 190 | keyboard.Start(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 191 | PrintPrompt(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 192 | |
| 193 | // Process events received from debugged VM and from the keyboard. |
| 194 | bool terminate = false; |
| 195 | while (!terminate) { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 196 | event_available_.Wait(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 197 | RemoteDebuggerEvent* event = GetEvent(); |
| 198 | switch (event->type()) { |
| 199 | case RemoteDebuggerEvent::kMessage: |
| 200 | HandleMessageReceived(event->data()); |
| 201 | break; |
| 202 | case RemoteDebuggerEvent::kKeyboard: |
| 203 | HandleKeyboardCommand(event->data()); |
| 204 | break; |
| 205 | case RemoteDebuggerEvent::kDisconnect: |
| 206 | terminate = true; |
| 207 | break; |
| 208 | |
| 209 | default: |
| 210 | UNREACHABLE(); |
| 211 | } |
| 212 | delete event; |
| 213 | } |
| 214 | |
| 215 | // Wait for the receiver thread to end. |
| 216 | receiver.Join(); |
| 217 | } |
| 218 | |
| 219 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 220 | void RemoteDebugger::MessageReceived(i::SmartArrayPointer<char> message) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 221 | RemoteDebuggerEvent* event = |
| 222 | new RemoteDebuggerEvent(RemoteDebuggerEvent::kMessage, message); |
| 223 | AddEvent(event); |
| 224 | } |
| 225 | |
| 226 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 227 | void RemoteDebugger::KeyboardCommand(i::SmartArrayPointer<char> command) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 228 | RemoteDebuggerEvent* event = |
| 229 | new RemoteDebuggerEvent(RemoteDebuggerEvent::kKeyboard, command); |
| 230 | AddEvent(event); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | void RemoteDebugger::ConnectionClosed() { |
| 235 | RemoteDebuggerEvent* event = |
| 236 | new RemoteDebuggerEvent(RemoteDebuggerEvent::kDisconnect, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 237 | i::SmartArrayPointer<char>()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 238 | AddEvent(event); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | void RemoteDebugger::AddEvent(RemoteDebuggerEvent* event) { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 243 | i::LockGuard<i::Mutex> lock_guard(&event_access_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 244 | if (head_ == NULL) { |
| 245 | ASSERT(tail_ == NULL); |
| 246 | head_ = event; |
| 247 | tail_ = event; |
| 248 | } else { |
| 249 | ASSERT(tail_ != NULL); |
| 250 | tail_->set_next(event); |
| 251 | tail_ = event; |
| 252 | } |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 253 | event_available_.Signal(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | |
| 257 | RemoteDebuggerEvent* RemoteDebugger::GetEvent() { |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 258 | i::LockGuard<i::Mutex> lock_guard(&event_access_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 259 | ASSERT(head_ != NULL); |
| 260 | RemoteDebuggerEvent* result = head_; |
| 261 | head_ = head_->next(); |
| 262 | if (head_ == NULL) { |
| 263 | ASSERT(tail_ == result); |
| 264 | tail_ = NULL; |
| 265 | } |
| 266 | return result; |
| 267 | } |
| 268 | |
| 269 | |
| 270 | void RemoteDebugger::HandleMessageReceived(char* message) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 271 | Locker lock(isolate_); |
| 272 | HandleScope scope(isolate_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 273 | |
| 274 | // Print the event details. |
| 275 | TryCatch try_catch; |
| 276 | Handle<Object> details = |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 277 | Shell::DebugMessageDetails(isolate_, |
| 278 | Handle<String>::Cast(String::New(message))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 279 | if (try_catch.HasCaught()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 280 | Shell::ReportException(isolate_, &try_catch); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 281 | PrintPrompt(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | String::Utf8Value str(details->Get(String::New("text"))); |
| 285 | if (str.length() == 0) { |
| 286 | // Empty string is used to signal not to process this event. |
| 287 | return; |
| 288 | } |
| 289 | if (*str != NULL) { |
| 290 | printf("%s\n", *str); |
| 291 | } else { |
| 292 | printf("???\n"); |
| 293 | } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 294 | |
| 295 | bool is_running = details->Get(String::New("running"))->ToBoolean()->Value(); |
| 296 | PrintPrompt(is_running); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | |
| 300 | void RemoteDebugger::HandleKeyboardCommand(char* command) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 301 | Locker lock(isolate_); |
| 302 | HandleScope scope(isolate_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 303 | |
| 304 | // Convert the debugger command to a JSON debugger request. |
| 305 | TryCatch try_catch; |
| 306 | Handle<Value> request = |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 307 | Shell::DebugCommandToJSONRequest(isolate_, String::New(command)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 308 | if (try_catch.HasCaught()) { |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 309 | Shell::ReportException(isolate_, &try_catch); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 310 | PrintPrompt(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 311 | return; |
| 312 | } |
| 313 | |
| 314 | // If undefined is returned the command was handled internally and there is |
| 315 | // no JSON to send. |
| 316 | if (request->IsUndefined()) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 317 | PrintPrompt(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 318 | return; |
| 319 | } |
| 320 | |
| 321 | // Send the JSON debugger request. |
| 322 | i::DebuggerAgentUtil::SendMessage(conn_, Handle<String>::Cast(request)); |
| 323 | } |
| 324 | |
| 325 | |
| 326 | void ReceiverThread::Run() { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 327 | // Receive the connect message (with empty body). |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 328 | i::SmartArrayPointer<char> message = |
| 329 | i::DebuggerAgentUtil::ReceiveMessage(remote_debugger_->conn()); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 330 | ASSERT(*message == NULL); |
| 331 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 332 | while (true) { |
| 333 | // Receive a message. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 334 | i::SmartArrayPointer<char> message = |
| 335 | i::DebuggerAgentUtil::ReceiveMessage(remote_debugger_->conn()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 336 | if (*message == NULL) { |
| 337 | remote_debugger_->ConnectionClosed(); |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | // Pass the message to the main thread. |
| 342 | remote_debugger_->MessageReceived(message); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | |
| 347 | void KeyboardThread::Run() { |
| 348 | static const int kBufferSize = 256; |
| 349 | while (true) { |
| 350 | // read keyboard input. |
| 351 | char command[kBufferSize]; |
| 352 | char* str = fgets(command, kBufferSize, stdin); |
| 353 | if (str == NULL) { |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | // Pass the keyboard command to the main thread. |
| 358 | remote_debugger_->KeyboardCommand( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 359 | i::SmartArrayPointer<char>(i::StrDup(command))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 364 | } // namespace v8 |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 365 | |
| 366 | #endif // ENABLE_DEBUGGER_SUPPORT |