Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: runtime/vm/disassembler_ia32.cc

Issue 12431016: Copies Simulator Debugger from ARM to MIPS. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/globals.h" // Needed here to get TARGET_ARCH_IA32. 7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32.
8 #if defined(TARGET_ARCH_IA32) 8 #if defined(TARGET_ARCH_IA32)
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/allocation.h" 10 #include "vm/allocation.h"
(...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 } 1737 }
1738 } 1738 }
1739 1739
1740 int instr_len = data - reinterpret_cast<uint8_t*>(pc); 1740 int instr_len = data - reinterpret_cast<uint8_t*>(pc);
1741 ASSERT(instr_len > 0); // Ensure progress. 1741 ASSERT(instr_len > 0); // Ensure progress.
1742 1742
1743 return instr_len; 1743 return instr_len;
1744 } 1744 }
1745 1745
1746 1746
1747 int Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size, 1747 bool Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size,
1748 char* human_buffer, intptr_t human_size, 1748 char* human_buffer, intptr_t human_size,
1749 uword pc) { 1749 int* out_instr_len, uword pc) {
1750 ASSERT(hex_size > 0); 1750 ASSERT(hex_size > 0);
1751 ASSERT(human_size > 0); 1751 ASSERT(human_size > 0);
1752 X86Decoder decoder(human_buffer, human_size); 1752 X86Decoder decoder(human_buffer, human_size);
1753 int instruction_length = decoder.InstructionDecode(pc); 1753 int instruction_length = decoder.InstructionDecode(pc);
1754 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); 1754 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc);
1755 int hex_index = 0; 1755 int hex_index = 0;
1756 int remaining_size = hex_size - hex_index; 1756 int remaining_size = hex_size - hex_index;
1757 for (int i = 0; (i < instruction_length) && (remaining_size > 2); ++i) { 1757 for (int i = 0; (i < instruction_length) && (remaining_size > 2); ++i) {
1758 OS::SNPrint(&hex_buffer[hex_index], remaining_size, "%02x", pc_ptr[i]); 1758 OS::SNPrint(&hex_buffer[hex_index], remaining_size, "%02x", pc_ptr[i]);
1759 hex_index += 2; 1759 hex_index += 2;
1760 remaining_size -= 2; 1760 remaining_size -= 2;
1761 } 1761 }
1762 hex_buffer[hex_index] = '\0'; 1762 hex_buffer[hex_index] = '\0';
1763 return instruction_length; 1763 if (out_instr_len) {
1764 *out_instr_len = instruction_length;
1765 }
1766 return true;
1764 } 1767 }
1765 1768
1766 1769
1767 void Disassembler::Disassemble(uword start, 1770 bool Disassembler::Disassemble(uword start,
1768 uword end, 1771 uword end,
1769 DisassemblyFormatter* formatter, 1772 DisassemblyFormatter* formatter,
1770 const Code::Comments& comments) { 1773 const Code::Comments& comments) {
1771 ASSERT(formatter != NULL); 1774 ASSERT(formatter != NULL);
1772 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. 1775 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form.
1773 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. 1776 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction.
1774 uword pc = start; 1777 uword pc = start;
1775 intptr_t comment_finger = 0; 1778 intptr_t comment_finger = 0;
1776 while (pc < end) { 1779 while (pc < end) {
1777 const intptr_t offset = pc - start; 1780 const intptr_t offset = pc - start;
1778 while (comment_finger < comments.Length() && 1781 while (comment_finger < comments.Length() &&
1779 comments.PCOffsetAt(comment_finger) <= offset) { 1782 comments.PCOffsetAt(comment_finger) <= offset) {
1780 formatter->Print( 1783 formatter->Print(
1781 " ;; %s\n", 1784 " ;; %s\n",
1782 String::Handle(comments.CommentAt(comment_finger)).ToCString()); 1785 String::Handle(comments.CommentAt(comment_finger)).ToCString());
1783 comment_finger++; 1786 comment_finger++;
1784 } 1787 }
1785 int instruction_length = DecodeInstruction(hex_buffer, 1788 int instruction_length;
1786 sizeof(hex_buffer), 1789 DecodeInstruction(hex_buffer,
1787 human_buffer, 1790 sizeof(hex_buffer),
1788 sizeof(human_buffer), 1791 human_buffer,
1789 pc); 1792 sizeof(human_buffer),
1793 &instruction_length, pc);
1790 formatter->ConsumeInstruction(hex_buffer, 1794 formatter->ConsumeInstruction(hex_buffer,
1791 sizeof(hex_buffer), 1795 sizeof(hex_buffer),
1792 human_buffer, 1796 human_buffer,
1793 sizeof(human_buffer), 1797 sizeof(human_buffer),
1794 pc); 1798 pc);
1795 pc += instruction_length; 1799 pc += instruction_length;
1796 } 1800 }
1801
1802 return true;
1797 } 1803 }
1798 1804
1799 } // namespace dart 1805 } // namespace dart
1800 1806
1801 #endif // defined TARGET_ARCH_IA32 1807 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698