OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 const char* V8NameConverter::NameInCode(byte* addr) const { | 93 const char* V8NameConverter::NameInCode(byte* addr) const { |
94 // The V8NameConverter is used for well known code, so we can "safely" | 94 // The V8NameConverter is used for well known code, so we can "safely" |
95 // dereference pointers in generated code. | 95 // dereference pointers in generated code. |
96 return (code_ != NULL) ? reinterpret_cast<const char*>(addr) : ""; | 96 return (code_ != NULL) ? reinterpret_cast<const char*>(addr) : ""; |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 static void DumpBuffer(FILE* f, char* buff) { | 100 static void DumpBuffer(FILE* f, StringBuilder* out) { |
101 if (f == NULL) { | 101 if (f == NULL) { |
102 PrintF("%s", buff); | 102 PrintF("%s\n", out->Finalize()); |
103 } else { | 103 } else { |
104 fprintf(f, "%s", buff); | 104 fprintf(f, "%s\n", out->Finalize()); |
105 } | 105 } |
| 106 out->Reset(); |
106 } | 107 } |
107 | 108 |
| 109 |
| 110 |
108 static const int kOutBufferSize = 2048 + String::kMaxShortPrintLength; | 111 static const int kOutBufferSize = 2048 + String::kMaxShortPrintLength; |
109 static const int kRelocInfoPosition = 57; | 112 static const int kRelocInfoPosition = 57; |
110 | 113 |
111 static int DecodeIt(FILE* f, | 114 static int DecodeIt(FILE* f, |
112 const V8NameConverter& converter, | 115 const V8NameConverter& converter, |
113 byte* begin, | 116 byte* begin, |
114 byte* end) { | 117 byte* end) { |
115 NoHandleAllocation ha; | 118 NoHandleAllocation ha; |
116 AssertNoAllocation no_alloc; | 119 AssertNoAllocation no_alloc; |
117 ExternalReferenceEncoder ref_encoder; | 120 ExternalReferenceEncoder ref_encoder; |
118 Heap* heap = HEAP; | 121 Heap* heap = HEAP; |
119 | 122 |
120 v8::internal::EmbeddedVector<char, 128> decode_buffer; | 123 v8::internal::EmbeddedVector<char, 128> decode_buffer; |
121 v8::internal::EmbeddedVector<char, kOutBufferSize> out_buffer; | 124 v8::internal::EmbeddedVector<char, kOutBufferSize> out_buffer; |
| 125 StringBuilder out(out_buffer.start(), out_buffer.length()); |
122 byte* pc = begin; | 126 byte* pc = begin; |
123 disasm::Disassembler d(converter); | 127 disasm::Disassembler d(converter); |
124 RelocIterator* it = NULL; | 128 RelocIterator* it = NULL; |
125 if (converter.code() != NULL) { | 129 if (converter.code() != NULL) { |
126 it = new RelocIterator(converter.code()); | 130 it = new RelocIterator(converter.code()); |
127 } else { | 131 } else { |
128 // No relocation information when printing code stubs. | 132 // No relocation information when printing code stubs. |
129 } | 133 } |
130 int constants = -1; // no constants being decoded at the start | 134 int constants = -1; // no constants being decoded at the start |
131 | 135 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } else { | 178 } else { |
175 // For other reloc info collect all data. | 179 // For other reloc info collect all data. |
176 pcs.Add(it->rinfo()->pc()); | 180 pcs.Add(it->rinfo()->pc()); |
177 rmodes.Add(it->rinfo()->rmode()); | 181 rmodes.Add(it->rinfo()->rmode()); |
178 datas.Add(it->rinfo()->data()); | 182 datas.Add(it->rinfo()->data()); |
179 } | 183 } |
180 it->next(); | 184 it->next(); |
181 } | 185 } |
182 } | 186 } |
183 | 187 |
184 StringBuilder out(out_buffer.start(), out_buffer.length()); | |
185 | |
186 // Comments. | 188 // Comments. |
187 for (int i = 0; i < comments.length(); i++) { | 189 for (int i = 0; i < comments.length(); i++) { |
188 out.AddFormatted(" %s\n", comments[i]); | 190 out.AddFormatted(" %s", comments[i]); |
| 191 DumpBuffer(f, &out); |
189 } | 192 } |
190 | 193 |
191 // Write out comments, resets outp so that we can format the next line. | |
192 DumpBuffer(f, out.Finalize()); | |
193 out.Reset(); | |
194 | |
195 // Instruction address and instruction offset. | 194 // Instruction address and instruction offset. |
196 out.AddFormatted("%p %4d ", prev_pc, prev_pc - begin); | 195 out.AddFormatted("%p %4d ", prev_pc, prev_pc - begin); |
197 | 196 |
198 // Instruction. | 197 // Instruction. |
199 out.AddFormatted("%s", decode_buffer.start()); | 198 out.AddFormatted("%s", decode_buffer.start()); |
200 | 199 |
201 // Print all the reloc info for this instruction which are not comments. | 200 // Print all the reloc info for this instruction which are not comments. |
202 for (int i = 0; i < pcs.length(); i++) { | 201 for (int i = 0; i < pcs.length(); i++) { |
203 // Put together the reloc info | 202 // Put together the reloc info |
204 RelocInfo relocinfo(pcs[i], rmodes[i], datas[i]); | 203 RelocInfo relocinfo(pcs[i], rmodes[i], datas[i]); |
205 | 204 |
206 // Indent the printing of the reloc info. | 205 // Indent the printing of the reloc info. |
207 if (i == 0) { | 206 if (i == 0) { |
208 // The first reloc info is printed after the disassembled instruction. | 207 // The first reloc info is printed after the disassembled instruction. |
209 out.AddPadding(' ', kRelocInfoPosition - out.position()); | 208 out.AddPadding(' ', kRelocInfoPosition - out.position()); |
210 } else { | 209 } else { |
211 // Additional reloc infos are printed on separate lines. | 210 // Additional reloc infos are printed on separate lines. |
212 out.AddFormatted("\n"); | 211 DumpBuffer(f, &out); |
213 out.AddPadding(' ', kRelocInfoPosition); | 212 out.AddPadding(' ', kRelocInfoPosition); |
214 } | 213 } |
215 | 214 |
216 RelocInfo::Mode rmode = relocinfo.rmode(); | 215 RelocInfo::Mode rmode = relocinfo.rmode(); |
217 if (RelocInfo::IsPosition(rmode)) { | 216 if (RelocInfo::IsPosition(rmode)) { |
218 if (RelocInfo::IsStatementPosition(rmode)) { | 217 if (RelocInfo::IsStatementPosition(rmode)) { |
219 out.AddFormatted(" ;; debug: statement %d", relocinfo.data()); | 218 out.AddFormatted(" ;; debug: statement %d", relocinfo.data()); |
220 } else { | 219 } else { |
221 out.AddFormatted(" ;; debug: position %d", relocinfo.data()); | 220 out.AddFormatted(" ;; debug: position %d", relocinfo.data()); |
222 } | 221 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 int id = Deoptimizer::GetDeoptimizationId(addr, Deoptimizer::EAGER); | 291 int id = Deoptimizer::GetDeoptimizationId(addr, Deoptimizer::EAGER); |
293 if (id == Deoptimizer::kNotDeoptimizationEntry) { | 292 if (id == Deoptimizer::kNotDeoptimizationEntry) { |
294 out.AddFormatted(" ;; %s", RelocInfo::RelocModeName(rmode)); | 293 out.AddFormatted(" ;; %s", RelocInfo::RelocModeName(rmode)); |
295 } else { | 294 } else { |
296 out.AddFormatted(" ;; deoptimization bailout %d", id); | 295 out.AddFormatted(" ;; deoptimization bailout %d", id); |
297 } | 296 } |
298 } else { | 297 } else { |
299 out.AddFormatted(" ;; %s", RelocInfo::RelocModeName(rmode)); | 298 out.AddFormatted(" ;; %s", RelocInfo::RelocModeName(rmode)); |
300 } | 299 } |
301 } | 300 } |
302 out.AddString("\n"); | 301 DumpBuffer(f, &out); |
303 DumpBuffer(f, out.Finalize()); | 302 } |
304 out.Reset(); | 303 |
| 304 // Emit comments following the last instruction (if any). |
| 305 if (it != NULL) { |
| 306 for ( ; !it->done(); it->next()) { |
| 307 if (RelocInfo::IsComment(it->rinfo()->rmode())) { |
| 308 out.AddFormatted(" %s", |
| 309 reinterpret_cast<const char*>(it->rinfo()->data())); |
| 310 DumpBuffer(f, &out); |
| 311 } |
| 312 } |
305 } | 313 } |
306 | 314 |
307 delete it; | 315 delete it; |
308 return static_cast<int>(pc - begin); | 316 return static_cast<int>(pc - begin); |
309 } | 317 } |
310 | 318 |
311 | 319 |
312 int Disassembler::Decode(FILE* f, byte* begin, byte* end) { | 320 int Disassembler::Decode(FILE* f, byte* begin, byte* end) { |
313 V8NameConverter defaultConverter(NULL); | 321 V8NameConverter defaultConverter(NULL); |
314 return DecodeIt(f, defaultConverter, begin, end); | 322 return DecodeIt(f, defaultConverter, begin, end); |
(...skipping 19 matching lines...) Expand all Loading... |
334 | 342 |
335 #else // ENABLE_DISASSEMBLER | 343 #else // ENABLE_DISASSEMBLER |
336 | 344 |
337 void Disassembler::Dump(FILE* f, byte* begin, byte* end) {} | 345 void Disassembler::Dump(FILE* f, byte* begin, byte* end) {} |
338 int Disassembler::Decode(FILE* f, byte* begin, byte* end) { return 0; } | 346 int Disassembler::Decode(FILE* f, byte* begin, byte* end) { return 0; } |
339 void Disassembler::Decode(FILE* f, Code* code) {} | 347 void Disassembler::Decode(FILE* f, Code* code) {} |
340 | 348 |
341 #endif // ENABLE_DISASSEMBLER | 349 #endif // ENABLE_DISASSEMBLER |
342 | 350 |
343 } } // namespace v8::internal | 351 } } // namespace v8::internal |
OLD | NEW |