| 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/os.h" | 9 #include "vm/os.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 if (hex_length < kHexColumnWidth) { | 22 if (hex_length < kHexColumnWidth) { |
| 23 for (int i = kHexColumnWidth - hex_length; i > 0; i--) { | 23 for (int i = kHexColumnWidth - hex_length; i > 0; i--) { |
| 24 OS::Print(" "); | 24 OS::Print(" "); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 OS::Print("%s", human_buffer); | 27 OS::Print("%s", human_buffer); |
| 28 OS::Print("\n"); | 28 OS::Print("\n"); |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 void Disassembler::Disassemble(uword start, | 32 void DisassembleToStdout::Print(const char* format, ...) { |
| 33 uword end, | 33 va_list args; |
| 34 DisassemblyFormatter* formatter) { | 34 va_start(args, format); |
| 35 ASSERT(formatter != NULL); | 35 OS::VFPrint(stdout, format, args); |
| 36 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. | 36 va_end(args); |
| 37 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. | |
| 38 uword pc = start; | |
| 39 while (pc < end) { | |
| 40 int instruction_length = DecodeInstruction(hex_buffer, | |
| 41 sizeof(hex_buffer), | |
| 42 human_buffer, | |
| 43 sizeof(human_buffer), | |
| 44 pc); | |
| 45 formatter->ConsumeInstruction(hex_buffer, | |
| 46 sizeof(hex_buffer), | |
| 47 human_buffer, | |
| 48 sizeof(human_buffer), | |
| 49 pc); | |
| 50 pc += instruction_length; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 | |
| 55 void Disassembler::DisassembleMemoryRegionRange( | |
| 56 const MemoryRegion& instructions, | |
| 57 uword from, | |
| 58 uword to, | |
| 59 DisassemblyFormatter *formatter) { | |
| 60 ASSERT(formatter != NULL); | |
| 61 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. | |
| 62 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. | |
| 63 uword start = instructions.start(); | |
| 64 uword end = instructions.end(); | |
| 65 ASSERT((from >= start) && (to <= end) && (from <= to)); | |
| 66 uword pc = start; | |
| 67 uword stop = Utils::Minimum(end, to); | |
| 68 while (pc < stop) { | |
| 69 int instruction_length = DecodeInstruction(hex_buffer, | |
| 70 sizeof(hex_buffer), | |
| 71 human_buffer, | |
| 72 sizeof(human_buffer), | |
| 73 pc); | |
| 74 if (pc >= from) { | |
| 75 formatter->ConsumeInstruction(hex_buffer, | |
| 76 sizeof(hex_buffer), | |
| 77 human_buffer, | |
| 78 sizeof(human_buffer), | |
| 79 pc); | |
| 80 } | |
| 81 pc += instruction_length; | |
| 82 } | |
| 83 } | 37 } |
| 84 | 38 |
| 85 } // namespace dart | 39 } // namespace dart |
| OLD | NEW |