summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-objdump.cc14
-rw-r--r--src/binary-reader.cc25
-rw-r--r--src/binary-reader.h7
-rw-r--r--src/tools/wasm-interp.cc6
-rw-r--r--src/tools/wasm-objdump.cc14
-rw-r--r--src/tools/wasm2wat.cc3
6 files changed, 53 insertions, 16 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index 67b27cdc..d77cb8ad 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -37,6 +37,8 @@ class BinaryReaderObjdumpBase : public BinaryReaderNop {
ObjdumpOptions* options,
ObjdumpState* state);
+ bool OnError(const char* message) override;
+
Result BeginModule(uint32_t version) override;
Result BeginSection(BinarySection section_type, Offset size) override;
@@ -78,6 +80,13 @@ Result BinaryReaderObjdumpBase::BeginSection(BinarySection section_code,
return Result::Ok;
}
+bool BinaryReaderObjdumpBase::OnError(const char* message) {
+ // Tell the BinaryReader that this error is "handled" for all passes other
+ // than the prepass. When the error is handled the default message will be
+ // suppressed.
+ return options_->mode != ObjdumpMode::Prepass;
+}
+
Result BinaryReaderObjdumpBase::BeginModule(uint32_t version) {
switch (options_->mode) {
case ObjdumpMode::Headers:
@@ -1129,7 +1138,10 @@ Result ReadBinaryObjdump(const uint8_t* data,
ObjdumpState* state) {
Features features;
features.EnableAll();
- ReadBinaryOptions read_options(features, options->log_stream, true);
+ const bool kReadDebugNames = true;
+ const bool kStopOnFirstError = false;
+ ReadBinaryOptions read_options(features, options->log_stream, kReadDebugNames,
+ kStopOnFirstError);
switch (options->mode) {
case ObjdumpMode::Prepass: {
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 3a0b8be1..faeea4e9 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -1658,6 +1658,8 @@ Result BinaryReader::ReadDataSection(Offset section_size) {
}
Result BinaryReader::ReadSections() {
+ Result result = Result::Ok;
+
while (state_.offset < state_.size) {
uint32_t section_code;
Offset section_size;
@@ -1685,11 +1687,14 @@ Result BinaryReader::ReadSections() {
CALLBACK(BeginSection, section, section_size);
-#define V(Name, name, code) \
- case BinarySection::Name: \
- CHECK_RESULT(Read##Name##Section(section_size)); \
+#define V(Name, name, code) \
+ case BinarySection::Name: \
+ section_result = Read##Name##Section(section_size); \
+ result |= section_result; \
break;
+ Result section_result = Result::Error;
+
switch (section) {
WABT_FOREACH_BINARY_SECTION(V)
case BinarySection::Invalid:
@@ -1698,13 +1703,25 @@ Result BinaryReader::ReadSections() {
#undef V
+ if (Failed(section_result)) {
+ if (options_->stop_on_first_error) {
+ return Result::Error;
+ }
+
+ // If we're continuing after failing to read this section, move the
+ // offset to the expected section end. This way we may be able to read
+ // further sections.
+ state_.offset = read_end_;
+ }
+
ERROR_UNLESS(state_.offset == read_end_,
"unfinished section (expected end: 0x%" PRIzx ")", read_end_);
if (section != BinarySection::Custom)
last_known_section_ = section;
}
- return Result::Ok;
+
+ return result;
}
Result BinaryReader::ReadModule() {
diff --git a/src/binary-reader.h b/src/binary-reader.h
index 71cf9d35..907674f6 100644
--- a/src/binary-reader.h
+++ b/src/binary-reader.h
@@ -34,14 +34,17 @@ struct ReadBinaryOptions {
ReadBinaryOptions() = default;
ReadBinaryOptions(const Features& features,
Stream* log_stream,
- bool read_debug_names)
+ bool read_debug_names,
+ bool stop_on_first_error)
: features(features),
log_stream(log_stream),
- read_debug_names(read_debug_names) {}
+ read_debug_names(read_debug_names),
+ stop_on_first_error(stop_on_first_error) {}
Features features;
Stream* log_stream = nullptr;
bool read_debug_names = false;
+ bool stop_on_first_error = true;
};
class BinaryReaderDelegate {
diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc
index 12fdae04..1c4cf958 100644
--- a/src/tools/wasm-interp.cc
+++ b/src/tools/wasm-interp.cc
@@ -305,8 +305,10 @@ static wabt::Result ReadModule(const char* module_filename,
result = ReadFile(module_filename, &file_data);
if (Succeeded(result)) {
- ReadBinaryOptions options(s_features, s_log_stream.get(),
- true /* read_debug_names */);
+ const bool kReadDebugNames = true;
+ const bool kStopOnFirstError = true;
+ ReadBinaryOptions options(s_features, s_log_stream.get(), kReadDebugNames,
+ kStopOnFirstError);
result = ReadBinaryInterpreter(env, DataOrNull(file_data), file_data.size(),
&options, error_handler, out_module);
diff --git a/src/tools/wasm-objdump.cc b/src/tools/wasm-objdump.cc
index 5b907fc0..c8c8e7ad 100644
--- a/src/tools/wasm-objdump.cc
+++ b/src/tools/wasm-objdump.cc
@@ -82,36 +82,38 @@ Result dump_file(const char* filename) {
ObjdumpState state;
+ Result result = Result::Ok;
+
// Pass 0: Prepass
s_objdump_options.mode = ObjdumpMode::Prepass;
- CHECK_RESULT(ReadBinaryObjdump(data, size, &s_objdump_options, &state));
+ result |= ReadBinaryObjdump(data, size, &s_objdump_options, &state);
s_objdump_options.log_stream = nullptr;
// Pass 1: Print the section headers
if (s_objdump_options.headers) {
s_objdump_options.mode = ObjdumpMode::Headers;
- CHECK_RESULT(ReadBinaryObjdump(data, size, &s_objdump_options, &state));
+ result |= ReadBinaryObjdump(data, size, &s_objdump_options, &state);
}
// Pass 2: Print extra information based on section type
if (s_objdump_options.details) {
s_objdump_options.mode = ObjdumpMode::Details;
- CHECK_RESULT(ReadBinaryObjdump(data, size, &s_objdump_options, &state));
+ result |= ReadBinaryObjdump(data, size, &s_objdump_options, &state);
}
// Pass 3: Disassemble code section
if (s_objdump_options.disassemble) {
s_objdump_options.mode = ObjdumpMode::Disassemble;
- CHECK_RESULT(ReadBinaryObjdump(data, size, &s_objdump_options, &state));
+ result |= ReadBinaryObjdump(data, size, &s_objdump_options, &state);
}
// Pass 4: Dump to raw contents of the sections
if (s_objdump_options.raw) {
s_objdump_options.mode = ObjdumpMode::RawData;
- CHECK_RESULT(ReadBinaryObjdump(data, size, &s_objdump_options, &state));
+ result |= ReadBinaryObjdump(data, size, &s_objdump_options, &state);
}
- return Result::Ok;
+ return result;
}
int ProgramMain(int argc, char** argv) {
diff --git a/src/tools/wasm2wat.cc b/src/tools/wasm2wat.cc
index be1009b3..a0105bbf 100644
--- a/src/tools/wasm2wat.cc
+++ b/src/tools/wasm2wat.cc
@@ -103,8 +103,9 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
ErrorHandlerFile error_handler(Location::Type::Binary);
Module module;
+ const bool kStopOnFirstError = true;
ReadBinaryOptions options(s_features, s_log_stream.get(),
- s_read_debug_names);
+ s_read_debug_names, kStopOnFirstError);
result = ReadBinaryIr(s_infile.c_str(), DataOrNull(file_data),
file_data.size(), &options, &error_handler, &module);
if (Succeeded(result)) {