| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "src/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
| 8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 | 9 |
| 10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 WasmModule* module = compiled_module->module(); | 590 WasmModule* module = compiled_module->module(); |
| 591 if (func_index < 0 || | 591 if (func_index < 0 || |
| 592 static_cast<size_t>(func_index) > module->functions.size()) { | 592 static_cast<size_t>(func_index) > module->functions.size()) { |
| 593 return {0, 0}; | 593 return {0, 0}; |
| 594 } | 594 } |
| 595 WasmFunction& func = module->functions[func_index]; | 595 WasmFunction& func = module->functions[func_index]; |
| 596 return {static_cast<int>(func.code_start_offset), | 596 return {static_cast<int>(func.code_start_offset), |
| 597 static_cast<int>(func.code_end_offset - func.code_start_offset)}; | 597 static_cast<int>(func.code_end_offset - func.code_start_offset)}; |
| 598 } | 598 } |
| 599 | 599 |
| 600 Vector<const uint8_t> GetFunctionBytes( |
| 601 Handle<WasmCompiledModule> compiled_module, int func_index) { |
| 602 int offset, length; |
| 603 std::tie(offset, length) = |
| 604 GetFunctionOffsetAndLength(compiled_module, func_index); |
| 605 return Vector<const uint8_t>( |
| 606 compiled_module->module_bytes()->GetChars() + offset, length); |
| 607 } |
| 608 |
| 600 } // namespace | 609 } // namespace |
| 601 | 610 |
| 602 const char* wasm::SectionName(WasmSectionCode code) { | 611 const char* wasm::SectionName(WasmSectionCode code) { |
| 603 switch (code) { | 612 switch (code) { |
| 604 case kUnknownSectionCode: | 613 case kUnknownSectionCode: |
| 605 return "Unknown"; | 614 return "Unknown"; |
| 606 case kTypeSectionCode: | 615 case kTypeSectionCode: |
| 607 return "Type"; | 616 return "Type"; |
| 608 case kImportSectionCode: | 617 case kImportSectionCode: |
| 609 return "Import"; | 618 return "Import"; |
| (...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 return compiled_module->has_asm_js_offset_tables(); | 1884 return compiled_module->has_asm_js_offset_tables(); |
| 1876 } | 1885 } |
| 1877 | 1886 |
| 1878 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { | 1887 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { |
| 1879 DCHECK(IsWasmInstance(*instance)); | 1888 DCHECK(IsWasmInstance(*instance)); |
| 1880 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); | 1889 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); |
| 1881 DCHECK(compiled_module->has_script()); | 1890 DCHECK(compiled_module->has_script()); |
| 1882 return compiled_module->script(); | 1891 return compiled_module->script(); |
| 1883 } | 1892 } |
| 1884 | 1893 |
| 1894 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> |
| 1895 wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module, |
| 1896 int func_index) { |
| 1897 std::ostringstream disassembly_os; |
| 1898 std::vector<std::tuple<uint32_t, int, int>> offset_table; |
| 1899 |
| 1900 Vector<const uint8_t> func_bytes = |
| 1901 GetFunctionBytes(compiled_module, func_index); |
| 1902 DisallowHeapAllocation no_gc; |
| 1903 if (func_bytes.is_empty()) return {}; |
| 1904 |
| 1905 AccountingAllocator allocator; |
| 1906 bool ok = PrintAst( |
| 1907 &allocator, FunctionBodyForTesting(func_bytes.start(), func_bytes.end()), |
| 1908 disassembly_os, &offset_table); |
| 1909 CHECK(ok); |
| 1910 |
| 1911 return {disassembly_os.str(), std::move(offset_table)}; |
| 1912 } |
| 1913 |
| 1885 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, | 1914 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, |
| 1886 int byte_offset) { | 1915 int byte_offset) { |
| 1887 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance), | 1916 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance), |
| 1888 func_index, byte_offset); | 1917 func_index, byte_offset); |
| 1889 } | 1918 } |
| 1890 | 1919 |
| 1891 Handle<SeqOneByteString> wasm::GetWasmBytes(Handle<JSObject> object) { | 1920 Handle<SeqOneByteString> wasm::GetWasmBytes(Handle<JSObject> object) { |
| 1892 return Handle<WasmInstanceObject>::cast(object) | 1921 return Handle<WasmInstanceObject>::cast(object) |
| 1893 ->get_compiled_module() | 1922 ->get_compiled_module() |
| 1894 ->module_bytes(); | 1923 ->module_bytes(); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 2203 MaybeHandle<String> WasmCompiledModule::GetFunctionName( |
| 2175 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 2204 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { |
| 2176 DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 2205 DCHECK_LT(func_index, compiled_module->module()->functions.size()); |
| 2177 WasmFunction& function = compiled_module->module()->functions[func_index]; | 2206 WasmFunction& function = compiled_module->module()->functions[func_index]; |
| 2178 Isolate* isolate = compiled_module->GetIsolate(); | 2207 Isolate* isolate = compiled_module->GetIsolate(); |
| 2179 MaybeHandle<String> string = ExtractStringFromModuleBytes( | 2208 MaybeHandle<String> string = ExtractStringFromModuleBytes( |
| 2180 isolate, compiled_module, function.name_offset, function.name_length); | 2209 isolate, compiled_module, function.name_offset, function.name_length); |
| 2181 if (!string.is_null()) return string.ToHandleChecked(); | 2210 if (!string.is_null()) return string.ToHandleChecked(); |
| 2182 return {}; | 2211 return {}; |
| 2183 } | 2212 } |
| OLD | NEW |