Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1041)

Side by Side Diff: runtime/vm/service.cc

Issue 381383010: Add breakpoints and single-stepping to Observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix bugs, gen js Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 1413
1414 1414
1415 static bool HandleLibrariesScriptsCoverage( 1415 static bool HandleLibrariesScriptsCoverage(
1416 Isolate* isolate, const Script& script, JSONStream* js) { 1416 Isolate* isolate, const Script& script, JSONStream* js) {
1417 ScriptCoverageFilter sf(script); 1417 ScriptCoverageFilter sf(script);
1418 CodeCoverage::PrintJSON(isolate, js, &sf); 1418 CodeCoverage::PrintJSON(isolate, js, &sf);
1419 return true; 1419 return true;
1420 } 1420 }
1421 1421
1422 1422
1423 static bool HandleLibrariesScriptsSetBreakpoint(
1424 Isolate* isolate, const Script& script, JSONStream* js) {
1425 if (!js->HasOption("line")) {
1426 PrintError(js, "Missing 'line' option");
1427 return true;
1428 }
1429 const char* line_option = js->LookupOption("line");
1430 intptr_t line = -1;
1431 if (!GetIntegerId(line_option, &line)) {
1432 PrintError(js, "Invalid 'line' value: %s", line_option);
1433 return true;
1434 }
1435 const String& script_url = String::Handle(script.url());
1436 SourceBreakpoint* bpt =
1437 isolate->debugger()->SetBreakpointAtLine(script_url, line);
1438 if (bpt == NULL) {
1439 PrintError(js, "Unable to set breakpoint at line %s", line_option);
1440 return true;
1441 }
1442 bpt->PrintJSON(js);
1443 return true;
1444 }
1445
1446
1423 static bool HandleLibrariesScripts(Isolate* isolate, 1447 static bool HandleLibrariesScripts(Isolate* isolate,
1424 const Library& lib, 1448 const Library& lib,
1425 JSONStream* js) { 1449 JSONStream* js) {
1426 if (js->num_arguments() > 5) { 1450 if (js->num_arguments() > 5) {
1427 PrintError(js, "Command too long"); 1451 PrintError(js, "Command too long");
1428 return true; 1452 return true;
1429 } else if (js->num_arguments() < 4) { 1453 } else if (js->num_arguments() < 4) {
1430 PrintError(js, "Must specify collection object id: scripts/id"); 1454 PrintError(js, "Must specify collection object id: scripts/id");
1431 return true; 1455 return true;
1432 } 1456 }
(...skipping 18 matching lines...) Expand all
1451 PrintError(js, "Script %s not found", requested_url.ToCString()); 1475 PrintError(js, "Script %s not found", requested_url.ToCString());
1452 return true; 1476 return true;
1453 } 1477 }
1454 if (js->num_arguments() == 4) { 1478 if (js->num_arguments() == 4) {
1455 script.PrintJSON(js, false); 1479 script.PrintJSON(js, false);
1456 return true; 1480 return true;
1457 } else { 1481 } else {
1458 const char* subcollection = js->GetArgument(4); 1482 const char* subcollection = js->GetArgument(4);
1459 if (strcmp(subcollection, "coverage") == 0) { 1483 if (strcmp(subcollection, "coverage") == 0) {
1460 return HandleLibrariesScriptsCoverage(isolate, script, js); 1484 return HandleLibrariesScriptsCoverage(isolate, script, js);
1485 } else if (strcmp(subcollection, "setBreakpoint") == 0) {
1486 return HandleLibrariesScriptsSetBreakpoint(isolate, script, js);
1461 } else { 1487 } else {
1462 PrintError(js, "Invalid sub collection %s", subcollection); 1488 PrintError(js, "Invalid sub collection %s", subcollection);
1463 return true; 1489 return true;
1464 } 1490 }
1465 } 1491 }
1466 UNREACHABLE(); 1492 UNREACHABLE();
1467 return true; 1493 return true;
1468 } 1494 }
1469 1495
1470 1496
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 static bool HandleScripts(Isolate* isolate, JSONStream* js) { 1700 static bool HandleScripts(Isolate* isolate, JSONStream* js) {
1675 if (js->num_arguments() == 1) { 1701 if (js->num_arguments() == 1) {
1676 // Enumerate all scripts. 1702 // Enumerate all scripts.
1677 return HandleScriptsEnumerate(isolate, js); 1703 return HandleScriptsEnumerate(isolate, js);
1678 } 1704 }
1679 PrintError(js, "Command too long"); 1705 PrintError(js, "Command too long");
1680 return true; 1706 return true;
1681 } 1707 }
1682 1708
1683 1709
1684 static bool HandleDebugResume(Isolate* isolate, JSONStream* js) { 1710 static bool HandleDebugResume(Isolate* isolate,
1711 const char* step_option,
1712 JSONStream* js) {
1685 if (isolate->message_handler()->paused_on_start()) { 1713 if (isolate->message_handler()->paused_on_start()) {
1686 isolate->message_handler()->set_pause_on_start(false); 1714 isolate->message_handler()->set_pause_on_start(false);
1687 JSONObject jsobj(js); 1715 JSONObject jsobj(js);
1688 jsobj.AddProperty("type", "Success"); 1716 jsobj.AddProperty("type", "Success");
1689 jsobj.AddProperty("id", ""); 1717 jsobj.AddProperty("id", "");
1690 return true; 1718 return true;
1691 } 1719 }
1692 if (isolate->message_handler()->paused_on_exit()) { 1720 if (isolate->message_handler()->paused_on_exit()) {
1693 isolate->message_handler()->set_pause_on_exit(false); 1721 isolate->message_handler()->set_pause_on_exit(false);
1694 JSONObject jsobj(js); 1722 JSONObject jsobj(js);
1695 jsobj.AddProperty("type", "Success"); 1723 jsobj.AddProperty("type", "Success");
1696 jsobj.AddProperty("id", ""); 1724 jsobj.AddProperty("id", "");
1697 return true; 1725 return true;
1698 } 1726 }
1699 if (isolate->debugger()->PauseEvent() != NULL) { 1727 if (isolate->debugger()->PauseEvent() != NULL) {
1728 if (step_option != NULL) {
1729 if (strcmp(step_option, "into") == 0) {
1730 isolate->debugger()->SetSingleStep();
1731 } else if (strcmp(step_option, "over") == 0) {
1732 isolate->debugger()->SetStepOver();
1733 } else if (strcmp(step_option, "out") == 0) {
1734 isolate->debugger()->SetStepOut();
1735 } else {
1736 PrintError(js, "Invalid 'step' option: %s", step_option);
1737 return true;
1738 }
1739 }
1700 isolate->Resume(); 1740 isolate->Resume();
1701 JSONObject jsobj(js); 1741 JSONObject jsobj(js);
1702 jsobj.AddProperty("type", "Success"); 1742 jsobj.AddProperty("type", "Success");
1703 jsobj.AddProperty("id", ""); 1743 jsobj.AddProperty("id", "");
1704 return true; 1744 return true;
1705 } 1745 }
1706 1746
1707 PrintError(js, "VM was not paused"); 1747 PrintError(js, "VM was not paused");
1708 return true; 1748 return true;
1709 } 1749 }
1710 1750
1711 1751
1712 static bool HandleDebug(Isolate* isolate, JSONStream* js) { 1752 static bool HandleDebug(Isolate* isolate, JSONStream* js) {
1713 if (js->num_arguments() == 1) { 1753 if (js->num_arguments() == 1) {
1714 PrintError(js, "Must specify a subcommand"); 1754 PrintError(js, "Must specify a subcommand");
1715 return true; 1755 return true;
1716 } 1756 }
1717 const char* command = js->GetArgument(1); 1757 const char* command = js->GetArgument(1);
1718 if (strcmp(command, "breakpoints") == 0) { 1758 if (strcmp(command, "breakpoints") == 0) {
1719 if (js->num_arguments() == 2) { 1759 if (js->num_arguments() == 2) {
1720 // Print breakpoint list. 1760 // Print breakpoint list.
1721 JSONObject jsobj(js); 1761 JSONObject jsobj(js);
1722 jsobj.AddProperty("type", "BreakpointList"); 1762 jsobj.AddProperty("type", "BreakpointList");
1763 jsobj.AddProperty("id", "debug/breakpoints");
1723 JSONArray jsarr(&jsobj, "breakpoints"); 1764 JSONArray jsarr(&jsobj, "breakpoints");
1724 isolate->debugger()->PrintBreakpointsToJSONArray(&jsarr); 1765 isolate->debugger()->PrintBreakpointsToJSONArray(&jsarr);
1725 return true; 1766 return true;
1726 } else if (js->num_arguments() == 3) { 1767 } else {
1727 // Print individual breakpoint.
1728 intptr_t id = 0; 1768 intptr_t id = 0;
1729 SourceBreakpoint* bpt = NULL; 1769 SourceBreakpoint* bpt = NULL;
1730 if (GetIntegerId(js->GetArgument(2), &id)) { 1770 if (GetIntegerId(js->GetArgument(2), &id)) {
1731 bpt = isolate->debugger()->GetBreakpointById(id); 1771 bpt = isolate->debugger()->GetBreakpointById(id);
1732 } 1772 }
1733 if (bpt != NULL) { 1773 if (bpt == NULL) {
1774 PrintError(js, "Unrecognized breakpoint id: %s", js->GetArgument(2));
1775 return true;
1776 }
1777 if (js->num_arguments() == 3) {
1778 // Print individual breakpoint.
1734 bpt->PrintJSON(js); 1779 bpt->PrintJSON(js);
1735 return true; 1780 return true;
1781 } else if (js->num_arguments() == 4) {
1782 const char* sub_command = js->GetArgument(3);
1783 if (strcmp(sub_command, "clear") == 0) {
1784 // Clear this breakpoint.
1785 isolate->debugger()->RemoveBreakpoint(id);
1786
1787 JSONObject jsobj(js);
1788 jsobj.AddProperty("type", "Success");
1789 jsobj.AddProperty("id", "");
1790 return true;
1791 } else {
1792 PrintError(js, "Unrecognized subcommand: %s", sub_command);
1793 return true;
1794 }
1736 } else { 1795 } else {
1737 PrintError(js, "Unrecognized breakpoint id %s", js->GetArgument(2)); 1796 PrintError(js, "Command too long");
1738 return true; 1797 return true;
1739 } 1798 }
1740 } else {
1741 PrintError(js, "Command too long");
1742 return true;
1743 } 1799 }
1744 } else if (strcmp(command, "pause") == 0) { 1800 } else if (strcmp(command, "pause") == 0) {
1745 if (js->num_arguments() == 2) { 1801 if (js->num_arguments() == 2) {
1746 // TODO(turnidge): Don't double-interrupt the isolate here. 1802 // TODO(turnidge): Don't double-interrupt the isolate here.
1747 isolate->ScheduleInterrupts(Isolate::kApiInterrupt); 1803 isolate->ScheduleInterrupts(Isolate::kApiInterrupt);
1748 JSONObject jsobj(js); 1804 JSONObject jsobj(js);
1749 jsobj.AddProperty("type", "Success"); 1805 jsobj.AddProperty("type", "Success");
1750 jsobj.AddProperty("id", ""); 1806 jsobj.AddProperty("id", "");
1751 return true; 1807 return true;
1752 } else { 1808 } else {
1753 PrintError(js, "Command too long"); 1809 PrintError(js, "Command too long");
1754 return true; 1810 return true;
1755 } 1811 }
1756 } else if (strcmp(command, "resume") == 0) { 1812 } else if (strcmp(command, "resume") == 0) {
1757 if (js->num_arguments() == 2) { 1813 if (js->num_arguments() == 2) {
1758 return HandleDebugResume(isolate, js); 1814 const char* step_option = js->LookupOption("step");
1815 return HandleDebugResume(isolate, step_option, js);
1759 } else { 1816 } else {
1760 PrintError(js, "Command too long"); 1817 PrintError(js, "Command too long");
1761 return true; 1818 return true;
1762 } 1819 }
1763 } else { 1820 } else {
1764 PrintError(js, "Unrecognized subcommand '%s'", js->GetArgument(1)); 1821 PrintError(js, "Unrecognized subcommand '%s'", js->GetArgument(1));
1765 return true; 1822 return true;
1766 } 1823 }
1767 } 1824 }
1768 1825
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 while (current != NULL) { 2441 while (current != NULL) {
2385 if (strcmp(name, current->name()) == 0) { 2442 if (strcmp(name, current->name()) == 0) {
2386 return current; 2443 return current;
2387 } 2444 }
2388 current = current->next(); 2445 current = current->next();
2389 } 2446 }
2390 return NULL; 2447 return NULL;
2391 } 2448 }
2392 2449
2393 } // namespace dart 2450 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698