| 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" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 // Froward declaration. | 14 // Froward declaration. |
| 15 class MemoryRegion; | 15 class MemoryRegion; |
| 16 | 16 |
| 17 // Disassembly formatter interface, which consumes the | 17 // Disassembly formatter interface, which consumes the |
| 18 // disassembled instructions in any desired form. | 18 // disassembled instructions in any desired form. |
| 19 class DisassemblyFormatter { | 19 class DisassemblyFormatter { |
| 20 public: | 20 public: |
| 21 DisassemblyFormatter() { } | 21 DisassemblyFormatter() { } |
| 22 virtual ~DisassemblyFormatter() { } | 22 virtual ~DisassemblyFormatter() { } |
| 23 | 23 |
| 24 // Consume the decoded instruction at the given pc. | 24 // Consume the decoded instruction at the given pc. |
| 25 virtual void ConsumeInstruction(char* hex_buffer, | 25 virtual void ConsumeInstruction(char* hex_buffer, |
| 26 intptr_t hex_size, | 26 intptr_t hex_size, |
| 27 char* human_buffer, | 27 char* human_buffer, |
| 28 intptr_t human_size, | 28 intptr_t human_size, |
| 29 uword pc) = 0; | 29 uword pc) = 0; |
| 30 |
| 31 // TODO(regis): Remove Print function once we have a real x64 disassembler. |
| 32 // Print a formatted message. |
| 33 virtual void Print(const char* format, ...) = 0; |
| 30 }; | 34 }; |
| 31 | 35 |
| 32 | 36 |
| 33 // Basic disassembly formatter that outputs the disassembled instruction | 37 // Basic disassembly formatter that outputs the disassembled instruction |
| 34 // to stdout. | 38 // to stdout. |
| 35 class DisassembleToStdout : public DisassemblyFormatter { | 39 class DisassembleToStdout : public DisassemblyFormatter { |
| 36 public: | 40 public: |
| 37 DisassembleToStdout() : DisassemblyFormatter() { } | 41 DisassembleToStdout() : DisassemblyFormatter() { } |
| 38 ~DisassembleToStdout() { } | 42 ~DisassembleToStdout() { } |
| 39 | 43 |
| 40 virtual void ConsumeInstruction(char* hex_buffer, | 44 virtual void ConsumeInstruction(char* hex_buffer, |
| 41 intptr_t hex_size, | 45 intptr_t hex_size, |
| 42 char* human_buffer, | 46 char* human_buffer, |
| 43 intptr_t human_size, | 47 intptr_t human_size, |
| 44 uword pc); | 48 uword pc); |
| 45 | 49 |
| 50 virtual void Print(const char* format, ...); |
| 51 |
| 46 private: | 52 private: |
| 47 DISALLOW_ALLOCATION() | 53 DISALLOW_ALLOCATION() |
| 48 DISALLOW_COPY_AND_ASSIGN(DisassembleToStdout); | 54 DISALLOW_COPY_AND_ASSIGN(DisassembleToStdout); |
| 49 }; | 55 }; |
| 50 | 56 |
| 51 | 57 |
| 52 // Disassemble instructions. | 58 // Disassemble instructions. |
| 53 class Disassembler : public AllStatic { | 59 class Disassembler : public AllStatic { |
| 54 public: | 60 public: |
| 55 // Disassemble instructions between start and end. | 61 // Disassemble instructions between start and end. |
| 56 // (The assumption is that start is at a valid instruction). | 62 // (The assumption is that start is at a valid instruction). |
| 57 static void Disassemble(uword start, | 63 static void Disassemble(uword start, |
| 58 uword end, | 64 uword end, |
| 59 DisassemblyFormatter* formatter); | 65 DisassemblyFormatter* formatter); |
| 60 static void Disassemble(uword start, uword end) { | 66 static void Disassemble(uword start, uword end) { |
| 61 DisassembleToStdout stdout_formatter; | 67 DisassembleToStdout stdout_formatter; |
| 62 Disassemble(start, end, &stdout_formatter); | 68 Disassemble(start, end, &stdout_formatter); |
| 63 } | 69 } |
| 64 | 70 |
| 65 // Disassemble instructions in a memory region. | 71 // Disassemble instructions in a memory region. |
| 66 static void DisassembleMemoryRegionRange(const MemoryRegion& instructions, | |
| 67 uword from, | |
| 68 uword to, | |
| 69 DisassemblyFormatter* formatter); | |
| 70 static void DisassembleMemoryRegion(const MemoryRegion& instructions, | 72 static void DisassembleMemoryRegion(const MemoryRegion& instructions, |
| 71 DisassemblyFormatter* formatter) { | 73 DisassemblyFormatter* formatter) { |
| 72 uword start = instructions.start(); | 74 uword start = instructions.start(); |
| 73 uword end = instructions.end(); | 75 uword end = instructions.end(); |
| 74 Disassemble(start, end, formatter); | 76 Disassemble(start, end, formatter); |
| 75 } | 77 } |
| 76 static void DisassembleMemoryRegion(const MemoryRegion& instructions) { | 78 static void DisassembleMemoryRegion(const MemoryRegion& instructions) { |
| 77 uword start = instructions.start(); | 79 uword start = instructions.start(); |
| 78 uword end = instructions.end(); | 80 uword end = instructions.end(); |
| 79 Disassemble(start, end); | 81 Disassemble(start, end); |
| 80 } | 82 } |
| 81 | 83 |
| 82 // Decodes one instruction. | 84 // Decodes one instruction. |
| 83 // Writes a hexadecimal representation into the hex_buffer and a | 85 // Writes a hexadecimal representation into the hex_buffer and a |
| 84 // human-readable representation into the human_buffer. | 86 // human-readable representation into the human_buffer. |
| 85 // Returns the length of the decoded instruction in bytes. | 87 // Returns the length of the decoded instruction in bytes. |
| 86 static int DecodeInstruction(char* hex_buffer, intptr_t hex_size, | 88 static int DecodeInstruction(char* hex_buffer, intptr_t hex_size, |
| 87 char* human_buffer, intptr_t human_size, | 89 char* human_buffer, intptr_t human_size, |
| 88 uword pc); | 90 uword pc); |
| 89 | 91 |
| 90 // Returns the name for the given register. For instance the Register EAX | |
| 91 // returns the string "eax". | |
| 92 static const char* RegisterName(Register reg); | |
| 93 | |
| 94 private: | 92 private: |
| 95 static const int kHexadecimalBufferSize = 32; | 93 static const int kHexadecimalBufferSize = 32; |
| 96 static const int kUserReadableBufferSize = 256; | 94 static const int kUserReadableBufferSize = 256; |
| 97 }; | 95 }; |
| 98 | 96 |
| 99 } // namespace dart | 97 } // namespace dart |
| 100 | 98 |
| 101 #endif // VM_DISASSEMBLER_H_ | 99 #endif // VM_DISASSEMBLER_H_ |
| OLD | NEW |