Greg Clayton | 9b8ff51 | 2012-02-01 01:46:19 +0000 | [diff] [blame] | 1 | //===-- ObjCLanguageRuntime.cpp ---------------------------------*- C++ -*-===// |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 9 | #include "clang/AST/Type.h" |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 10 | |
Jim Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 11 | #include "lldb/Core/Log.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Module.h" |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 13 | #include "lldb/Core/PluginManager.h" |
Jim Ingham | 324067b | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 14 | #include "lldb/Core/ValueObject.h" |
| 15 | #include "lldb/Symbol/ClangASTContext.h" |
Jim Ingham | ef80aab | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/Type.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/TypeList.h" |
Jim Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 18 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Target.h" |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | //---------------------------------------------------------------------- |
| 25 | // Destructor |
| 26 | //---------------------------------------------------------------------- |
| 27 | ObjCLanguageRuntime::~ObjCLanguageRuntime() |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | ObjCLanguageRuntime::ObjCLanguageRuntime (Process *process) : |
Sean Callanan | 6e12c7a | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 32 | LanguageRuntime (process), |
Sean Callanan | 6fe8d36 | 2012-09-15 01:05:12 +0000 | [diff] [blame] | 33 | m_has_new_literals_and_indexing (eLazyBoolCalculate), |
Greg Clayton | a510437 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 34 | m_isa_to_descriptor_cache(), |
Sean Callanan | 6fe8d36 | 2012-09-15 01:05:12 +0000 | [diff] [blame] | 35 | m_isa_to_descriptor_cache_is_up_to_date (false) |
Jim Ingham | 642036f | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 36 | { |
| 37 | |
Jim Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void |
| 41 | ObjCLanguageRuntime::AddToMethodCache (lldb::addr_t class_addr, lldb::addr_t selector, lldb::addr_t impl_addr) |
| 42 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 43 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 44 | if (log) |
| 45 | { |
| 46 | log->Printf ("Caching: class 0x%llx selector 0x%llx implementation 0x%llx.", class_addr, selector, impl_addr); |
| 47 | } |
| 48 | m_impl_cache.insert (std::pair<ClassAndSel,lldb::addr_t> (ClassAndSel(class_addr, selector), impl_addr)); |
| 49 | } |
| 50 | |
| 51 | lldb::addr_t |
| 52 | ObjCLanguageRuntime::LookupInMethodCache (lldb::addr_t class_addr, lldb::addr_t selector) |
| 53 | { |
| 54 | MsgImplMap::iterator pos, end = m_impl_cache.end(); |
| 55 | pos = m_impl_cache.find (ClassAndSel(class_addr, selector)); |
| 56 | if (pos != end) |
| 57 | return (*pos).second; |
| 58 | return LLDB_INVALID_ADDRESS; |
| 59 | } |
Jim Ingham | ef80aab | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 60 | |
Jim Ingham | 5851366 | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 61 | |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 62 | lldb::TypeSP |
| 63 | ObjCLanguageRuntime::LookupInCompleteClassCache (ConstString &name) |
| 64 | { |
| 65 | CompleteClassMap::iterator complete_class_iter = m_complete_class_cache.find(name); |
| 66 | |
| 67 | if (complete_class_iter != m_complete_class_cache.end()) |
| 68 | { |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 69 | // Check the weak pointer to make sure the type hasn't been unloaded |
| 70 | TypeSP complete_type_sp (complete_class_iter->second.lock()); |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 71 | |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 72 | if (complete_type_sp) |
| 73 | return complete_type_sp; |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 74 | else |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 75 | m_complete_class_cache.erase(name); |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | ModuleList &modules = m_process->GetTarget().GetImages(); |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 79 | |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 80 | SymbolContextList sc_list; |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 81 | const size_t matching_symbols = modules.FindSymbolsWithNameAndType (name, |
| 82 | eSymbolTypeObjCClass, |
| 83 | sc_list); |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 84 | |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 85 | if (matching_symbols) |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 86 | { |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 87 | SymbolContext sc; |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 88 | |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 89 | sc_list.GetContextAtIndex(0, sc); |
| 90 | |
| 91 | ModuleSP module_sp(sc.module_sp); |
| 92 | |
| 93 | if (!module_sp) |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 94 | return TypeSP(); |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 95 | |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 96 | const SymbolContext null_sc; |
| 97 | const bool exact_match = true; |
| 98 | const uint32_t max_matches = UINT32_MAX; |
| 99 | TypeList types; |
| 100 | |
| 101 | const uint32_t num_types = module_sp->FindTypes (null_sc, |
| 102 | name, |
| 103 | exact_match, |
| 104 | max_matches, |
| 105 | types); |
| 106 | |
| 107 | if (num_types) |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 108 | { |
Greg Clayton | ef22b90 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 109 | TypeSP incomplete_type_sp; |
| 110 | |
| 111 | uint32_t i; |
| 112 | for (i = 0; i < num_types; ++i) |
| 113 | { |
| 114 | TypeSP type_sp (types.GetTypeAtIndex(i)); |
| 115 | |
| 116 | if (ClangASTContext::IsObjCClassType(type_sp->GetClangForwardType())) |
| 117 | { |
| 118 | if (type_sp->IsCompleteObjCClass()) |
| 119 | { |
| 120 | m_complete_class_cache[name] = type_sp; |
| 121 | return type_sp; |
| 122 | } |
| 123 | else if (!incomplete_type_sp) |
| 124 | incomplete_type_sp = type_sp; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // We didn't find any "real" definitions, so just use any??? Why was |
| 129 | // this being done? Prior to this, if there was 1 match only, then it |
| 130 | // would always use any objc definition, else we would only accept a |
| 131 | // definition if it was the real thing???? Doesn't make sense. |
| 132 | |
| 133 | if (incomplete_type_sp) |
| 134 | { |
| 135 | m_complete_class_cache[name] = incomplete_type_sp; |
| 136 | return incomplete_type_sp; |
| 137 | } |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 140 | return TypeSP(); |
| 141 | } |
| 142 | |
Jim Ingham | 5851366 | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 143 | size_t |
| 144 | ObjCLanguageRuntime::GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name) |
| 145 | { |
| 146 | return LLDB_INVALID_IVAR_OFFSET; |
| 147 | } |
| 148 | |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 149 | |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 150 | uint32_t |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 151 | ObjCLanguageRuntime::ParseMethodName (const char *name, |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 152 | ConstString *class_name, // Class name (with category if any) |
| 153 | ConstString *selector_name, // selector on its own |
| 154 | ConstString *name_sans_category, // Full function prototype with no category |
| 155 | ConstString *class_name_sans_category)// Class name with no category (or empty if no category as answer will be in "class_name" |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 156 | { |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 157 | if (class_name) |
| 158 | class_name->Clear(); |
| 159 | if (selector_name) |
| 160 | selector_name->Clear(); |
| 161 | if (name_sans_category) |
| 162 | name_sans_category->Clear(); |
| 163 | if (class_name_sans_category) |
| 164 | class_name_sans_category->Clear(); |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 165 | |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 166 | uint32_t result = 0; |
| 167 | |
Jim Ingham | fdf24ef | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 168 | if (IsPossibleObjCMethodName (name)) |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 169 | { |
| 170 | int name_len = strlen (name); |
| 171 | // Objective C methods must have at least: |
| 172 | // "-[" or "+[" prefix |
| 173 | // One character for a class name |
| 174 | // One character for the space between the class name |
| 175 | // One character for the method name |
| 176 | // "]" suffix |
| 177 | if (name_len >= 6 && name[name_len - 1] == ']') |
| 178 | { |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 179 | const char *selector_name_ptr = strchr (name, ' '); |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 180 | if (selector_name_ptr) |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 181 | { |
| 182 | if (class_name) |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 183 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 184 | class_name->SetCStringWithLength (name + 2, selector_name_ptr - name - 2); |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 185 | ++result; |
| 186 | } |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 187 | |
| 188 | // Skip the space |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 189 | ++selector_name_ptr; |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 190 | // Extract the objective C basename and add it to the |
| 191 | // accelerator tables |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 192 | size_t selector_name_len = name_len - (selector_name_ptr - name) - 1; |
| 193 | if (selector_name) |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 194 | { |
Greg Clayton | 00db215 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 195 | selector_name->SetCStringWithLength (selector_name_ptr, selector_name_len); |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 196 | ++result; |
| 197 | } |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 198 | |
| 199 | // Also see if this is a "category" on our class. If so strip off the category name, |
| 200 | // and add the class name without it to the basename table. |
| 201 | |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 202 | if (name_sans_category || class_name_sans_category) |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 203 | { |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 204 | const char *open_paren = strchr (name, '('); |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 205 | if (open_paren) |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 206 | { |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 207 | if (class_name_sans_category) |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 208 | { |
Greg Clayton | e14d3d3 | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 209 | class_name_sans_category->SetCStringWithLength (name + 2, open_paren - name - 2); |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 210 | ++result; |
| 211 | } |
Sean Callanan | c1cd379 | 2012-01-19 01:10:27 +0000 | [diff] [blame] | 212 | |
| 213 | if (name_sans_category) |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 214 | { |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 215 | const char *close_paren = strchr (open_paren, ')'); |
| 216 | if (open_paren < close_paren) |
Sean Callanan | c1cd379 | 2012-01-19 01:10:27 +0000 | [diff] [blame] | 217 | { |
| 218 | std::string buffer (name, open_paren - name); |
| 219 | buffer.append (close_paren + 1); |
| 220 | name_sans_category->SetCString (buffer.c_str()); |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 221 | ++result; |
Sean Callanan | c1cd379 | 2012-01-19 01:10:27 +0000 | [diff] [blame] | 222 | } |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 227 | } |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 228 | } |
Greg Clayton | 662e567 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 229 | return result; |
Jim Ingham | 3ad4da0 | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 230 | } |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 231 | |
| 232 | bool |
| 233 | ObjCLanguageRuntime::ClassDescriptor::IsPointerValid (lldb::addr_t value, |
| 234 | uint32_t ptr_size, |
| 235 | bool allow_NULLs, |
| 236 | bool allow_tagged, |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 237 | bool check_version_specific) const |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 238 | { |
| 239 | if (!value) |
| 240 | return allow_NULLs; |
| 241 | if ( (value % 2) == 1 && allow_tagged) |
| 242 | return true; |
| 243 | if ((value % ptr_size) == 0) |
| 244 | return (check_version_specific ? CheckPointer(value,ptr_size) : true); |
| 245 | else |
| 246 | return false; |
| 247 | } |
| 248 | |
| 249 | ObjCLanguageRuntime::ObjCISA |
Sean Callanan | c718b96 | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 250 | ObjCLanguageRuntime::GetISA(const ConstString &name) |
| 251 | { |
Sean Callanan | 6fe8d36 | 2012-09-15 01:05:12 +0000 | [diff] [blame] | 252 | UpdateISAToDescriptorMap(); |
Sean Callanan | c718b96 | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 253 | for (const ISAToDescriptorMap::value_type &val : m_isa_to_descriptor_cache) |
| 254 | if (val.second && val.second->GetClassName() == name) |
| 255 | return val.first; |
Sean Callanan | c718b96 | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | ObjCLanguageRuntime::ObjCISA |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 260 | ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) |
| 261 | { |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 262 | ClassDescriptorSP objc_class_sp (GetClassDescriptor(isa)); |
| 263 | if (objc_class_sp) |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 264 | { |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 265 | ClassDescriptorSP objc_super_class_sp (objc_class_sp->GetSuperclass()); |
| 266 | if (objc_super_class_sp) |
| 267 | return objc_super_class_sp->GetISA(); |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 268 | } |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 269 | return 0; |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 272 | ConstString |
| 273 | ObjCLanguageRuntime::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) |
| 274 | { |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 275 | ClassDescriptorSP objc_class_sp (GetNonKVOClassDescriptor(isa)); |
| 276 | if (objc_class_sp) |
| 277 | return objc_class_sp->GetClassName(); |
| 278 | return ConstString(); |
Enrico Granata | ae2ae94 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 279 | } |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 280 | |
| 281 | ObjCLanguageRuntime::ClassDescriptorSP |
Greg Clayton | a510437 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 282 | ObjCLanguageRuntime::GetClassDescriptor (const ConstString &class_name) |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 283 | { |
Greg Clayton | a510437 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 284 | UpdateISAToDescriptorMap(); |
| 285 | for (const ISAToDescriptorMap::value_type &val : m_isa_to_descriptor_cache) |
| 286 | if (val.second && val.second->GetClassName() == class_name) |
| 287 | return val.second; |
| 288 | return ClassDescriptorSP(); |
| 289 | |
| 290 | } |
| 291 | |
| 292 | ObjCLanguageRuntime::ClassDescriptorSP |
| 293 | ObjCLanguageRuntime::GetClassDescriptor (ValueObject& valobj) |
| 294 | { |
| 295 | ClassDescriptorSP objc_class_sp; |
| 296 | // if we get an invalid VO (which might still happen when playing around |
| 297 | // with pointers returned by the expression parser, don't consider this |
| 298 | // a valid ObjC object) |
| 299 | if (valobj.GetValue().GetContextType() != Value::eContextTypeInvalid) |
| 300 | { |
| 301 | addr_t isa_pointer = valobj.GetPointerValue(); |
| 302 | if (isa_pointer != LLDB_INVALID_ADDRESS) |
| 303 | { |
| 304 | ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); |
| 305 | |
| 306 | Process *process = exe_ctx.GetProcessPtr(); |
| 307 | if (process) |
| 308 | { |
| 309 | Error error; |
| 310 | ObjCISA isa = process->ReadPointerFromMemory(isa_pointer, error); |
| 311 | if (isa != LLDB_INVALID_ADDRESS) |
| 312 | objc_class_sp = GetClassDescriptor (isa); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | return objc_class_sp; |
| 317 | } |
| 318 | |
| 319 | ObjCLanguageRuntime::ClassDescriptorSP |
| 320 | ObjCLanguageRuntime::GetNonKVOClassDescriptor (ValueObject& valobj) |
| 321 | { |
| 322 | ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (GetClassDescriptor (valobj)); |
| 323 | if (objc_class_sp) |
| 324 | { |
| 325 | if (!objc_class_sp->IsKVO()) |
| 326 | return objc_class_sp; |
| 327 | |
| 328 | ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass()); |
| 329 | if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid()) |
| 330 | return non_kvo_objc_class_sp; |
| 331 | } |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 332 | return ClassDescriptorSP(); |
| 333 | } |
| 334 | |
Greg Clayton | a510437 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 335 | |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 336 | ObjCLanguageRuntime::ClassDescriptorSP |
| 337 | ObjCLanguageRuntime::GetClassDescriptor (ObjCISA isa) |
| 338 | { |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 339 | if (isa) |
| 340 | { |
Greg Clayton | a510437 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 341 | UpdateISAToDescriptorMap(); |
| 342 | ObjCLanguageRuntime::ISAToDescriptorIterator pos = m_isa_to_descriptor_cache.find(isa); |
| 343 | if (pos != m_isa_to_descriptor_cache.end()) |
| 344 | return pos->second; |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 345 | } |
Greg Clayton | a510437 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 346 | return ClassDescriptorSP(); |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | ObjCLanguageRuntime::ClassDescriptorSP |
| 350 | ObjCLanguageRuntime::GetNonKVOClassDescriptor (ObjCISA isa) |
| 351 | { |
| 352 | if (isa) |
| 353 | { |
| 354 | ClassDescriptorSP objc_class_sp = GetClassDescriptor (isa); |
| 355 | if (objc_class_sp && objc_class_sp->IsValid()) |
| 356 | { |
Greg Clayton | a510437 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 357 | if (!objc_class_sp->IsKVO()) |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 358 | return objc_class_sp; |
Greg Clayton | a510437 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 359 | |
| 360 | ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass()); |
| 361 | if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid()) |
| 362 | return non_kvo_objc_class_sp; |
Greg Clayton | be2f3aa | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | return ClassDescriptorSP(); |
| 366 | } |
| 367 | |
| 368 | |
| 369 | |