| OLD | NEW |
| 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_X64) | 8 #if defined(TARGET_ARCH_X64) |
| 9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
| 10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| (...skipping 1847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 | 1858 |
| 1859 ASSERT(buffer_[buffer_pos_] == '\0'); | 1859 ASSERT(buffer_[buffer_pos_] == '\0'); |
| 1860 | 1860 |
| 1861 int instr_len = data - reinterpret_cast<uint8_t*>(pc); | 1861 int instr_len = data - reinterpret_cast<uint8_t*>(pc); |
| 1862 ASSERT(instr_len > 0); // Ensure progress. | 1862 ASSERT(instr_len > 0); // Ensure progress. |
| 1863 | 1863 |
| 1864 return instr_len; | 1864 return instr_len; |
| 1865 } | 1865 } |
| 1866 | 1866 |
| 1867 | 1867 |
| 1868 bool Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size, | 1868 void Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size, |
| 1869 char* human_buffer, intptr_t human_size, | 1869 char* human_buffer, intptr_t human_size, |
| 1870 int* out_instr_len, uword pc) { | 1870 int* out_instr_len, uword pc) { |
| 1871 ASSERT(hex_size > 0); | 1871 ASSERT(hex_size > 0); |
| 1872 ASSERT(human_size > 0); | 1872 ASSERT(human_size > 0); |
| 1873 DisassemblerX64 decoder(human_buffer, human_size); | 1873 DisassemblerX64 decoder(human_buffer, human_size); |
| 1874 int instruction_length = decoder.InstructionDecode(pc); | 1874 int instruction_length = decoder.InstructionDecode(pc); |
| 1875 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); | 1875 uint8_t* pc_ptr = reinterpret_cast<uint8_t*>(pc); |
| 1876 int hex_index = 0; | 1876 int hex_index = 0; |
| 1877 int remaining_size = hex_size - hex_index; | 1877 int remaining_size = hex_size - hex_index; |
| 1878 for (int i = 0; (i < instruction_length) && (remaining_size > 2); ++i) { | 1878 for (int i = 0; (i < instruction_length) && (remaining_size > 2); ++i) { |
| 1879 OS::SNPrint(&hex_buffer[hex_index], remaining_size, "%02x", pc_ptr[i]); | 1879 OS::SNPrint(&hex_buffer[hex_index], remaining_size, "%02x", pc_ptr[i]); |
| 1880 hex_index += 2; | 1880 hex_index += 2; |
| 1881 remaining_size -= 2; | 1881 remaining_size -= 2; |
| 1882 } | 1882 } |
| 1883 hex_buffer[hex_index] = '\0'; | 1883 hex_buffer[hex_index] = '\0'; |
| 1884 if (out_instr_len) { | 1884 if (out_instr_len) { |
| 1885 *out_instr_len = instruction_length; | 1885 *out_instr_len = instruction_length; |
| 1886 } | 1886 } |
| 1887 return true; | |
| 1888 } | 1887 } |
| 1889 | 1888 |
| 1890 | 1889 |
| 1891 bool Disassembler::Disassemble(uword start, | 1890 void Disassembler::Disassemble(uword start, |
| 1892 uword end, | 1891 uword end, |
| 1893 DisassemblyFormatter* formatter, | 1892 DisassemblyFormatter* formatter, |
| 1894 const Code::Comments& comments) { | 1893 const Code::Comments& comments) { |
| 1895 ASSERT(formatter != NULL); | 1894 ASSERT(formatter != NULL); |
| 1896 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. | 1895 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. |
| 1897 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. | 1896 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. |
| 1898 uword pc = start; | 1897 uword pc = start; |
| 1899 intptr_t comment_finger = 0; | 1898 intptr_t comment_finger = 0; |
| 1900 while (pc < end) { | 1899 while (pc < end) { |
| 1901 const intptr_t offset = pc - start; | 1900 const intptr_t offset = pc - start; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1913 sizeof(human_buffer), | 1912 sizeof(human_buffer), |
| 1914 &instruction_length, pc); | 1913 &instruction_length, pc); |
| 1915 formatter->ConsumeInstruction(hex_buffer, | 1914 formatter->ConsumeInstruction(hex_buffer, |
| 1916 sizeof(hex_buffer), | 1915 sizeof(hex_buffer), |
| 1917 human_buffer, | 1916 human_buffer, |
| 1918 sizeof(human_buffer), | 1917 sizeof(human_buffer), |
| 1919 pc); | 1918 pc); |
| 1920 pc += instruction_length; | 1919 pc += instruction_length; |
| 1921 } | 1920 } |
| 1922 | 1921 |
| 1923 return true; | 1922 return; |
| 1924 } | 1923 } |
| 1925 | 1924 |
| 1926 } // namespace dart | 1925 } // namespace dart |
| 1927 | 1926 |
| 1928 #endif // defined TARGET_ARCH_X64 | 1927 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |