Skip to content

Commit 77fa398

Browse files
RReverserkripken
authored andcommitted
Print custom section contents if printable (#2326)
This helps with debugging human-readable sections like sourceMappingURL.
1 parent 7b4f978 commit 77fa398

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/passes/Print.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,25 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
21222122
doIndent(o, indent);
21232123
o << ";; custom section \"" << section.name << "\", size "
21242124
<< section.data.size();
2125+
bool isPrintable = true;
2126+
for (auto c : section.data) {
2127+
if (!isprint(c)) {
2128+
isPrintable = false;
2129+
break;
2130+
}
2131+
}
2132+
if (isPrintable) {
2133+
o << ", contents: ";
2134+
// std::quoted is not available in all the supported compilers yet.
2135+
o << '"';
2136+
for (auto c : section.data) {
2137+
if (c == '\\' || c == '"') {
2138+
o << '\\';
2139+
}
2140+
o << c;
2141+
}
2142+
o << '"';
2143+
}
21252144
o << maybeNewLine;
21262145
}
21272146
decIndent();

test/fib-dbg.wasm.fromBinary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,6 @@
214214
(local $0 i32)
215215
(nop)
216216
)
217-
;; custom section "sourceMappingURL", size 35
217+
;; custom section "sourceMappingURL", size 35, contents: "\"http://localhost:8000/fib.wasm.map"
218218
)
219219

0 commit comments

Comments
 (0)