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