ObjCLanguageRuntime.h revision 3ad4da0f2c2afdea3352deaaf9c044855dc5c95b
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
102protected:
103    //------------------------------------------------------------------
104    // Classes that inherit from ObjCLanguageRuntime can see and modify these
105    //------------------------------------------------------------------
106    ObjCLanguageRuntime(Process *process);
107private:
108    // We keep a map of <Class,Selector>->Implementation so we don't have to call the resolver
109    // function over and over.
110
111    // FIXME: We need to watch for the loading of Protocols, and flush the cache for any
112    // class that we see so changed.
113
114    struct ClassAndSel
115    {
116        ClassAndSel()
117        {
118            sel_addr = LLDB_INVALID_ADDRESS;
119            class_addr = LLDB_INVALID_ADDRESS;
120        }
121        ClassAndSel (lldb::addr_t in_sel_addr, lldb::addr_t in_class_addr) :
122            class_addr (in_class_addr),
123            sel_addr(in_sel_addr)
124        {
125        }
126        bool operator== (const ClassAndSel &rhs)
127        {
128            if (class_addr == rhs.class_addr
129                && sel_addr == rhs.sel_addr)
130                return true;
131            else
132                return false;
133        }
134
135        bool operator< (const ClassAndSel &rhs) const
136        {
137            if (class_addr < rhs.class_addr)
138                return true;
139            else if (class_addr > rhs.class_addr)
140                return false;
141            else
142            {
143                if (sel_addr < rhs.sel_addr)
144                    return true;
145                else
146                    return false;
147            }
148        }
149
150        lldb::addr_t class_addr;
151        lldb::addr_t sel_addr;
152    };
153
154    typedef std::map<ClassAndSel,lldb::addr_t> MsgImplMap;
155    MsgImplMap m_impl_cache;
156
157    typedef std::map<lldb::addr_t,TypeAndOrName> ClassNameMap;
158    ClassNameMap m_class_name_cache;
159
160    DISALLOW_COPY_AND_ASSIGN (ObjCLanguageRuntime);
161};
162
163} // namespace lldb_private
164
165#endif  // liblldb_ObjCLanguageRuntime_h_
166