| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (text_str.length() > 0) { | 152 if (text_str.length() > 0) { |
| 153 printf("%s\n", *text_str); | 153 printf("%s\n", *text_str); |
| 154 } | 154 } |
| 155 running = | 155 running = |
| 156 response_details->Get(String::New("running"))->ToBoolean()->Value(); | 156 response_details->Get(String::New("running"))->ToBoolean()->Value(); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 | 160 |
| 161 void RunRemoteDebugger(int port) { | 161 void RunRemoteDebugger(int port) { |
| 162 RemoteDebugger debugger(i::Isolate::Current(), port); | 162 RemoteDebugger debugger(port); |
| 163 debugger.Run(); | 163 debugger.Run(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 void RemoteDebugger::Run() { | 167 void RemoteDebugger::Run() { |
| 168 bool ok; | 168 bool ok; |
| 169 | 169 |
| 170 // Make sure that socket support is initialized. | 170 // Make sure that socket support is initialized. |
| 171 ok = i::Socket::Setup(); | 171 ok = i::Socket::Setup(); |
| 172 if (!ok) { | 172 if (!ok) { |
| 173 printf("Unable to initialize socket support %d\n", i::Socket::LastError()); | 173 printf("Unable to initialize socket support %d\n", i::Socket::LastError()); |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Connect to the debugger agent. | 177 // Connect to the debugger agent. |
| 178 conn_ = i::OS::CreateSocket(); | 178 conn_ = i::OS::CreateSocket(); |
| 179 static const int kPortStrSize = 6; | 179 static const int kPortStrSize = 6; |
| 180 char port_str[kPortStrSize]; | 180 char port_str[kPortStrSize]; |
| 181 i::OS::SNPrintF(i::Vector<char>(port_str, kPortStrSize), "%d", port_); | 181 i::OS::SNPrintF(i::Vector<char>(port_str, kPortStrSize), "%d", port_); |
| 182 ok = conn_->Connect("localhost", port_str); | 182 ok = conn_->Connect("localhost", port_str); |
| 183 if (!ok) { | 183 if (!ok) { |
| 184 printf("Unable to connect to debug agent %d\n", i::Socket::LastError()); | 184 printf("Unable to connect to debug agent %d\n", i::Socket::LastError()); |
| 185 return; | 185 return; |
| 186 } | 186 } |
| 187 | 187 |
| 188 // Start the receiver thread. | 188 // Start the receiver thread. |
| 189 ReceiverThread receiver(isolate_, this); | 189 ReceiverThread receiver(this); |
| 190 receiver.Start(); | 190 receiver.Start(); |
| 191 | 191 |
| 192 // Start the keyboard thread. | 192 // Start the keyboard thread. |
| 193 KeyboardThread keyboard(isolate_, this); | 193 KeyboardThread keyboard(this); |
| 194 keyboard.Start(); | 194 keyboard.Start(); |
| 195 PrintPrompt(); | 195 PrintPrompt(); |
| 196 | 196 |
| 197 // Process events received from debugged VM and from the keyboard. | 197 // Process events received from debugged VM and from the keyboard. |
| 198 bool terminate = false; | 198 bool terminate = false; |
| 199 while (!terminate) { | 199 while (!terminate) { |
| 200 event_available_->Wait(); | 200 event_available_->Wait(); |
| 201 RemoteDebuggerEvent* event = GetEvent(); | 201 RemoteDebuggerEvent* event = GetEvent(); |
| 202 switch (event->type()) { | 202 switch (event->type()) { |
| 203 case RemoteDebuggerEvent::kMessage: | 203 case RemoteDebuggerEvent::kMessage: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 head_ = head_->next(); | 265 head_ = head_->next(); |
| 266 if (head_ == NULL) { | 266 if (head_ == NULL) { |
| 267 ASSERT(tail_ == result); | 267 ASSERT(tail_ == result); |
| 268 tail_ = NULL; | 268 tail_ = NULL; |
| 269 } | 269 } |
| 270 return result; | 270 return result; |
| 271 } | 271 } |
| 272 | 272 |
| 273 | 273 |
| 274 void RemoteDebugger::HandleMessageReceived(char* message) { | 274 void RemoteDebugger::HandleMessageReceived(char* message) { |
| 275 Locker lock; |
| 275 HandleScope scope; | 276 HandleScope scope; |
| 276 | 277 |
| 277 // Print the event details. | 278 // Print the event details. |
| 278 TryCatch try_catch; | 279 TryCatch try_catch; |
| 279 Handle<Object> details = | 280 Handle<Object> details = |
| 280 Shell::DebugMessageDetails(Handle<String>::Cast(String::New(message))); | 281 Shell::DebugMessageDetails(Handle<String>::Cast(String::New(message))); |
| 281 if (try_catch.HasCaught()) { | 282 if (try_catch.HasCaught()) { |
| 282 Shell::ReportException(&try_catch); | 283 Shell::ReportException(&try_catch); |
| 283 PrintPrompt(); | 284 PrintPrompt(); |
| 284 return; | 285 return; |
| 285 } | 286 } |
| 286 String::Utf8Value str(details->Get(String::New("text"))); | 287 String::Utf8Value str(details->Get(String::New("text"))); |
| 287 if (str.length() == 0) { | 288 if (str.length() == 0) { |
| 288 // Empty string is used to signal not to process this event. | 289 // Empty string is used to signal not to process this event. |
| 289 return; | 290 return; |
| 290 } | 291 } |
| 291 if (*str != NULL) { | 292 if (*str != NULL) { |
| 292 printf("%s\n", *str); | 293 printf("%s\n", *str); |
| 293 } else { | 294 } else { |
| 294 printf("???\n"); | 295 printf("???\n"); |
| 295 } | 296 } |
| 296 | 297 |
| 297 bool is_running = details->Get(String::New("running"))->ToBoolean()->Value(); | 298 bool is_running = details->Get(String::New("running"))->ToBoolean()->Value(); |
| 298 PrintPrompt(is_running); | 299 PrintPrompt(is_running); |
| 299 } | 300 } |
| 300 | 301 |
| 301 | 302 |
| 302 void RemoteDebugger::HandleKeyboardCommand(char* command) { | 303 void RemoteDebugger::HandleKeyboardCommand(char* command) { |
| 304 Locker lock; |
| 303 HandleScope scope; | 305 HandleScope scope; |
| 304 | 306 |
| 305 // Convert the debugger command to a JSON debugger request. | 307 // Convert the debugger command to a JSON debugger request. |
| 306 TryCatch try_catch; | 308 TryCatch try_catch; |
| 307 Handle<Value> request = | 309 Handle<Value> request = |
| 308 Shell::DebugCommandToJSONRequest(String::New(command)); | 310 Shell::DebugCommandToJSONRequest(String::New(command)); |
| 309 if (try_catch.HasCaught()) { | 311 if (try_catch.HasCaught()) { |
| 310 v8::String::Utf8Value exception(try_catch.Exception()); | 312 v8::String::Utf8Value exception(try_catch.Exception()); |
| 311 const char* exception_string = Shell::ToCString(exception); | 313 const char* exception_string = Shell::ToCString(exception); |
| 312 printf("%s\n", exception_string); | 314 printf("%s\n", exception_string); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 360 } |
| 359 | 361 |
| 360 // Pass the keyboard command to the main thread. | 362 // Pass the keyboard command to the main thread. |
| 361 remote_debugger_->KeyboardCommand( | 363 remote_debugger_->KeyboardCommand( |
| 362 i::SmartPointer<char>(i::StrDup(command))); | 364 i::SmartPointer<char>(i::StrDup(command))); |
| 363 } | 365 } |
| 364 } | 366 } |
| 365 | 367 |
| 366 | 368 |
| 367 } // namespace v8 | 369 } // namespace v8 |
| OLD | NEW |