summaryrefslogtreecommitdiff
path: root/src/binary-reader-objdump.cc
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2020-12-03 14:08:18 -0800
committerGitHub <noreply@github.com>2020-12-03 14:08:18 -0800
commit2a487fc00594a54e5085fb6915e0575db3cb4013 (patch)
treef182043ff899e14fb60f4fa51c698299bff322f6 /src/binary-reader-objdump.cc
parent24af5fa65c3c730d4b36810b4e2b0aa43794d29b (diff)
downloadwabt-2a487fc00594a54e5085fb6915e0575db3cb4013.tar.gz
wabt-2a487fc00594a54e5085fb6915e0575db3cb4013.tar.bz2
wabt-2a487fc00594a54e5085fb6915e0575db3cb4013.zip
Use stderr for all logging and error output (#1579)
I'm not sure why we were using stdout but the convention is normally to write all logging and error message to stderr.
Diffstat (limited to 'src/binary-reader-objdump.cc')
-rw-r--r--src/binary-reader-objdump.cc25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index c4ffdfa9..2468afd3 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -75,6 +75,8 @@ class BinaryReaderObjdumpBase : public BinaryReaderNop {
std::vector<BinarySection> section_types_;
bool section_found_ = false;
std::string module_name_;
+
+ std::unique_ptr<FileStream> err_stream_;
};
BinaryReaderObjdumpBase::BinaryReaderObjdumpBase(const uint8_t* data,
@@ -84,7 +86,8 @@ BinaryReaderObjdumpBase::BinaryReaderObjdumpBase(const uint8_t* data,
: options_(options),
objdump_state_(objdump_state),
data_(data),
- size_(size) {
+ size_(size),
+ err_stream_(FileStream::CreateStderr()) {
ZeroMemory(section_starts_);
}
@@ -194,8 +197,8 @@ void BinaryReaderObjdumpBase::PrintRelocation(const Reloc& reloc,
Result BinaryReaderObjdumpBase::OnRelocCount(Index count, Index section_index) {
if (section_index >= section_types_.size()) {
- fprintf(stderr, "invalid relocation section index: %" PRIindex "\n",
- section_index);
+ err_stream_->Writef("invalid relocation section index: %" PRIindex "\n",
+ section_index);
reloc_section_ = BinarySection::Invalid;
return Result::Error;
}
@@ -485,7 +488,8 @@ std::string BinaryReaderObjdumpDisassemble::BlockSigToString(Type type) const {
Result BinaryReaderObjdumpDisassemble::OnOpcode(Opcode opcode) {
if (options_->debug) {
const char* opcode_name = opcode.GetName();
- printf("on_opcode: %#" PRIzx ": %s\n", state->offset, opcode_name);
+ err_stream_->Writef("on_opcode: %#" PRIzx ": %s\n", state->offset,
+ opcode_name);
}
if (last_opcode_end) {
@@ -961,6 +965,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Result OnEventType(Index index, Index sig_index) override;
private:
+ Result InitExprToConstOffset(const InitExpr& expr, uint32_t* out_offset);
Result HandleInitExpr(const InitExpr& expr);
bool ShouldPrintDetails();
void PrintDetails(const char* fmt, ...);
@@ -1083,13 +1088,13 @@ Result BinaryReaderObjdump::OnCount(Index count) {
Result BinaryReaderObjdump::EndModule() {
if (options_->section_name && !section_found_) {
- fprintf(stderr, "Section not found: %s\n", options_->section_name);
+ err_stream_->Writef("Section not found: %s\n", options_->section_name);
return Result::Error;
}
if (options_->relocs) {
if (next_data_reloc_ != objdump_state_->data_relocations.size()) {
- fprintf(stderr, "Data reloctions outside of segments\n");
+ err_stream_->Writef("Data reloctions outside of segments\n");
return Result::Error;
}
}
@@ -1489,8 +1494,8 @@ void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) {
}
}
-static Result InitExprToConstOffset(const InitExpr& expr,
- uint32_t* out_offset) {
+Result BinaryReaderObjdump::InitExprToConstOffset(const InitExpr& expr,
+ uint32_t* out_offset) {
switch (expr.type) {
case InitExprType::I32:
*out_offset = expr.value.i32;
@@ -1504,7 +1509,7 @@ static Result InitExprToConstOffset(const InitExpr& expr,
case InitExprType::V128:
case InitExprType::FuncRef:
case InitExprType::NullRef:
- fprintf(stderr, "Segment/Elem offset must be an i32 init expr");
+ err_stream_->Writef("Segment/Elem offset must be an i32 init expr");
return Result::Error;
break;
}
@@ -1750,7 +1755,7 @@ Result BinaryReaderObjdump::OnSymbolCount(Index count) {
Result BinaryReaderObjdump::PrintSymbolFlags(uint32_t flags) {
if (flags > WABT_SYMBOL_FLAG_MAX) {
- fprintf(stderr, "Unknown symbols flags: %x\n", flags);
+ err_stream_->Writef("Unknown symbols flags: %x\n", flags);
return Result::Error;
}