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

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2493773003: [inspector] Introduce translation of wasm frames (Closed)
Patch Set: More signed/unsigned 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
OLDNEW
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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 WasmModule* module = compiled_module->cpp_module(); 634 WasmModule* module = compiled_module->cpp_module();
635 if (func_index < 0 || 635 if (func_index < 0 ||
636 static_cast<size_t>(func_index) > module->functions.size()) { 636 static_cast<size_t>(func_index) > module->functions.size()) {
637 return {0, 0}; 637 return {0, 0};
638 } 638 }
639 WasmFunction& func = module->functions[func_index]; 639 WasmFunction& func = module->functions[func_index];
640 return {static_cast<int>(func.code_start_offset), 640 return {static_cast<int>(func.code_start_offset),
641 static_cast<int>(func.code_end_offset - func.code_start_offset)}; 641 static_cast<int>(func.code_end_offset - func.code_start_offset)};
642 } 642 }
643 643
644 Vector<const uint8_t> GetFunctionBytes(
645 Handle<WasmCompiledModule> compiled_module, int func_index) {
646 int offset, length;
647 std::tie(offset, length) =
648 GetFunctionOffsetAndLength(compiled_module, func_index);
649 return Vector<const uint8_t>(
650 compiled_module->module_bytes()->GetChars() + offset, length);
651 }
652
644 } // namespace 653 } // namespace
645 654
646 const char* wasm::SectionName(WasmSectionCode code) { 655 const char* wasm::SectionName(WasmSectionCode code) {
647 switch (code) { 656 switch (code) {
648 case kUnknownSectionCode: 657 case kUnknownSectionCode:
649 return "Unknown"; 658 return "Unknown";
650 case kTypeSectionCode: 659 case kTypeSectionCode:
651 return "Type"; 660 return "Type";
652 case kImportSectionCode: 661 case kImportSectionCode:
653 return "Import"; 662 return "Import";
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 return compiled_module->has_asm_js_offset_tables(); 2034 return compiled_module->has_asm_js_offset_tables();
2026 } 2035 }
2027 2036
2028 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { 2037 Handle<Script> wasm::GetScript(Handle<JSObject> instance) {
2029 DCHECK(IsWasmInstance(*instance)); 2038 DCHECK(IsWasmInstance(*instance));
2030 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); 2039 WasmCompiledModule* compiled_module = GetCompiledModule(*instance);
2031 DCHECK(compiled_module->has_script()); 2040 DCHECK(compiled_module->has_script());
2032 return compiled_module->script(); 2041 return compiled_module->script();
2033 } 2042 }
2034 2043
2044 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>>
2045 wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module,
2046 int func_index) {
2047 std::ostringstream disassembly_os;
2048 std::vector<std::tuple<uint32_t, int, int>> offset_table;
2049
2050 Vector<const uint8_t> func_bytes =
2051 GetFunctionBytes(compiled_module, func_index);
2052 DisallowHeapAllocation no_gc;
2053 if (func_bytes.is_empty()) return {};
2054
2055 AccountingAllocator allocator;
2056 bool ok = PrintAst(
2057 &allocator, FunctionBodyForTesting(func_bytes.start(), func_bytes.end()),
2058 disassembly_os, &offset_table);
2059 DCHECK(ok);
2060 USE(ok);
2061
2062 return {disassembly_os.str(), std::move(offset_table)};
2063 }
2064
2035 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, 2065 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index,
2036 int byte_offset) { 2066 int byte_offset) {
2037 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance), 2067 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance),
2038 func_index, byte_offset); 2068 func_index, byte_offset);
2039 } 2069 }
2040 2070
2041 Handle<SeqOneByteString> wasm::GetWasmBytes(Handle<JSObject> instance) { 2071 Handle<SeqOneByteString> wasm::GetWasmBytes(Handle<JSObject> instance) {
2042 DCHECK(IsWasmInstance(*instance)); 2072 DCHECK(IsWasmInstance(*instance));
2043 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); 2073 WasmCompiledModule* compiled_module = GetCompiledModule(*instance);
2044 return compiled_module->module_bytes(); 2074 return compiled_module->module_bytes();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2339 CHECK_NOT_NULL(result.val); 2369 CHECK_NOT_NULL(result.val);
2340 module = const_cast<WasmModule*>(result.val); 2370 module = const_cast<WasmModule*>(result.val);
2341 } 2371 }
2342 2372
2343 Handle<WasmModuleWrapper> module_wrapper = 2373 Handle<WasmModuleWrapper> module_wrapper =
2344 WasmModuleWrapper::New(isolate, module); 2374 WasmModuleWrapper::New(isolate, module);
2345 2375
2346 compiled_module->set_module_wrapper(module_wrapper); 2376 compiled_module->set_module_wrapper(module_wrapper);
2347 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); 2377 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
2348 } 2378 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698