OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 void PrintPrompt() { | 48 void PrintPrompt() { |
49 PrintPrompt(was_running); | 49 PrintPrompt(was_running); |
50 } | 50 } |
51 | 51 |
52 | 52 |
53 void HandleDebugEvent(DebugEvent event, | 53 void HandleDebugEvent(DebugEvent event, |
54 Handle<Object> exec_state, | 54 Handle<Object> exec_state, |
55 Handle<Object> event_data, | 55 Handle<Object> event_data, |
56 Handle<Value> data) { | 56 Handle<Value> data) { |
57 HandleScope scope; | 57 // TODO(svenpanne) There should be a way to retrieve this in the callback. |
| 58 Isolate* isolate = Isolate::GetCurrent(); |
| 59 HandleScope scope(isolate); |
58 | 60 |
59 // Check for handled event. | 61 // Check for handled event. |
60 if (event != Break && event != Exception && event != AfterCompile) { | 62 if (event != Break && event != Exception && event != AfterCompile) { |
61 return; | 63 return; |
62 } | 64 } |
63 | 65 |
64 TryCatch try_catch; | 66 TryCatch try_catch; |
65 | 67 |
66 // Get the toJSONProtocol function on the event and get the JSON format. | 68 // Get the toJSONProtocol function on the event and get the JSON format. |
67 Local<String> to_json_fun_name = String::New("toJSONProtocol"); | 69 Local<String> to_json_fun_name = String::New("toJSONProtocol"); |
68 Local<Function> to_json_fun = | 70 Local<Function> to_json_fun = |
69 Function::Cast(*event_data->Get(to_json_fun_name)); | 71 Function::Cast(*event_data->Get(to_json_fun_name)); |
70 Local<Value> event_json = to_json_fun->Call(event_data, 0, NULL); | 72 Local<Value> event_json = to_json_fun->Call(event_data, 0, NULL); |
71 if (try_catch.HasCaught()) { | 73 if (try_catch.HasCaught()) { |
72 Shell::ReportException(&try_catch); | 74 Shell::ReportException(isolate, &try_catch); |
73 return; | 75 return; |
74 } | 76 } |
75 | 77 |
76 // Print the event details. | 78 // Print the event details. |
77 Handle<Object> details = | 79 Handle<Object> details = |
78 Shell::DebugMessageDetails(Handle<String>::Cast(event_json)); | 80 Shell::DebugMessageDetails(Handle<String>::Cast(event_json)); |
79 if (try_catch.HasCaught()) { | 81 if (try_catch.HasCaught()) { |
80 Shell::ReportException(&try_catch); | 82 Shell::ReportException(isolate, &try_catch); |
81 return; | 83 return; |
82 } | 84 } |
83 String::Utf8Value str(details->Get(String::New("text"))); | 85 String::Utf8Value str(details->Get(String::New("text"))); |
84 if (str.length() == 0) { | 86 if (str.length() == 0) { |
85 // Empty string is used to signal not to process this event. | 87 // Empty string is used to signal not to process this event. |
86 return; | 88 return; |
87 } | 89 } |
88 printf("%s\n", *str); | 90 printf("%s\n", *str); |
89 | 91 |
90 // Get the debug command processor. | 92 // Get the debug command processor. |
91 Local<String> fun_name = String::New("debugCommandProcessor"); | 93 Local<String> fun_name = String::New("debugCommandProcessor"); |
92 Local<Function> fun = Function::Cast(*exec_state->Get(fun_name)); | 94 Local<Function> fun = Function::Cast(*exec_state->Get(fun_name)); |
93 Local<Object> cmd_processor = | 95 Local<Object> cmd_processor = |
94 Object::Cast(*fun->Call(exec_state, 0, NULL)); | 96 Object::Cast(*fun->Call(exec_state, 0, NULL)); |
95 if (try_catch.HasCaught()) { | 97 if (try_catch.HasCaught()) { |
96 Shell::ReportException(&try_catch); | 98 Shell::ReportException(isolate, &try_catch); |
97 return; | 99 return; |
98 } | 100 } |
99 | 101 |
100 static const int kBufferSize = 256; | 102 static const int kBufferSize = 256; |
101 bool running = false; | 103 bool running = false; |
102 while (!running) { | 104 while (!running) { |
103 char command[kBufferSize]; | 105 char command[kBufferSize]; |
104 PrintPrompt(running); | 106 PrintPrompt(running); |
105 char* str = fgets(command, kBufferSize, stdin); | 107 char* str = fgets(command, kBufferSize, stdin); |
106 if (str == NULL) break; | 108 if (str == NULL) break; |
107 | 109 |
108 // Ignore empty commands. | 110 // Ignore empty commands. |
109 if (strlen(command) == 0) continue; | 111 if (strlen(command) == 0) continue; |
110 | 112 |
111 TryCatch try_catch; | 113 TryCatch try_catch; |
112 | 114 |
113 // Convert the debugger command to a JSON debugger request. | 115 // Convert the debugger command to a JSON debugger request. |
114 Handle<Value> request = | 116 Handle<Value> request = |
115 Shell::DebugCommandToJSONRequest(String::New(command)); | 117 Shell::DebugCommandToJSONRequest(String::New(command)); |
116 if (try_catch.HasCaught()) { | 118 if (try_catch.HasCaught()) { |
117 Shell::ReportException(&try_catch); | 119 Shell::ReportException(isolate, &try_catch); |
118 continue; | 120 continue; |
119 } | 121 } |
120 | 122 |
121 // If undefined is returned the command was handled internally and there is | 123 // If undefined is returned the command was handled internally and there is |
122 // no JSON to send. | 124 // no JSON to send. |
123 if (request->IsUndefined()) { | 125 if (request->IsUndefined()) { |
124 continue; | 126 continue; |
125 } | 127 } |
126 | 128 |
127 Handle<String> fun_name; | 129 Handle<String> fun_name; |
128 Handle<Function> fun; | 130 Handle<Function> fun; |
129 // All the functions used below take one argument. | 131 // All the functions used below take one argument. |
130 static const int kArgc = 1; | 132 static const int kArgc = 1; |
131 Handle<Value> args[kArgc]; | 133 Handle<Value> args[kArgc]; |
132 | 134 |
133 // Invoke the JavaScript to convert the debug command line to a JSON | 135 // Invoke the JavaScript to convert the debug command line to a JSON |
134 // request, invoke the JSON request and convert the JSON respose to a text | 136 // request, invoke the JSON request and convert the JSON respose to a text |
135 // representation. | 137 // representation. |
136 fun_name = String::New("processDebugRequest"); | 138 fun_name = String::New("processDebugRequest"); |
137 fun = Handle<Function>::Cast(cmd_processor->Get(fun_name)); | 139 fun = Handle<Function>::Cast(cmd_processor->Get(fun_name)); |
138 args[0] = request; | 140 args[0] = request; |
139 Handle<Value> response_val = fun->Call(cmd_processor, kArgc, args); | 141 Handle<Value> response_val = fun->Call(cmd_processor, kArgc, args); |
140 if (try_catch.HasCaught()) { | 142 if (try_catch.HasCaught()) { |
141 Shell::ReportException(&try_catch); | 143 Shell::ReportException(isolate, &try_catch); |
142 continue; | 144 continue; |
143 } | 145 } |
144 Handle<String> response = Handle<String>::Cast(response_val); | 146 Handle<String> response = Handle<String>::Cast(response_val); |
145 | 147 |
146 // Convert the debugger response into text details and the running state. | 148 // Convert the debugger response into text details and the running state. |
147 Handle<Object> response_details = Shell::DebugMessageDetails(response); | 149 Handle<Object> response_details = Shell::DebugMessageDetails(response); |
148 if (try_catch.HasCaught()) { | 150 if (try_catch.HasCaught()) { |
149 Shell::ReportException(&try_catch); | 151 Shell::ReportException(isolate, &try_catch); |
150 continue; | 152 continue; |
151 } | 153 } |
152 String::Utf8Value text_str(response_details->Get(String::New("text"))); | 154 String::Utf8Value text_str(response_details->Get(String::New("text"))); |
153 if (text_str.length() > 0) { | 155 if (text_str.length() > 0) { |
154 printf("%s\n", *text_str); | 156 printf("%s\n", *text_str); |
155 } | 157 } |
156 running = | 158 running = |
157 response_details->Get(String::New("running"))->ToBoolean()->Value(); | 159 response_details->Get(String::New("running"))->ToBoolean()->Value(); |
158 } | 160 } |
159 } | 161 } |
160 | 162 |
161 | 163 |
162 void RunRemoteDebugger(int port) { | 164 void RunRemoteDebugger(Isolate* isolate, int port) { |
163 RemoteDebugger debugger(port); | 165 RemoteDebugger debugger(isolate, port); |
164 debugger.Run(); | 166 debugger.Run(); |
165 } | 167 } |
166 | 168 |
167 | 169 |
168 void RemoteDebugger::Run() { | 170 void RemoteDebugger::Run() { |
169 bool ok; | 171 bool ok; |
170 | 172 |
171 // Make sure that socket support is initialized. | 173 // Make sure that socket support is initialized. |
172 ok = i::Socket::SetUp(); | 174 ok = i::Socket::SetUp(); |
173 if (!ok) { | 175 if (!ok) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 head_ = head_->next(); | 268 head_ = head_->next(); |
267 if (head_ == NULL) { | 269 if (head_ == NULL) { |
268 ASSERT(tail_ == result); | 270 ASSERT(tail_ == result); |
269 tail_ = NULL; | 271 tail_ = NULL; |
270 } | 272 } |
271 return result; | 273 return result; |
272 } | 274 } |
273 | 275 |
274 | 276 |
275 void RemoteDebugger::HandleMessageReceived(char* message) { | 277 void RemoteDebugger::HandleMessageReceived(char* message) { |
276 Locker lock(v8::Isolate::GetCurrent()); | 278 Locker lock(isolate_); |
277 HandleScope scope; | 279 HandleScope scope(isolate_); |
278 | 280 |
279 // Print the event details. | 281 // Print the event details. |
280 TryCatch try_catch; | 282 TryCatch try_catch; |
281 Handle<Object> details = | 283 Handle<Object> details = |
282 Shell::DebugMessageDetails(Handle<String>::Cast(String::New(message))); | 284 Shell::DebugMessageDetails(Handle<String>::Cast(String::New(message))); |
283 if (try_catch.HasCaught()) { | 285 if (try_catch.HasCaught()) { |
284 Shell::ReportException(&try_catch); | 286 Shell::ReportException(isolate_, &try_catch); |
285 PrintPrompt(); | 287 PrintPrompt(); |
286 return; | 288 return; |
287 } | 289 } |
288 String::Utf8Value str(details->Get(String::New("text"))); | 290 String::Utf8Value str(details->Get(String::New("text"))); |
289 if (str.length() == 0) { | 291 if (str.length() == 0) { |
290 // Empty string is used to signal not to process this event. | 292 // Empty string is used to signal not to process this event. |
291 return; | 293 return; |
292 } | 294 } |
293 if (*str != NULL) { | 295 if (*str != NULL) { |
294 printf("%s\n", *str); | 296 printf("%s\n", *str); |
295 } else { | 297 } else { |
296 printf("???\n"); | 298 printf("???\n"); |
297 } | 299 } |
298 | 300 |
299 bool is_running = details->Get(String::New("running"))->ToBoolean()->Value(); | 301 bool is_running = details->Get(String::New("running"))->ToBoolean()->Value(); |
300 PrintPrompt(is_running); | 302 PrintPrompt(is_running); |
301 } | 303 } |
302 | 304 |
303 | 305 |
304 void RemoteDebugger::HandleKeyboardCommand(char* command) { | 306 void RemoteDebugger::HandleKeyboardCommand(char* command) { |
305 Locker lock(v8::Isolate::GetCurrent()); | 307 Locker lock(isolate_); |
306 HandleScope scope; | 308 HandleScope scope(isolate_); |
307 | 309 |
308 // Convert the debugger command to a JSON debugger request. | 310 // Convert the debugger command to a JSON debugger request. |
309 TryCatch try_catch; | 311 TryCatch try_catch; |
310 Handle<Value> request = | 312 Handle<Value> request = |
311 Shell::DebugCommandToJSONRequest(String::New(command)); | 313 Shell::DebugCommandToJSONRequest(String::New(command)); |
312 if (try_catch.HasCaught()) { | 314 if (try_catch.HasCaught()) { |
313 Shell::ReportException(&try_catch); | 315 Shell::ReportException(isolate_, &try_catch); |
314 PrintPrompt(); | 316 PrintPrompt(); |
315 return; | 317 return; |
316 } | 318 } |
317 | 319 |
318 // If undefined is returned the command was handled internally and there is | 320 // If undefined is returned the command was handled internally and there is |
319 // no JSON to send. | 321 // no JSON to send. |
320 if (request->IsUndefined()) { | 322 if (request->IsUndefined()) { |
321 PrintPrompt(); | 323 PrintPrompt(); |
322 return; | 324 return; |
323 } | 325 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 // Pass the keyboard command to the main thread. | 363 // Pass the keyboard command to the main thread. |
362 remote_debugger_->KeyboardCommand( | 364 remote_debugger_->KeyboardCommand( |
363 i::SmartArrayPointer<char>(i::StrDup(command))); | 365 i::SmartArrayPointer<char>(i::StrDup(command))); |
364 } | 366 } |
365 } | 367 } |
366 | 368 |
367 | 369 |
368 } // namespace v8 | 370 } // namespace v8 |
369 | 371 |
370 #endif // ENABLE_DEBUGGER_SUPPORT | 372 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |