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