From 77fa3988c7e272425c72bcc04c8a10e02b3a12ec Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 6 Sep 2019 18:16:59 +0200 Subject: Print custom section contents if printable (#2326) This helps with debugging human-readable sections like sourceMappingURL. --- src/passes/Print.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') 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 { 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(); -- cgit v1.2.3