Chromium Code Reviews| 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 // Print a formatted message. | |
| 32 virtual void Print(const char* format, ...) = 0; | |
|
Ivan Posva
2011/11/30 22:42:12
Can you add a TODO to remove this once we have the
regis
2011/11/30 23:11:52
Done.
| |
| 30 }; | 33 }; |
| 31 | 34 |
| 32 | 35 |
| 33 // Basic disassembly formatter that outputs the disassembled instruction | 36 // Basic disassembly formatter that outputs the disassembled instruction |
| 34 // to stdout. | 37 // to stdout. |
| 35 class DisassembleToStdout : public DisassemblyFormatter { | 38 class DisassembleToStdout : public DisassemblyFormatter { |
| 36 public: | 39 public: |
| 37 DisassembleToStdout() : DisassemblyFormatter() { } | 40 DisassembleToStdout() : DisassemblyFormatter() { } |
| 38 ~DisassembleToStdout() { } | 41 ~DisassembleToStdout() { } |
| 39 | 42 |
| 40 virtual void ConsumeInstruction(char* hex_buffer, | 43 virtual void ConsumeInstruction(char* hex_buffer, |
| 41 intptr_t hex_size, | 44 intptr_t hex_size, |
| 42 char* human_buffer, | 45 char* human_buffer, |
| 43 intptr_t human_size, | 46 intptr_t human_size, |
| 44 uword pc); | 47 uword pc); |
| 45 | 48 |
| 49 virtual void Print(const char* format, ...); | |
| 50 | |
| 46 private: | 51 private: |
| 47 DISALLOW_ALLOCATION() | 52 DISALLOW_ALLOCATION() |
| 48 DISALLOW_COPY_AND_ASSIGN(DisassembleToStdout); | 53 DISALLOW_COPY_AND_ASSIGN(DisassembleToStdout); |
| 49 }; | 54 }; |
| 50 | 55 |
| 51 | 56 |
| 52 // Disassemble instructions. | 57 // Disassemble instructions. |
| 53 class Disassembler : public AllStatic { | 58 class Disassembler : public AllStatic { |
| 54 public: | 59 public: |
| 55 // Disassemble instructions between start and end. | 60 // Disassemble instructions between start and end. |
| 56 // (The assumption is that start is at a valid instruction). | 61 // (The assumption is that start is at a valid instruction). |
| 57 static void Disassemble(uword start, | 62 static void Disassemble(uword start, |
| 58 uword end, | 63 uword end, |
| 59 DisassemblyFormatter* formatter); | 64 DisassemblyFormatter* formatter); |
| 60 static void Disassemble(uword start, uword end) { | 65 static void Disassemble(uword start, uword end) { |
| 61 DisassembleToStdout stdout_formatter; | 66 DisassembleToStdout stdout_formatter; |
| 62 Disassemble(start, end, &stdout_formatter); | 67 Disassemble(start, end, &stdout_formatter); |
| 63 } | 68 } |
| 64 | 69 |
| 65 // Disassemble instructions in a memory region. | 70 // Disassemble instructions in a memory region. |
| 66 static void DisassembleMemoryRegionRange(const MemoryRegion& instructions, | 71 static void DisassembleMemoryRegionRange(const MemoryRegion& instructions, |
|
Ivan Posva
2011/11/30 22:42:12
Not sure if this is really needed. Siva, do you se
regis
2011/11/30 23:11:52
Removed for now since unused.
| |
| 67 uword from, | 72 uword from, |
| 68 uword to, | 73 uword to, |
| 69 DisassemblyFormatter* formatter); | 74 DisassemblyFormatter* formatter); |
| 70 static void DisassembleMemoryRegion(const MemoryRegion& instructions, | 75 static void DisassembleMemoryRegion(const MemoryRegion& instructions, |
| 71 DisassemblyFormatter* formatter) { | 76 DisassemblyFormatter* formatter) { |
| 72 uword start = instructions.start(); | 77 uword start = instructions.start(); |
| 73 uword end = instructions.end(); | 78 uword end = instructions.end(); |
| 74 Disassemble(start, end, formatter); | 79 Disassemble(start, end, formatter); |
| 75 } | 80 } |
| 76 static void DisassembleMemoryRegion(const MemoryRegion& instructions) { | 81 static void DisassembleMemoryRegion(const MemoryRegion& instructions) { |
| 77 uword start = instructions.start(); | 82 uword start = instructions.start(); |
| 78 uword end = instructions.end(); | 83 uword end = instructions.end(); |
| 79 Disassemble(start, end); | 84 Disassemble(start, end); |
| 80 } | 85 } |
| 81 | 86 |
| 82 // Decodes one instruction. | 87 // Decodes one instruction. |
| 83 // Writes a hexadecimal representation into the hex_buffer and a | 88 // Writes a hexadecimal representation into the hex_buffer and a |
| 84 // human-readable representation into the human_buffer. | 89 // human-readable representation into the human_buffer. |
| 85 // Returns the length of the decoded instruction in bytes. | 90 // Returns the length of the decoded instruction in bytes. |
| 86 static int DecodeInstruction(char* hex_buffer, intptr_t hex_size, | 91 static int DecodeInstruction(char* hex_buffer, intptr_t hex_size, |
| 87 char* human_buffer, intptr_t human_size, | 92 char* human_buffer, intptr_t human_size, |
| 88 uword pc); | 93 uword pc); |
| 89 | 94 |
| 90 // Returns the name for the given register. For instance the Register EAX | 95 // Returns the name for the given register. For instance the Register EAX |
| 91 // returns the string "eax". | 96 // returns the string "eax". |
| 92 static const char* RegisterName(Register reg); | 97 static const char* RegisterName(Register reg); |
|
regis
2011/11/30 23:11:52
Also removed since unused.
| |
| 93 | 98 |
| 94 private: | 99 private: |
| 95 static const int kHexadecimalBufferSize = 32; | 100 static const int kHexadecimalBufferSize = 32; |
| 96 static const int kUserReadableBufferSize = 256; | 101 static const int kUserReadableBufferSize = 256; |
| 97 }; | 102 }; |
| 98 | 103 |
| 99 } // namespace dart | 104 } // namespace dart |
| 100 | 105 |
| 101 #endif // VM_DISASSEMBLER_H_ | 106 #endif // VM_DISASSEMBLER_H_ |
| OLD | NEW |