summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
blob: c472bee8572ddb74208a9e8e2835d3d735e0d9f0 (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
//===-- SystemRuntimeMacOSX.h -----------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_SystemRuntimeMacOSX_h_
#define liblldb_SystemRuntimeMacOSX_h_

// C Includes
// C++ Includes
#include <map>
#include <vector>
#include <string>

// Other libraries and framework includes
#include "llvm/Support/MachO.h"

#include "lldb/Target/SystemRuntime.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/UUID.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Target/Process.h"

class SystemRuntimeMacOSX : public lldb_private::SystemRuntime
{
public:
    //------------------------------------------------------------------
    // Static Functions
    //------------------------------------------------------------------
    static void
    Initialize();

    static void
    Terminate();

    static lldb_private::ConstString
    GetPluginNameStatic();

    static const char *
    GetPluginDescriptionStatic();

    static lldb_private::SystemRuntime *
    CreateInstance (lldb_private::Process *process);

    SystemRuntimeMacOSX (lldb_private::Process *process);

    virtual
    ~SystemRuntimeMacOSX ();

    void
    Clear (bool clear_process);

    void
    DidAttach ();

    void
    DidLaunch();

    void
    ModulesDidLoad (lldb_private::ModuleList &module_list);

    const std::vector<lldb_private::ConstString> &
    GetExtendedBacktraceTypes ();

    lldb::ThreadSP
    GetExtendedBacktraceThread (lldb::ThreadSP thread, lldb_private::ConstString type);

    // REMOVE THE FOLLOWING 4
    bool 
    SetItemEnqueuedBreakpoint ();

    bool
    DidSetItemEnqueuedBreakpoint () const;

    static bool
    ItemEnqueuedCallback (void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);

    bool
    ItemEnqueuedBreakpointHit (lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);

    //------------------------------------------------------------------
    // PluginInterface protocol
    //------------------------------------------------------------------
    virtual lldb_private::ConstString
    GetPluginName();

    virtual uint32_t
    GetPluginVersion();

private:
    struct ArchivedBacktrace {
        uint32_t stop_id;
        bool stop_id_is_valid;
        lldb::queue_id_t libdispatch_queue_id;   // LLDB_INVALID_QUEUE_ID if unavailable
        std::vector<lldb::addr_t> pcs;
    };

    SystemRuntimeMacOSX::ArchivedBacktrace
    GetLibdispatchExtendedBacktrace (lldb::ThreadSP thread);

protected:
    lldb::user_id_t m_break_id;
    mutable lldb_private::Mutex m_mutex;

private:

    void
    ParseLdiHeaders ();

    bool
    LdiHeadersInitialized ();

    lldb::addr_t
    GetQueuesHead ();

    lldb::addr_t
    GetItemsHead ();

    lldb::addr_t
    GetThreadCreatorItem (lldb::ThreadSP thread);

    lldb::tid_t
    GetNewThreadUniqueThreadID (lldb::ThreadSP original_thread_sp);

    void
    SetNewThreadThreadName (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);

    void
    SetNewThreadQueueName (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);

    void
    SetNewThreadExtendedBacktraceToken (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);

    void
    SetNewThreadQueueID (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);

    struct ldi_queue_offsets {
        uint16_t next;
        uint16_t prev;
        uint16_t queue_id;
        uint16_t current_item_ptr;
    };

    struct ldi_item_offsets {
        uint16_t next;
        uint16_t prev;
        uint16_t type;
        uint16_t identifier;
        uint16_t stop_id;
        uint16_t backtrace_length;
        uint16_t backtrace_ptr;
        uint16_t thread_name_ptr;
        uint16_t queue_name_ptr;
        uint16_t unique_thread_id;
        uint16_t pthread_id;
        uint16_t enqueueing_thread_dispatch_queue_t;
        uint16_t enqueueing_thread_dispatch_block_ptr;
        uint16_t queue_id_from_thread_info;
    };

    struct ldi_header {
        uint16_t                    version;
        uint16_t                    ldi_header_size;
        uint16_t                    initialized;        // 0 means uninitialized
        uint16_t                    queue_size;
        uint16_t                    item_size;
        uint64_t                    queues_head_ptr_address;  // Address of queues head structure
        uint64_t                    items_head_ptr_address;   // Address of items_head
        struct ldi_queue_offsets    queue_offsets;
        struct ldi_item_offsets     item_offsets;
    };

    struct ldi_header   m_ldi_header;

    DISALLOW_COPY_AND_ASSIGN (SystemRuntimeMacOSX);
};

#endif  // liblldb_SystemRuntimeMacOSX_h_
OpenPOWER on IntegriCloud