| 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 #ifndef VM_DISASSEMBLER_H_ | 5 #ifndef VM_DISASSEMBLER_H_ |
| 6 #define VM_DISASSEMBLER_H_ | 6 #define VM_DISASSEMBLER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 public: | 22 public: |
| 23 DisassemblyFormatter() { } | 23 DisassemblyFormatter() { } |
| 24 virtual ~DisassemblyFormatter() { } | 24 virtual ~DisassemblyFormatter() { } |
| 25 | 25 |
| 26 // Consume the decoded instruction at the given pc. | 26 // Consume the decoded instruction at the given pc. |
| 27 virtual void ConsumeInstruction(const Code& code, | 27 virtual void ConsumeInstruction(const Code& code, |
| 28 char* hex_buffer, | 28 char* hex_buffer, |
| 29 intptr_t hex_size, | 29 intptr_t hex_size, |
| 30 char* human_buffer, | 30 char* human_buffer, |
| 31 intptr_t human_size, | 31 intptr_t human_size, |
| 32 Object* object, |
| 32 uword pc) = 0; | 33 uword pc) = 0; |
| 33 | 34 |
| 34 // Print a formatted message. | 35 // Print a formatted message. |
| 35 virtual void Print(const char* format, ...) = 0; | 36 virtual void Print(const char* format, ...) = 0; |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 | 39 |
| 39 // Basic disassembly formatter that outputs the disassembled instruction | 40 // Basic disassembly formatter that outputs the disassembled instruction |
| 40 // to stdout. | 41 // to stdout. |
| 41 class DisassembleToStdout : public DisassemblyFormatter { | 42 class DisassembleToStdout : public DisassemblyFormatter { |
| 42 public: | 43 public: |
| 43 DisassembleToStdout() : DisassemblyFormatter() { } | 44 DisassembleToStdout() : DisassemblyFormatter() { } |
| 44 ~DisassembleToStdout() { } | 45 ~DisassembleToStdout() { } |
| 45 | 46 |
| 46 virtual void ConsumeInstruction(const Code& code, | 47 virtual void ConsumeInstruction(const Code& code, |
| 47 char* hex_buffer, | 48 char* hex_buffer, |
| 48 intptr_t hex_size, | 49 intptr_t hex_size, |
| 49 char* human_buffer, | 50 char* human_buffer, |
| 50 intptr_t human_size, | 51 intptr_t human_size, |
| 52 Object* object, |
| 51 uword pc); | 53 uword pc); |
| 52 | 54 |
| 53 virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 55 virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 54 | 56 |
| 55 private: | 57 private: |
| 56 DISALLOW_ALLOCATION() | 58 DISALLOW_ALLOCATION() |
| 57 DISALLOW_COPY_AND_ASSIGN(DisassembleToStdout); | 59 DISALLOW_COPY_AND_ASSIGN(DisassembleToStdout); |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 | 62 |
| 61 // Disassemble into a JSONStream. | 63 // Disassemble into a JSONStream. |
| 62 class DisassembleToJSONStream : public DisassemblyFormatter { | 64 class DisassembleToJSONStream : public DisassemblyFormatter { |
| 63 public: | 65 public: |
| 64 explicit DisassembleToJSONStream(const JSONArray& jsarr) | 66 explicit DisassembleToJSONStream(const JSONArray& jsarr) |
| 65 : DisassemblyFormatter(), jsarr_(jsarr) { } | 67 : DisassemblyFormatter(), jsarr_(jsarr) { } |
| 66 ~DisassembleToJSONStream() { } | 68 ~DisassembleToJSONStream() { } |
| 67 | 69 |
| 68 virtual void ConsumeInstruction(const Code& code, | 70 virtual void ConsumeInstruction(const Code& code, |
| 69 char* hex_buffer, | 71 char* hex_buffer, |
| 70 intptr_t hex_size, | 72 intptr_t hex_size, |
| 71 char* human_buffer, | 73 char* human_buffer, |
| 72 intptr_t human_size, | 74 intptr_t human_size, |
| 75 Object* object, |
| 73 uword pc); | 76 uword pc); |
| 74 | 77 |
| 75 virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 78 virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 76 | 79 |
| 77 private: | 80 private: |
| 78 const JSONArray& jsarr_; | 81 const JSONArray& jsarr_; |
| 79 DISALLOW_ALLOCATION(); | 82 DISALLOW_ALLOCATION(); |
| 80 DISALLOW_COPY_AND_ASSIGN(DisassembleToJSONStream); | 83 DISALLOW_COPY_AND_ASSIGN(DisassembleToJSONStream); |
| 81 }; | 84 }; |
| 82 | 85 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 105 LogBlock lb; | 108 LogBlock lb; |
| 106 Disassemble(start, end, &stdout_formatter, code); | 109 Disassemble(start, end, &stdout_formatter, code); |
| 107 } | 110 } |
| 108 | 111 |
| 109 static void Disassemble(uword start, uword end) { | 112 static void Disassemble(uword start, uword end) { |
| 110 DisassembleToStdout stdout_formatter; | 113 DisassembleToStdout stdout_formatter; |
| 111 LogBlock lb; | 114 LogBlock lb; |
| 112 Disassemble(start, end, &stdout_formatter); | 115 Disassemble(start, end, &stdout_formatter); |
| 113 } | 116 } |
| 114 | 117 |
| 115 // Disassemble instructions in a memory region. | |
| 116 static void DisassembleMemoryRegion(const MemoryRegion& instructions, | |
| 117 DisassemblyFormatter* formatter) { | |
| 118 uword start = instructions.start(); | |
| 119 uword end = instructions.end(); | |
| 120 Disassemble(start, end, formatter); | |
| 121 } | |
| 122 | |
| 123 static void DisassembleMemoryRegion(const MemoryRegion& instructions) { | |
| 124 uword start = instructions.start(); | |
| 125 uword end = instructions.end(); | |
| 126 Disassemble(start, end); | |
| 127 } | |
| 128 | |
| 129 // Decodes one instruction. | 118 // Decodes one instruction. |
| 130 // Writes a hexadecimal representation into the hex_buffer and a | 119 // Writes a hexadecimal representation into the hex_buffer and a |
| 131 // human-readable representation into the human_buffer. | 120 // human-readable representation into the human_buffer. |
| 132 // Writes the length of the decoded instruction in bytes in out_instr_len. | 121 // Writes the length of the decoded instruction in bytes in out_instr_len. |
| 133 static void DecodeInstruction(char* hex_buffer, intptr_t hex_size, | 122 static void DecodeInstruction(char* hex_buffer, intptr_t hex_size, |
| 134 char* human_buffer, intptr_t human_size, | 123 char* human_buffer, intptr_t human_size, |
| 135 int* out_instr_len, uword pc); | 124 int* out_instr_len, const Code& code, |
| 136 | 125 Object** object, uword pc); |
| 137 static bool CanFindOldObject(uword addr); | |
| 138 | 126 |
| 139 static void DisassembleCode(const Function& function, bool optimized); | 127 static void DisassembleCode(const Function& function, bool optimized); |
| 140 static void DisassembleCodeUnoptimized( | 128 static void DisassembleCodeUnoptimized( |
| 141 const Function& function, bool optimized); | 129 const Function& function, bool optimized); |
| 142 | 130 |
| 143 private: | 131 private: |
| 144 static void DisassembleCodeHelper( | 132 static void DisassembleCodeHelper( |
| 145 const char* function_fullname, const Code& code, bool optimized); | 133 const char* function_fullname, const Code& code, bool optimized); |
| 146 | 134 |
| 147 static const int kHexadecimalBufferSize = 32; | 135 static const int kHexadecimalBufferSize = 32; |
| 148 static const int kUserReadableBufferSize = 256; | 136 static const int kUserReadableBufferSize = 256; |
| 149 }; | 137 }; |
| 150 | 138 |
| 151 } // namespace dart | 139 } // namespace dart |
| 152 | 140 |
| 153 #endif // VM_DISASSEMBLER_H_ | 141 #endif // VM_DISASSEMBLER_H_ |
| OLD | NEW |