ObjCLanguageRuntime.h revision b344843f75ef893762c93fd0a22d2d45712ce74d
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    virtual ClangUtilityFunction *
59    CreateObjectChecker (const char *) = 0;
60
61    virtual ObjCRuntimeVersions
62    GetRuntimeVersion ()
63    {
64        return eObjC_VersionUnknown;
65    }
66
67protected:
68    //------------------------------------------------------------------
69    // Classes that inherit from ObjCLanguageRuntime can see and modify these
70    //------------------------------------------------------------------
71    ObjCLanguageRuntime(Process *process);
72private:
73    // We keep a map of <Class,Selector>->Implementation so we don't have to call the resolver
74    // function over and over.
75
76    // FIXME: We need to watch for the loading of Protocols, and flush the cache for any
77    // class that we see so changed.
78
79    struct ClassAndSel
80    {
81        ClassAndSel()
82        {
83            sel_addr = LLDB_INVALID_ADDRESS;
84            class_addr = LLDB_INVALID_ADDRESS;
85        }
86        ClassAndSel (lldb::addr_t in_sel_addr, lldb::addr_t in_class_addr) :
87            class_addr (in_class_addr),
88            sel_addr(in_sel_addr)
89        {
90        }
91        bool operator== (const ClassAndSel &rhs)
92        {
93            if (class_addr == rhs.class_addr
94                && sel_addr == rhs.sel_addr)
95                return true;
96            else
97                return false;
98        }
99
100        bool operator< (const ClassAndSel &rhs) const
101        {
102            if (class_addr < rhs.class_addr)
103                return true;
104            else if (class_addr > rhs.class_addr)
105                return false;
106            else
107            {
108                if (sel_addr < rhs.sel_addr)
109                    return true;
110                else
111                    return false;
112            }
113        }
114
115        lldb::addr_t class_addr;
116        lldb::addr_t sel_addr;
117    };
118
119    typedef std::map<ClassAndSel,lldb::addr_t> MsgImplMap;
120    MsgImplMap m_impl_cache;
121
122    DISALLOW_COPY_AND_ASSIGN (ObjCLanguageRuntime);
123};
124
125} // namespace lldb_private
126
127#endif  // liblldb_ObjCLanguageRuntime_h_
128