From: svenpanne@chromium.org Date: Thu, 28 Aug 2014 07:30:58 +0000 (+0000) Subject: Fix disassembly redirection from stdout into a file. X-Git-Tag: upstream/4.7.83~7311 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a0d5fa72c53c64cd518206c7705d080d30366dbf;p=platform%2Fupstream%2Fv8.git Fix disassembly redirection from stdout into a file. Pass \n, \r and \t through OStream without escaping. BUG= R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/458533002 Patch from Vyacheslav Egorov . git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23478 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/hydrogen.cc b/src/hydrogen.cc index dd23771..41ed0f8 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -3500,7 +3500,7 @@ int HGraph::TraceInlinedFunction( shared->end_position() - shared->start_position() + 1; for (int i = 0; i < source_len; i++) { if (stream.HasMore()) { - os << AsUC16(stream.GetNext()); + os << AsReversiblyEscapedUC16(stream.GetNext()); } } } diff --git a/src/objects.cc b/src/objects.cc index 7a4c6f5..ed349cc 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -10923,7 +10923,10 @@ void Code::Disassemble(const char* name, OStream& os) { // NOLINT os << "Instructions (size = " << instruction_size() << ")\n"; // TODO(svenpanne) The Disassembler should use streams, too! - Disassembler::Decode(stdout, this); + { + CodeTracer::Scope trace_scope(GetIsolate()->GetCodeTracer()); + Disassembler::Decode(trace_scope.file(), this); + } os << "\n"; if (kind() == FUNCTION) { diff --git a/src/ostreams.cc b/src/ostreams.cc index 0f5bec4..847dc31 100644 --- a/src/ostreams.cc +++ b/src/ostreams.cc @@ -163,6 +163,16 @@ OFStream& OFStream::flush() { } +OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c) { + char buf[10]; + const char* format = (0x20 <= c.value && c.value <= 0x7F) && (c.value != 0x52) + ? "%c" + : (c.value <= 0xff) ? "\\x%02x" : "\\u%04x"; + snprintf(buf, sizeof(buf), format, c.value); + return os << buf; +} + + OStream& operator<<(OStream& os, const AsUC16& c) { char buf[10]; const char* format = (0x20 <= c.value && c.value <= 0x7F) diff --git a/src/ostreams.h b/src/ostreams.h index f70b6de..de6a844 100644 --- a/src/ostreams.h +++ b/src/ostreams.h @@ -117,13 +117,26 @@ class OFStream: public OStream { }; -// A wrapper to disambiguate uint16_t and uc16. +// Wrappers to disambiguate uint16_t and uc16. struct AsUC16 { explicit AsUC16(uint16_t v) : value(v) {} uint16_t value; }; +struct AsReversiblyEscapedUC16 { + explicit AsReversiblyEscapedUC16(uint16_t v) : value(v) {} + uint16_t value; +}; + + +// Writes the given character to the output escaping everything outside +// of printable ASCII range. Additionally escapes '\' making escaping +// reversible. +OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c); + +// Writes the given character to the output escaping everything outside +// of printable ASCII range. OStream& operator<<(OStream& os, const AsUC16& c); } } // namespace v8::internal