OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/service.h" | 5 #include "vm/service.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
10 | 10 |
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 if ((id < 0) || (id >= libs.Length())) { | 1444 if ((id < 0) || (id >= libs.Length())) { |
1445 return Object::sentinel().raw(); | 1445 return Object::sentinel().raw(); |
1446 } | 1446 } |
1447 Library& lib = Library::Handle(); | 1447 Library& lib = Library::Handle(); |
1448 lib ^= libs.At(id); | 1448 lib ^= libs.At(id); |
1449 ASSERT(!lib.IsNull()); | 1449 ASSERT(!lib.IsNull()); |
1450 if (num_parts == 2) { | 1450 if (num_parts == 2) { |
1451 return lib.raw(); | 1451 return lib.raw(); |
1452 } | 1452 } |
1453 if (strcmp(parts[2], "scripts") == 0) { | 1453 if (strcmp(parts[2], "scripts") == 0) { |
1454 // Script ids look like "libraries/35/scripts/library%2Furl.dart" | 1454 // Script ids look like "libraries/35/scripts/library%2Furl.dart/12345" |
1455 if (num_parts != 4) { | 1455 if (num_parts != 5) { |
1456 return Object::sentinel().raw(); | 1456 return Object::sentinel().raw(); |
1457 } | 1457 } |
1458 const String& id = String::Handle(String::New(parts[3])); | 1458 const String& id = String::Handle(String::New(parts[3])); |
1459 ASSERT(!id.IsNull()); | 1459 ASSERT(!id.IsNull()); |
1460 // The id is the url of the script % encoded, decode it. | 1460 // The id is the url of the script % encoded, decode it. |
1461 const String& requested_url = String::Handle(String::DecodeIRI(id)); | 1461 const String& requested_url = String::Handle(String::DecodeIRI(id)); |
| 1462 |
| 1463 // Each script id is tagged with a load time. |
| 1464 int64_t timestamp; |
| 1465 if (!GetInteger64Id(parts[4], ×tamp, 16) || (timestamp < 0)) { |
| 1466 return Object::sentinel().raw(); |
| 1467 } |
| 1468 |
1462 Script& script = Script::Handle(); | 1469 Script& script = Script::Handle(); |
1463 String& script_url = String::Handle(); | 1470 String& script_url = String::Handle(); |
1464 const Array& loaded_scripts = Array::Handle(lib.LoadedScripts()); | 1471 const Array& loaded_scripts = Array::Handle(lib.LoadedScripts()); |
1465 ASSERT(!loaded_scripts.IsNull()); | 1472 ASSERT(!loaded_scripts.IsNull()); |
1466 intptr_t i; | 1473 intptr_t i; |
1467 for (i = 0; i < loaded_scripts.Length(); i++) { | 1474 for (i = 0; i < loaded_scripts.Length(); i++) { |
1468 script ^= loaded_scripts.At(i); | 1475 script ^= loaded_scripts.At(i); |
1469 ASSERT(!script.IsNull()); | 1476 ASSERT(!script.IsNull()); |
1470 script_url ^= script.url(); | 1477 script_url ^= script.url(); |
1471 if (script_url.Equals(requested_url)) { | 1478 if (script_url.Equals(requested_url) && |
| 1479 (timestamp == script.load_timestamp())) { |
1472 return script.raw(); | 1480 return script.raw(); |
1473 } | 1481 } |
1474 } | 1482 } |
1475 } | 1483 } |
1476 | 1484 |
1477 // Not found. | 1485 // Not found. |
1478 return Object::sentinel().raw(); | 1486 return Object::sentinel().raw(); |
1479 } | 1487 } |
1480 | 1488 |
1481 static RawObject* LookupHeapObjectClasses(Thread* thread, | 1489 static RawObject* LookupHeapObjectClasses(Thread* thread, |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2367 } | 2375 } |
2368 SourceReport report(report_set, compile_mode); | 2376 SourceReport report(report_set, compile_mode); |
2369 report.PrintJSON(js, | 2377 report.PrintJSON(js, |
2370 script, | 2378 script, |
2371 TokenPosition(start_pos), | 2379 TokenPosition(start_pos), |
2372 TokenPosition(end_pos)); | 2380 TokenPosition(end_pos)); |
2373 return true; | 2381 return true; |
2374 } | 2382 } |
2375 | 2383 |
2376 | 2384 |
| 2385 static const MethodParameter* reload_sources_params[] = { |
| 2386 RUNNABLE_ISOLATE_PARAMETER, |
| 2387 NULL, |
| 2388 }; |
| 2389 |
| 2390 |
| 2391 static bool ReloadSources(Thread* thread, JSONStream* js) { |
| 2392 Isolate* isolate = thread->isolate(); |
| 2393 if (!isolate->compilation_allowed()) { |
| 2394 js->PrintError(kFeatureDisabled, |
| 2395 "Cannot reload source when running a precompiled program."); |
| 2396 return true; |
| 2397 } |
| 2398 if (Dart::snapshot_kind() == Snapshot::kAppWithJIT) { |
| 2399 js->PrintError(kFeatureDisabled, |
| 2400 "Cannot reload source when running an app snapshot."); |
| 2401 return true; |
| 2402 } |
| 2403 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); |
| 2404 if (handler == NULL) { |
| 2405 js->PrintError(kFeatureDisabled, |
| 2406 "A library tag handler must be installed."); |
| 2407 return true; |
| 2408 } |
| 2409 if (isolate->IsReloading()) { |
| 2410 js->PrintError(kIsolateIsReloading, |
| 2411 "This isolate is being reloaded."); |
| 2412 return true; |
| 2413 } |
| 2414 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); |
| 2415 ASSERT(isolate->CanReload()); |
| 2416 |
| 2417 if (stack->Length() > 0) { |
| 2418 // TODO(turnidge): We need to support this case. |
| 2419 js->PrintError(kFeatureDisabled, |
| 2420 "Source can only be reloaded when stack is empty."); |
| 2421 return true; |
| 2422 } else { |
| 2423 isolate->ReloadSources(); |
| 2424 } |
| 2425 |
| 2426 PrintSuccess(js); |
| 2427 return true; |
| 2428 } |
| 2429 |
| 2430 |
2377 static bool AddBreakpointCommon(Thread* thread, | 2431 static bool AddBreakpointCommon(Thread* thread, |
2378 JSONStream* js, | 2432 JSONStream* js, |
2379 const String& script_uri) { | 2433 const String& script_uri) { |
2380 if (!thread->isolate()->compilation_allowed()) { | 2434 if (!thread->isolate()->compilation_allowed()) { |
2381 js->PrintError(kFeatureDisabled, | 2435 js->PrintError(kFeatureDisabled, |
2382 "Cannot use breakpoints when running a precompiled program."); | 2436 "Cannot use breakpoints when running a precompiled program."); |
2383 return true; | 2437 return true; |
2384 } | 2438 } |
2385 const char* line_param = js->LookupParam("line"); | 2439 const char* line_param = js->LookupParam("line"); |
2386 intptr_t line = UIntParameter::Parse(line_param); | 2440 intptr_t line = UIntParameter::Parse(line_param); |
(...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3940 { "_getVMTimeline", GetVMTimeline, | 3994 { "_getVMTimeline", GetVMTimeline, |
3941 get_vm_timeline_params }, | 3995 get_vm_timeline_params }, |
3942 { "_getVMTimelineFlags", GetVMTimelineFlags, | 3996 { "_getVMTimelineFlags", GetVMTimelineFlags, |
3943 get_vm_timeline_flags_params }, | 3997 get_vm_timeline_flags_params }, |
3944 { "pause", Pause, | 3998 { "pause", Pause, |
3945 pause_params }, | 3999 pause_params }, |
3946 { "removeBreakpoint", RemoveBreakpoint, | 4000 { "removeBreakpoint", RemoveBreakpoint, |
3947 remove_breakpoint_params }, | 4001 remove_breakpoint_params }, |
3948 { "_restartVM", RestartVM, | 4002 { "_restartVM", RestartVM, |
3949 restart_vm_params }, | 4003 restart_vm_params }, |
| 4004 { "_reloadSources", ReloadSources, |
| 4005 reload_sources_params }, |
3950 { "resume", Resume, | 4006 { "resume", Resume, |
3951 resume_params }, | 4007 resume_params }, |
3952 { "_requestHeapSnapshot", RequestHeapSnapshot, | 4008 { "_requestHeapSnapshot", RequestHeapSnapshot, |
3953 request_heap_snapshot_params }, | 4009 request_heap_snapshot_params }, |
3954 { "setExceptionPauseMode", SetExceptionPauseMode, | 4010 { "setExceptionPauseMode", SetExceptionPauseMode, |
3955 set_exception_pause_mode_params }, | 4011 set_exception_pause_mode_params }, |
3956 { "_setFlag", SetFlag, | 4012 { "_setFlag", SetFlag, |
3957 set_flags_params }, | 4013 set_flags_params }, |
3958 { "setLibraryDebuggable", SetLibraryDebuggable, | 4014 { "setLibraryDebuggable", SetLibraryDebuggable, |
3959 set_library_debuggable_params }, | 4015 set_library_debuggable_params }, |
(...skipping 16 matching lines...) Expand all Loading... |
3976 if (strcmp(method_name, method.name) == 0) { | 4032 if (strcmp(method_name, method.name) == 0) { |
3977 return &method; | 4033 return &method; |
3978 } | 4034 } |
3979 } | 4035 } |
3980 return NULL; | 4036 return NULL; |
3981 } | 4037 } |
3982 | 4038 |
3983 #endif // !PRODUCT | 4039 #endif // !PRODUCT |
3984 | 4040 |
3985 } // namespace dart | 4041 } // namespace dart |
OLD | NEW |