blob: f3a5404aa1009133958d198145b77d11a2beca8b [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"
15#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016
17using namespace lldb;
18using namespace lldb_private;
19
Greg Clayton31f1d2f2011-05-11 18:39:18 +000020ABISP
Greg Clayton514487e2011-02-15 21:59:32 +000021ABI::FindPlugin (const ArchSpec &arch)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022{
Greg Clayton31f1d2f2011-05-11 18:39:18 +000023 ABISP abi_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024 ABICreateInstance create_callback;
25
26 for (uint32_t idx = 0;
27 (create_callback = PluginManager::GetABICreateCallbackAtIndex(idx)) != NULL;
28 ++idx)
29 {
Greg Clayton31f1d2f2011-05-11 18:39:18 +000030 abi_sp = create_callback(arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
Greg Clayton31f1d2f2011-05-11 18:39:18 +000032 if (abi_sp)
33 return abi_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034 }
Greg Clayton31f1d2f2011-05-11 18:39:18 +000035 abi_sp.reset();
36 return abi_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037}
38
39//----------------------------------------------------------------------
40// Constructor
41//----------------------------------------------------------------------
42ABI::ABI()
43{
44}
45
46//----------------------------------------------------------------------
47// Destructor
48//----------------------------------------------------------------------
49ABI::~ABI()
50{
51}
Greg Clayton56d9a1b2011-08-22 02:49:39 +000052
53
54bool
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,
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