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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 | 28 |
29 #include "d8.h" | 29 #include "d8.h" |
30 #include "d8-debug.h" | 30 #include "d8-debug.h" |
31 #include "platform.h" | 31 #include "platform.h" |
32 #include "debug-agent.h" | 32 #include "debug-agent.h" |
33 | 33 |
34 | 34 |
35 namespace v8 { | 35 namespace v8 { |
36 | 36 |
| 37 void PrintPrompt() { |
| 38 printf("dbg> "); |
| 39 fflush(stdout); |
| 40 } |
| 41 |
37 | 42 |
38 void HandleDebugEvent(DebugEvent event, | 43 void HandleDebugEvent(DebugEvent event, |
39 Handle<Object> exec_state, | 44 Handle<Object> exec_state, |
40 Handle<Object> event_data, | 45 Handle<Object> event_data, |
41 Handle<Value> data) { | 46 Handle<Value> data) { |
42 HandleScope scope; | 47 HandleScope scope; |
43 | 48 |
44 // Check for handled event. | 49 // Check for handled event. |
45 if (event != Break && event != Exception && event != AfterCompile) { | 50 if (event != Break && event != Exception && event != AfterCompile) { |
46 return; | 51 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 Object::Cast(*fun->Call(exec_state, 0, NULL)); | 84 Object::Cast(*fun->Call(exec_state, 0, NULL)); |
80 if (try_catch.HasCaught()) { | 85 if (try_catch.HasCaught()) { |
81 Shell::ReportException(&try_catch); | 86 Shell::ReportException(&try_catch); |
82 return; | 87 return; |
83 } | 88 } |
84 | 89 |
85 static const int kBufferSize = 256; | 90 static const int kBufferSize = 256; |
86 bool running = false; | 91 bool running = false; |
87 while (!running) { | 92 while (!running) { |
88 char command[kBufferSize]; | 93 char command[kBufferSize]; |
89 printf("dbg> "); | 94 PrintPrompt(); |
90 char* str = fgets(command, kBufferSize, stdin); | 95 char* str = fgets(command, kBufferSize, stdin); |
91 if (str == NULL) break; | 96 if (str == NULL) break; |
92 | 97 |
93 // Ignore empty commands. | 98 // Ignore empty commands. |
94 if (strlen(command) == 0) continue; | 99 if (strlen(command) == 0) continue; |
95 | 100 |
96 TryCatch try_catch; | 101 TryCatch try_catch; |
97 | 102 |
98 // Convert the debugger command to a JSON debugger request. | 103 // Convert the debugger command to a JSON debugger request. |
99 Handle<Value> request = | 104 Handle<Value> request = |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 return; | 176 return; |
172 } | 177 } |
173 | 178 |
174 // Start the receiver thread. | 179 // Start the receiver thread. |
175 ReceiverThread receiver(this); | 180 ReceiverThread receiver(this); |
176 receiver.Start(); | 181 receiver.Start(); |
177 | 182 |
178 // Start the keyboard thread. | 183 // Start the keyboard thread. |
179 KeyboardThread keyboard(this); | 184 KeyboardThread keyboard(this); |
180 keyboard.Start(); | 185 keyboard.Start(); |
| 186 PrintPrompt(); |
181 | 187 |
182 // Process events received from debugged VM and from the keyboard. | 188 // Process events received from debugged VM and from the keyboard. |
183 bool terminate = false; | 189 bool terminate = false; |
184 while (!terminate) { | 190 while (!terminate) { |
185 event_available_->Wait(); | 191 event_available_->Wait(); |
186 RemoteDebuggerEvent* event = GetEvent(); | 192 RemoteDebuggerEvent* event = GetEvent(); |
187 switch (event->type()) { | 193 switch (event->type()) { |
188 case RemoteDebuggerEvent::kMessage: | 194 case RemoteDebuggerEvent::kMessage: |
189 HandleMessageReceived(event->data()); | 195 HandleMessageReceived(event->data()); |
190 break; | 196 break; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 263 |
258 | 264 |
259 void RemoteDebugger::HandleMessageReceived(char* message) { | 265 void RemoteDebugger::HandleMessageReceived(char* message) { |
260 HandleScope scope; | 266 HandleScope scope; |
261 | 267 |
262 // Print the event details. | 268 // Print the event details. |
263 TryCatch try_catch; | 269 TryCatch try_catch; |
264 Handle<Object> details = | 270 Handle<Object> details = |
265 Shell::DebugMessageDetails(Handle<String>::Cast(String::New(message))); | 271 Shell::DebugMessageDetails(Handle<String>::Cast(String::New(message))); |
266 if (try_catch.HasCaught()) { | 272 if (try_catch.HasCaught()) { |
267 Shell::ReportException(&try_catch); | 273 Shell::ReportException(&try_catch); |
| 274 PrintPrompt(); |
268 return; | 275 return; |
269 } | 276 } |
270 String::Utf8Value str(details->Get(String::New("text"))); | 277 String::Utf8Value str(details->Get(String::New("text"))); |
271 if (str.length() == 0) { | 278 if (str.length() == 0) { |
272 // Empty string is used to signal not to process this event. | 279 // Empty string is used to signal not to process this event. |
273 return; | 280 return; |
274 } | 281 } |
275 if (*str != NULL) { | 282 if (*str != NULL) { |
276 printf("%s\n", *str); | 283 printf("%s\n", *str); |
277 } else { | 284 } else { |
278 printf("???\n"); | 285 printf("???\n"); |
279 } | 286 } |
280 printf("dbg> "); | 287 PrintPrompt(); |
281 } | 288 } |
282 | 289 |
283 | 290 |
284 void RemoteDebugger::HandleKeyboardCommand(char* command) { | 291 void RemoteDebugger::HandleKeyboardCommand(char* command) { |
285 HandleScope scope; | 292 HandleScope scope; |
286 | 293 |
287 // Convert the debugger command to a JSON debugger request. | 294 // Convert the debugger command to a JSON debugger request. |
288 TryCatch try_catch; | 295 TryCatch try_catch; |
289 Handle<Value> request = | 296 Handle<Value> request = |
290 Shell::DebugCommandToJSONRequest(String::New(command)); | 297 Shell::DebugCommandToJSONRequest(String::New(command)); |
291 if (try_catch.HasCaught()) { | 298 if (try_catch.HasCaught()) { |
292 Shell::ReportException(&try_catch); | 299 v8::String::Utf8Value exception(try_catch.Exception()); |
| 300 const char* exception_string = Shell::ToCString(exception); |
| 301 printf("%s\n", exception_string); |
| 302 PrintPrompt(); |
293 return; | 303 return; |
294 } | 304 } |
295 | 305 |
296 // If undefined is returned the command was handled internally and there is | 306 // If undefined is returned the command was handled internally and there is |
297 // no JSON to send. | 307 // no JSON to send. |
298 if (request->IsUndefined()) { | 308 if (request->IsUndefined()) { |
| 309 PrintPrompt(); |
299 return; | 310 return; |
300 } | 311 } |
301 | 312 |
302 // Send the JSON debugger request. | 313 // Send the JSON debugger request. |
303 i::DebuggerAgentUtil::SendMessage(conn_, Handle<String>::Cast(request)); | 314 i::DebuggerAgentUtil::SendMessage(conn_, Handle<String>::Cast(request)); |
304 } | 315 } |
305 | 316 |
306 | 317 |
307 void ReceiverThread::Run() { | 318 void ReceiverThread::Run() { |
308 // Receive the connect message (with empty body). | 319 // Receive the connect message (with empty body). |
(...skipping 27 matching lines...) Expand all Loading... |
336 } | 347 } |
337 | 348 |
338 // Pass the keyboard command to the main thread. | 349 // Pass the keyboard command to the main thread. |
339 remote_debugger_->KeyboardCommand( | 350 remote_debugger_->KeyboardCommand( |
340 i::SmartPointer<char>(i::StrDup(command))); | 351 i::SmartPointer<char>(i::StrDup(command))); |
341 } | 352 } |
342 } | 353 } |
343 | 354 |
344 | 355 |
345 } // namespace v8 | 356 } // namespace v8 |
OLD | NEW |