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

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

Issue 2493773003: [inspector] Introduce translation of wasm frames (Closed)
Patch Set: Very last-minute changes 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
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/inspector/debugger/wasm-stack.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index b74e176288a2daf11edb3dc8015bfb07e197fd56..3ac9c832eb749b61fd78ef3fe4186a1313493ac2 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) {
@@ -1882,6 +1891,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),
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/inspector/debugger/wasm-stack.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698