| 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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 static const char* ObjectToCStringNoGC(const Object& obj) { | 783 static const char* ObjectToCStringNoGC(const Object& obj) { |
| 784 if (obj.IsSmi() || | 784 if (obj.IsSmi() || |
| 785 obj.IsMint() || | 785 obj.IsMint() || |
| 786 obj.IsDouble() || | 786 obj.IsDouble() || |
| 787 obj.IsString() || | 787 obj.IsString() || |
| 788 obj.IsNull() || | 788 obj.IsNull() || |
| 789 obj.IsBool() || | 789 obj.IsBool() || |
| 790 obj.IsClass() || | 790 obj.IsClass() || |
| 791 obj.IsFunction() || | 791 obj.IsFunction() || |
| 792 obj.IsICData() || | 792 obj.IsICData() || |
| 793 obj.IsField()) { | 793 obj.IsField() || |
| 794 obj.IsCode()) { |
| 794 return obj.ToCString(); | 795 return obj.ToCString(); |
| 795 } | 796 } |
| 796 | 797 |
| 797 const Class& clazz = Class::Handle(obj.clazz()); | 798 const Class& clazz = Class::Handle(obj.clazz()); |
| 798 const char* full_class_name = clazz.ToCString(); | 799 const char* full_class_name = clazz.ToCString(); |
| 799 return OS::SCreate(Thread::Current()->zone(), | 800 return OS::SCreate(Thread::Current()->zone(), |
| 800 "instance of %s", full_class_name); | 801 "instance of %s", full_class_name); |
| 801 } | 802 } |
| 802 | 803 |
| 803 | 804 |
| 804 void DisassemblerX64::AppendAddressToBuffer(uint8_t* addr_byte_ptr) { | 805 void DisassemblerX64::AppendAddressToBuffer(uint8_t* addr_byte_ptr) { |
| 805 uword addr = reinterpret_cast<uword>(addr_byte_ptr); | 806 uword addr = reinterpret_cast<uword>(addr_byte_ptr); |
| 806 AppendToBuffer("%#" Px "", addr); | 807 AppendToBuffer("%#" Px "", addr); |
| 807 // Try to print as heap object or stub name | 808 // Try to print as heap object or stub name |
| 808 if (((addr & kSmiTagMask) == kHeapObjectTag) && | 809 if (((addr & kSmiTagMask) == kHeapObjectTag) && |
| 809 reinterpret_cast<RawObject*>(addr)->IsWellFormed() && | 810 reinterpret_cast<RawObject*>(addr)->IsWellFormed() && |
| 810 reinterpret_cast<RawObject*>(addr)->IsOldObject() && | 811 reinterpret_cast<RawObject*>(addr)->IsOldObject() && |
| 812 !Dart::vm_isolate()->heap()->CodeContains(addr) && |
| 811 !Isolate::Current()->heap()->CodeContains(addr) && | 813 !Isolate::Current()->heap()->CodeContains(addr) && |
| 812 Disassembler::CanFindOldObject(addr)) { | 814 Disassembler::CanFindOldObject(addr)) { |
| 813 NoSafepointScope no_safepoint; | 815 NoSafepointScope no_safepoint; |
| 814 const Object& obj = Object::Handle(reinterpret_cast<RawObject*>(addr)); | 816 const Object& obj = Object::Handle(reinterpret_cast<RawObject*>(addr)); |
| 815 if (obj.IsArray()) { | 817 if (obj.IsArray()) { |
| 816 const Array& arr = Array::Cast(obj); | 818 const Array& arr = Array::Cast(obj); |
| 817 intptr_t len = arr.Length(); | 819 intptr_t len = arr.Length(); |
| 818 if (len > 5) len = 5; // Print a max of 5 elements. | 820 if (len > 5) len = 5; // Print a max of 5 elements. |
| 819 AppendToBuffer(" Array["); | 821 AppendToBuffer(" Array["); |
| 820 int i = 0; | 822 int i = 0; |
| 821 Object& element = Object::Handle(); | 823 Object& element = Object::Handle(); |
| 822 while (i < len) { | 824 while (i < len) { |
| 823 element = arr.At(i); | 825 element = arr.At(i); |
| 824 if (i > 0) AppendToBuffer(", "); | 826 if (i > 0) AppendToBuffer(", "); |
| 825 AppendToBuffer("%s", ObjectToCStringNoGC(element)); | 827 AppendToBuffer("%s", ObjectToCStringNoGC(element)); |
| 826 i++; | 828 i++; |
| 827 } | 829 } |
| 828 if (i < arr.Length()) AppendToBuffer(", ..."); | 830 if (i < arr.Length()) AppendToBuffer(", ..."); |
| 829 AppendToBuffer("]"); | 831 AppendToBuffer("]"); |
| 830 return; | 832 return; |
| 831 } | 833 } |
| 832 AppendToBuffer(" '%s'", ObjectToCStringNoGC(obj)); | 834 AppendToBuffer(" '%s'", ObjectToCStringNoGC(obj)); |
| 833 } else { | 835 } else { |
| 834 // 'addr' is not an object, but probably a code address. | 836 // 'addr' is not an object, but probably a code address. |
| 835 const char* name_of_stub = StubCode::NameOfStub(addr); | 837 const char* name_of_stub = StubCode::NameOfStub(addr); |
| 836 if (name_of_stub != NULL) { | 838 if (name_of_stub != NULL) { |
| 837 AppendToBuffer(" [stub: %s]", name_of_stub); | 839 AppendToBuffer(" [stub: %s]", name_of_stub); |
| 838 } else { | |
| 839 // Print only if jumping to entry point. | |
| 840 const Code& code = Code::Handle(Code::LookupCode(addr)); | |
| 841 if (!code.IsNull() && (code.EntryPoint() == addr)) { | |
| 842 const String& name = String::Handle(code.PrettyName()); | |
| 843 const char* name_c = name.ToCString(); | |
| 844 AppendToBuffer(" [%s]", name_c); | |
| 845 } | |
| 846 } | 840 } |
| 847 } | 841 } |
| 848 } | 842 } |
| 849 | 843 |
| 850 | 844 |
| 851 // Returns number of bytes used, including *data. | 845 // Returns number of bytes used, including *data. |
| 852 int DisassemblerX64::JumpShort(uint8_t* data) { | 846 int DisassemblerX64::JumpShort(uint8_t* data) { |
| 853 ASSERT(0xEB == *data); | 847 ASSERT(0xEB == *data); |
| 854 uint8_t b = *(data + 1); | 848 uint8_t b = *(data + 1); |
| 855 uint8_t* dest = data + static_cast<int8_t>(b) + 2; | 849 uint8_t* dest = data + static_cast<int8_t>(b) + 2; |
| (...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 } | 1943 } |
| 1950 hex_buffer[hex_index] = '\0'; | 1944 hex_buffer[hex_index] = '\0'; |
| 1951 if (out_instr_len) { | 1945 if (out_instr_len) { |
| 1952 *out_instr_len = instruction_length; | 1946 *out_instr_len = instruction_length; |
| 1953 } | 1947 } |
| 1954 } | 1948 } |
| 1955 | 1949 |
| 1956 } // namespace dart | 1950 } // namespace dart |
| 1957 | 1951 |
| 1958 #endif // defined TARGET_ARCH_X64 | 1952 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |