Chromium Code Reviews| 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 "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 | 9 |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1583 | 1583 |
| 1584 | 1584 |
| 1585 static bool HandleScriptsCoverage( | 1585 static bool HandleScriptsCoverage( |
| 1586 Isolate* isolate, const String& script_url, JSONStream* js) { | 1586 Isolate* isolate, const String& script_url, JSONStream* js) { |
| 1587 ScriptCoverageFilter sf(script_url); | 1587 ScriptCoverageFilter sf(script_url); |
| 1588 CodeCoverage::PrintJSON(isolate, js, &sf); | 1588 CodeCoverage::PrintJSON(isolate, js, &sf); |
| 1589 return true; | 1589 return true; |
| 1590 } | 1590 } |
| 1591 | 1591 |
| 1592 | 1592 |
| 1593 static bool HandleScriptsSetBreakpoint( | |
| 1594 Isolate* isolate, const String& script_url, JSONStream* js) { | |
| 1595 if (!js->HasOption("line")) { | |
| 1596 PrintError(js, "Missing 'line' option"); | |
| 1597 return true; | |
| 1598 } | |
| 1599 const char* line_option = js->LookupOption("line"); | |
| 1600 intptr_t line = -1; | |
| 1601 if (!GetIntegerId(line_option, &line)) { | |
| 1602 PrintError(js, "Invalid 'line' value: %s", line_option); | |
| 1603 return true; | |
| 1604 } | |
| 1605 SourceBreakpoint* bpt = | |
| 1606 isolate->debugger()->SetBreakpointAtLine(script_url, line); | |
| 1607 if (bpt == NULL) { | |
| 1608 PrintError(js, "Unable to set breakpoint at line %s", line_option); | |
| 1609 return true; | |
| 1610 } | |
| 1611 bpt->PrintJSON(js); | |
| 1612 return true; | |
| 1613 } | |
| 1614 | |
| 1615 | |
| 1593 static bool HandleScripts(Isolate* isolate, JSONStream* js) { | 1616 static bool HandleScripts(Isolate* isolate, JSONStream* js) { |
| 1594 if (js->num_arguments() == 1) { | 1617 if (js->num_arguments() == 1) { |
| 1595 // Enumerate all scripts. | 1618 // Enumerate all scripts. |
| 1596 return HandleScriptsEnumerate(isolate, js); | 1619 return HandleScriptsEnumerate(isolate, js); |
| 1597 } | 1620 } |
| 1598 // Subcommands of scripts require a valid script id. | 1621 // Subcommands of scripts require a valid script id. |
| 1599 const String& id = String::Handle(String::New(js->GetArgument(1))); | 1622 const String& id = String::Handle(String::New(js->GetArgument(1))); |
| 1600 ASSERT(!id.IsNull()); | 1623 ASSERT(!id.IsNull()); |
| 1601 // The id is the url of the script % encoded, decode it. | 1624 // The id is the url of the script % encoded, decode it. |
| 1602 String& requested_url = String::Handle(String::DecodeURI(id)); | 1625 String& requested_url = String::Handle(String::DecodeURI(id)); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1628 return true; | 1651 return true; |
| 1629 } | 1652 } |
| 1630 if (js->num_arguments() == 2) { | 1653 if (js->num_arguments() == 2) { |
| 1631 // If no subcommand is given, just fetch the script. | 1654 // If no subcommand is given, just fetch the script. |
| 1632 return HandleScriptsFetch(isolate, script, js); | 1655 return HandleScriptsFetch(isolate, script, js); |
| 1633 } else if (js->num_arguments() == 3) { | 1656 } else if (js->num_arguments() == 3) { |
| 1634 const char* arg = js->GetArgument(2); | 1657 const char* arg = js->GetArgument(2); |
| 1635 if (strcmp(arg, "coverage") == 0) { | 1658 if (strcmp(arg, "coverage") == 0) { |
| 1636 return HandleScriptsCoverage(isolate, requested_url, js); | 1659 return HandleScriptsCoverage(isolate, requested_url, js); |
| 1637 } | 1660 } |
| 1661 if (strcmp(arg, "setBreakpoint") == 0) { | |
| 1662 return HandleScriptsSetBreakpoint(isolate, requested_url, js); | |
| 1663 } | |
| 1638 PrintError(js, "Unrecognized subcommand '%s'", arg); | 1664 PrintError(js, "Unrecognized subcommand '%s'", arg); |
| 1639 return true; | 1665 return true; |
| 1640 } else { | 1666 } else { |
| 1641 PrintError(js, "Command too long"); | 1667 PrintError(js, "Command too long"); |
| 1642 return true; | 1668 return true; |
| 1643 } | 1669 } |
| 1644 } | 1670 } |
| 1645 | 1671 |
| 1646 | 1672 |
| 1647 static bool HandleDebugResume(Isolate* isolate, JSONStream* js) { | 1673 static bool HandleDebugResume(Isolate* isolate, |
| 1674 const char* step_option, | |
| 1675 JSONStream* js) { | |
| 1648 if (isolate->message_handler()->paused_on_start()) { | 1676 if (isolate->message_handler()->paused_on_start()) { |
| 1649 isolate->message_handler()->set_pause_on_start(false); | 1677 isolate->message_handler()->set_pause_on_start(false); |
| 1650 JSONObject jsobj(js); | 1678 JSONObject jsobj(js); |
| 1651 jsobj.AddProperty("type", "Success"); | 1679 jsobj.AddProperty("type", "Success"); |
| 1652 jsobj.AddProperty("id", ""); | 1680 jsobj.AddProperty("id", ""); |
| 1653 return true; | 1681 return true; |
| 1654 } | 1682 } |
| 1655 if (isolate->message_handler()->paused_on_exit()) { | 1683 if (isolate->message_handler()->paused_on_exit()) { |
| 1656 isolate->message_handler()->set_pause_on_exit(false); | 1684 isolate->message_handler()->set_pause_on_exit(false); |
| 1657 JSONObject jsobj(js); | 1685 JSONObject jsobj(js); |
| 1658 jsobj.AddProperty("type", "Success"); | 1686 jsobj.AddProperty("type", "Success"); |
| 1659 jsobj.AddProperty("id", ""); | 1687 jsobj.AddProperty("id", ""); |
| 1660 return true; | 1688 return true; |
| 1661 } | 1689 } |
| 1662 if (isolate->debugger()->PauseEvent() != NULL) { | 1690 if (isolate->debugger()->PauseEvent() != NULL) { |
| 1691 if (step_option != NULL) { | |
| 1692 fprintf(stderr, "step option is %s\n", step_option); | |
|
Cutch
2014/07/15 19:42:34
remove before committing.
turnidge
2014/07/15 23:37:24
Done.
| |
| 1693 if (strcmp(step_option, "into") == 0) { | |
| 1694 isolate->debugger()->SetSingleStep(); | |
| 1695 } else if (strcmp(step_option, "over") == 0) { | |
| 1696 isolate->debugger()->SetStepOver(); | |
| 1697 } else if (strcmp(step_option, "out") == 0) { | |
| 1698 isolate->debugger()->SetStepOut(); | |
| 1699 } else { | |
| 1700 PrintError(js, "Invalid 'step' option: %s", step_option); | |
| 1701 return true; | |
| 1702 } | |
| 1703 } | |
| 1663 isolate->Resume(); | 1704 isolate->Resume(); |
| 1664 JSONObject jsobj(js); | 1705 JSONObject jsobj(js); |
| 1665 jsobj.AddProperty("type", "Success"); | 1706 jsobj.AddProperty("type", "Success"); |
| 1666 jsobj.AddProperty("id", ""); | 1707 jsobj.AddProperty("id", ""); |
| 1667 return true; | 1708 return true; |
| 1668 } | 1709 } |
| 1669 | 1710 |
| 1670 PrintError(js, "VM was not paused"); | 1711 PrintError(js, "VM was not paused"); |
| 1671 return true; | 1712 return true; |
| 1672 } | 1713 } |
| 1673 | 1714 |
| 1674 | 1715 |
| 1675 static bool HandleDebug(Isolate* isolate, JSONStream* js) { | 1716 static bool HandleDebug(Isolate* isolate, JSONStream* js) { |
| 1676 if (js->num_arguments() == 1) { | 1717 if (js->num_arguments() == 1) { |
| 1677 PrintError(js, "Must specify a subcommand"); | 1718 PrintError(js, "Must specify a subcommand"); |
| 1678 return true; | 1719 return true; |
| 1679 } | 1720 } |
| 1680 const char* command = js->GetArgument(1); | 1721 const char* command = js->GetArgument(1); |
| 1681 if (strcmp(command, "breakpoints") == 0) { | 1722 if (strcmp(command, "breakpoints") == 0) { |
| 1682 if (js->num_arguments() == 2) { | 1723 if (js->num_arguments() == 2) { |
| 1683 // Print breakpoint list. | 1724 // Print breakpoint list. |
| 1684 JSONObject jsobj(js); | 1725 JSONObject jsobj(js); |
| 1685 jsobj.AddProperty("type", "BreakpointList"); | 1726 jsobj.AddProperty("type", "BreakpointList"); |
| 1727 jsobj.AddProperty("id", "debug/breakpoints"); | |
| 1686 JSONArray jsarr(&jsobj, "breakpoints"); | 1728 JSONArray jsarr(&jsobj, "breakpoints"); |
| 1687 isolate->debugger()->PrintBreakpointsToJSONArray(&jsarr); | 1729 isolate->debugger()->PrintBreakpointsToJSONArray(&jsarr); |
| 1688 return true; | 1730 return true; |
| 1689 } else if (js->num_arguments() == 3) { | 1731 } else { |
| 1690 // Print individual breakpoint. | |
| 1691 intptr_t id = 0; | 1732 intptr_t id = 0; |
| 1692 SourceBreakpoint* bpt = NULL; | 1733 SourceBreakpoint* bpt = NULL; |
| 1693 if (GetIntegerId(js->GetArgument(2), &id)) { | 1734 if (GetIntegerId(js->GetArgument(2), &id)) { |
| 1694 bpt = isolate->debugger()->GetBreakpointById(id); | 1735 bpt = isolate->debugger()->GetBreakpointById(id); |
| 1695 } | 1736 } |
| 1696 if (bpt != NULL) { | 1737 if (bpt == NULL) { |
| 1697 bpt->PrintJSON(js); | |
| 1698 return true; | |
| 1699 } else { | |
| 1700 PrintError(js, "Unrecognized breakpoint id %s", js->GetArgument(2)); | 1738 PrintError(js, "Unrecognized breakpoint id %s", js->GetArgument(2)); |
| 1701 return true; | 1739 return true; |
| 1702 } | 1740 } |
| 1703 } else { | 1741 if (js->num_arguments() == 3) { |
| 1704 PrintError(js, "Command too long"); | 1742 // Print individual breakpoint. |
| 1705 return true; | 1743 bpt->PrintJSON(js); |
| 1744 return true; | |
| 1745 } else if (js->num_arguments() == 4) { | |
| 1746 const char* sub_command = js->GetArgument(3); | |
| 1747 if (strcmp(sub_command, "clear") == 0) { | |
| 1748 // Clear this breakpoint. | |
| 1749 isolate->debugger()->RemoveBreakpoint(id); | |
| 1750 | |
| 1751 JSONObject jsobj(js); | |
| 1752 jsobj.AddProperty("type", "Success"); | |
| 1753 jsobj.AddProperty("id", ""); | |
| 1754 return true; | |
| 1755 } else { | |
| 1756 PrintError(js, "Unrecognized subcommand %s", sub_command); | |
| 1757 return true; | |
| 1758 } | |
| 1759 } else { | |
| 1760 PrintError(js, "Command too long"); | |
| 1761 return true; | |
| 1762 } | |
| 1706 } | 1763 } |
| 1707 } else if (strcmp(command, "pause") == 0) { | 1764 } else if (strcmp(command, "pause") == 0) { |
| 1708 if (js->num_arguments() == 2) { | 1765 if (js->num_arguments() == 2) { |
| 1709 // TODO(turnidge): Don't double-interrupt the isolate here. | 1766 // TODO(turnidge): Don't double-interrupt the isolate here. |
| 1710 isolate->ScheduleInterrupts(Isolate::kApiInterrupt); | 1767 isolate->ScheduleInterrupts(Isolate::kApiInterrupt); |
| 1711 JSONObject jsobj(js); | 1768 JSONObject jsobj(js); |
| 1712 jsobj.AddProperty("type", "Success"); | 1769 jsobj.AddProperty("type", "Success"); |
| 1713 jsobj.AddProperty("id", ""); | 1770 jsobj.AddProperty("id", ""); |
| 1714 return true; | 1771 return true; |
| 1715 } else { | 1772 } else { |
| 1716 PrintError(js, "Command too long"); | 1773 PrintError(js, "Command too long"); |
| 1717 return true; | 1774 return true; |
| 1718 } | 1775 } |
| 1719 } else if (strcmp(command, "resume") == 0) { | 1776 } else if (strcmp(command, "resume") == 0) { |
| 1720 if (js->num_arguments() == 2) { | 1777 if (js->num_arguments() == 2) { |
| 1721 return HandleDebugResume(isolate, js); | 1778 const char* step_option = js->LookupOption("step"); |
| 1779 return HandleDebugResume(isolate, step_option, js); | |
| 1722 } else { | 1780 } else { |
| 1723 PrintError(js, "Command too long"); | 1781 PrintError(js, "Command too long"); |
| 1724 return true; | 1782 return true; |
| 1725 } | 1783 } |
| 1726 } else { | 1784 } else { |
| 1727 PrintError(js, "Unrecognized subcommand '%s'", js->GetArgument(1)); | 1785 PrintError(js, "Unrecognized subcommand '%s'", js->GetArgument(1)); |
| 1728 return true; | 1786 return true; |
| 1729 } | 1787 } |
| 1730 } | 1788 } |
| 1731 | 1789 |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2347 while (current != NULL) { | 2405 while (current != NULL) { |
| 2348 if (strcmp(name, current->name()) == 0) { | 2406 if (strcmp(name, current->name()) == 0) { |
| 2349 return current; | 2407 return current; |
| 2350 } | 2408 } |
| 2351 current = current->next(); | 2409 current = current->next(); |
| 2352 } | 2410 } |
| 2353 return NULL; | 2411 return NULL; |
| 2354 } | 2412 } |
| 2355 | 2413 |
| 2356 } // namespace dart | 2414 } // namespace dart |
| OLD | NEW |