diff --git a/src/disassembler.cc b/src/disassembler.cc index 603f0bbe03..d06b3b789d 100644 --- a/src/disassembler.cc +++ b/src/disassembler.cc @@ -17,6 +17,7 @@ #include "src/objects-inl.h" #include "src/snapshot/serializer-common.h" #include "src/string-stream.h" +#include "src/wasm/wasm-heap.h" namespace v8 { namespace internal { @@ -37,21 +38,28 @@ class V8NameConverter: public disasm::NameConverter { const char* V8NameConverter::NameOfAddress(byte* pc) const { - const char* name = - code_ == nullptr ? nullptr : code_->GetIsolate()->builtins()->Lookup(pc); - - if (name != nullptr) { - SNPrintF(v8_buffer_, "%p (%s)", static_cast(pc), name); - return v8_buffer_.start(); - } - if (code_ != nullptr) { + Isolate* isolate = code_->GetIsolate(); + const char* name = isolate->builtins()->Lookup(pc); + + if (name != nullptr) { + SNPrintF(v8_buffer_, "%p (%s)", static_cast(pc), name); + return v8_buffer_.start(); + } + int offs = static_cast(pc - code_->instruction_start()); // print as code offset, if it seems reasonable if (0 <= offs && offs < code_->instruction_size()) { SNPrintF(v8_buffer_, "%p <+0x%x>", static_cast(pc), offs); return v8_buffer_.start(); } + + wasm::WasmCode* wasm_code = isolate->wasm_code_manager()->LookupCode(pc); + if (wasm_code != nullptr) { + SNPrintF(v8_buffer_, "%p (%s)", static_cast(pc), + GetWasmCodeKindAsString(wasm_code->kind())); + return v8_buffer_.start(); + } } return disasm::NameConverter::NameOfAddress(pc); diff --git a/src/wasm/wasm-heap.cc b/src/wasm/wasm-heap.cc index e111ec55f5..ac1b8b9845 100644 --- a/src/wasm/wasm-heap.cc +++ b/src/wasm/wasm-heap.cc @@ -190,6 +190,26 @@ void WasmCode::Print(Isolate* isolate) const { Disassemble(isolate, "", os); } +const char* GetWasmCodeKindAsString(WasmCode::Kind kind) { + switch (kind) { + case WasmCode::Function: + return "wasm function"; + case WasmCode::WasmToWasmWrapper: + return "wasm-to-wasm"; + case WasmCode::WasmToJsWrapper: + return "wasm-to-js"; + case WasmCode::LazyStub: + return "lazy-compile"; + case WasmCode::InterpreterStub: + return "interpreter-entry"; + case WasmCode::CopiedStub: + return "copied stub"; + case WasmCode::Trampoline: + return "trampoline"; + } + return "unknown kind"; +} + WasmCode::~WasmCode() { // Depending on finalizer order, the WasmCompiledModule finalizer may be // called first, case in which we release here. If the InstanceFinalizer is @@ -847,7 +867,11 @@ void WasmCodeManager::FreeNativeModuleMemories(NativeModule* native_module) { // easily identify those places where we know we have the first // instruction PC. WasmCode* WasmCodeManager::GetCodeFromStartAddress(Address pc) const { - return LookupCode(pc); + WasmCode* code = LookupCode(pc); + // This method can only be called for valid instruction start addresses. + DCHECK_NOT_NULL(code); + DCHECK_EQ(pc, code->instructions().start()); + return code; } WasmCode* WasmCodeManager::LookupCode(Address pc) const { diff --git a/src/wasm/wasm-heap.h b/src/wasm/wasm-heap.h index 9775f18b9b..4cb12f219f 100644 --- a/src/wasm/wasm-heap.h +++ b/src/wasm/wasm-heap.h @@ -174,6 +174,9 @@ class V8_EXPORT_PRIVATE WasmCode final { bool is_liftoff_; }; +// Return a textual description of the kind. +const char* GetWasmCodeKindAsString(WasmCode::Kind); + class WasmCodeManager; // Note that we currently need to add code on the main thread, because we may