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

Unified Diff: src/wasm/wasm-module.cc

Issue 2493773003: [inspector] Introduce translation of wasm frames (Closed)
Patch Set: Fix last patch 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 side-by-side diff with in-line comments
Download patch
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 79b99fe04d90f0618cfdf557ff3dd10f14809d34..f28958786386ef360063fdc051b8ccf66a100929 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -597,6 +597,15 @@ std::pair<int, int> GetFunctionOffsetAndLength(
static_cast<int>(func.code_end_offset - func.code_start_offset)};
}
+Vector<const uint8_t> GetFunctionBytes(
+ Handle<WasmCompiledModule> compiled_module, int func_index) {
+ int offset, length;
+ std::tie(offset, length) =
+ GetFunctionOffsetAndLength(compiled_module, func_index);
+ return Vector<const uint8_t>(
+ compiled_module->module_bytes()->GetChars() + offset, length);
+}
+
} // namespace
const char* wasm::SectionName(WasmSectionCode code) {
@@ -1881,6 +1890,26 @@ Handle<Script> wasm::GetScript(Handle<JSObject> instance) {
return compiled_module->script();
}
+std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>>
+wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module,
+ int func_index) {
+ std::ostringstream disassembly_os;
+ std::vector<std::tuple<uint32_t, int, int>> offset_table;
+
+ Vector<const uint8_t> func_bytes =
+ GetFunctionBytes(compiled_module, func_index);
+ DisallowHeapAllocation no_gc;
+ if (func_bytes.is_empty()) return {};
+
+ AccountingAllocator allocator;
+ bool ok = PrintAst(
+ &allocator, FunctionBodyForTesting(func_bytes.start(), func_bytes.end()),
+ disassembly_os, &offset_table);
+ CHECK(ok);
+
+ return {disassembly_os.str(), std::move(offset_table)};
+}
+
int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index,
int byte_offset) {
return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance),

Powered by Google App Engine
This is Rietveld 408576698