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