ObjCLanguageRuntime.h revision fdf24efe672bf3fa041cdbebd2d7f406b11882bd
1//===-- ObjCLanguageRuntime.h ---------------------------------------------------*- C++ -*-===// 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//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_ObjCLanguageRuntime_h_ 11#define liblldb_ObjCLanguageRuntime_h_ 12 13// C Includes 14// C++ Includes 15#include <map> 16 17// Other libraries and framework includes 18// Project includes 19#include "lldb/lldb-private.h" 20#include "lldb/Core/PluginInterface.h" 21#include "lldb/Target/LanguageRuntime.h" 22 23namespace lldb_private { 24 25class ClangUtilityFunction; 26 27class ObjCLanguageRuntime : 28 public LanguageRuntime 29{ 30public: 31 virtual 32 ~ObjCLanguageRuntime(); 33 34 virtual lldb::LanguageType 35 GetLanguageType () const 36 { 37 return lldb::eLanguageTypeObjC; 38 } 39 40 virtual bool 41 IsModuleObjCLibrary (const lldb::ModuleSP &module_sp) = 0; 42 43 virtual bool 44 ReadObjCLibrary (const lldb::ModuleSP &module_sp) = 0; 45 46 virtual bool 47 HasReadObjCLibrary () = 0; 48 49 virtual lldb::ThreadPlanSP 50 GetStepThroughTrampolinePlan (Thread &thread, bool stop_others) = 0; 51 52 lldb::addr_t 53 LookupInMethodCache (lldb::addr_t class_addr, lldb::addr_t sel); 54 55 void 56 AddToMethodCache (lldb::addr_t class_addr, lldb::addr_t sel, lldb::addr_t impl_addr); 57 58 TypeAndOrName 59 LookupInClassNameCache (lldb::addr_t class_addr); 60 61 void 62 AddToClassNameCache (lldb::addr_t class_addr, const char *name, lldb::TypeSP type_sp); 63 64 void 65 AddToClassNameCache (lldb::addr_t class_addr, const TypeAndOrName &class_or_type_name); 66 67 virtual ClangUtilityFunction * 68 CreateObjectChecker (const char *) = 0; 69 70 virtual ObjCRuntimeVersions 71 GetRuntimeVersion () 72 { 73 return eObjC_VersionUnknown; 74 } 75 76 typedef lldb::addr_t ObjCISA; 77 78 virtual bool 79 IsValidISA(ObjCISA isa) = 0; 80 81 virtual ObjCISA 82 GetISA(ValueObject& valobj) = 0; 83 84 virtual ConstString 85 GetActualTypeName(ObjCISA isa) = 0; 86 87 virtual ObjCISA 88 GetParentClass(ObjCISA isa) = 0; 89 90 // Finds the byte offset of the child_type ivar in parent_type. If it can't find the 91 // offset, returns LLDB_INVALID_IVAR_OFFSET. 92 93 virtual size_t 94 GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name); 95 96 // If the passed in "name" is an ObjC method, return true. Also, fill in any of the 97 // sub-parts that are passed in non-NULL. The base_name means the name stripped of 98 // category attributes. 99 static bool 100 ParseMethodName (const char *name, ConstString *class_name, ConstString *method_name, ConstString *base_name); 101 102 static bool 103 IsPossibleObjCMethodName (const char *name) 104 { 105 return (name && (name[0] == '+' || name[0] == '-') && name[1] == '['); 106 } 107 108protected: 109 //------------------------------------------------------------------ 110 // Classes that inherit from ObjCLanguageRuntime can see and modify these 111 //------------------------------------------------------------------ 112 ObjCLanguageRuntime(Process *process); 113private: 114 // We keep a map of <Class,Selector>->Implementation so we don't have to call the resolver 115 // function over and over. 116 117 // FIXME: We need to watch for the loading of Protocols, and flush the cache for any 118 // class that we see so changed. 119 120 struct ClassAndSel 121 { 122 ClassAndSel() 123 { 124 sel_addr = LLDB_INVALID_ADDRESS; 125 class_addr = LLDB_INVALID_ADDRESS; 126 } 127 ClassAndSel (lldb::addr_t in_sel_addr, lldb::addr_t in_class_addr) : 128 class_addr (in_class_addr), 129 sel_addr(in_sel_addr) 130 { 131 } 132 bool operator== (const ClassAndSel &rhs) 133 { 134 if (class_addr == rhs.class_addr 135 && sel_addr == rhs.sel_addr) 136 return true; 137 else 138 return false; 139 } 140 141 bool operator< (const ClassAndSel &rhs) const 142 { 143 if (class_addr < rhs.class_addr) 144 return true; 145 else if (class_addr > rhs.class_addr) 146 return false; 147 else 148 { 149 if (sel_addr < rhs.sel_addr) 150 return true; 151 else 152 return false; 153 } 154 } 155 156 lldb::addr_t class_addr; 157 lldb::addr_t sel_addr; 158 }; 159 160 typedef std::map<ClassAndSel,lldb::addr_t> MsgImplMap; 161 MsgImplMap m_impl_cache; 162 163protected: 164 typedef std::map<lldb::addr_t,TypeAndOrName> ClassNameMap; 165 typedef ClassNameMap::iterator ClassNameIterator; 166 ClassNameMap m_class_name_cache; 167 168 DISALLOW_COPY_AND_ASSIGN (ObjCLanguageRuntime); 169}; 170 171} // namespace lldb_private 172 173#endif // liblldb_ObjCLanguageRuntime_h_ 174