blob: e02f360680fb87b11808fb2bfbdcba5a7677b44a [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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"
Jim Ingham73ca05a2011-12-17 01:35:57 +000012#include "lldb/Core/Value.h"
13#include "lldb/Core/ValueObjectConstResult.h"
14#include "lldb/Symbol/ClangASTType.h"
Jim Inghamef651602011-12-22 19:12:40 +000015#include "lldb/Target/Target.h"
Jim Ingham73ca05a2011-12-17 01:35:57 +000016#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017
18using namespace lldb;
19using namespace lldb_private;
20
Greg Clayton31f1d2f2011-05-11 18:39:18 +000021ABISP
Greg Clayton514487e2011-02-15 21:59:32 +000022ABI::FindPlugin (const ArchSpec &arch)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023{
Greg Clayton31f1d2f2011-05-11 18:39:18 +000024 ABISP abi_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025 ABICreateInstance create_callback;
26
27 for (uint32_t idx = 0;
28 (create_callback = PluginManager::GetABICreateCallbackAtIndex(idx)) != NULL;
29 ++idx)
30 {
Greg Clayton31f1d2f2011-05-11 18:39:18 +000031 abi_sp = create_callback(arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Clayton31f1d2f2011-05-11 18:39:18 +000033 if (abi_sp)
34 return abi_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035 }
Greg Clayton31f1d2f2011-05-11 18:39:18 +000036 abi_sp.reset();
37 return abi_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038}
39
40//----------------------------------------------------------------------
41// Constructor
42//----------------------------------------------------------------------
43ABI::ABI()
44{
45}
46
47//----------------------------------------------------------------------
48// Destructor
49//----------------------------------------------------------------------
50ABI::~ABI()
51{
52}
Greg Clayton56d9a1b2011-08-22 02:49:39 +000053
Greg Clayton56d9a1b2011-08-22 02:49:39 +000054bool
55ABI::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
83bool
84ABI::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}
Jim Ingham73ca05a2011-12-17 01:35:57 +0000104
105ValueObjectSP
106ABI::GetReturnValueObject (Thread &thread,
Greg Clayton1ac04c32012-02-21 00:09:25 +0000107 ClangASTType &ast_type,
108 bool persistent) const
Jim Ingham73ca05a2011-12-17 01:35:57 +0000109{
110 if (!ast_type.IsValid())
111 return ValueObjectSP();
112
Jim Inghamef651602011-12-22 19:12:40 +0000113 ValueObjectSP return_valobj_sp;
114
115 return_valobj_sp = GetReturnValueObjectImpl(thread, ast_type);
116 if (!return_valobj_sp)
117 return return_valobj_sp;
118
119 // Now turn this into a persistent variable.
120 // FIXME: This code is duplicated from Target::EvaluateExpression, and it is used in similar form in a couple
121 // of other places. Figure out the correct Create function to do all this work.
122
123 if (persistent)
Jim Ingham73ca05a2011-12-17 01:35:57 +0000124 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000125 ClangPersistentVariables& persistent_variables = thread.CalculateTarget()->GetPersistentVariables();
Jim Inghamef651602011-12-22 19:12:40 +0000126 ConstString persistent_variable_name (persistent_variables.GetNextPersistentVariableName());
127
128 lldb::ValueObjectSP const_valobj_sp;
129
130 // Check in case our value is already a constant value
131 if (return_valobj_sp->GetIsConstant())
132 {
133 const_valobj_sp = return_valobj_sp;
134 const_valobj_sp->SetName (persistent_variable_name);
135 }
136 else
137 const_valobj_sp = return_valobj_sp->CreateConstantValue (persistent_variable_name);
138
139 lldb::ValueObjectSP live_valobj_sp = return_valobj_sp;
140
141 return_valobj_sp = const_valobj_sp;
142
143 ClangExpressionVariableSP clang_expr_variable_sp(persistent_variables.CreatePersistentVariable(return_valobj_sp));
144
145 assert (clang_expr_variable_sp.get());
146
147 // Set flags and live data as appropriate
148
149 const Value &result_value = live_valobj_sp->GetValue();
150
151 switch (result_value.GetValueType())
152 {
153 case Value::eValueTypeHostAddress:
154 case Value::eValueTypeFileAddress:
155 // we don't do anything with these for now
156 break;
157 case Value::eValueTypeScalar:
Greg Clayton2fb45d02012-10-30 23:56:14 +0000158 case Value::eValueTypeVector:
Sean Callanan31a8d052012-01-05 01:11:09 +0000159 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsFreezeDried;
Jim Inghamef651602011-12-22 19:12:40 +0000160 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
161 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
162 break;
163 case Value::eValueTypeLoadAddress:
164 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
165 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
166 break;
167 }
Sean Callanan31a8d052012-01-05 01:11:09 +0000168
Jim Inghamef651602011-12-22 19:12:40 +0000169 return_valobj_sp = clang_expr_variable_sp->GetValueObject();
Jim Ingham73ca05a2011-12-17 01:35:57 +0000170 }
Jim Inghamef651602011-12-22 19:12:40 +0000171 return return_valobj_sp;
Jim Ingham73ca05a2011-12-17 01:35:57 +0000172}
173
Deepak Panickal2526ee52014-07-21 17:21:01 +0000174ValueObjectSP
175ABI::GetReturnValueObject(Thread &thread, llvm::Type &ast_type, bool persistent) const
176{
177 ValueObjectSP return_valobj_sp;
178 return_valobj_sp = GetReturnValueObjectImpl( thread, ast_type );
179 return return_valobj_sp;
180}
Jim Ingham73ca05a2011-12-17 01:35:57 +0000181
Deepak Panickal2526ee52014-07-21 17:21:01 +0000182// specialized to work with llvm IR types
183//
184// for now we will specify a default implementation so that we don't need to
185// modify other ABIs
186lldb::ValueObjectSP
187ABI::GetReturnValueObjectImpl( Thread &thread, llvm::Type &ir_type ) const
188{
189 ValueObjectSP return_valobj_sp;
190
191 /* this is a dummy and will only be called if an ABI does not override this */
192
193 return return_valobj_sp;
194}
195
196bool
197ABI::PrepareTrivialCall (Thread &thread,
198 lldb::addr_t sp,
199 lldb::addr_t functionAddress,
200 lldb::addr_t returnAddress,
201 llvm::Type &returntype,
202 llvm::ArrayRef<ABI::CallArgument> args) const
203{
204 // dummy prepare trivial call
205 assert( !"Should never get here!" );
206 return false;
207}