1 //===-- ABI.cpp -------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Other libraries and framework includes
14 #include "lldb/Target/ABI.h"
15 #include "lldb/Core/PluginManager.h"
16 #include "lldb/Core/Value.h"
17 #include "lldb/Core/ValueObjectConstResult.h"
18 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
19 #include "lldb/Symbol/CompilerType.h"
20 #include "lldb/Symbol/TypeSystem.h"
21 #include "lldb/Target/Target.h"
22 #include "lldb/Target/Thread.h"
25 using namespace lldb_private;
28 ABI::FindPlugin (const ArchSpec &arch)
31 ABICreateInstance create_callback;
33 for (uint32_t idx = 0;
34 (create_callback = PluginManager::GetABICreateCallbackAtIndex(idx)) != nullptr;
37 abi_sp = create_callback(arch);
48 ABI::~ABI() = default;
51 ABI::GetRegisterInfoByName (const ConstString &name, RegisterInfo &info)
54 const RegisterInfo *register_info_array = GetRegisterInfoArray (count);
55 if (register_info_array)
57 const char *unique_name_cstr = name.GetCString();
59 for (i = 0; i < count; ++i)
61 if (register_info_array[i].name == unique_name_cstr)
63 info = register_info_array[i];
67 for (i = 0; i < count; ++i)
69 if (register_info_array[i].alt_name == unique_name_cstr)
71 info = register_info_array[i];
80 ABI::GetRegisterInfoByKind (RegisterKind reg_kind, uint32_t reg_num, RegisterInfo &info)
82 if (reg_kind < eRegisterKindEHFrame || reg_kind >= kNumRegisterKinds)
86 const RegisterInfo *register_info_array = GetRegisterInfoArray (count);
87 if (register_info_array)
89 for (uint32_t i = 0; i < count; ++i)
91 if (register_info_array[i].kinds[reg_kind] == reg_num)
93 info = register_info_array[i];
102 ABI::GetReturnValueObject (Thread &thread,
103 CompilerType &ast_type,
104 bool persistent) const
106 if (!ast_type.IsValid())
107 return ValueObjectSP();
109 ValueObjectSP return_valobj_sp;
111 return_valobj_sp = GetReturnValueObjectImpl(thread, ast_type);
112 if (!return_valobj_sp)
113 return return_valobj_sp;
115 // Now turn this into a persistent variable.
116 // FIXME: This code is duplicated from Target::EvaluateExpression, and it is used in similar form in a couple
117 // of other places. Figure out the correct Create function to do all this work.
121 PersistentExpressionState *persistent_expression_state = thread.CalculateTarget()->GetPersistentExpressionStateForLanguage(ast_type.GetMinimumLanguage());
123 if (!persistent_expression_state)
124 return ValueObjectSP();
126 ConstString persistent_variable_name (persistent_expression_state->GetNextPersistentVariableName());
128 lldb::ValueObjectSP const_valobj_sp;
130 // Check in case our value is already a constant value
131 if (return_valobj_sp->GetIsConstant())
133 const_valobj_sp = return_valobj_sp;
134 const_valobj_sp->SetName (persistent_variable_name);
137 const_valobj_sp = return_valobj_sp->CreateConstantValue (persistent_variable_name);
139 lldb::ValueObjectSP live_valobj_sp = return_valobj_sp;
141 return_valobj_sp = const_valobj_sp;
143 ExpressionVariableSP clang_expr_variable_sp(persistent_expression_state->CreatePersistentVariable(return_valobj_sp));
145 assert (clang_expr_variable_sp);
147 // Set flags and live data as appropriate
149 const Value &result_value = live_valobj_sp->GetValue();
151 switch (result_value.GetValueType())
153 case Value::eValueTypeHostAddress:
154 case Value::eValueTypeFileAddress:
155 // we don't do anything with these for now
157 case Value::eValueTypeScalar:
158 case Value::eValueTypeVector:
159 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsFreezeDried;
160 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
161 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
163 case Value::eValueTypeLoadAddress:
164 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
165 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
169 return_valobj_sp = clang_expr_variable_sp->GetValueObject();
171 return return_valobj_sp;
175 ABI::GetReturnValueObject(Thread &thread, llvm::Type &ast_type, bool persistent) const
177 ValueObjectSP return_valobj_sp;
178 return_valobj_sp = GetReturnValueObjectImpl( thread, ast_type );
179 return return_valobj_sp;
182 // specialized to work with llvm IR types
184 // for now we will specify a default implementation so that we don't need to
187 ABI::GetReturnValueObjectImpl( Thread &thread, llvm::Type &ir_type ) const
189 ValueObjectSP return_valobj_sp;
191 /* this is a dummy and will only be called if an ABI does not override this */
193 return return_valobj_sp;
197 ABI::PrepareTrivialCall (Thread &thread,
199 lldb::addr_t functionAddress,
200 lldb::addr_t returnAddress,
201 llvm::Type &returntype,
202 llvm::ArrayRef<ABI::CallArgument> args) const
204 // dummy prepare trivial call
205 assert( !"Should never get here!" );
210 ABI::GetFallbackRegisterLocation (const RegisterInfo *reg_info,
211 UnwindPlan::Row::RegisterLocation &unwind_regloc)
213 // Did the UnwindPlan fail to give us the caller's stack pointer?
214 // The stack pointer is defined to be the same as THIS frame's CFA, so return the CFA value as
215 // the caller's stack pointer. This is true on x86-32/x86-64 at least.
216 if (reg_info->kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_SP)
218 unwind_regloc.SetIsCFAPlusOffset(0);
222 // If a volatile register is being requested, we don't want to forward the next frame's register contents
223 // up the stack -- the register is not retrievable at this frame.
224 if (RegisterIsVolatile(reg_info))
226 unwind_regloc.SetUndefined();