Commit f66ffd54 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Remove disassembly support

This was used for debugging only. The DevTools frontend now receives the
raw wasm bytes, and disassembles the functions it needed. The inspector
change was done in https://crrev.com/c/1991481.
This CL removes all code which is now dead in v8.

R=ahaas@chromium.org, bmeurer@chromium.org

Change-Id: I2d433613f1270a1ddac9af0bae8d990ef190712a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2005072Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65831}
parent 90db2b74
This diff is collapsed.
...@@ -9717,17 +9717,6 @@ uint32_t debug::WasmScript::GetFunctionHash(int function_index) { ...@@ -9717,17 +9717,6 @@ uint32_t debug::WasmScript::GetFunctionHash(int function_index) {
function_bytes.length(), 0); function_bytes.length(), 0);
} }
debug::WasmDisassembly debug::WasmScript::DisassembleFunction(
int function_index) const {
i::DisallowHeapAllocation no_gc;
i::Handle<i::Script> script = Utils::OpenHandle(this);
DCHECK_EQ(i::Script::TYPE_WASM, script->type());
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) debug::Location::Location(int line_number, int column_number)
: line_number_(line_number), : line_number_(line_number),
column_number_(column_number), column_number_(column_number),
......
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-opcodes.h" #include "src/wasm/wasm-opcodes.h"
#include "src/wasm/wasm-text.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
......
...@@ -173,7 +173,6 @@ class WasmScript : public Script { ...@@ -173,7 +173,6 @@ class WasmScript : public Script {
std::pair<int, int> GetFunctionRange(int function_index) const; std::pair<int, int> GetFunctionRange(int function_index) const;
int GetContainingFunction(int byte_offset) const; int GetContainingFunction(int byte_offset) const;
debug::WasmDisassembly DisassembleFunction(int function_index) const;
uint32_t GetFunctionHash(int function_index); uint32_t GetFunctionHash(int function_index);
}; };
......
...@@ -42,33 +42,6 @@ class V8_EXPORT_PRIVATE Location { ...@@ -42,33 +42,6 @@ class V8_EXPORT_PRIVATE Location {
bool is_empty_; bool is_empty_;
}; };
/**
* The result of disassembling a wasm function.
* Consists of the disassembly string and an offset table mapping wasm byte
* offsets to line and column in the disassembly.
* The offset table entries are ordered by the byte_offset.
* All numbers are 0-based.
*/
struct WasmDisassemblyOffsetTableEntry {
WasmDisassemblyOffsetTableEntry(uint32_t byte_offset, int line, int column)
: byte_offset(byte_offset), line(line), column(column) {}
uint32_t byte_offset;
int line;
int column;
};
struct WasmDisassembly {
using OffsetTable = std::vector<WasmDisassemblyOffsetTableEntry>;
WasmDisassembly() = default;
WasmDisassembly(std::string disassembly, OffsetTable offset_table)
: disassembly(std::move(disassembly)),
offset_table(std::move(offset_table)) {}
std::string disassembly;
OffsetTable offset_table;
};
enum DebugAsyncActionType { enum DebugAsyncActionType {
kDebugPromiseThen, kDebugPromiseThen,
kDebugPromiseCatch, kDebugPromiseCatch,
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-result.h" #include "src/wasm/wasm-result.h"
#include "src/wasm/wasm-text.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -103,23 +102,6 @@ int GetContainingWasmFunction(const WasmModule* module, uint32_t byte_offset) { ...@@ -103,23 +102,6 @@ int GetContainingWasmFunction(const WasmModule* module, uint32_t byte_offset) {
return func_index; return func_index;
} }
// 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 DecodedFunctionNames::AddForTesting(int function_index, void DecodedFunctionNames::AddForTesting(int function_index,
WireBytesRef name) { WireBytesRef name) {
base::MutexGuard lock(&mutex_); base::MutexGuard lock(&mutex_);
......
...@@ -17,10 +17,6 @@ ...@@ -17,10 +17,6 @@
namespace v8 { namespace v8 {
namespace debug {
struct WasmDisassembly;
}
namespace internal { namespace internal {
class WasmModuleObject; class WasmModuleObject;
...@@ -268,15 +264,6 @@ int GetContainingWasmFunction(const WasmModule* module, uint32_t byte_offset); ...@@ -268,15 +264,6 @@ int GetContainingWasmFunction(const WasmModule* module, uint32_t byte_offset);
// contained within a function. // contained within a function.
int GetNearestWasmFunction(const WasmModule* module, uint32_t byte_offset); int GetNearestWasmFunction(const WasmModule* module, uint32_t byte_offset);
// 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. // Interface to the storage (wire bytes) of a wasm module.
// It is illegal for anyone receiving a ModuleWireBytes to store pointers based // 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 // on module_bytes, as this storage is only guaranteed to be alive as long as
......
This diff is collapsed.
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_WASM_WASM_TEXT_H_
#define V8_WASM_WASM_TEXT_H_
#include <cstdint>
#include <ostream>
#include <vector>
#include "src/common/globals.h"
namespace v8 {
namespace debug {
struct WasmDisassemblyOffsetTableEntry;
} // namespace debug
namespace internal {
namespace wasm {
// Forward declaration.
struct WasmModule;
struct ModuleWireBytes;
// Generate disassembly according to official text format.
// Output disassembly to the given output stream, and optionally return an
// offset table of <byte offset, line, column> via the given pointer.
V8_EXPORT_PRIVATE void PrintWasmText(
const WasmModule* module, const ModuleWireBytes& wire_bytes,
uint32_t func_index, std::ostream& os,
std::vector<debug::WasmDisassemblyOffsetTableEntry>* offset_table);
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_WASM_TEXT_H_
...@@ -942,46 +942,6 @@ TEST(MemoryWithOOBEmptyDataSegment) { ...@@ -942,46 +942,6 @@ TEST(MemoryWithOOBEmptyDataSegment) {
Cleanup(); Cleanup();
} }
TEST(AtomicOpDisassembly) {
{
EXPERIMENTAL_FLAG_SCOPE(threads);
TestSignatures sigs;
Isolate* isolate = CcTest::InitIsolateOnce();
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
builder->SetHasSharedMemory();
builder->SetMaxMemorySize(16);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
ExportAsMain(f);
byte code[] = {
WASM_ATOMICS_STORE_OP(kExprI32AtomicStore, WASM_ZERO, WASM_GET_LOCAL(0),
MachineRepresentation::kWord32),
WASM_ATOMICS_LOAD_OP(kExprI32AtomicLoad, WASM_ZERO,
MachineRepresentation::kWord32)};
EMIT_CODE_WITH_END(f, code);
HandleScope scope(isolate);
ZoneBuffer buffer(&zone);
builder->WriteTo(&buffer);
testing::SetupIsolateForWasmModule(isolate);
ErrorThrower thrower(isolate, "Test");
auto enabled_features = WasmFeatures::FromIsolate(isolate);
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());
DisassembleWasmFunction(native_module->module(), wire_bytes, 0);
}
Cleanup();
}
#undef EMIT_CODE_WITH_END #undef EMIT_CODE_WITH_END
} // namespace test_run_wasm_module } // namespace test_run_wasm_module
......
...@@ -245,7 +245,6 @@ v8_source_set("unittests_sources") { ...@@ -245,7 +245,6 @@ v8_source_set("unittests_sources") {
"wasm/wasm-module-builder-unittest.cc", "wasm/wasm-module-builder-unittest.cc",
"wasm/wasm-module-sourcemap-unittest.cc", "wasm/wasm-module-sourcemap-unittest.cc",
"wasm/wasm-opcodes-unittest.cc", "wasm/wasm-opcodes-unittest.cc",
"wasm/wasm-text-unittest.cc",
"zone/zone-allocator-unittest.cc", "zone/zone-allocator-unittest.cc",
"zone/zone-chunk-list-unittest.cc", "zone/zone-chunk-list-unittest.cc",
"zone/zone-unittest.cc", "zone/zone-unittest.cc",
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <sstream>
#include "test/unittests/test-utils.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-module-builder.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/wasm/wasm-text.h"
#include "test/common/wasm/test-signatures.h"
namespace v8 {
namespace internal {
namespace wasm {
class WasmTextTest : public TestWithIsolateAndZone {
public:
TestSignatures sigs;
WasmFeatures enabled_features_;
void TestInstruction(const byte* func_start, size_t func_size) {
WasmModuleBuilder mb(zone());
auto* fb = mb.AddFunction(sigs.v_v());
fb->EmitCode(func_start, static_cast<uint32_t>(func_size));
fb->Emit(kExprEnd);
ZoneBuffer buffer(zone());
mb.WriteTo(&buffer);
ModuleWireBytes wire_bytes(
Vector<const byte>(buffer.begin(), buffer.size()));
ModuleResult result = DecodeWasmModule(
enabled_features_, buffer.begin(), buffer.end(), false, kWasmOrigin,
isolate()->counters(), isolate()->wasm_engine()->allocator());
EXPECT_TRUE(result.ok());
std::stringstream ss;
PrintWasmText(result.value().get(), wire_bytes, 0, ss, nullptr);
}
};
TEST_F(WasmTextTest, EveryOpcodeCanBeDecoded) {
static const struct {
WasmOpcode opcode;
const char* debug_name;
} kValues[] = {
#define DECLARE_ELEMENT(name, opcode, sig) {kExpr##name, "kExpr" #name},
FOREACH_OPCODE(DECLARE_ELEMENT)};
#undef DECLARE_ELEMENT
for (const auto& value : kValues) {
// Pad with 0 for any immediate values. If they're not needed, they'll be
// interpreted as unreachable.
byte data[20] = {0};
printf("%s\n", value.debug_name);
switch (value.opcode) {
// Instructions that have a special case because they affect the control
// depth.
case kExprBlock:
case kExprLoop:
case kExprIf:
case kExprTry:
data[0] = value.opcode;
data[1] = kLocalVoid;
data[2] = kExprEnd;
break;
case kExprElse:
data[0] = kExprIf;
data[1] = value.opcode;
data[2] = kExprEnd;
break;
case kExprCatch:
data[0] = kExprTry;
data[1] = value.opcode;
data[2] = kExprEnd;
break;
case kExprEnd:
break;
// Instructions with special requirements for immediates.
case kExprSelectWithType:
data[0] = kExprSelectWithType;
data[1] = 1;
data[2] = kLocalI32;
break;
default: {
if (value.opcode >= 0x100) {
data[0] = value.opcode >> 8; // Prefix byte.
byte opcode = value.opcode & 0xff; // Actual opcode.
if (opcode >= 0x80) {
// Opcode with prefix, and needs to be LEB encoded (3 bytes).
// For now, this can only be in the range [0x80, 0xff], which means
// that the third byte is always 1.
data[1] = (opcode & 0x7f) | 0x80;
data[2] = 1;
} else {
// Opcode with prefix (2 bytes).
data[1] = opcode;
}
} else {
// Single-byte opcode.
data[0] = value.opcode;
}
break;
}
}
TestInstruction(data, arraysize(data));
}
}
} // namespace wasm
} // namespace internal
} // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment