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 | a66c4d9 | 2013-02-13 22:56:14 +0000 | [diff] [blame] | 12 | #include "lldb/Core/MappedHash.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 14 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Timer.h" |
Jim Ingham | 6c68fb4 | 2010-09-30 00:54:27 +0000 | [diff] [blame] | 16 | #include "lldb/Core/ValueObject.h" |
| 17 | #include "lldb/Symbol/ClangASTContext.h" |
Zachary Turner | 32abc6e | 2015-03-03 19:23:09 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/SymbolContext.h" |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/Type.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/TypeList.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 21 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Target.h" |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 23 | |
Greg Clayton | 1b3815c | 2013-01-30 00:18:29 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringRef.h" |
| 25 | |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 26 | using namespace lldb; |
| 27 | using namespace lldb_private; |
| 28 | |
| 29 | //---------------------------------------------------------------------- |
| 30 | // Destructor |
| 31 | //---------------------------------------------------------------------- |
| 32 | ObjCLanguageRuntime::~ObjCLanguageRuntime() |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | ObjCLanguageRuntime::ObjCLanguageRuntime (Process *process) : |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 37 | LanguageRuntime (process), |
Enrico Granata | 3842b9f | 2015-01-28 00:45:42 +0000 | [diff] [blame] | 38 | m_impl_cache(), |
Sean Callanan | c09d9d8 | 2012-09-15 01:05:12 +0000 | [diff] [blame] | 39 | m_has_new_literals_and_indexing (eLazyBoolCalculate), |
Greg Clayton | a66c4d9 | 2013-02-13 22:56:14 +0000 | [diff] [blame] | 40 | m_isa_to_descriptor(), |
Enrico Granata | 3842b9f | 2015-01-28 00:45:42 +0000 | [diff] [blame] | 41 | m_hash_to_isa_map(), |
| 42 | m_type_size_cache(), |
| 43 | m_isa_to_descriptor_stop_id (UINT32_MAX), |
| 44 | m_complete_class_cache(), |
| 45 | m_negative_complete_class_cache() |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 46 | { |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Greg Clayton | a66c4d9 | 2013-02-13 22:56:14 +0000 | [diff] [blame] | 49 | bool |
| 50 | ObjCLanguageRuntime::AddClass (ObjCISA isa, const ClassDescriptorSP &descriptor_sp, const char *class_name) |
| 51 | { |
| 52 | if (isa != 0) |
| 53 | { |
| 54 | m_isa_to_descriptor[isa] = descriptor_sp; |
| 55 | // class_name is assumed to be valid |
| 56 | m_hash_to_isa_map.insert(std::make_pair(MappedHash::HashStringUsingDJB(class_name), isa)); |
| 57 | return true; |
| 58 | } |
| 59 | return false; |
| 60 | } |
| 61 | |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 62 | void |
| 63 | ObjCLanguageRuntime::AddToMethodCache (lldb::addr_t class_addr, lldb::addr_t selector, lldb::addr_t impl_addr) |
| 64 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 65 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 66 | if (log) |
| 67 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 68 | log->Printf ("Caching: class 0x%" PRIx64 " selector 0x%" PRIx64 " implementation 0x%" PRIx64 ".", class_addr, selector, impl_addr); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 69 | } |
| 70 | m_impl_cache.insert (std::pair<ClassAndSel,lldb::addr_t> (ClassAndSel(class_addr, selector), impl_addr)); |
| 71 | } |
| 72 | |
| 73 | lldb::addr_t |
| 74 | ObjCLanguageRuntime::LookupInMethodCache (lldb::addr_t class_addr, lldb::addr_t selector) |
| 75 | { |
| 76 | MsgImplMap::iterator pos, end = m_impl_cache.end(); |
| 77 | pos = m_impl_cache.find (ClassAndSel(class_addr, selector)); |
| 78 | if (pos != end) |
| 79 | return (*pos).second; |
| 80 | return LLDB_INVALID_ADDRESS; |
| 81 | } |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 82 | |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 83 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 84 | lldb::TypeSP |
| 85 | ObjCLanguageRuntime::LookupInCompleteClassCache (ConstString &name) |
| 86 | { |
| 87 | CompleteClassMap::iterator complete_class_iter = m_complete_class_cache.find(name); |
| 88 | |
| 89 | if (complete_class_iter != m_complete_class_cache.end()) |
| 90 | { |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 91 | // Check the weak pointer to make sure the type hasn't been unloaded |
| 92 | TypeSP complete_type_sp (complete_class_iter->second.lock()); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 93 | |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 94 | if (complete_type_sp) |
| 95 | return complete_type_sp; |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 96 | else |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 97 | m_complete_class_cache.erase(name); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Enrico Granata | f15ee4e | 2013-04-05 18:49:06 +0000 | [diff] [blame] | 100 | if (m_negative_complete_class_cache.count(name) > 0) |
| 101 | return TypeSP(); |
| 102 | |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 103 | const ModuleList &modules = m_process->GetTarget().GetImages(); |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 104 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 105 | SymbolContextList sc_list; |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 106 | const size_t matching_symbols = modules.FindSymbolsWithNameAndType (name, |
| 107 | eSymbolTypeObjCClass, |
| 108 | sc_list); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 109 | |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 110 | if (matching_symbols) |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 111 | { |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 112 | SymbolContext sc; |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 113 | |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 114 | sc_list.GetContextAtIndex(0, sc); |
| 115 | |
| 116 | ModuleSP module_sp(sc.module_sp); |
| 117 | |
| 118 | if (!module_sp) |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 119 | return TypeSP(); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 120 | |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 121 | const SymbolContext null_sc; |
| 122 | const bool exact_match = true; |
| 123 | const uint32_t max_matches = UINT32_MAX; |
| 124 | TypeList types; |
| 125 | |
| 126 | const uint32_t num_types = module_sp->FindTypes (null_sc, |
| 127 | name, |
| 128 | exact_match, |
| 129 | max_matches, |
| 130 | types); |
| 131 | |
| 132 | if (num_types) |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 133 | { |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 134 | uint32_t i; |
| 135 | for (i = 0; i < num_types; ++i) |
| 136 | { |
| 137 | TypeSP type_sp (types.GetTypeAtIndex(i)); |
| 138 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 139 | if (ClangASTContext::IsObjCObjectOrInterfaceType(type_sp->GetForwardCompilerType ())) |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 140 | { |
| 141 | if (type_sp->IsCompleteObjCClass()) |
| 142 | { |
| 143 | m_complete_class_cache[name] = type_sp; |
| 144 | return type_sp; |
| 145 | } |
Greg Clayton | d64dd12 | 2012-10-23 22:41:19 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
Enrico Granata | f15ee4e | 2013-04-05 18:49:06 +0000 | [diff] [blame] | 150 | m_negative_complete_class_cache.insert(name); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 151 | return TypeSP(); |
| 152 | } |
| 153 | |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 154 | size_t |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 155 | ObjCLanguageRuntime::GetByteOffsetForIvar (CompilerType &parent_qual_type, const char *ivar_name) |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 156 | { |
| 157 | return LLDB_INVALID_IVAR_OFFSET; |
| 158 | } |
| 159 | |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 160 | bool |
| 161 | ObjCLanguageRuntime::ClassDescriptor::IsPointerValid (lldb::addr_t value, |
| 162 | uint32_t ptr_size, |
| 163 | bool allow_NULLs, |
| 164 | bool allow_tagged, |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 165 | bool check_version_specific) const |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 166 | { |
| 167 | if (!value) |
| 168 | return allow_NULLs; |
| 169 | if ( (value % 2) == 1 && allow_tagged) |
| 170 | return true; |
| 171 | if ((value % ptr_size) == 0) |
| 172 | return (check_version_specific ? CheckPointer(value,ptr_size) : true); |
| 173 | else |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | ObjCLanguageRuntime::ObjCISA |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 178 | ObjCLanguageRuntime::GetISA(const ConstString &name) |
| 179 | { |
Greg Clayton | a66c4d9 | 2013-02-13 22:56:14 +0000 | [diff] [blame] | 180 | ISAToDescriptorIterator pos = GetDescriptorIterator (name); |
| 181 | if (pos != m_isa_to_descriptor.end()) |
| 182 | return pos->first; |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
Greg Clayton | a66c4d9 | 2013-02-13 22:56:14 +0000 | [diff] [blame] | 186 | ObjCLanguageRuntime::ISAToDescriptorIterator |
| 187 | ObjCLanguageRuntime::GetDescriptorIterator (const ConstString &name) |
| 188 | { |
| 189 | ISAToDescriptorIterator end = m_isa_to_descriptor.end(); |
| 190 | |
| 191 | if (name) |
| 192 | { |
| 193 | UpdateISAToDescriptorMap(); |
| 194 | if (m_hash_to_isa_map.empty()) |
| 195 | { |
| 196 | // No name hashes were provided, we need to just linearly power through the |
| 197 | // names and find a match |
| 198 | for (ISAToDescriptorIterator pos = m_isa_to_descriptor.begin(); pos != end; ++pos) |
| 199 | { |
| 200 | if (pos->second->GetClassName() == name) |
| 201 | return pos; |
| 202 | } |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | // Name hashes were provided, so use them to efficiently lookup name to isa/descriptor |
| 207 | const uint32_t name_hash = MappedHash::HashStringUsingDJB (name.GetCString()); |
| 208 | std::pair <HashToISAIterator, HashToISAIterator> range = m_hash_to_isa_map.equal_range(name_hash); |
| 209 | for (HashToISAIterator range_pos = range.first; range_pos != range.second; ++range_pos) |
| 210 | { |
| 211 | ISAToDescriptorIterator pos = m_isa_to_descriptor.find (range_pos->second); |
| 212 | if (pos != m_isa_to_descriptor.end()) |
| 213 | { |
| 214 | if (pos->second->GetClassName() == name) |
| 215 | return pos; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | return end; |
| 221 | } |
| 222 | |
Enrico Granata | ba4b8b0 | 2015-05-06 21:01:07 +0000 | [diff] [blame] | 223 | std::pair<ObjCLanguageRuntime::ISAToDescriptorIterator,ObjCLanguageRuntime::ISAToDescriptorIterator> |
| 224 | ObjCLanguageRuntime::GetDescriptorIteratorPair (bool update_if_needed) |
| 225 | { |
| 226 | if (update_if_needed) |
| 227 | UpdateISAToDescriptorMapIfNeeded(); |
Colin Riley | 5de4251 | 2015-05-08 12:17:27 +0000 | [diff] [blame] | 228 | |
| 229 | return std::pair<ObjCLanguageRuntime::ISAToDescriptorIterator, |
| 230 | ObjCLanguageRuntime::ISAToDescriptorIterator>( |
| 231 | m_isa_to_descriptor.begin(), |
| 232 | m_isa_to_descriptor.end()); |
Enrico Granata | ba4b8b0 | 2015-05-06 21:01:07 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Greg Clayton | a66c4d9 | 2013-02-13 22:56:14 +0000 | [diff] [blame] | 235 | |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 236 | ObjCLanguageRuntime::ObjCISA |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 237 | ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) |
| 238 | { |
Greg Clayton | 03da4cc | 2013-04-19 21:31:16 +0000 | [diff] [blame] | 239 | ClassDescriptorSP objc_class_sp (GetClassDescriptorFromISA(isa)); |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 240 | if (objc_class_sp) |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 241 | { |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 242 | ClassDescriptorSP objc_super_class_sp (objc_class_sp->GetSuperclass()); |
| 243 | if (objc_super_class_sp) |
| 244 | return objc_super_class_sp->GetISA(); |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 245 | } |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 246 | return 0; |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 249 | ConstString |
| 250 | ObjCLanguageRuntime::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) |
| 251 | { |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 252 | ClassDescriptorSP objc_class_sp (GetNonKVOClassDescriptor(isa)); |
| 253 | if (objc_class_sp) |
| 254 | return objc_class_sp->GetClassName(); |
| 255 | return ConstString(); |
Enrico Granata | 3467d80 | 2012-09-04 18:47:54 +0000 | [diff] [blame] | 256 | } |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 257 | |
| 258 | ObjCLanguageRuntime::ClassDescriptorSP |
Greg Clayton | 03da4cc | 2013-04-19 21:31:16 +0000 | [diff] [blame] | 259 | ObjCLanguageRuntime::GetClassDescriptorFromClassName (const ConstString &class_name) |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 260 | { |
Greg Clayton | a66c4d9 | 2013-02-13 22:56:14 +0000 | [diff] [blame] | 261 | ISAToDescriptorIterator pos = GetDescriptorIterator (class_name); |
| 262 | if (pos != m_isa_to_descriptor.end()) |
| 263 | return pos->second; |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 264 | return ClassDescriptorSP(); |
| 265 | |
| 266 | } |
| 267 | |
| 268 | ObjCLanguageRuntime::ClassDescriptorSP |
| 269 | ObjCLanguageRuntime::GetClassDescriptor (ValueObject& valobj) |
| 270 | { |
| 271 | ClassDescriptorSP objc_class_sp; |
| 272 | // if we get an invalid VO (which might still happen when playing around |
| 273 | // with pointers returned by the expression parser, don't consider this |
| 274 | // a valid ObjC object) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 275 | if (valobj.GetCompilerType().IsValid()) |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 276 | { |
| 277 | addr_t isa_pointer = valobj.GetPointerValue(); |
| 278 | if (isa_pointer != LLDB_INVALID_ADDRESS) |
| 279 | { |
| 280 | ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); |
| 281 | |
| 282 | Process *process = exe_ctx.GetProcessPtr(); |
| 283 | if (process) |
| 284 | { |
| 285 | Error error; |
| 286 | ObjCISA isa = process->ReadPointerFromMemory(isa_pointer, error); |
| 287 | if (isa != LLDB_INVALID_ADDRESS) |
Greg Clayton | 03da4cc | 2013-04-19 21:31:16 +0000 | [diff] [blame] | 288 | objc_class_sp = GetClassDescriptorFromISA (isa); |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | } |
| 292 | return objc_class_sp; |
| 293 | } |
| 294 | |
| 295 | ObjCLanguageRuntime::ClassDescriptorSP |
| 296 | ObjCLanguageRuntime::GetNonKVOClassDescriptor (ValueObject& valobj) |
| 297 | { |
| 298 | ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (GetClassDescriptor (valobj)); |
| 299 | if (objc_class_sp) |
| 300 | { |
| 301 | if (!objc_class_sp->IsKVO()) |
| 302 | return objc_class_sp; |
| 303 | |
| 304 | ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass()); |
| 305 | if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid()) |
| 306 | return non_kvo_objc_class_sp; |
| 307 | } |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 308 | return ClassDescriptorSP(); |
| 309 | } |
| 310 | |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 311 | |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 312 | ObjCLanguageRuntime::ClassDescriptorSP |
Greg Clayton | 03da4cc | 2013-04-19 21:31:16 +0000 | [diff] [blame] | 313 | ObjCLanguageRuntime::GetClassDescriptorFromISA (ObjCISA isa) |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 314 | { |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 315 | if (isa) |
| 316 | { |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 317 | UpdateISAToDescriptorMap(); |
Greg Clayton | a66c4d9 | 2013-02-13 22:56:14 +0000 | [diff] [blame] | 318 | ObjCLanguageRuntime::ISAToDescriptorIterator pos = m_isa_to_descriptor.find(isa); |
| 319 | if (pos != m_isa_to_descriptor.end()) |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 320 | return pos->second; |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 321 | } |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 322 | return ClassDescriptorSP(); |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | ObjCLanguageRuntime::ClassDescriptorSP |
| 326 | ObjCLanguageRuntime::GetNonKVOClassDescriptor (ObjCISA isa) |
| 327 | { |
| 328 | if (isa) |
| 329 | { |
Greg Clayton | 03da4cc | 2013-04-19 21:31:16 +0000 | [diff] [blame] | 330 | ClassDescriptorSP objc_class_sp = GetClassDescriptorFromISA (isa); |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 331 | if (objc_class_sp && objc_class_sp->IsValid()) |
| 332 | { |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 333 | if (!objc_class_sp->IsKVO()) |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 334 | return objc_class_sp; |
Greg Clayton | f0246d1 | 2012-10-11 18:07:21 +0000 | [diff] [blame] | 335 | |
| 336 | ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass()); |
| 337 | if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid()) |
| 338 | return non_kvo_objc_class_sp; |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | return ClassDescriptorSP(); |
| 342 | } |
| 343 | |
| 344 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 345 | CompilerType |
Sean Callanan | a330933 | 2014-10-31 18:02:30 +0000 | [diff] [blame] | 346 | ObjCLanguageRuntime::EncodingToType::RealizeType (const char* name, bool for_expression) |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 347 | { |
| 348 | if (m_scratch_ast_ctx_ap) |
Sean Callanan | a330933 | 2014-10-31 18:02:30 +0000 | [diff] [blame] | 349 | return RealizeType(*m_scratch_ast_ctx_ap, name, for_expression); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 350 | return CompilerType(); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 351 | } |
Greg Clayton | 77fbc81 | 2012-10-09 17:51:53 +0000 | [diff] [blame] | 352 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 353 | CompilerType |
Sean Callanan | a330933 | 2014-10-31 18:02:30 +0000 | [diff] [blame] | 354 | ObjCLanguageRuntime::EncodingToType::RealizeType (ClangASTContext& ast_ctx, const char* name, bool for_expression) |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 355 | { |
| 356 | clang::ASTContext *clang_ast = ast_ctx.getASTContext(); |
| 357 | if (!clang_ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 358 | return CompilerType(); |
Sean Callanan | a330933 | 2014-10-31 18:02:30 +0000 | [diff] [blame] | 359 | return RealizeType(*clang_ast, name, for_expression); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | ObjCLanguageRuntime::EncodingToType::~EncodingToType() {} |
| 363 | |
| 364 | ObjCLanguageRuntime::EncodingToTypeSP |
| 365 | ObjCLanguageRuntime::GetEncodingToType () |
| 366 | { |
| 367 | return nullptr; |
| 368 | } |
Enrico Granata | 3842b9f | 2015-01-28 00:45:42 +0000 | [diff] [blame] | 369 | |
| 370 | bool |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 371 | ObjCLanguageRuntime::GetTypeBitSize (const CompilerType& compiler_type, |
Enrico Granata | 3842b9f | 2015-01-28 00:45:42 +0000 | [diff] [blame] | 372 | uint64_t &size) |
| 373 | { |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 374 | void *opaque_ptr = compiler_type.GetOpaqueQualType(); |
Enrico Granata | 3842b9f | 2015-01-28 00:45:42 +0000 | [diff] [blame] | 375 | size = m_type_size_cache.Lookup(opaque_ptr); |
| 376 | // an ObjC object will at least have an ISA, so 0 is definitely not OK |
| 377 | if (size > 0) |
| 378 | return true; |
| 379 | |
Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 380 | ClassDescriptorSP class_descriptor_sp = GetClassDescriptorFromClassName(compiler_type.GetTypeName()); |
Enrico Granata | 3842b9f | 2015-01-28 00:45:42 +0000 | [diff] [blame] | 381 | if (!class_descriptor_sp) |
| 382 | return false; |
| 383 | |
| 384 | int32_t max_offset = INT32_MIN; |
| 385 | uint64_t sizeof_max = 0; |
| 386 | bool found = false; |
| 387 | |
| 388 | for (size_t idx = 0; |
| 389 | idx < class_descriptor_sp->GetNumIVars(); |
| 390 | idx++) |
| 391 | { |
| 392 | const auto& ivar = class_descriptor_sp->GetIVarAtIndex(idx); |
| 393 | int32_t cur_offset = ivar.m_offset; |
| 394 | if (cur_offset > max_offset) |
| 395 | { |
| 396 | max_offset = cur_offset; |
| 397 | sizeof_max = ivar.m_size; |
| 398 | found = true; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | size = 8 * (max_offset + sizeof_max); |
| 403 | if (found) |
| 404 | m_type_size_cache.Insert(opaque_ptr, size); |
| 405 | |
| 406 | return found; |
| 407 | } |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 408 | |
| 409 | //------------------------------------------------------------------ |
| 410 | // Exception breakpoint Precondition class for ObjC: |
| 411 | //------------------------------------------------------------------ |
| 412 | void |
| 413 | ObjCLanguageRuntime::ObjCExceptionPrecondition::AddClassName(const char *class_name) |
| 414 | { |
| 415 | m_class_names.insert(class_name); |
| 416 | } |
| 417 | |
| 418 | ObjCLanguageRuntime::ObjCExceptionPrecondition::ObjCExceptionPrecondition() |
| 419 | { |
| 420 | } |
| 421 | |
| 422 | bool |
| 423 | ObjCLanguageRuntime::ObjCExceptionPrecondition::EvaluatePrecondition(StoppointCallbackContext &context) |
| 424 | { |
| 425 | return true; |
| 426 | } |
| 427 | |
| 428 | void |
| 429 | ObjCLanguageRuntime::ObjCExceptionPrecondition::DescribePrecondition(Stream &stream, lldb::DescriptionLevel level) |
| 430 | { |
| 431 | } |
| 432 | |
| 433 | Error |
| 434 | ObjCLanguageRuntime::ObjCExceptionPrecondition::ConfigurePrecondition(Args &args) |
| 435 | { |
| 436 | Error error; |
| 437 | if (args.GetArgumentCount() > 0) |
| 438 | error.SetErrorString("The ObjC Exception breakpoint doesn't support extra options."); |
| 439 | return error; |
| 440 | } |