Fix disassembly redirection from stdout into a file.
authorsvenpanne@chromium.org <svenpanne@chromium.org>
Thu, 28 Aug 2014 07:30:58 +0000 (07:30 +0000)
committersvenpanne@chromium.org <svenpanne@chromium.org>
Thu, 28 Aug 2014 07:30:58 +0000 (07:30 +0000)
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 <vegorov@google.com>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23478 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/hydrogen.cc
src/objects.cc
src/ostreams.cc
src/ostreams.h

index dd23771..41ed0f8 100644 (file)
@@ -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());
             }
           }
         }
index 7a4c6f5..ed349cc 100644 (file)
@@ -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) {
index 0f5bec4..847dc31 100644 (file)
@@ -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)
index f70b6de..de6a844 100644 (file)
@@ -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