Commit d43969ea authored by Jakob Kummerow's avatar Jakob Kummerow Committed by V8 LUCI CQ

[tools][wasm] wami: Support hexdump for invalid modules

When trying to understand why a given module fails to validate, it
can be helpful to disassemble it as far as possible until reaching
the erroneous byte(s).

Change-Id: I0056ba1a81b85a486c0446d15bbf54ccb2e8332e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3827866Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82433}
parent a19316d9
...@@ -246,7 +246,6 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc, ...@@ -246,7 +246,6 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
decoder, pc, decoder, pc,
"invalid heap type '%s', enable with --experimental-wasm-gc", "invalid heap type '%s', enable with --experimental-wasm-gc",
HeapType::from_code(code).name().c_str()); HeapType::from_code(code).name().c_str());
return HeapType(HeapType::kBottom);
} }
V8_FALLTHROUGH; V8_FALLTHROUGH;
case kExternRefCode: case kExternRefCode:
...@@ -261,7 +260,6 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc, ...@@ -261,7 +260,6 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
"invalid heap type '%s', enable with " "invalid heap type '%s', enable with "
"--experimental-wasm-stringref", "--experimental-wasm-stringref",
HeapType::from_code(code).name().c_str()); HeapType::from_code(code).name().c_str());
return HeapType(HeapType::kBottom);
} }
return HeapType::from_code(code); return HeapType::from_code(code);
default: default:
...@@ -274,7 +272,6 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc, ...@@ -274,7 +272,6 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
DecodeError<validate>(decoder, pc, DecodeError<validate>(decoder, pc,
"Invalid indexed heap type, enable with " "Invalid indexed heap type, enable with "
"--experimental-wasm-typed-funcref"); "--experimental-wasm-typed-funcref");
return HeapType(HeapType::kBottom);
} }
uint32_t type_index = static_cast<uint32_t>(heap_index); uint32_t type_index = static_cast<uint32_t>(heap_index);
if (!VALIDATE(type_index < kV8MaxWasmTypes)) { if (!VALIDATE(type_index < kV8MaxWasmTypes)) {
...@@ -289,7 +286,6 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc, ...@@ -289,7 +286,6 @@ HeapType read_heap_type(Decoder* decoder, const byte* pc,
if (!VALIDATE(module == nullptr || type_index < module->types.capacity())) { if (!VALIDATE(module == nullptr || type_index < module->types.capacity())) {
DecodeError<validate>(decoder, pc, "Type index %u is out of bounds", DecodeError<validate>(decoder, pc, "Type index %u is out of bounds",
type_index); type_index);
return HeapType(HeapType::kBottom);
} }
return HeapType(type_index); return HeapType(type_index);
} }
......
...@@ -33,6 +33,7 @@ class NoTracer { ...@@ -33,6 +33,7 @@ class NoTracer {
// Hooks for extracting byte offsets of things. // Hooks for extracting byte offsets of things.
void TypeOffset(uint32_t offset) {} void TypeOffset(uint32_t offset) {}
void ImportOffset(uint32_t offset) {} void ImportOffset(uint32_t offset) {}
void ImportsDone() {}
void TableOffset(uint32_t offset) {} void TableOffset(uint32_t offset) {}
void MemoryOffset(uint32_t offset) {} void MemoryOffset(uint32_t offset) {}
void TagOffset(uint32_t offset) {} void TagOffset(uint32_t offset) {}
...@@ -866,6 +867,7 @@ class ModuleDecoderTemplate : public Decoder { ...@@ -866,6 +867,7 @@ class ModuleDecoderTemplate : public Decoder {
break; break;
} }
} }
tracer_.ImportsDone();
} }
void DecodeFunctionSection() { void DecodeFunctionSection() {
...@@ -1676,7 +1678,7 @@ class ModuleDecoderTemplate : public Decoder { ...@@ -1676,7 +1678,7 @@ class ModuleDecoderTemplate : public Decoder {
} }
// Shift the offset by the remaining section payload // Shift the offset by the remaining section payload
offset += section_iter.payload_length(); offset += section_iter.payload_length();
if (!section_iter.more()) break; if (!section_iter.more() || !ok()) break;
section_iter.advance(true); section_iter.advance(true);
} }
...@@ -2203,6 +2205,7 @@ class ModuleDecoderTemplate : public Decoder { ...@@ -2203,6 +2205,7 @@ class ModuleDecoderTemplate : public Decoder {
tracer_.NextLineIfFull(); tracer_.NextLineIfFull();
} }
tracer_.NextLineIfNonEmpty(); tracer_.NextLineIfNonEmpty();
if (failed()) return nullptr;
// Parse return types. // Parse return types.
std::vector<ValueType> returns; std::vector<ValueType> returns;
......
...@@ -608,6 +608,7 @@ class OffsetsProvider { ...@@ -608,6 +608,7 @@ class OffsetsProvider {
void DataOffset(uint32_t offset) { data_offsets_.push_back(offset); } void DataOffset(uint32_t offset) { data_offsets_.push_back(offset); }
// Unused by this tracer: // Unused by this tracer:
void ImportsDone() {}
void Bytes(const byte* start, uint32_t count) {} void Bytes(const byte* start, uint32_t count) {}
void Description(const char* desc) {} void Description(const char* desc) {}
void Description(const char* desc, size_t length) {} void Description(const char* desc, size_t length) {}
......
This diff is collapsed.
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