[wasm] Move {WasmModuleObject::DisassembleFunction}.

This introduces {DisassembleWasmFunction} to replace the above method,
since disassembling a function is independent of the concrete module
object and hence can be done for shared decoded modules.

R=clemensh@chromium.org
BUG=v8:6847

Change-Id: I5abea2a1381a9b8d3717a55d0b2b937dfbbafefd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1809359
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63860}
This commit is contained in:
Michael Starzinger 2019-09-18 11:25:11 +02:00 committed by Commit Bot
parent 9d8aa1a6d1
commit d7903dd3de
6 changed files with 44 additions and 36 deletions

View File

@ -9379,9 +9379,10 @@ debug::WasmDisassembly debug::WasmScript::DisassembleFunction(
i::DisallowHeapAllocation no_gc;
i::Handle<i::Script> script = Utils::OpenHandle(this);
DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject module_object =
i::WasmModuleObject::cast(script->wasm_module_object());
return module_object.DisassembleFunction(function_index);
i::wasm::NativeModule* native_module = script->wasm_native_module();
const i::wasm::WasmModule* module = native_module->module();
i::wasm::ModuleWireBytes wire_bytes(native_module->wire_bytes());
return DisassembleWasmFunction(module, wire_bytes, function_index);
}
debug::Location::Location(int line_number, int column_number)

View File

@ -22,6 +22,7 @@
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-result.h"
#include "src/wasm/wasm-text.h"
namespace v8 {
namespace internal {
@ -58,6 +59,23 @@ int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig,
return result;
}
// static
v8::debug::WasmDisassembly DisassembleWasmFunction(
const WasmModule* module, const ModuleWireBytes& wire_bytes,
int func_index) {
if (func_index < 0 ||
static_cast<uint32_t>(func_index) >= module->functions.size())
return {};
std::ostringstream disassembly_os;
v8::debug::WasmDisassembly::OffsetTable offset_table;
PrintWasmText(module, wire_bytes, static_cast<uint32_t>(func_index),
disassembly_os, &offset_table);
return {disassembly_os.str(), std::move(offset_table)};
}
void WasmModule::AddFunctionNameForTesting(int function_index,
WireBytesRef name) {
if (!function_names) {

View File

@ -16,6 +16,11 @@
#include "src/wasm/wasm-opcodes.h"
namespace v8 {
namespace debug {
struct WasmDisassembly;
}
namespace internal {
class WasmDebugInfo;
@ -240,6 +245,15 @@ V8_EXPORT_PRIVATE int MaxNumExportWrappers(const WasmModule* module);
int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig,
bool is_import);
// Compute the disassembly of a wasm function.
// Returns the disassembly string and a list of <byte_offset, line, column>
// entries, mapping wasm byte offsets to line and column in the disassembly.
// The list is guaranteed to be ordered by the byte_offset.
// Returns an empty string and empty vector if the function index is invalid.
V8_EXPORT_PRIVATE debug::WasmDisassembly DisassembleWasmFunction(
const WasmModule* module, const ModuleWireBytes& wire_bytes,
int func_index);
// Interface to the storage (wire bytes) of a wasm module.
// It is illegal for anyone receiving a ModuleWireBytes to store pointers based
// on module_bytes, as this storage is only guaranteed to be alive as long as

View File

@ -27,7 +27,6 @@
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-text.h"
#define TRACE(...) \
do { \
@ -529,25 +528,6 @@ int WasmModuleObject::GetSourcePosition(Handle<WasmModuleObject> module_object,
return offset_table->get_int(kOTESize * left + idx);
}
v8::debug::WasmDisassembly WasmModuleObject::DisassembleFunction(
int func_index) {
DisallowHeapAllocation no_gc;
if (func_index < 0 ||
static_cast<uint32_t>(func_index) >= module()->functions.size())
return {};
wasm::ModuleWireBytes wire_bytes(native_module()->wire_bytes());
std::ostringstream disassembly_os;
v8::debug::WasmDisassembly::OffsetTable offset_table;
PrintWasmText(module(), wire_bytes, static_cast<uint32_t>(func_index),
disassembly_os, &offset_table);
return {disassembly_os.str(), std::move(offset_table)};
}
bool WasmModuleObject::GetPossibleBreakpoints(
const v8::debug::Location& start, const v8::debug::Location& end,
std::vector<v8::debug::BreakLocation>* locations) {

View File

@ -10,7 +10,6 @@
#include "src/base/bits.h"
#include "src/codegen/signature.h"
#include "src/debug/debug.h"
#include "src/debug/interface-types.h"
#include "src/heap/heap.h"
#include "src/objects/objects.h"
#include "src/objects/script.h"
@ -220,13 +219,6 @@ class WasmModuleObject : public JSObject {
uint32_t byte_offset,
bool is_at_number_conversion);
// Compute the disassembly of a wasm function.
// Returns the disassembly string and a list of <byte_offset, line, column>
// entries, mapping wasm byte offsets to line and column in the disassembly.
// The list is guaranteed to be ordered by the byte_offset.
// Returns an empty string and empty vector if the function index is invalid.
V8_EXPORT_PRIVATE debug::WasmDisassembly DisassembleFunction(int func_index);
// Extract a portion of the wire bytes as UTF-8 string.
// Returns a null handle if the respective bytes do not form a valid UTF-8
// string.

View File

@ -969,12 +969,15 @@ TEST(AtomicOpDisassembly) {
ErrorThrower thrower(isolate, "Test");
auto enabled_features = WasmFeaturesFromIsolate(isolate);
MaybeHandle<WasmModuleObject> module_object =
isolate->wasm_engine()->SyncCompile(
isolate, enabled_features, &thrower,
ModuleWireBytes(buffer.begin(), buffer.end()));
Handle<WasmModuleObject> module_object =
isolate->wasm_engine()
->SyncCompile(isolate, enabled_features, &thrower,
ModuleWireBytes(buffer.begin(), buffer.end()))
.ToHandleChecked();
NativeModule* native_module = module_object->native_module();
ModuleWireBytes wire_bytes(native_module->wire_bytes());
module_object.ToHandleChecked()->DisassembleFunction(0);
DisassembleWasmFunction(native_module->module(), wire_bytes, 0);
}
Cleanup();
}