diff options
author | Ingvar Stepanyan <rreverser@google.com> | 2019-09-06 18:16:59 +0200 |
---|---|---|
committer | Alon Zakai <azakai@google.com> | 2019-09-06 09:16:59 -0700 |
commit | 77fa3988c7e272425c72bcc04c8a10e02b3a12ec (patch) | |
tree | 56e3fa9dc606e8cf9fbfece93304d7d778868122 | |
parent | 7b4f97823cf46532ac65b980a957f67a681e3002 (diff) | |
download | binaryen-77fa3988c7e272425c72bcc04c8a10e02b3a12ec.tar.gz binaryen-77fa3988c7e272425c72bcc04c8a10e02b3a12ec.tar.bz2 binaryen-77fa3988c7e272425c72bcc04c8a10e02b3a12ec.zip |
Print custom section contents if printable (#2326)
This helps with debugging human-readable sections like sourceMappingURL.
-rw-r--r-- | src/passes/Print.cpp | 19 | ||||
-rw-r--r-- | test/fib-dbg.wasm.fromBinary | 2 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index ad4d20bae..20c585859 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2122,6 +2122,25 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { doIndent(o, indent); o << ";; custom section \"" << section.name << "\", size " << section.data.size(); + bool isPrintable = true; + for (auto c : section.data) { + if (!isprint(c)) { + isPrintable = false; + break; + } + } + if (isPrintable) { + o << ", contents: "; + // std::quoted is not available in all the supported compilers yet. + o << '"'; + for (auto c : section.data) { + if (c == '\\' || c == '"') { + o << '\\'; + } + o << c; + } + o << '"'; + } o << maybeNewLine; } decIndent(); diff --git a/test/fib-dbg.wasm.fromBinary b/test/fib-dbg.wasm.fromBinary index 9645ec675..297911b8d 100644 --- a/test/fib-dbg.wasm.fromBinary +++ b/test/fib-dbg.wasm.fromBinary @@ -214,6 +214,6 @@ (local $0 i32) (nop) ) - ;; custom section "sourceMappingURL", size 35 + ;; custom section "sourceMappingURL", size 35, contents: "\"http://localhost:8000/fib.wasm.map" ) |