Skip to content

Commit be6e432

Browse files
Fix disassembly redirection from stdout into a file.
Pass \n, \r and \t through OStream without escaping. BUG= [email protected] Review URL: https://codereview.chromium.org/458533002 Patch from Vyacheslav Egorov <[email protected]>. git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23478 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent 7e976de commit be6e432

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/hydrogen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,7 @@ int HGraph::TraceInlinedFunction(
35003500
shared->end_position() - shared->start_position() + 1;
35013501
for (int i = 0; i < source_len; i++) {
35023502
if (stream.HasMore()) {
3503-
os << AsUC16(stream.GetNext());
3503+
os << AsReversiblyEscapedUC16(stream.GetNext());
35043504
}
35053505
}
35063506
}

src/objects.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10923,7 +10923,10 @@ void Code::Disassemble(const char* name, OStream& os) { // NOLINT
1092310923

1092410924
os << "Instructions (size = " << instruction_size() << ")\n";
1092510925
// TODO(svenpanne) The Disassembler should use streams, too!
10926-
Disassembler::Decode(stdout, this);
10926+
{
10927+
CodeTracer::Scope trace_scope(GetIsolate()->GetCodeTracer());
10928+
Disassembler::Decode(trace_scope.file(), this);
10929+
}
1092710930
os << "\n";
1092810931

1092910932
if (kind() == FUNCTION) {

src/ostreams.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ OFStream& OFStream::flush() {
163163
}
164164

165165

166+
OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c) {
167+
char buf[10];
168+
const char* format = (0x20 <= c.value && c.value <= 0x7F) && (c.value != 0x52)
169+
? "%c"
170+
: (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
171+
snprintf(buf, sizeof(buf), format, c.value);
172+
return os << buf;
173+
}
174+
175+
166176
OStream& operator<<(OStream& os, const AsUC16& c) {
167177
char buf[10];
168178
const char* format = (0x20 <= c.value && c.value <= 0x7F)

src/ostreams.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,26 @@ class OFStream: public OStream {
117117
};
118118

119119

120-
// A wrapper to disambiguate uint16_t and uc16.
120+
// Wrappers to disambiguate uint16_t and uc16.
121121
struct AsUC16 {
122122
explicit AsUC16(uint16_t v) : value(v) {}
123123
uint16_t value;
124124
};
125125

126126

127+
struct AsReversiblyEscapedUC16 {
128+
explicit AsReversiblyEscapedUC16(uint16_t v) : value(v) {}
129+
uint16_t value;
130+
};
131+
132+
133+
// Writes the given character to the output escaping everything outside
134+
// of printable ASCII range. Additionally escapes '\' making escaping
135+
// reversible.
136+
OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c);
137+
138+
// Writes the given character to the output escaping everything outside
139+
// of printable ASCII range.
127140
OStream& operator<<(OStream& os, const AsUC16& c);
128141
} } // namespace v8::internal
129142

0 commit comments

Comments
 (0)