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

Side by Side Diff: src/runtime/runtime-debug.cc

Issue 2447073007: [debugger] Various break-related functionality in test wrapper (Closed)
Patch Set: Move DebugEvent to DebugWrapper to preserve old API Created 4 years, 1 month 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
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-function.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/debug/debug-evaluate.h" 8 #include "src/debug/debug-evaluate.h"
9 #include "src/debug/debug-frames.h" 9 #include "src/debug/debug-frames.h"
10 #include "src/debug/debug-scopes.h" 10 #include "src/debug/debug-scopes.h"
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 HandleScope shs(isolate); 1422 HandleScope shs(isolate);
1423 DCHECK(args.length() == 1); 1423 DCHECK(args.length() == 1);
1424 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); 1424 CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
1425 // TODO(1543): Come up with a solution for clients to handle potential errors 1425 // TODO(1543): Come up with a solution for clients to handle potential errors
1426 // thrown by an intermediate proxy. 1426 // thrown by an intermediate proxy.
1427 RETURN_RESULT_OR_FAILURE(isolate, JSReceiver::GetPrototype(isolate, obj)); 1427 RETURN_RESULT_OR_FAILURE(isolate, JSReceiver::GetPrototype(isolate, obj));
1428 } 1428 }
1429 1429
1430 1430
1431 // Patches script source (should be called upon BeforeCompile event). 1431 // Patches script source (should be called upon BeforeCompile event).
1432 // TODO(5530): Remove once uses in debug.js are gone.
1432 RUNTIME_FUNCTION(Runtime_DebugSetScriptSource) { 1433 RUNTIME_FUNCTION(Runtime_DebugSetScriptSource) {
1433 HandleScope scope(isolate); 1434 HandleScope scope(isolate);
1434 DCHECK(args.length() == 2); 1435 DCHECK(args.length() == 2);
1435 1436
1436 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0); 1437 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0);
1437 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); 1438 CONVERT_ARG_HANDLE_CHECKED(String, source, 1);
1438 1439
1439 CHECK(script_wrapper->value()->IsScript()); 1440 CHECK(script_wrapper->value()->IsScript());
1440 Handle<Script> script(Script::cast(script_wrapper->value())); 1441 Handle<Script> script(Script::cast(script_wrapper->value()));
1441 1442
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 found = Handle<Script>(script, isolate); 1563 found = Handle<Script>(script, isolate);
1563 break; 1564 break;
1564 } 1565 }
1565 } 1566 }
1566 } 1567 }
1567 1568
1568 if (found.is_null()) return isolate->heap()->undefined_value(); 1569 if (found.is_null()) return isolate->heap()->undefined_value();
1569 return *Script::GetWrapper(found); 1570 return *Script::GetWrapper(found);
1570 } 1571 }
1571 1572
1573 // TODO(5530): Remove once uses in debug.js are gone.
1572 RUNTIME_FUNCTION(Runtime_ScriptLineCount) { 1574 RUNTIME_FUNCTION(Runtime_ScriptLineCount) {
1573 HandleScope scope(isolate); 1575 HandleScope scope(isolate);
1574 DCHECK(args.length() == 1); 1576 DCHECK(args.length() == 1);
1575 CONVERT_ARG_CHECKED(JSValue, script, 0); 1577 CONVERT_ARG_CHECKED(JSValue, script, 0);
1576 1578
1577 CHECK(script->value()->IsScript()); 1579 CHECK(script->value()->IsScript());
1578 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 1580 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1579 1581
1580 Script::InitLineEnds(script_handle); 1582 Script::InitLineEnds(script_handle);
1581 1583
1582 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends()); 1584 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends());
1583 return Smi::FromInt(line_ends_array->length()); 1585 return Smi::FromInt(line_ends_array->length());
1584 } 1586 }
1585 1587
1588 // TODO(5530): Remove once uses in debug.js are gone.
1586 RUNTIME_FUNCTION(Runtime_ScriptLineStartPosition) { 1589 RUNTIME_FUNCTION(Runtime_ScriptLineStartPosition) {
1587 HandleScope scope(isolate); 1590 HandleScope scope(isolate);
1588 DCHECK(args.length() == 2); 1591 DCHECK(args.length() == 2);
1589 CONVERT_ARG_CHECKED(JSValue, script, 0); 1592 CONVERT_ARG_CHECKED(JSValue, script, 0);
1590 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]); 1593 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]);
1591 1594
1592 CHECK(script->value()->IsScript()); 1595 CHECK(script->value()->IsScript());
1593 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 1596 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1594 1597
1595 Script::InitLineEnds(script_handle); 1598 Script::InitLineEnds(script_handle);
1596 1599
1597 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends()); 1600 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends());
1598 const int line_count = line_ends_array->length(); 1601 const int line_count = line_ends_array->length();
1599 1602
1600 // If line == line_count, we return the first position beyond the last line. 1603 // If line == line_count, we return the first position beyond the last line.
1601 if (line < 0 || line > line_count) { 1604 if (line < 0 || line > line_count) {
1602 return Smi::FromInt(-1); 1605 return Smi::FromInt(-1);
1603 } else if (line == 0) { 1606 } else if (line == 0) {
1604 return Smi::kZero; 1607 return Smi::kZero;
1605 } else { 1608 } else {
1606 DCHECK(0 < line && line <= line_count); 1609 DCHECK(0 < line && line <= line_count);
1607 const int pos = Smi::cast(line_ends_array->get(line - 1))->value() + 1; 1610 const int pos = Smi::cast(line_ends_array->get(line - 1))->value() + 1;
1608 return Smi::FromInt(pos); 1611 return Smi::FromInt(pos);
1609 } 1612 }
1610 } 1613 }
1611 1614
1615 // TODO(5530): Remove once uses in debug.js are gone.
1612 RUNTIME_FUNCTION(Runtime_ScriptLineEndPosition) { 1616 RUNTIME_FUNCTION(Runtime_ScriptLineEndPosition) {
1613 HandleScope scope(isolate); 1617 HandleScope scope(isolate);
1614 DCHECK(args.length() == 2); 1618 DCHECK(args.length() == 2);
1615 CONVERT_ARG_CHECKED(JSValue, script, 0); 1619 CONVERT_ARG_CHECKED(JSValue, script, 0);
1616 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]); 1620 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]);
1617 1621
1618 CHECK(script->value()->IsScript()); 1622 CHECK(script->value()->IsScript());
1619 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 1623 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1620 1624
1621 Script::InitLineEnds(script_handle); 1625 Script::InitLineEnds(script_handle);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 JSObject::AddProperty(jsinfo, isolate->factory()->line_string(), 1658 JSObject::AddProperty(jsinfo, isolate->factory()->line_string(),
1655 handle(Smi::FromInt(info.line), isolate), NONE); 1659 handle(Smi::FromInt(info.line), isolate), NONE);
1656 JSObject::AddProperty(jsinfo, isolate->factory()->column_string(), 1660 JSObject::AddProperty(jsinfo, isolate->factory()->column_string(),
1657 handle(Smi::FromInt(info.column), isolate), NONE); 1661 handle(Smi::FromInt(info.column), isolate), NONE);
1658 JSObject::AddProperty(jsinfo, isolate->factory()->sourceText_string(), 1662 JSObject::AddProperty(jsinfo, isolate->factory()->sourceText_string(),
1659 sourceText, NONE); 1663 sourceText, NONE);
1660 1664
1661 return jsinfo; 1665 return jsinfo;
1662 } 1666 }
1663 1667
1664 // Get information on a specific source line and column possibly offset by a 1668 namespace {
1665 // fixed source position. This function is used to find a source position from
1666 // a line and column position. The fixed source position offset is typically
1667 // used to find a source position in a function based on a line and column in
1668 // the source for the function alone. The offset passed will then be the
1669 // start position of the source for the function within the full script source.
1670 // Note that incoming line and column parameters may be undefined, and are
1671 // assumed to be passed *with* offsets.
1672 RUNTIME_FUNCTION(Runtime_ScriptLocationFromLine) {
1673 HandleScope scope(isolate);
1674 DCHECK(args.length() == 4);
1675 CONVERT_ARG_CHECKED(JSValue, script, 0);
1676 1669
1677 CHECK(script->value()->IsScript()); 1670 Handle<Object> ScriptLocationFromLine(Isolate* isolate, Handle<Script> script,
1678 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 1671 Handle<Object> opt_line,
1679 1672 Handle<Object> opt_column,
1673 int32_t offset) {
1680 // Line and column are possibly undefined and we need to handle these cases, 1674 // Line and column are possibly undefined and we need to handle these cases,
1681 // additionally subtracting corresponding offsets. 1675 // additionally subtracting corresponding offsets.
1682 1676
1683 int32_t line; 1677 int32_t line;
1684 if (args[1]->IsNull(isolate) || args[1]->IsUndefined(isolate)) { 1678 if (opt_line->IsNull(isolate) || opt_line->IsUndefined(isolate)) {
1685 line = 0; 1679 line = 0;
1686 } else { 1680 } else {
1687 CHECK(args[1]->IsNumber()); 1681 CHECK(opt_line->IsNumber());
1688 line = NumberToInt32(args[1]) - script_handle->line_offset(); 1682 line = NumberToInt32(*opt_line) - script->line_offset();
1689 } 1683 }
1690 1684
1691 int32_t column; 1685 int32_t column;
1692 if (args[2]->IsNull(isolate) || args[2]->IsUndefined(isolate)) { 1686 if (opt_column->IsNull(isolate) || opt_column->IsUndefined(isolate)) {
1693 column = 0; 1687 column = 0;
1694 } else { 1688 } else {
1695 CHECK(args[2]->IsNumber()); 1689 CHECK(opt_column->IsNumber());
1696 column = NumberToInt32(args[2]); 1690 column = NumberToInt32(*opt_column);
1697 if (line == 0) column -= script_handle->column_offset(); 1691 if (line == 0) column -= script->column_offset();
1698 } 1692 }
1699 1693
1700 CONVERT_NUMBER_CHECKED(int32_t, offset_position, Int32, args[3]); 1694 if (line < 0 || column < 0 || offset < 0) {
1701 1695 return isolate->factory()->null_value();
1702 if (line < 0 || column < 0 || offset_position < 0) {
1703 return isolate->heap()->null_value();
1704 } 1696 }
1705 1697
1706 Script::InitLineEnds(script_handle); 1698 Script::InitLineEnds(script);
1707 1699
1708 FixedArray* line_ends_array = FixedArray::cast(script_handle->line_ends()); 1700 FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
1709 const int line_count = line_ends_array->length(); 1701 const int line_count = line_ends_array->length();
1710 1702
1711 int position; 1703 int position;
1712 if (line == 0) { 1704 if (line == 0) {
1713 position = offset_position + column; 1705 position = offset + column;
1714 } else { 1706 } else {
1715 Script::PositionInfo info; 1707 Script::PositionInfo info;
1716 if (!script_handle->GetPositionInfo(offset_position, &info, 1708 if (!script->GetPositionInfo(offset, &info, Script::NO_OFFSET) ||
1717 Script::NO_OFFSET) ||
1718 info.line + line >= line_count) { 1709 info.line + line >= line_count) {
1719 return isolate->heap()->null_value(); 1710 return isolate->factory()->null_value();
1720 } 1711 }
1721 1712
1722 const int offset_line = info.line + line; 1713 const int offset_line = info.line + line;
1723 const int offset_line_position = 1714 const int offset_line_position =
1724 (offset_line == 0) 1715 (offset_line == 0)
1725 ? 0 1716 ? 0
1726 : Smi::cast(line_ends_array->get(offset_line - 1))->value() + 1; 1717 : Smi::cast(line_ends_array->get(offset_line - 1))->value() + 1;
1727 position = offset_line_position + column; 1718 position = offset_line_position + column;
1728 } 1719 }
1729 1720
1730 return *GetJSPositionInfo(script_handle, position, Script::NO_OFFSET, 1721 return GetJSPositionInfo(script, position, Script::NO_OFFSET, isolate);
1731 isolate);
1732 } 1722 }
1733 1723
1724 // Slow traversal over all scripts on the heap.
1725 bool GetScriptById(Isolate* isolate, int needle, Handle<Script>* result) {
1726 Script::Iterator iterator(isolate);
1727 Script* script = NULL;
1728 while ((script = iterator.Next()) != NULL) {
1729 if (script->id() == needle) {
1730 *result = handle(script);
1731 return true;
1732 }
1733 }
1734
1735 return false;
1736 }
1737
1738 } // namespace
1739
1740 // Get information on a specific source line and column possibly offset by a
1741 // fixed source position. This function is used to find a source position from
1742 // a line and column position. The fixed source position offset is typically
1743 // used to find a source position in a function based on a line and column in
1744 // the source for the function alone. The offset passed will then be the
1745 // start position of the source for the function within the full script source.
1746 // Note that incoming line and column parameters may be undefined, and are
1747 // assumed to be passed *with* offsets.
1748 // TODO(5530): Remove once uses in debug.js are gone.
1749 RUNTIME_FUNCTION(Runtime_ScriptLocationFromLine) {
1750 HandleScope scope(isolate);
1751 DCHECK(args.length() == 4);
1752 CONVERT_ARG_HANDLE_CHECKED(JSValue, script, 0);
1753 CONVERT_ARG_HANDLE_CHECKED(Object, opt_line, 1);
1754 CONVERT_ARG_HANDLE_CHECKED(Object, opt_column, 2);
1755 CONVERT_NUMBER_CHECKED(int32_t, offset, Int32, args[3]);
1756
1757 CHECK(script->value()->IsScript());
1758 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1759
1760 return *ScriptLocationFromLine(isolate, script_handle, opt_line, opt_column,
1761 offset);
1762 }
1763
1764 // TODO(5530): Rename once conflicting function has been deleted.
1765 RUNTIME_FUNCTION(Runtime_ScriptLocationFromLine2) {
1766 HandleScope scope(isolate);
1767 DCHECK(args.length() == 4);
1768 CONVERT_NUMBER_CHECKED(int32_t, scriptid, Int32, args[0]);
1769 CONVERT_ARG_HANDLE_CHECKED(Object, opt_line, 1);
1770 CONVERT_ARG_HANDLE_CHECKED(Object, opt_column, 2);
1771 CONVERT_NUMBER_CHECKED(int32_t, offset, Int32, args[3]);
1772
1773 Handle<Script> script;
1774 CHECK(GetScriptById(isolate, scriptid, &script));
1775
1776 return *ScriptLocationFromLine(isolate, script, opt_line, opt_column, offset);
1777 }
1778
1779 // TODO(5530): Remove once uses in debug.js are gone.
1734 RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) { 1780 RUNTIME_FUNCTION(Runtime_ScriptPositionInfo) {
1735 HandleScope scope(isolate); 1781 HandleScope scope(isolate);
1736 DCHECK(args.length() == 3); 1782 DCHECK(args.length() == 3);
1737 CONVERT_ARG_CHECKED(JSValue, script, 0); 1783 CONVERT_ARG_CHECKED(JSValue, script, 0);
1738 CONVERT_NUMBER_CHECKED(int32_t, position, Int32, args[1]); 1784 CONVERT_NUMBER_CHECKED(int32_t, position, Int32, args[1]);
1739 CONVERT_BOOLEAN_ARG_CHECKED(with_offset, 2); 1785 CONVERT_BOOLEAN_ARG_CHECKED(with_offset, 2);
1740 1786
1741 CHECK(script->value()->IsScript()); 1787 CHECK(script->value()->IsScript());
1742 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 1788 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1743 1789
1744 const Script::OffsetFlag offset_flag = 1790 const Script::OffsetFlag offset_flag =
1745 with_offset ? Script::WITH_OFFSET : Script::NO_OFFSET; 1791 with_offset ? Script::WITH_OFFSET : Script::NO_OFFSET;
1746 return *GetJSPositionInfo(script_handle, position, offset_flag, isolate); 1792 return *GetJSPositionInfo(script_handle, position, offset_flag, isolate);
1747 } 1793 }
1748 1794
1749 // Returns the given line as a string, or null if line is out of bounds. 1795 // Returns the given line as a string, or null if line is out of bounds.
1750 // The parameter line is expected to include the script's line offset. 1796 // The parameter line is expected to include the script's line offset.
1797 // TODO(5530): Remove once uses in debug.js are gone.
1751 RUNTIME_FUNCTION(Runtime_ScriptSourceLine) { 1798 RUNTIME_FUNCTION(Runtime_ScriptSourceLine) {
1752 HandleScope scope(isolate); 1799 HandleScope scope(isolate);
1753 DCHECK(args.length() == 2); 1800 DCHECK(args.length() == 2);
1754 CONVERT_ARG_CHECKED(JSValue, script, 0); 1801 CONVERT_ARG_CHECKED(JSValue, script, 0);
1755 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]); 1802 CONVERT_NUMBER_CHECKED(int32_t, line, Int32, args[1]);
1756 1803
1757 CHECK(script->value()->IsScript()); 1804 CHECK(script->value()->IsScript());
1758 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); 1805 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
1759 1806
1760 Script::InitLineEnds(script_handle); 1807 Script::InitLineEnds(script_handle);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 SealHandleScope shs(isolate); 1890 SealHandleScope shs(isolate);
1844 return Smi::FromInt(isolate->debug()->is_active()); 1891 return Smi::FromInt(isolate->debug()->is_active());
1845 } 1892 }
1846 1893
1847 1894
1848 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { 1895 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) {
1849 UNIMPLEMENTED(); 1896 UNIMPLEMENTED();
1850 return NULL; 1897 return NULL;
1851 } 1898 }
1852 1899
1900 // TODO(5530): Remove once uses in debug.js are gone.
1853 RUNTIME_FUNCTION(Runtime_GetWasmFunctionOffsetTable) { 1901 RUNTIME_FUNCTION(Runtime_GetWasmFunctionOffsetTable) {
1854 DCHECK(args.length() == 1); 1902 DCHECK(args.length() == 1);
1855 HandleScope scope(isolate); 1903 HandleScope scope(isolate);
1856 CONVERT_ARG_CHECKED(JSValue, script_val, 0); 1904 CONVERT_ARG_CHECKED(JSValue, script_val, 0);
1857 1905
1858 CHECK(script_val->value()->IsScript()); 1906 CHECK(script_val->value()->IsScript());
1859 Handle<Script> script = Handle<Script>(Script::cast(script_val->value())); 1907 Handle<Script> script = Handle<Script>(Script::cast(script_val->value()));
1860 1908
1861 Handle<wasm::WasmDebugInfo> debug_info = 1909 Handle<wasm::WasmDebugInfo> debug_info =
1862 wasm::GetDebugInfo(handle(script->wasm_instance(), isolate)); 1910 wasm::GetDebugInfo(handle(script->wasm_instance(), isolate));
1863 Handle<FixedArray> elements = wasm::WasmDebugInfo::GetFunctionOffsetTable( 1911 Handle<FixedArray> elements = wasm::WasmDebugInfo::GetFunctionOffsetTable(
1864 debug_info, script->wasm_function_index()); 1912 debug_info, script->wasm_function_index());
1865 return *isolate->factory()->NewJSArrayWithElements(elements); 1913 return *isolate->factory()->NewJSArrayWithElements(elements);
1866 } 1914 }
1867 1915
1916 // TODO(5530): Remove once uses in debug.js are gone.
1868 RUNTIME_FUNCTION(Runtime_DisassembleWasmFunction) { 1917 RUNTIME_FUNCTION(Runtime_DisassembleWasmFunction) {
1869 DCHECK(args.length() == 1); 1918 DCHECK(args.length() == 1);
1870 HandleScope scope(isolate); 1919 HandleScope scope(isolate);
1871 CONVERT_ARG_CHECKED(JSValue, script_val, 0); 1920 CONVERT_ARG_CHECKED(JSValue, script_val, 0);
1872 1921
1873 CHECK(script_val->value()->IsScript()); 1922 CHECK(script_val->value()->IsScript());
1874 Handle<Script> script = Handle<Script>(Script::cast(script_val->value())); 1923 Handle<Script> script = Handle<Script>(Script::cast(script_val->value()));
1875 1924
1876 Handle<wasm::WasmDebugInfo> debug_info = 1925 Handle<wasm::WasmDebugInfo> debug_info =
1877 wasm::GetDebugInfo(handle(script->wasm_instance(), isolate)); 1926 wasm::GetDebugInfo(handle(script->wasm_instance(), isolate));
1878 return *wasm::WasmDebugInfo::DisassembleFunction( 1927 return *wasm::WasmDebugInfo::DisassembleFunction(
1879 debug_info, script->wasm_function_index()); 1928 debug_info, script->wasm_function_index());
1880 } 1929 }
1881 1930
1882 } // namespace internal 1931 } // namespace internal
1883 } // namespace v8 1932 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698