ObjCLanguageRuntime.h revision ef80aabe53b7fdf61309ba6d3d6865c94c681345
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 76protected: 77 //------------------------------------------------------------------ 78 // Classes that inherit from ObjCLanguageRuntime can see and modify these 79 //------------------------------------------------------------------ 80 ObjCLanguageRuntime(Process *process); 81private: 82 // We keep a map of <Class,Selector>->Implementation so we don't have to call the resolver 83 // function over and over. 84 85 // FIXME: We need to watch for the loading of Protocols, and flush the cache for any 86 // class that we see so changed. 87 88 struct ClassAndSel 89 { 90 ClassAndSel() 91 { 92 sel_addr = LLDB_INVALID_ADDRESS; 93 class_addr = LLDB_INVALID_ADDRESS; 94 } 95 ClassAndSel (lldb::addr_t in_sel_addr, lldb::addr_t in_class_addr) : 96 class_addr (in_class_addr), 97 sel_addr(in_sel_addr) 98 { 99 } 100 bool operator== (const ClassAndSel &rhs) 101 { 102 if (class_addr == rhs.class_addr 103 && sel_addr == rhs.sel_addr) 104 return true; 105 else 106 return false; 107 } 108 109 bool operator< (const ClassAndSel &rhs) const 110 { 111 if (class_addr < rhs.class_addr) 112 return true; 113 else if (class_addr > rhs.class_addr) 114 return false; 115 else 116 { 117 if (sel_addr < rhs.sel_addr) 118 return true; 119 else 120 return false; 121 } 122 } 123 124 lldb::addr_t class_addr; 125 lldb::addr_t sel_addr; 126 }; 127 128 typedef std::map<ClassAndSel,lldb::addr_t> MsgImplMap; 129 MsgImplMap m_impl_cache; 130 131 typedef std::map<lldb::addr_t,TypeAndOrName> ClassNameMap; 132 ClassNameMap m_class_name_cache; 133 134 DISALLOW_COPY_AND_ASSIGN (ObjCLanguageRuntime); 135}; 136 137} // namespace lldb_private 138 139#endif // liblldb_ObjCLanguageRuntime_h_ 140