summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.h
blob: 8c8bea8f0a3211edddcf1382593b04fc05714e5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//===-- AppleObjCTrampolineHandler.h ----------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef lldb_AppleObjCTrampolineHandler_h_
#define lldb_AppleObjCTrampolineHandler_h_

// C Includes
// C++ Includes
#include <map>
#include <string>
// Other libraries and framework includes
// Project includes
#include "lldb/Expression/ClangExpression.h"
#include "lldb/Expression/ClangFunction.h"
#include "lldb/Host/Mutex.h"


namespace lldb_private
{
using namespace lldb;
  
class AppleObjCTrampolineHandler {
public:
    
    AppleObjCTrampolineHandler (ProcessSP process_sp, ModuleSP objc_module_sp);
    
    ~AppleObjCTrampolineHandler() {}
            
    ThreadPlanSP
    GetStepThroughDispatchPlan (Thread &thread, bool stop_others);
    
    ClangFunction *
    GetLookupImplementationWrapperFunction ();
    
    
    struct DispatchFunction {
    public:
        typedef enum 
        {
            eFixUpNone,
            eFixUpFixed,
            eFixUpToFix
        } FixUpState;
                
        const char *name;
        bool stret_return;
        bool is_super;
        FixUpState fixedup;
    };
    
private:

    class AppleObjCVTables
    {
    public:
        // These come from objc-gdb.h.
        enum VTableFlags
        {
             eOBJC_TRAMPOLINE_MESSAGE = (1<<0),   // trampoline acts like objc_msgSend                                                           
             eOBJC_TRAMPOLINE_STRET   = (1<<1),   // trampoline is struct-returning                                                              
             eOBJC_TRAMPOLINE_VTABLE  = (1<<2),   // trampoline is vtable dispatcher                                                             
        };
            
    private:
        struct VTableDescriptor 
        {
            VTableDescriptor(uint32_t in_flags, addr_t in_code_start) :
                flags(in_flags),
                code_start(in_code_start) {}
            
            uint32_t flags;
            lldb::addr_t code_start;
        };


        class VTableRegion 
        {
        public:
            VTableRegion() :
                    m_valid (false),
                    m_owner (NULL),
                    m_header_addr (LLDB_INVALID_ADDRESS),
                    m_code_start_addr(0),
                    m_code_end_addr (0),
                    m_next_region (0)
            {}
            
            VTableRegion(AppleObjCVTables *owner, lldb::addr_t header_addr);
            
            void SetUpRegion();
                        
            lldb::addr_t GetNextRegionAddr ()
            {
                return m_next_region;
            }
            
            lldb::addr_t
            GetCodeStart ()
            {
                return m_code_start_addr;
            }
            
            lldb::addr_t
            GetCodeEnd ()
            {
                return m_code_end_addr;
            }
            
            uint32_t
            GetFlagsForVTableAtAddress (lldb::addr_t address)
            {
                return 0;
            }
            
            bool
            IsValid ()
            {
                return m_valid;
            }
            
            bool 
            AddressInRegion (lldb::addr_t addr, uint32_t &flags);
            
            void
            Dump (Stream &s);
            
        public:
            bool m_valid;
            AppleObjCVTables *m_owner;
            lldb::addr_t m_header_addr;
            lldb::addr_t m_code_start_addr;
            lldb::addr_t m_code_end_addr;
            std::vector<VTableDescriptor> m_descriptors;
            lldb::addr_t m_next_region;
        };
        
    public:
        AppleObjCVTables(ProcessSP &process_sp, ModuleSP &objc_module_sp);
        
        ~AppleObjCVTables();
                
        bool
        InitializeVTableSymbols ();
                
        static bool RefreshTrampolines (void *baton, 
                                        StoppointCallbackContext *context, 
                                        lldb::user_id_t break_id, 
                                        lldb::user_id_t break_loc_id);
        bool
        ReadRegions ();
        
        bool
        ReadRegions (lldb::addr_t region_addr);
                
        bool
        IsAddressInVTables (lldb::addr_t addr, uint32_t &flags);
                
        Process *GetProcess ()
        {   
            return m_process_sp.get();
        }

    private:
        ProcessSP m_process_sp;
        typedef std::vector<VTableRegion> region_collection;
        lldb::addr_t m_trampoline_header;
        lldb::break_id_t m_trampolines_changed_bp_id;
        region_collection m_regions;
        lldb::ModuleSP m_objc_module_sp;
        
    };
    
    static const DispatchFunction g_dispatch_functions[];
    
    typedef std::map<lldb::addr_t, int> MsgsendMap; // This table maps an dispatch fn address to the index in g_dispatch_functions
    MsgsendMap m_msgSend_map;
    ProcessSP m_process_sp;
    ModuleSP m_objc_module_sp;
    lldb::addr_t get_impl_addr;
    std::auto_ptr<ClangFunction> m_impl_function;
    Mutex m_impl_function_mutex;
    lldb::addr_t m_impl_fn_addr;
    lldb::addr_t m_impl_stret_fn_addr;
    std::auto_ptr<AppleObjCVTables> m_vtables_ap;
    
     
};

}  // using namespace lldb_private

#endif	// lldb_AppleObjCTrampolineHandler_h_
OpenPOWER on IntegriCloud