blob: a567a8802af745847f08ba2b249780c2d06319c0 [file] [log] [blame]
Greg Clayton9b8ff512012-02-01 01:46:19 +00001//===-- ObjCLanguageRuntime.cpp ---------------------------------*- C++ -*-===//
Jim Ingham642036f2010-09-23 02:01:19 +00002//
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 Ingham324067b2010-09-30 00:54:27 +00009#include "clang/AST/Type.h"
Jim Ingham642036f2010-09-23 02:01:19 +000010
Jim Inghamb66cd072010-09-28 01:25:32 +000011#include "lldb/Core/Log.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000012#include "lldb/Core/Module.h"
Jim Ingham642036f2010-09-23 02:01:19 +000013#include "lldb/Core/PluginManager.h"
Greg Claytonf892c422013-01-30 00:18:29 +000014#include "lldb/Core/Timer.h"
Jim Ingham324067b2010-09-30 00:54:27 +000015#include "lldb/Core/ValueObject.h"
16#include "lldb/Symbol/ClangASTContext.h"
Jim Inghamef80aab2011-05-02 18:13:59 +000017#include "lldb/Symbol/Type.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000018#include "lldb/Symbol/TypeList.h"
Jim Inghamb66cd072010-09-28 01:25:32 +000019#include "lldb/Target/ObjCLanguageRuntime.h"
Sean Callanan931acec2012-02-22 23:57:45 +000020#include "lldb/Target/Target.h"
Jim Ingham642036f2010-09-23 02:01:19 +000021
Greg Claytonf892c422013-01-30 00:18:29 +000022#include "llvm/ADT/StringRef.h"
23
Jim Ingham642036f2010-09-23 02:01:19 +000024using namespace lldb;
25using namespace lldb_private;
26
27//----------------------------------------------------------------------
28// Destructor
29//----------------------------------------------------------------------
30ObjCLanguageRuntime::~ObjCLanguageRuntime()
31{
32}
33
34ObjCLanguageRuntime::ObjCLanguageRuntime (Process *process) :
Sean Callanan6e12c7a2012-03-08 02:39:03 +000035 LanguageRuntime (process),
Sean Callanan6fe8d362012-09-15 01:05:12 +000036 m_has_new_literals_and_indexing (eLazyBoolCalculate),
Greg Claytona5104372012-10-11 18:07:21 +000037 m_isa_to_descriptor_cache(),
Greg Clayton90c6cd52012-10-25 16:54:22 +000038 m_isa_to_descriptor_cache_stop_id (UINT32_MAX)
Jim Ingham642036f2010-09-23 02:01:19 +000039{
40
Jim Inghamb66cd072010-09-28 01:25:32 +000041}
42
43void
44ObjCLanguageRuntime::AddToMethodCache (lldb::addr_t class_addr, lldb::addr_t selector, lldb::addr_t impl_addr)
45{
Greg Claytone005f2c2010-11-06 01:53:30 +000046 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghamb66cd072010-09-28 01:25:32 +000047 if (log)
48 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +000049 log->Printf ("Caching: class 0x%" PRIx64 " selector 0x%" PRIx64 " implementation 0x%" PRIx64 ".", class_addr, selector, impl_addr);
Jim Inghamb66cd072010-09-28 01:25:32 +000050 }
51 m_impl_cache.insert (std::pair<ClassAndSel,lldb::addr_t> (ClassAndSel(class_addr, selector), impl_addr));
52}
53
54lldb::addr_t
55ObjCLanguageRuntime::LookupInMethodCache (lldb::addr_t class_addr, lldb::addr_t selector)
56{
57 MsgImplMap::iterator pos, end = m_impl_cache.end();
58 pos = m_impl_cache.find (ClassAndSel(class_addr, selector));
59 if (pos != end)
60 return (*pos).second;
61 return LLDB_INVALID_ADDRESS;
62}
Jim Inghamef80aab2011-05-02 18:13:59 +000063
Jim Ingham58513662011-06-24 22:03:24 +000064
Sean Callanan931acec2012-02-22 23:57:45 +000065lldb::TypeSP
66ObjCLanguageRuntime::LookupInCompleteClassCache (ConstString &name)
67{
68 CompleteClassMap::iterator complete_class_iter = m_complete_class_cache.find(name);
69
70 if (complete_class_iter != m_complete_class_cache.end())
71 {
Greg Claytonef22b902012-10-23 22:41:19 +000072 // Check the weak pointer to make sure the type hasn't been unloaded
73 TypeSP complete_type_sp (complete_class_iter->second.lock());
Sean Callanan931acec2012-02-22 23:57:45 +000074
Greg Claytonef22b902012-10-23 22:41:19 +000075 if (complete_type_sp)
76 return complete_type_sp;
Sean Callanan931acec2012-02-22 23:57:45 +000077 else
Greg Claytonef22b902012-10-23 22:41:19 +000078 m_complete_class_cache.erase(name);
Sean Callanan931acec2012-02-22 23:57:45 +000079 }
80
Enrico Granata146d9522012-11-08 02:22:02 +000081 const ModuleList &modules = m_process->GetTarget().GetImages();
Greg Claytonef22b902012-10-23 22:41:19 +000082
Sean Callanan931acec2012-02-22 23:57:45 +000083 SymbolContextList sc_list;
Greg Claytonef22b902012-10-23 22:41:19 +000084 const size_t matching_symbols = modules.FindSymbolsWithNameAndType (name,
85 eSymbolTypeObjCClass,
86 sc_list);
Sean Callanan931acec2012-02-22 23:57:45 +000087
Greg Claytonef22b902012-10-23 22:41:19 +000088 if (matching_symbols)
Sean Callanan931acec2012-02-22 23:57:45 +000089 {
Greg Claytonef22b902012-10-23 22:41:19 +000090 SymbolContext sc;
Sean Callanan931acec2012-02-22 23:57:45 +000091
Greg Claytonef22b902012-10-23 22:41:19 +000092 sc_list.GetContextAtIndex(0, sc);
93
94 ModuleSP module_sp(sc.module_sp);
95
96 if (!module_sp)
Sean Callanan931acec2012-02-22 23:57:45 +000097 return TypeSP();
Sean Callanan931acec2012-02-22 23:57:45 +000098
Greg Claytonef22b902012-10-23 22:41:19 +000099 const SymbolContext null_sc;
100 const bool exact_match = true;
101 const uint32_t max_matches = UINT32_MAX;
102 TypeList types;
103
104 const uint32_t num_types = module_sp->FindTypes (null_sc,
105 name,
106 exact_match,
107 max_matches,
108 types);
109
110 if (num_types)
Sean Callanan282c22c2012-12-19 23:05:01 +0000111 {
Greg Claytonef22b902012-10-23 22:41:19 +0000112 uint32_t i;
113 for (i = 0; i < num_types; ++i)
114 {
115 TypeSP type_sp (types.GetTypeAtIndex(i));
116
117 if (ClangASTContext::IsObjCClassType(type_sp->GetClangForwardType()))
118 {
119 if (type_sp->IsCompleteObjCClass())
120 {
121 m_complete_class_cache[name] = type_sp;
122 return type_sp;
123 }
Greg Claytonef22b902012-10-23 22:41:19 +0000124 }
125 }
Sean Callanan931acec2012-02-22 23:57:45 +0000126 }
127 }
Sean Callanan931acec2012-02-22 23:57:45 +0000128 return TypeSP();
129}
130
Jim Ingham58513662011-06-24 22:03:24 +0000131size_t
132ObjCLanguageRuntime::GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name)
133{
134 return LLDB_INVALID_IVAR_OFFSET;
135}
136
Greg Claytonf892c422013-01-30 00:18:29 +0000137void
138ObjCLanguageRuntime::MethodName::Clear()
Jim Ingham3ad4da02011-08-15 01:32:22 +0000139{
Greg Claytonf892c422013-01-30 00:18:29 +0000140 m_full.Clear();
141 m_class.Clear();
142 m_category.Clear();
143 m_selector.Clear();
144 m_type = eTypeUnspecified;
145 m_category_is_valid = false;
146}
Greg Clayton662e5672012-01-19 03:24:53 +0000147
Greg Claytonf892c422013-01-30 00:18:29 +0000148//bool
149//ObjCLanguageRuntime::MethodName::SetName (const char *name, bool strict)
150//{
151// Clear();
152// if (name && name[0])
153// {
154// // If "strict" is true. then the method must be specified with a
155// // '+' or '-' at the beginning. If "strict" is false, then the '+'
156// // or '-' can be omitted
157// bool valid_prefix = false;
158//
159// if (name[0] == '+' || name[0] == '-')
160// {
161// valid_prefix = name[1] == '[';
162// }
163// else if (!strict)
164// {
165// // "strict" is false, the name just needs to start with '['
166// valid_prefix = name[0] == '[';
167// }
168//
169// if (valid_prefix)
170// {
171// static RegularExpression g_regex("^([-+]?)\\[([A-Za-z_][A-Za-z_0-9]*)(\\([A-Za-z_][A-Za-z_0-9]*\\))? ([A-Za-z_][A-Za-z_0-9:]*)\\]$");
172// llvm::StringRef matches[4];
173// // Since we are using a global regular expression, we must use the threadsafe version of execute
174// if (g_regex.ExecuteThreadSafe(name, matches, 4))
175// {
176// m_full.SetCString(name);
177// if (matches[0].empty())
178// m_type = eTypeUnspecified;
179// else if (matches[0][0] == '+')
180// m_type = eTypeClassMethod;
181// else
182// m_type = eTypeInstanceMethod;
183// m_class.SetString(matches[1]);
184// m_selector.SetString(matches[3]);
185// if (!matches[2].empty())
186// m_category.SetString(matches[2]);
187// }
188// }
189// }
190// return IsValid(strict);
191//}
192
193bool
194ObjCLanguageRuntime::MethodName::SetName (const char *name, bool strict)
195{
196 Clear();
197 if (name && name[0])
Jim Ingham3ad4da02011-08-15 01:32:22 +0000198 {
Greg Claytonf892c422013-01-30 00:18:29 +0000199 // If "strict" is true. then the method must be specified with a
200 // '+' or '-' at the beginning. If "strict" is false, then the '+'
201 // or '-' can be omitted
202 bool valid_prefix = false;
203
204 if (name[0] == '+' || name[0] == '-')
Jim Ingham3ad4da02011-08-15 01:32:22 +0000205 {
Greg Claytonf892c422013-01-30 00:18:29 +0000206 valid_prefix = name[1] == '[';
207 if (name[0] == '+')
208 m_type = eTypeClassMethod;
209 else
210 m_type = eTypeInstanceMethod;
211 }
212 else if (!strict)
213 {
214 // "strict" is false, the name just needs to start with '['
215 valid_prefix = name[0] == '[';
216 }
217
218 if (valid_prefix)
219 {
220 int name_len = strlen (name);
221 // Objective C methods must have at least:
222 // "-[" or "+[" prefix
223 // One character for a class name
224 // One character for the space between the class name
225 // One character for the method name
226 // "]" suffix
227 if (name_len >= (5 + (strict ? 1 : 0)) && name[name_len - 1] == ']')
Jim Ingham3ad4da02011-08-15 01:32:22 +0000228 {
Greg Claytonf892c422013-01-30 00:18:29 +0000229 m_full.SetCStringWithLength(name, name_len);
230 }
231 }
232 }
233 return IsValid(strict);
234}
235
236const ConstString &
237ObjCLanguageRuntime::MethodName::GetClassName ()
238{
239 if (!m_class)
240 {
241 if (IsValid(false))
242 {
243 const char *full = m_full.GetCString();
244 const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
245 const char *paren_pos = strchr (class_start, '(');
246 if (paren_pos)
247 {
248 m_class.SetCStringWithLength (class_start, paren_pos - class_start);
249 }
250 else
251 {
252 // No '(' was found in the full name, we can definitively say
253 // that our category was valid (and empty).
254 m_category_is_valid = true;
255 const char *space_pos = strchr (full, ' ');
256 if (space_pos)
Greg Clayton662e5672012-01-19 03:24:53 +0000257 {
Greg Claytonf892c422013-01-30 00:18:29 +0000258 m_class.SetCStringWithLength (class_start, space_pos - class_start);
259 if (!m_class_category)
Jim Ingham3ad4da02011-08-15 01:32:22 +0000260 {
Greg Claytonf892c422013-01-30 00:18:29 +0000261 // No category in name, so we can also fill in the m_class_category
262 m_class_category = m_class;
Jim Ingham3ad4da02011-08-15 01:32:22 +0000263 }
264 }
265 }
Jim Ingham3ad4da02011-08-15 01:32:22 +0000266 }
Jim Ingham3ad4da02011-08-15 01:32:22 +0000267 }
Greg Claytonf892c422013-01-30 00:18:29 +0000268 return m_class;
Jim Ingham3ad4da02011-08-15 01:32:22 +0000269}
Enrico Granataae2ae942012-09-04 18:47:54 +0000270
Greg Claytonf892c422013-01-30 00:18:29 +0000271const ConstString &
272ObjCLanguageRuntime::MethodName::GetClassNameWithCategory ()
273{
274 if (!m_class_category)
275 {
276 if (IsValid(false))
277 {
278 const char *full = m_full.GetCString();
279 const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
280 const char *space_pos = strchr (full, ' ');
281 if (space_pos)
282 {
283 m_class_category.SetCStringWithLength (class_start, space_pos - class_start);
284 // If m_class hasn't been filled in and the class with category doesn't
285 // contain a '(', then we can also fill in the m_class
286 if (!m_class && strchr (m_class_category.GetCString(), '(') == NULL)
287 {
288 m_class = m_class_category;
289 // No '(' was found in the full name, we can definitively say
290 // that our category was valid (and empty).
291 m_category_is_valid = true;
292
293 }
294 }
295 }
296 }
297 return m_class_category;
298}
299
300const ConstString &
301ObjCLanguageRuntime::MethodName::GetSelector ()
302{
303 if (!m_selector)
304 {
305 if (IsValid(false))
306 {
307 const char *full = m_full.GetCString();
308 const char *space_pos = strchr (full, ' ');
309 if (space_pos)
310 {
311 ++space_pos; // skip the space
312 m_selector.SetCStringWithLength (space_pos, m_full.GetLength() - (space_pos - full) - 1);
313 }
314 }
315 }
316 return m_selector;
317}
318
319const ConstString &
320ObjCLanguageRuntime::MethodName::GetCategory ()
321{
322 if (!m_category_is_valid && !m_category)
323 {
324 if (IsValid(false))
325 {
326 m_category_is_valid = true;
327 const char *full = m_full.GetCString();
328 const char *class_start = (full[0] == '[' ? full + 1 : full + 2);
329 const char *open_paren_pos = strchr (class_start, '(');
330 if (open_paren_pos)
331 {
332 ++open_paren_pos; // Skip the open paren
333 const char *close_paren_pos = strchr (open_paren_pos, ')');
334 if (close_paren_pos)
335 m_category.SetCStringWithLength (open_paren_pos, close_paren_pos - open_paren_pos);
336 }
337 }
338 }
339 return m_category;
340}
341
342ConstString
343ObjCLanguageRuntime::MethodName::GetFullNameWithoutCategory (bool empty_if_no_category)
344{
345 if (IsValid(false))
346 {
347 if (HasCategory())
348 {
349 StreamString strm;
350 if (m_type == eTypeClassMethod)
351 strm.PutChar('+');
352 else if (m_type == eTypeInstanceMethod)
353 strm.PutChar('-');
354 strm.Printf("[%s %s]", GetClassName().GetCString(), GetSelector().GetCString());
355 return ConstString(strm.GetString().c_str());
356 }
357
358 if (!empty_if_no_category)
359 {
360 // Just return the full name since it doesn't have a category
361 return GetFullName();
362 }
363 }
364 return ConstString();
365}
366
367size_t
368ObjCLanguageRuntime::MethodName::GetFullNames (std::vector<ConstString> &names, bool append)
369{
370 if (!append)
371 names.clear();
372 if (IsValid(false))
373 {
374 StreamString strm;
375 const bool is_class_method = m_type == eTypeClassMethod;
376 const bool is_instance_method = m_type == eTypeInstanceMethod;
377 const ConstString &category = GetCategory();
378 if (is_class_method || is_instance_method)
379 {
380 names.push_back (m_full);
381 if (category)
382 {
383 strm.Printf("%c[%s %s]",
384 is_class_method ? '+' : '-',
385 GetClassName().GetCString(),
386 GetSelector().GetCString());
387 names.push_back(ConstString(strm.GetString().c_str()));
388 }
389 }
390 else
391 {
392 const ConstString &class_name = GetClassName();
393 const ConstString &selector = GetSelector();
394 strm.Printf("+[%s %s]", class_name.GetCString(), selector.GetCString());
395 names.push_back(ConstString(strm.GetString().c_str()));
396 strm.Clear();
397 strm.Printf("-[%s %s]", class_name.GetCString(), selector.GetCString());
398 names.push_back(ConstString(strm.GetString().c_str()));
399 strm.Clear();
400 if (category)
401 {
402 strm.Printf("+[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
403 names.push_back(ConstString(strm.GetString().c_str()));
404 strm.Clear();
405 strm.Printf("-[%s(%s) %s]", class_name.GetCString(), category.GetCString(), selector.GetCString());
406 names.push_back(ConstString(strm.GetString().c_str()));
407 }
408 }
409 }
410 return names.size();
411}
412
413
414//uint32_t
415//ObjCLanguageRuntime::ParseMethodName (const char *name,
416// ConstString *class_name, // Class name (with category if any)
417// ConstString *selector_name, // selector on its own
418// ConstString *name_sans_category, // Full function prototype with no category
419// ConstString *class_name_sans_category)// Class name with no category (or empty if no category as answer will be in "class_name"
420//{
421// static ScopedTimerAggregator g_scoped_timer_aggregator ("ObjCLanguageRuntime::ParseMethodName");
422// ScopedTimer scoped_timer;
423// uint32_t result = 0;
424// if (class_name)
425// class_name->Clear();
426// if (selector_name)
427// selector_name->Clear();
428// if (name_sans_category)
429// name_sans_category->Clear();
430// if (class_name_sans_category)
431// class_name_sans_category->Clear();
432//
433//
434// if (IsPossibleObjCMethodName (name))
435// {
436// int name_len = strlen (name);
437// // Objective C methods must have at least:
438// // "-[" or "+[" prefix
439// // One character for a class name
440// // One character for the space between the class name
441// // One character for the method name
442// // "]" suffix
443// if (name_len >= 6 && name[name_len - 1] == ']')
444// {
445// const char *selector_name_ptr = strchr (name, ' ');
446// if (selector_name_ptr)
447// {
448// if (class_name)
449// {
450// class_name->SetCStringWithLength (name + 2, selector_name_ptr - name - 2);
451// ++result;
452// }
453//
454// // Skip the space
455// ++selector_name_ptr;
456// // Extract the objective C basename and add it to the
457// // accelerator tables
458// size_t selector_name_len = name_len - (selector_name_ptr - name) - 1;
459// if (selector_name)
460// {
461// selector_name->SetCStringWithLength (selector_name_ptr, selector_name_len);
462// ++result;
463// }
464//
465// // Also see if this is a "category" on our class. If so strip off the category name,
466// // and add the class name without it to the basename table.
467//
468// if (name_sans_category || class_name_sans_category)
469// {
470// const char *open_paren = strchr (name, '(');
471// if (open_paren)
472// {
473// if (class_name_sans_category)
474// {
475// class_name_sans_category->SetCStringWithLength (name + 2, open_paren - name - 2);
476// ++result;
477// }
478//
479// if (name_sans_category)
480// {
481// const char *close_paren = strchr (open_paren, ')');
482// if (open_paren < close_paren)
483// {
484// std::string buffer (name, open_paren - name);
485// buffer.append (close_paren + 1);
486// name_sans_category->SetCString (buffer.c_str());
487// ++result;
488// }
489// }
490// }
491// }
492// }
493// }
494// }
495// ObjCLanguageRuntime::MethodName method_name(name, true);
496// if (class_name)
497// assert (*class_name == method_name.GetClassNameWithCategory());
498// if (selector_name)
499// assert (*selector_name == method_name.GetSelector());
500// if (class_name_sans_category)
501// assert (*class_name_sans_category == method_name.GetClassName());
502// g_scoped_timer_aggregator.Aggregate (scoped_timer);
503// return result;
504//}
505
Enrico Granataae2ae942012-09-04 18:47:54 +0000506bool
507ObjCLanguageRuntime::ClassDescriptor::IsPointerValid (lldb::addr_t value,
508 uint32_t ptr_size,
509 bool allow_NULLs,
510 bool allow_tagged,
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000511 bool check_version_specific) const
Enrico Granataae2ae942012-09-04 18:47:54 +0000512{
513 if (!value)
514 return allow_NULLs;
515 if ( (value % 2) == 1 && allow_tagged)
516 return true;
517 if ((value % ptr_size) == 0)
518 return (check_version_specific ? CheckPointer(value,ptr_size) : true);
519 else
520 return false;
521}
522
523ObjCLanguageRuntime::ObjCISA
Sean Callananc718b962012-09-11 21:44:01 +0000524ObjCLanguageRuntime::GetISA(const ConstString &name)
525{
Sean Callanan6fe8d362012-09-15 01:05:12 +0000526 UpdateISAToDescriptorMap();
Sean Callananc718b962012-09-11 21:44:01 +0000527 for (const ISAToDescriptorMap::value_type &val : m_isa_to_descriptor_cache)
528 if (val.second && val.second->GetClassName() == name)
529 return val.first;
Sean Callananc718b962012-09-11 21:44:01 +0000530 return 0;
531}
532
533ObjCLanguageRuntime::ObjCISA
Enrico Granataae2ae942012-09-04 18:47:54 +0000534ObjCLanguageRuntime::GetParentClass(ObjCLanguageRuntime::ObjCISA isa)
535{
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000536 ClassDescriptorSP objc_class_sp (GetClassDescriptor(isa));
537 if (objc_class_sp)
Enrico Granataae2ae942012-09-04 18:47:54 +0000538 {
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000539 ClassDescriptorSP objc_super_class_sp (objc_class_sp->GetSuperclass());
540 if (objc_super_class_sp)
541 return objc_super_class_sp->GetISA();
Enrico Granataae2ae942012-09-04 18:47:54 +0000542 }
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000543 return 0;
Enrico Granataae2ae942012-09-04 18:47:54 +0000544}
545
Enrico Granataae2ae942012-09-04 18:47:54 +0000546ConstString
547ObjCLanguageRuntime::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa)
548{
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000549 ClassDescriptorSP objc_class_sp (GetNonKVOClassDescriptor(isa));
550 if (objc_class_sp)
551 return objc_class_sp->GetClassName();
552 return ConstString();
Enrico Granataae2ae942012-09-04 18:47:54 +0000553}
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000554
555ObjCLanguageRuntime::ClassDescriptorSP
Greg Claytona5104372012-10-11 18:07:21 +0000556ObjCLanguageRuntime::GetClassDescriptor (const ConstString &class_name)
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000557{
Greg Claytona5104372012-10-11 18:07:21 +0000558 UpdateISAToDescriptorMap();
559 for (const ISAToDescriptorMap::value_type &val : m_isa_to_descriptor_cache)
560 if (val.second && val.second->GetClassName() == class_name)
561 return val.second;
562 return ClassDescriptorSP();
563
564}
565
566ObjCLanguageRuntime::ClassDescriptorSP
567ObjCLanguageRuntime::GetClassDescriptor (ValueObject& valobj)
568{
569 ClassDescriptorSP objc_class_sp;
570 // if we get an invalid VO (which might still happen when playing around
571 // with pointers returned by the expression parser, don't consider this
572 // a valid ObjC object)
573 if (valobj.GetValue().GetContextType() != Value::eContextTypeInvalid)
574 {
575 addr_t isa_pointer = valobj.GetPointerValue();
576 if (isa_pointer != LLDB_INVALID_ADDRESS)
577 {
578 ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
579
580 Process *process = exe_ctx.GetProcessPtr();
581 if (process)
582 {
583 Error error;
584 ObjCISA isa = process->ReadPointerFromMemory(isa_pointer, error);
585 if (isa != LLDB_INVALID_ADDRESS)
586 objc_class_sp = GetClassDescriptor (isa);
587 }
588 }
589 }
590 return objc_class_sp;
591}
592
593ObjCLanguageRuntime::ClassDescriptorSP
594ObjCLanguageRuntime::GetNonKVOClassDescriptor (ValueObject& valobj)
595{
596 ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (GetClassDescriptor (valobj));
597 if (objc_class_sp)
598 {
599 if (!objc_class_sp->IsKVO())
600 return objc_class_sp;
601
602 ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass());
603 if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid())
604 return non_kvo_objc_class_sp;
605 }
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000606 return ClassDescriptorSP();
607}
608
Greg Claytona5104372012-10-11 18:07:21 +0000609
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000610ObjCLanguageRuntime::ClassDescriptorSP
611ObjCLanguageRuntime::GetClassDescriptor (ObjCISA isa)
612{
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000613 if (isa)
614 {
Greg Claytona5104372012-10-11 18:07:21 +0000615 UpdateISAToDescriptorMap();
616 ObjCLanguageRuntime::ISAToDescriptorIterator pos = m_isa_to_descriptor_cache.find(isa);
617 if (pos != m_isa_to_descriptor_cache.end())
618 return pos->second;
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000619 }
Greg Claytona5104372012-10-11 18:07:21 +0000620 return ClassDescriptorSP();
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000621}
622
623ObjCLanguageRuntime::ClassDescriptorSP
624ObjCLanguageRuntime::GetNonKVOClassDescriptor (ObjCISA isa)
625{
626 if (isa)
627 {
628 ClassDescriptorSP objc_class_sp = GetClassDescriptor (isa);
629 if (objc_class_sp && objc_class_sp->IsValid())
630 {
Greg Claytona5104372012-10-11 18:07:21 +0000631 if (!objc_class_sp->IsKVO())
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000632 return objc_class_sp;
Greg Claytona5104372012-10-11 18:07:21 +0000633
634 ClassDescriptorSP non_kvo_objc_class_sp(objc_class_sp->GetSuperclass());
635 if (non_kvo_objc_class_sp && non_kvo_objc_class_sp->IsValid())
636 return non_kvo_objc_class_sp;
Greg Claytonbe2f3aa2012-10-09 17:51:53 +0000637 }
638 }
639 return ClassDescriptorSP();
640}
641
642
643