1 //===-- ABI.cpp -------------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Target/ABI.h" 11 #include "lldb/Core/PluginManager.h" 12 #include "lldb/Core/Value.h" 13 #include "lldb/Core/ValueObjectConstResult.h" 14 #include "lldb/Symbol/ClangASTType.h" 15 #include "lldb/Target/Thread.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 ABISP 21 ABI::FindPlugin (const ArchSpec &arch) 22 { 23 ABISP abi_sp; 24 ABICreateInstance create_callback; 25 26 for (uint32_t idx = 0; 27 (create_callback = PluginManager::GetABICreateCallbackAtIndex(idx)) != NULL; 28 ++idx) 29 { 30 abi_sp = create_callback(arch); 31 32 if (abi_sp) 33 return abi_sp; 34 } 35 abi_sp.reset(); 36 return abi_sp; 37 } 38 39 //---------------------------------------------------------------------- 40 // Constructor 41 //---------------------------------------------------------------------- 42 ABI::ABI() 43 { 44 } 45 46 //---------------------------------------------------------------------- 47 // Destructor 48 //---------------------------------------------------------------------- 49 ABI::~ABI() 50 { 51 } 52 53 54 bool 55 ABI::GetRegisterInfoByName (const ConstString &name, RegisterInfo &info) 56 { 57 uint32_t count = 0; 58 const RegisterInfo *register_info_array = GetRegisterInfoArray (count); 59 if (register_info_array) 60 { 61 const char *unique_name_cstr = name.GetCString(); 62 uint32_t i; 63 for (i=0; i<count; ++i) 64 { 65 if (register_info_array[i].name == unique_name_cstr) 66 { 67 info = register_info_array[i]; 68 return true; 69 } 70 } 71 for (i=0; i<count; ++i) 72 { 73 if (register_info_array[i].alt_name == unique_name_cstr) 74 { 75 info = register_info_array[i]; 76 return true; 77 } 78 } 79 } 80 return false; 81 } 82 83 bool 84 ABI::GetRegisterInfoByKind (RegisterKind reg_kind, uint32_t reg_num, RegisterInfo &info) 85 { 86 if (reg_kind < eRegisterKindGCC || reg_kind >= kNumRegisterKinds) 87 return false; 88 89 uint32_t count = 0; 90 const RegisterInfo *register_info_array = GetRegisterInfoArray (count); 91 if (register_info_array) 92 { 93 for (uint32_t i=0; i<count; ++i) 94 { 95 if (register_info_array[i].kinds[reg_kind] == reg_num) 96 { 97 info = register_info_array[i]; 98 return true; 99 } 100 } 101 } 102 return false; 103 } 104 105 ValueObjectSP 106 ABI::GetReturnValueObject (Thread &thread, 107 ClangASTType &ast_type) const 108 { 109 if (!ast_type.IsValid()) 110 return ValueObjectSP(); 111 112 Value ret_value; 113 ret_value.SetContext(Value::eContextTypeClangType, 114 ast_type.GetOpaqueQualType()); 115 if (GetReturnValue (thread, ret_value)) 116 { 117 return ValueObjectConstResult::Create( 118 thread.GetStackFrameAtIndex(0).get(), 119 ast_type.GetASTContext(), 120 ret_value, 121 ConstString("FunctionReturn")); 122 123 } 124 else 125 return ValueObjectSP(); 126 } 127 128 129