OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 explicit V8NameConverter(Code* code) : code_(code) {} | 56 explicit V8NameConverter(Code* code) : code_(code) {} |
57 virtual const char* NameOfAddress(byte* pc) const; | 57 virtual const char* NameOfAddress(byte* pc) const; |
58 virtual const char* NameInCode(byte* addr) const; | 58 virtual const char* NameInCode(byte* addr) const; |
59 Code* code() const { return code_; } | 59 Code* code() const { return code_; } |
60 private: | 60 private: |
61 Code* code_; | 61 Code* code_; |
62 }; | 62 }; |
63 | 63 |
64 | 64 |
65 const char* V8NameConverter::NameOfAddress(byte* pc) const { | 65 const char* V8NameConverter::NameOfAddress(byte* pc) const { |
66 static char buffer[128]; | 66 static v8::internal::EmbeddedVector<char, 128> buffer; |
67 | 67 |
68 const char* name = Builtins::Lookup(pc); | 68 const char* name = Builtins::Lookup(pc); |
69 if (name != NULL) { | 69 if (name != NULL) { |
70 OS::SNPrintF(buffer, sizeof buffer, "%s (%p)", name, pc); | 70 OS::SNPrintF(buffer, "%s (%p)", name, pc); |
71 return buffer; | 71 return buffer.start(); |
72 } | 72 } |
73 | 73 |
74 if (code_ != NULL) { | 74 if (code_ != NULL) { |
75 int offs = pc - code_->instruction_start(); | 75 int offs = pc - code_->instruction_start(); |
76 // print as code offset, if it seems reasonable | 76 // print as code offset, if it seems reasonable |
77 if (0 <= offs && offs < code_->instruction_size()) { | 77 if (0 <= offs && offs < code_->instruction_size()) { |
78 OS::SNPrintF(buffer, sizeof buffer, "%d (%p)", offs, pc); | 78 OS::SNPrintF(buffer, "%d (%p)", offs, pc); |
79 return buffer; | 79 return buffer.start(); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 return disasm::NameConverter::NameOfAddress(pc); | 83 return disasm::NameConverter::NameOfAddress(pc); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 const char* V8NameConverter::NameInCode(byte* addr) const { | 87 const char* V8NameConverter::NameInCode(byte* addr) const { |
88 // The V8NameConverter is used for well known code, so we can "safely" | 88 // The V8NameConverter is used for well known code, so we can "safely" |
89 // dereference pointers in generated code. | 89 // dereference pointers in generated code. |
(...skipping 13 matching lines...) Expand all Loading... |
103 static const int kRelocInfoPosition = 57; | 103 static const int kRelocInfoPosition = 57; |
104 | 104 |
105 static int DecodeIt(FILE* f, | 105 static int DecodeIt(FILE* f, |
106 const V8NameConverter& converter, | 106 const V8NameConverter& converter, |
107 byte* begin, | 107 byte* begin, |
108 byte* end) { | 108 byte* end) { |
109 NoHandleAllocation ha; | 109 NoHandleAllocation ha; |
110 AssertNoAllocation no_alloc; | 110 AssertNoAllocation no_alloc; |
111 ExternalReferenceEncoder ref_encoder; | 111 ExternalReferenceEncoder ref_encoder; |
112 | 112 |
113 char decode_buffer[128]; | 113 v8::internal::EmbeddedVector<char, 128> decode_buffer; |
114 char out_buffer[kOutBufferSize]; | 114 v8::internal::EmbeddedVector<char, kOutBufferSize> out_buffer; |
115 byte* pc = begin; | 115 byte* pc = begin; |
116 disasm::Disassembler d(converter); | 116 disasm::Disassembler d(converter); |
117 RelocIterator* it = NULL; | 117 RelocIterator* it = NULL; |
118 if (converter.code() != NULL) { | 118 if (converter.code() != NULL) { |
119 it = new RelocIterator(converter.code()); | 119 it = new RelocIterator(converter.code()); |
120 } else { | 120 } else { |
121 // No relocation information when printing code stubs. | 121 // No relocation information when printing code stubs. |
122 } | 122 } |
123 int constants = -1; // no constants being decoded at the start | 123 int constants = -1; // no constants being decoded at the start |
124 | 124 |
125 while (pc < end) { | 125 while (pc < end) { |
126 // First decode instruction so that we know its length. | 126 // First decode instruction so that we know its length. |
127 byte* prev_pc = pc; | 127 byte* prev_pc = pc; |
128 if (constants > 0) { | 128 if (constants > 0) { |
129 OS::SNPrintF(decode_buffer, | 129 OS::SNPrintF(decode_buffer, |
130 sizeof(decode_buffer), | |
131 "%08x constant", | 130 "%08x constant", |
132 *reinterpret_cast<int32_t*>(pc)); | 131 *reinterpret_cast<int32_t*>(pc)); |
133 constants--; | 132 constants--; |
134 pc += 4; | 133 pc += 4; |
135 } else { | 134 } else { |
136 int num_const = d.ConstantPoolSizeAt(pc); | 135 int num_const = d.ConstantPoolSizeAt(pc); |
137 if (num_const >= 0) { | 136 if (num_const >= 0) { |
138 OS::SNPrintF(decode_buffer, | 137 OS::SNPrintF(decode_buffer, |
139 sizeof(decode_buffer), | |
140 "%08x constant pool begin", | 138 "%08x constant pool begin", |
141 *reinterpret_cast<int32_t*>(pc)); | 139 *reinterpret_cast<int32_t*>(pc)); |
142 constants = num_const; | 140 constants = num_const; |
143 pc += 4; | 141 pc += 4; |
144 } else { | 142 } else { |
145 decode_buffer[0] = '\0'; | 143 decode_buffer[0] = '\0'; |
146 pc += d.InstructionDecode(decode_buffer, sizeof decode_buffer, pc); | 144 pc += d.InstructionDecode(decode_buffer, pc); |
147 } | 145 } |
148 } | 146 } |
149 | 147 |
150 // Collect RelocInfo for this instruction (prev_pc .. pc-1) | 148 // Collect RelocInfo for this instruction (prev_pc .. pc-1) |
151 List<const char*> comments(4); | 149 List<const char*> comments(4); |
152 List<byte*> pcs(1); | 150 List<byte*> pcs(1); |
153 List<RelocMode> rmodes(1); | 151 List<RelocMode> rmodes(1); |
154 List<intptr_t> datas(1); | 152 List<intptr_t> datas(1); |
155 if (it != NULL) { | 153 if (it != NULL) { |
156 while (!it->done() && it->rinfo()->pc() < pc) { | 154 while (!it->done() && it->rinfo()->pc() < pc) { |
157 if (is_comment(it->rinfo()->rmode())) { | 155 if (is_comment(it->rinfo()->rmode())) { |
158 // For comments just collect the text. | 156 // For comments just collect the text. |
159 comments.Add(reinterpret_cast<const char*>(it->rinfo()->data())); | 157 comments.Add(reinterpret_cast<const char*>(it->rinfo()->data())); |
160 } else { | 158 } else { |
161 // For other reloc info collect all data. | 159 // For other reloc info collect all data. |
162 pcs.Add(it->rinfo()->pc()); | 160 pcs.Add(it->rinfo()->pc()); |
163 rmodes.Add(it->rinfo()->rmode()); | 161 rmodes.Add(it->rinfo()->rmode()); |
164 datas.Add(it->rinfo()->data()); | 162 datas.Add(it->rinfo()->data()); |
165 } | 163 } |
166 it->next(); | 164 it->next(); |
167 } | 165 } |
168 } | 166 } |
169 | 167 |
170 StringBuilder out(out_buffer, sizeof(out_buffer)); | 168 StringBuilder out(out_buffer.start(), out_buffer.length()); |
171 | 169 |
172 // Comments. | 170 // Comments. |
173 for (int i = 0; i < comments.length(); i++) { | 171 for (int i = 0; i < comments.length(); i++) { |
174 out.AddFormatted(" %s\n", comments[i]); | 172 out.AddFormatted(" %s\n", comments[i]); |
175 } | 173 } |
176 | 174 |
177 // Write out comments, resets outp so that we can format the next line. | 175 // Write out comments, resets outp so that we can format the next line. |
178 DumpBuffer(f, out.Finalize()); | 176 DumpBuffer(f, out.Finalize()); |
179 out.Reset(); | 177 out.Reset(); |
180 | 178 |
181 // Instruction address and instruction offset. | 179 // Instruction address and instruction offset. |
182 out.AddFormatted("%p %4d ", prev_pc, prev_pc - begin); | 180 out.AddFormatted("%p %4d ", prev_pc, prev_pc - begin); |
183 | 181 |
184 // Instruction. | 182 // Instruction. |
185 out.AddFormatted("%s", decode_buffer); | 183 out.AddFormatted("%s", decode_buffer.start()); |
186 | 184 |
187 // Print all the reloc info for this instruction which are not comments. | 185 // Print all the reloc info for this instruction which are not comments. |
188 for (int i = 0; i < pcs.length(); i++) { | 186 for (int i = 0; i < pcs.length(); i++) { |
189 // Put together the reloc info | 187 // Put together the reloc info |
190 RelocInfo relocinfo(pcs[i], rmodes[i], datas[i]); | 188 RelocInfo relocinfo(pcs[i], rmodes[i], datas[i]); |
191 | 189 |
192 // Indent the printing of the reloc info. | 190 // Indent the printing of the reloc info. |
193 if (i == 0) { | 191 if (i == 0) { |
194 // The first reloc info is printed after the disassembled instruction. | 192 // The first reloc info is printed after the disassembled instruction. |
195 out.AddPadding(' ', kRelocInfoPosition - out.position()); | 193 out.AddPadding(' ', kRelocInfoPosition - out.position()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 274 |
277 #else // ENABLE_DISASSEMBLER | 275 #else // ENABLE_DISASSEMBLER |
278 | 276 |
279 void Disassembler::Dump(FILE* f, byte* begin, byte* end) {} | 277 void Disassembler::Dump(FILE* f, byte* begin, byte* end) {} |
280 int Disassembler::Decode(FILE* f, byte* begin, byte* end) { return 0; } | 278 int Disassembler::Decode(FILE* f, byte* begin, byte* end) { return 0; } |
281 void Disassembler::Decode(FILE* f, Code* code) {} | 279 void Disassembler::Decode(FILE* f, Code* code) {} |
282 | 280 |
283 #endif // ENABLE_DISASSEMBLER | 281 #endif // ENABLE_DISASSEMBLER |
284 | 282 |
285 } } // namespace v8::internal | 283 } } // namespace v8::internal |
OLD | NEW |