| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/disassembler.h" | 5 #include "vm/disassembler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
| 9 #include "vm/il_printer.h" | 9 #include "vm/il_printer.h" |
| 10 #include "vm/instructions.h" |
| 10 #include "vm/json_stream.h" | 11 #include "vm/json_stream.h" |
| 11 #include "vm/log.h" | 12 #include "vm/log.h" |
| 12 #include "vm/os.h" | 13 #include "vm/os.h" |
| 14 #include "vm/code_patcher.h" |
| 13 | 15 |
| 14 | 16 |
| 15 namespace dart { | 17 namespace dart { |
| 16 | 18 |
| 17 void DisassembleToStdout::ConsumeInstruction(char* hex_buffer, | 19 void DisassembleToStdout::ConsumeInstruction(const Code& code, |
| 20 char* hex_buffer, |
| 18 intptr_t hex_size, | 21 intptr_t hex_size, |
| 19 char* human_buffer, | 22 char* human_buffer, |
| 20 intptr_t human_size, | 23 intptr_t human_size, |
| 21 uword pc) { | 24 uword pc) { |
| 22 static const int kHexColumnWidth = 23; | 25 static const int kHexColumnWidth = 23; |
| 23 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); | 26 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); |
| 24 THR_Print("%p %s", pc_ptr, hex_buffer); | 27 THR_Print("%p %s", pc_ptr, hex_buffer); |
| 25 int hex_length = strlen(hex_buffer); | 28 int hex_length = strlen(hex_buffer); |
| 26 if (hex_length < kHexColumnWidth) { | 29 if (hex_length < kHexColumnWidth) { |
| 27 for (int i = kHexColumnWidth - hex_length; i > 0; i--) { | 30 for (int i = kHexColumnWidth - hex_length; i > 0; i--) { |
| 28 THR_Print(" "); | 31 THR_Print(" "); |
| 29 } | 32 } |
| 30 } | 33 } |
| 31 THR_Print("%s", human_buffer); | 34 THR_Print("%s", human_buffer); |
| 32 THR_Print("\n"); | 35 THR_Print("\n"); |
| 33 } | 36 } |
| 34 | 37 |
| 35 | 38 |
| 36 void DisassembleToStdout::Print(const char* format, ...) { | 39 void DisassembleToStdout::Print(const char* format, ...) { |
| 37 va_list args; | 40 va_list args; |
| 38 va_start(args, format); | 41 va_start(args, format); |
| 39 THR_VPrint(format, args); | 42 THR_VPrint(format, args); |
| 40 va_end(args); | 43 va_end(args); |
| 41 } | 44 } |
| 42 | 45 |
| 43 | 46 |
| 44 void DisassembleToJSONStream::ConsumeInstruction(char* hex_buffer, | 47 void DisassembleToJSONStream::ConsumeInstruction(const Code& code, |
| 48 char* hex_buffer, |
| 45 intptr_t hex_size, | 49 intptr_t hex_size, |
| 46 char* human_buffer, | 50 char* human_buffer, |
| 47 intptr_t human_size, | 51 intptr_t human_size, |
| 48 uword pc) { | 52 uword pc) { |
| 49 // Instructions are represented as three consecutive values in a JSON array. | 53 // Instructions are represented as four consecutive values in a JSON array. |
| 50 // All three are strings. The first is the address of the instruction, | 54 // The first is the address of the instruction, the second is the hex string, |
| 51 // the second is the hex string of the code, and the final is a human | 55 // of the code, and the third is a human readable string, and the fourth is |
| 52 // readable string. | 56 // the object loaded by the instruction. |
| 53 jsarr_.AddValueF("%" Pp "", pc); | 57 jsarr_.AddValueF("%" Pp "", pc); |
| 54 jsarr_.AddValue(hex_buffer); | 58 jsarr_.AddValue(hex_buffer); |
| 55 jsarr_.AddValue(human_buffer); | 59 jsarr_.AddValue(human_buffer); |
| 60 |
| 61 Object& object = Object::Handle(); |
| 62 if (DecodeLoadObjectFromPoolOrThread(pc, code, &object)) { |
| 63 jsarr_.AddValue(object); |
| 64 } else { |
| 65 jsarr_.AddValueNull(); // Not a reference to null. |
| 66 } |
| 56 } | 67 } |
| 57 | 68 |
| 58 | 69 |
| 59 void DisassembleToJSONStream::Print(const char* format, ...) { | 70 void DisassembleToJSONStream::Print(const char* format, ...) { |
| 60 va_list args; | 71 va_list args; |
| 61 va_start(args, format); | 72 va_start(args, format); |
| 62 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 73 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 63 va_end(args); | 74 va_end(args); |
| 64 char* p = reinterpret_cast<char*>(malloc(len+1)); | 75 char* p = reinterpret_cast<char*>(malloc(len+1)); |
| 65 va_start(args, format); | 76 va_start(args, format); |
| 66 intptr_t len2 = OS::VSNPrint(p, len, format, args); | 77 intptr_t len2 = OS::VSNPrint(p, len, format, args); |
| 67 va_end(args); | 78 va_end(args); |
| 68 ASSERT(len == len2); | 79 ASSERT(len == len2); |
| 69 for (intptr_t i = 0; i < len; i++) { | 80 for (intptr_t i = 0; i < len; i++) { |
| 70 if (p[i] == '\n' || p[i] == '\r') { | 81 if (p[i] == '\n' || p[i] == '\r') { |
| 71 p[i] = ' '; | 82 p[i] = ' '; |
| 72 } | 83 } |
| 73 } | 84 } |
| 74 // Instructions are represented as three consecutive values in a JSON array. | 85 // Instructions are represented as four consecutive values in a JSON array. |
| 75 // All three are strings. Comments only use the third slot. See above comment | 86 // Comments only use the third slot. See above comment for more information. |
| 76 // for more information. | 87 jsarr_.AddValueNull(); |
| 77 jsarr_.AddValue(""); | 88 jsarr_.AddValueNull(); |
| 78 jsarr_.AddValue(""); | |
| 79 jsarr_.AddValue(p); | 89 jsarr_.AddValue(p); |
| 90 jsarr_.AddValueNull(); |
| 80 free(p); | 91 free(p); |
| 81 } | 92 } |
| 82 | 93 |
| 83 | 94 |
| 84 class FindAddrVisitor : public FindObjectVisitor { | 95 class FindAddrVisitor : public FindObjectVisitor { |
| 85 public: | 96 public: |
| 86 explicit FindAddrVisitor(uword addr) | 97 explicit FindAddrVisitor(uword addr) |
| 87 : FindObjectVisitor(Isolate::Current()), addr_(addr) { } | 98 : FindObjectVisitor(Isolate::Current()), addr_(addr) { } |
| 88 virtual ~FindAddrVisitor() { } | 99 virtual ~FindAddrVisitor() { } |
| 89 | 100 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 f.Print("]\n"); | 162 f.Print("]\n"); |
| 152 formatter->Print(str); | 163 formatter->Print(str); |
| 153 } | 164 } |
| 154 } | 165 } |
| 155 int instruction_length; | 166 int instruction_length; |
| 156 DecodeInstruction(hex_buffer, | 167 DecodeInstruction(hex_buffer, |
| 157 sizeof(hex_buffer), | 168 sizeof(hex_buffer), |
| 158 human_buffer, | 169 human_buffer, |
| 159 sizeof(human_buffer), | 170 sizeof(human_buffer), |
| 160 &instruction_length, pc); | 171 &instruction_length, pc); |
| 161 formatter->ConsumeInstruction(hex_buffer, | 172 formatter->ConsumeInstruction(code, |
| 173 hex_buffer, |
| 162 sizeof(hex_buffer), | 174 sizeof(hex_buffer), |
| 163 human_buffer, | 175 human_buffer, |
| 164 sizeof(human_buffer), | 176 sizeof(human_buffer), |
| 165 pc); | 177 pc); |
| 166 pc += instruction_length; | 178 pc += instruction_length; |
| 167 } | 179 } |
| 168 } | 180 } |
| 169 | 181 |
| 170 } // namespace dart | 182 } // namespace dart |
| OLD | NEW |