ObjCLanguageRuntime.h revision 673f3dbea64b116166dfa668006cdc84224a27c0
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 virtual SymbolVendor * 91 GetSymbolVendor() 92 { 93 return NULL; 94 } 95 96 // Finds the byte offset of the child_type ivar in parent_type. If it can't find the 97 // offset, returns LLDB_INVALID_IVAR_OFFSET. 98 99 virtual size_t 100 GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name); 101 102 // If the passed in "name" is an ObjC method, return true. Also, fill in any of the 103 // sub-parts that are passed in non-NULL. The base_name means the name stripped of 104 // category attributes. 105 static bool 106 ParseMethodName (const char *name, ConstString *class_name, ConstString *method_name, ConstString *base_name); 107 108 static bool 109 IsPossibleObjCMethodName (const char *name) 110 { 111 if (!name) 112 return false; 113 bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '['; 114 bool ends_right = (name[strlen(name) - 1] == ']'); 115 return (starts_right && ends_right); 116 } 117 118 static bool 119 IsPossibleObjCSelector (const char *name) 120 { 121 if (!name) 122 return false; 123 124 if (strchr(name, ':') == NULL) 125 return true; 126 else if (name[strlen(name) - 1] == ':') 127 return true; 128 else 129 return false; 130 } 131 132protected: 133 //------------------------------------------------------------------ 134 // Classes that inherit from ObjCLanguageRuntime can see and modify these 135 //------------------------------------------------------------------ 136 ObjCLanguageRuntime(Process *process); 137private: 138 // We keep a map of <Class,Selector>->Implementation so we don't have to call the resolver 139 // function over and over. 140 141 // FIXME: We need to watch for the loading of Protocols, and flush the cache for any 142 // class that we see so changed. 143 144 struct ClassAndSel 145 { 146 ClassAndSel() 147 { 148 sel_addr = LLDB_INVALID_ADDRESS; 149 class_addr = LLDB_INVALID_ADDRESS; 150 } 151 ClassAndSel (lldb::addr_t in_sel_addr, lldb::addr_t in_class_addr) : 152 class_addr (in_class_addr), 153 sel_addr(in_sel_addr) 154 { 155 } 156 bool operator== (const ClassAndSel &rhs) 157 { 158 if (class_addr == rhs.class_addr 159 && sel_addr == rhs.sel_addr) 160 return true; 161 else 162 return false; 163 } 164 165 bool operator< (const ClassAndSel &rhs) const 166 { 167 if (class_addr < rhs.class_addr) 168 return true; 169 else if (class_addr > rhs.class_addr) 170 return false; 171 else 172 { 173 if (sel_addr < rhs.sel_addr) 174 return true; 175 else 176 return false; 177 } 178 } 179 180 lldb::addr_t class_addr; 181 lldb::addr_t sel_addr; 182 }; 183 184 typedef std::map<ClassAndSel,lldb::addr_t> MsgImplMap; 185 MsgImplMap m_impl_cache; 186 187protected: 188 typedef std::map<lldb::addr_t,TypeAndOrName> ClassNameMap; 189 typedef ClassNameMap::iterator ClassNameIterator; 190 ClassNameMap m_class_name_cache; 191 192 DISALLOW_COPY_AND_ASSIGN (ObjCLanguageRuntime); 193}; 194 195} // namespace lldb_private 196 197#endif // liblldb_ObjCLanguageRuntime_h_ 198