Greg Clayton | 05e8d19 | 2012-02-01 01:46:19 +0000 | [diff] [blame] | 1 | //===-- ObjCLanguageRuntime.cpp ---------------------------------*- C++ -*-===// |
Jim Ingham | 2277701 | 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 | 6c68fb4 | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 9 | #include "clang/AST/Type.h" |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 10 | |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 11 | #include "lldb/Core/Log.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Module.h" |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 13 | #include "lldb/Core/PluginManager.h" |
Jim Ingham | 6c68fb4 | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 14 | #include "lldb/Core/ValueObject.h" |
| 15 | #include "lldb/Symbol/ClangASTContext.h" |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/Type.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/TypeList.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 18 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Target.h" |
Jim Ingham | 2277701 | 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 | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 32 | LanguageRuntime (process), |
Sean Callanan | c09d9d8 | 2012-09-15 01:05:12 +0000 | [diff] [blame] | 33 | m_has_new_literals_and_indexing (eLazyBoolCalculate), |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame^] | 34 | m_isa_to_descriptor_cache(), |
Sean Callanan | c09d9d8 | 2012-09-15 01:05:12 +0000 | [diff] [blame] | 35 | m_isa_to_descriptor_cache_is_up_to_date (false) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 36 | { |
| 37 | |
Jim Ingham | 5a36912 | 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 | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 43 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 5a36912 | 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 | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 60 | |
| 61 | void |
| 62 | ObjCLanguageRuntime::AddToClassNameCache (lldb::addr_t class_addr, const char *name, lldb::TypeSP type_sp) |
| 63 | { |
| 64 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 65 | if (log) |
| 66 | { |
| 67 | log->Printf ("Caching: class 0x%llx name: %s.", class_addr, name); |
| 68 | } |
| 69 | |
| 70 | TypeAndOrName class_type_or_name; |
| 71 | |
Greg Clayton | 85ae2e1 | 2011-10-18 23:36:41 +0000 | [diff] [blame] | 72 | if (type_sp) |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 73 | class_type_or_name.SetTypeSP (type_sp); |
| 74 | else if (name && *name != '\0') |
| 75 | class_type_or_name.SetName (name); |
| 76 | else |
| 77 | return; |
| 78 | m_class_name_cache.insert (std::pair<lldb::addr_t,TypeAndOrName> (class_addr, class_type_or_name)); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | ObjCLanguageRuntime::AddToClassNameCache (lldb::addr_t class_addr, const TypeAndOrName &class_type_or_name) |
| 83 | { |
| 84 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 85 | if (log) |
| 86 | { |
| 87 | log->Printf ("Caching: class 0x%llx name: %s.", class_addr, class_type_or_name.GetName().AsCString()); |
| 88 | } |
| 89 | |
| 90 | m_class_name_cache.insert (std::pair<lldb::addr_t,TypeAndOrName> (class_addr, class_type_or_name)); |
| 91 | } |
| 92 | |
| 93 | TypeAndOrName |
| 94 | ObjCLanguageRuntime::LookupInClassNameCache (lldb::addr_t class_addr) |
| 95 | { |
| 96 | ClassNameMap::iterator pos, end = m_class_name_cache.end(); |
| 97 | pos = m_class_name_cache.find (class_addr); |
| 98 | if (pos != end) |
| 99 | return (*pos).second; |
| 100 | return TypeAndOrName (); |
| 101 | } |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 102 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 103 | lldb::TypeSP |
| 104 | ObjCLanguageRuntime::LookupInCompleteClassCache (ConstString &name) |
| 105 | { |
| 106 | CompleteClassMap::iterator complete_class_iter = m_complete_class_cache.find(name); |
| 107 | |
| 108 | if (complete_class_iter != m_complete_class_cache.end()) |
| 109 | { |
| 110 | TypeSP ret(complete_class_iter->second); |
| 111 | |
| 112 | if (!ret) |
| 113 | m_complete_class_cache.erase(name); |
| 114 | else |
| 115 | return TypeSP(complete_class_iter->second); |
| 116 | } |
| 117 | |
| 118 | ModuleList &modules = m_process->GetTarget().GetImages(); |
| 119 | |
| 120 | SymbolContextList sc_list; |
| 121 | |
| 122 | modules.FindSymbolsWithNameAndType(name, eSymbolTypeObjCClass, sc_list); |
| 123 | |
| 124 | if (sc_list.GetSize() == 0) |
| 125 | return TypeSP(); |
| 126 | |
| 127 | SymbolContext sc; |
| 128 | |
| 129 | sc_list.GetContextAtIndex(0, sc); |
| 130 | |
| 131 | ModuleSP module_sp(sc.module_sp); |
| 132 | |
| 133 | if (!module_sp) |
| 134 | return TypeSP(); |
| 135 | |
| 136 | const SymbolContext null_sc; |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 137 | const bool exact_match = true; |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 138 | const uint32_t max_matches = UINT32_MAX; |
| 139 | TypeList types; |
| 140 | |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 141 | module_sp->FindTypes (null_sc, |
| 142 | name, |
| 143 | exact_match, |
| 144 | max_matches, |
| 145 | types); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 146 | |
| 147 | if (types.GetSize() == 1) |
| 148 | { |
| 149 | TypeSP candidate_type = types.GetTypeAtIndex(0); |
| 150 | |
| 151 | if (ClangASTContext::IsObjCClassType(candidate_type->GetClangForwardType())) |
| 152 | { |
| 153 | m_complete_class_cache[name] = TypeWP(candidate_type); |
| 154 | return candidate_type; |
| 155 | } |
| 156 | else |
| 157 | { |
| 158 | return TypeSP(); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | for (uint32_t ti = 0, te = types.GetSize(); |
| 163 | ti < te; |
| 164 | ++ti) |
| 165 | { |
| 166 | TypeSP candidate_type = types.GetTypeAtIndex(ti); |
| 167 | |
| 168 | if (candidate_type->IsCompleteObjCClass() && |
| 169 | ClangASTContext::IsObjCClassType(candidate_type->GetClangForwardType())) |
| 170 | { |
| 171 | m_complete_class_cache[name] = TypeWP(candidate_type); |
| 172 | return candidate_type; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | return TypeSP(); |
| 177 | } |
| 178 | |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 179 | size_t |
| 180 | ObjCLanguageRuntime::GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name) |
| 181 | { |
| 182 | return LLDB_INVALID_IVAR_OFFSET; |
| 183 | } |
| 184 | |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 185 | |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 186 | uint32_t |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 187 | ObjCLanguageRuntime::ParseMethodName (const char *name, |
Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 188 | ConstString *class_name, // Class name (with category if any) |
| 189 | ConstString *selector_name, // selector on its own |
| 190 | ConstString *name_sans_category, // Full function prototype with no category |
| 191 | ConstString *class_name_sans_category)// Class name with no category (or empty if no category as answer will be in "class_name" |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 192 | { |
Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 193 | if (class_name) |
| 194 | class_name->Clear(); |
| 195 | if (selector_name) |
| 196 | selector_name->Clear(); |
| 197 | if (name_sans_category) |
| 198 | name_sans_category->Clear(); |
| 199 | if (class_name_sans_category) |
| 200 | class_name_sans_category->Clear(); |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 201 | |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 202 | uint32_t result = 0; |
| 203 | |
Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 204 | if (IsPossibleObjCMethodName (name)) |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 205 | { |
| 206 | int name_len = strlen (name); |
| 207 | // Objective C methods must have at least: |
| 208 | // "-[" or "+[" prefix |
| 209 | // One character for a class name |
| 210 | // One character for the space between the class name |
| 211 | // One character for the method name |
| 212 | // "]" suffix |
| 213 | if (name_len >= 6 && name[name_len - 1] == ']') |
| 214 | { |
Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 215 | const char *selector_name_ptr = strchr (name, ' '); |
Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 216 | if (selector_name_ptr) |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 217 | { |
| 218 | if (class_name) |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 219 | { |
Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 220 | class_name->SetCStringWithLength (name + 2, selector_name_ptr - name - 2); |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 221 | ++result; |
| 222 | } |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 223 | |
| 224 | // Skip the space |
Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 225 | ++selector_name_ptr; |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 226 | // Extract the objective C basename and add it to the |
| 227 | // accelerator tables |
Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 228 | size_t selector_name_len = name_len - (selector_name_ptr - name) - 1; |
| 229 | if (selector_name) |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 230 | { |
Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 231 | selector_name->SetCStringWithLength (selector_name_ptr, selector_name_len); |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 232 | ++result; |
| 233 | } |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 234 | |
| 235 | // Also see if this is a "category" on our class. If so strip off the category name, |
| 236 | // and add the class name without it to the basename table. |
| 237 | |
Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 238 | if (name_sans_category || class_name_sans_category) |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 239 | { |
Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 240 | const char *open_paren = strchr (name, '('); |
Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 241 | if (open_paren) |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 242 | { |
Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 243 | if (class_name_sans_category) |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 244 | { |
Greg Clayton | 278a16b | 2012-01-19 00:52:59 +0000 | [diff] [blame] | 245 | class_name_sans_category->SetCStringWithLength (name + 2, open_paren - name - 2); |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 246 | ++result; |
| 247 | } |
Sean Callanan | b811e4b | 2012-01-19 01:10:27 +0000 | [diff] [blame] | 248 | |
| 249 | if (name_sans_category) |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 250 | { |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 251 | const char *close_paren = strchr (open_paren, ')'); |
| 252 | if (open_paren < close_paren) |
Sean Callanan | b811e4b | 2012-01-19 01:10:27 +0000 | [diff] [blame] | 253 | { |
| 254 | std::string buffer (name, open_paren - name); |
| 255 | buffer.append (close_paren + 1); |
| 256 | name_sans_category->SetCString (buffer.c_str()); |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 257 | ++result; |
Sean Callanan | b811e4b | 2012-01-19 01:10:27 +0000 | [diff] [blame] | 258 | } |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 263 | } |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 264 | } |
Greg Clayton | e42ae84 | 2012-01-19 03:24:53 +0000 | [diff] [blame] | 265 | return result; |
Jim Ingham | ff5f5ff | 2011-08-15 01:32:22 +0000 | [diff] [blame] | 266 | } |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 267 | |
| 268 | bool |
| 269 | ObjCLanguageRuntime::ClassDescriptor::IsPointerValid (lldb::addr_t value, |
| 270 | uint32_t ptr_size, |
| 271 | bool allow_NULLs, |
| 272 | bool allow_tagged, |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 273 | bool check_version_specific) const |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 274 | { |
| 275 | if (!value) |
| 276 | return allow_NULLs; |
| 277 | if ( (value % 2) == 1 && allow_tagged) |
| 278 | return true; |
| 279 | if ((value % ptr_size) == 0) |
| 280 | return (check_version_specific ? CheckPointer(value,ptr_size) : true); |
| 281 | else |
| 282 | return false; |
| 283 | } |
| 284 | |
| 285 | ObjCLanguageRuntime::ObjCISA |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 286 | ObjCLanguageRuntime::GetISA(const ConstString &name) |
| 287 | { |
Sean Callanan | c09d9d8 | 2012-09-15 01:05:12 +0000 | [diff] [blame] | 288 | UpdateISAToDescriptorMap(); |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 289 | for (const ISAToDescriptorMap::value_type &val : m_isa_to_descriptor_cache) |
| 290 | if (val.second && val.second->GetClassName() == name) |
| 291 | return val.first; |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | ObjCLanguageRuntime::ObjCISA |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 296 | ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) |
| 297 | { |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 298 | ClassDescriptorSP objc_class_sp (GetClassDescriptor(isa)); |
| 299 | if (objc_class_sp) |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 300 | { |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 301 | ClassDescriptorSP objc_super_class_sp (objc_class_sp->GetSuperclass()); |
| 302 | if (objc_super_class_sp) |
| 303 | return objc_super_class_sp->GetISA(); |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 304 | } |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 305 | return 0; |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 308 | ConstString |
| 309 | ObjCLanguageRuntime::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) |
| 310 | { |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 311 | ClassDescriptorSP objc_class_sp (GetNonKVOClassDescriptor(isa)); |
| 312 | if (objc_class_sp) |
| 313 | return objc_class_sp->GetClassName(); |
| 314 | return ConstString(); |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 315 | } |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 316 | |
| 317 | ObjCLanguageRuntime::ClassDescriptorSP |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame^] | 318 | ObjCLanguageRuntime::GetClassDescriptor (const ConstString &class_name) |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 319 | { |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame^] | 320 | UpdateISAToDescriptorMap(); |
| 321 | for (const ISAToDescriptorMap::value_type &val : m_isa_to_descriptor_cache) |
| 322 | if (val.second && val.second->GetClassName() == class_name) |
| 323 | return val.second; |
| 324 | return ClassDescriptorSP(); |
| 325 | |
| 326 | } |
| 327 | |
| 328 | ObjCLanguageRuntime::ClassDescriptorSP |
| 329 | ObjCLanguageRuntime::GetClassDescriptor (ValueObject& valobj) |
| 330 | { |
| 331 | ClassDescriptorSP objc_class_sp; |
| 332 | // if we get an invalid VO (which might still happen when playing around |
| 333 | // with pointers returned by the expression parser, don't consider this |
| 334 | // a valid ObjC object) |
| 335 | if (valobj.GetValue().GetContextType() != Value::eContextTypeInvalid) |
| 336 | { |
| 337 | addr_t isa_pointer = valobj.GetPointerValue(); |
| 338 | if (isa_pointer != LLDB_INVALID_ADDRESS) |
| 339 | { |
| 340 | ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); |
| 341 | |
| 342 | Process *process = exe_ctx.GetProcessPtr(); |
| 343 | if (process) |
| 344 | { |
| 345 | Error error; |
| 346 | ObjCISA isa = process->ReadPointerFromMemory(isa_pointer, error); |
| 347 | if (isa != LLDB_INVALID_ADDRESS) |
| 348 | objc_class_sp = GetClassDescriptor (isa); |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | return objc_class_sp; |
| 353 | } |
| 354 | |
| 355 | ObjCLanguageRuntime::ClassDescriptorSP |
| 356 | ObjCLanguageRuntime::GetNonKVOClassDescriptor (ValueObject& valobj) |
| 357 | { |
| 358 | ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (GetClassDescriptor (valobj)); |
| 359 | if (objc_class_sp) |
| 360 | { |
| 361 | if (!objc_class_sp->IsKVO()) |
| 362 | return objc_class_sp; |
| 363 | |
| 364 | ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass()); |
| 365 | if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid()) |
| 366 | return non_kvo_objc_class_sp; |
| 367 | } |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 368 | return ClassDescriptorSP(); |
| 369 | } |
| 370 | |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame^] | 371 | |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 372 | ObjCLanguageRuntime::ClassDescriptorSP |
| 373 | ObjCLanguageRuntime::GetClassDescriptor (ObjCISA isa) |
| 374 | { |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 375 | if (isa) |
| 376 | { |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame^] | 377 | UpdateISAToDescriptorMap(); |
| 378 | ObjCLanguageRuntime::ISAToDescriptorIterator pos = m_isa_to_descriptor_cache.find(isa); |
| 379 | if (pos != m_isa_to_descriptor_cache.end()) |
| 380 | return pos->second; |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 381 | } |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame^] | 382 | return ClassDescriptorSP(); |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | ObjCLanguageRuntime::ClassDescriptorSP |
| 386 | ObjCLanguageRuntime::GetNonKVOClassDescriptor (ObjCISA isa) |
| 387 | { |
| 388 | if (isa) |
| 389 | { |
| 390 | ClassDescriptorSP objc_class_sp = GetClassDescriptor (isa); |
| 391 | if (objc_class_sp && objc_class_sp->IsValid()) |
| 392 | { |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame^] | 393 | if (!objc_class_sp->IsKVO()) |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 394 | return objc_class_sp; |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame^] | 395 | |
| 396 | ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass()); |
| 397 | if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid()) |
| 398 | return non_kvo_objc_class_sp; |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | return ClassDescriptorSP(); |
| 402 | } |
| 403 | |
| 404 | |
| 405 | |