| 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 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 int Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size, | 1868 int 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 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 return instruction_length; | 1884 if (out_instr_len) { |
| 1885 *out_instr_len = instruction_length; |
| 1886 } |
| 1887 return true; |
| 1885 } | 1888 } |
| 1886 | 1889 |
| 1887 | 1890 |
| 1888 void Disassembler::Disassemble(uword start, | 1891 bool Disassembler::Disassemble(uword start, |
| 1889 uword end, | 1892 uword end, |
| 1890 DisassemblyFormatter* formatter, | 1893 DisassemblyFormatter* formatter, |
| 1891 const Code::Comments& comments) { | 1894 const Code::Comments& comments) { |
| 1892 ASSERT(formatter != NULL); | 1895 ASSERT(formatter != NULL); |
| 1893 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. | 1896 char hex_buffer[kHexadecimalBufferSize]; // Instruction in hexadecimal form. |
| 1894 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. | 1897 char human_buffer[kUserReadableBufferSize]; // Human-readable instruction. |
| 1895 uword pc = start; | 1898 uword pc = start; |
| 1896 intptr_t comment_finger = 0; | 1899 intptr_t comment_finger = 0; |
| 1897 while (pc < end) { | 1900 while (pc < end) { |
| 1898 const intptr_t offset = pc - start; | 1901 const intptr_t offset = pc - start; |
| 1899 while (comment_finger < comments.Length() && | 1902 while (comment_finger < comments.Length() && |
| 1900 comments.PCOffsetAt(comment_finger) <= offset) { | 1903 comments.PCOffsetAt(comment_finger) <= offset) { |
| 1901 formatter->Print( | 1904 formatter->Print( |
| 1902 " ;; %s\n", | 1905 " ;; %s\n", |
| 1903 String::Handle(comments.CommentAt(comment_finger)).ToCString()); | 1906 String::Handle(comments.CommentAt(comment_finger)).ToCString()); |
| 1904 comment_finger++; | 1907 comment_finger++; |
| 1905 } | 1908 } |
| 1906 int instruction_length = DecodeInstruction(hex_buffer, | 1909 int instruction_length; |
| 1907 sizeof(hex_buffer), | 1910 DecodeInstruction(hex_buffer, |
| 1908 human_buffer, | 1911 sizeof(hex_buffer), |
| 1909 sizeof(human_buffer), | 1912 human_buffer, |
| 1910 pc); | 1913 sizeof(human_buffer), |
| 1914 &instruction_length, pc); |
| 1911 formatter->ConsumeInstruction(hex_buffer, | 1915 formatter->ConsumeInstruction(hex_buffer, |
| 1912 sizeof(hex_buffer), | 1916 sizeof(hex_buffer), |
| 1913 human_buffer, | 1917 human_buffer, |
| 1914 sizeof(human_buffer), | 1918 sizeof(human_buffer), |
| 1915 pc); | 1919 pc); |
| 1916 pc += instruction_length; | 1920 pc += instruction_length; |
| 1917 } | 1921 } |
| 1922 |
| 1923 return true; |
| 1918 } | 1924 } |
| 1919 | 1925 |
| 1920 } // namespace dart | 1926 } // namespace dart |
| 1921 | 1927 |
| 1922 #endif // defined TARGET_ARCH_X64 | 1928 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |