blob: 24029d789969f7e95cf118fc2b784b8aff11c912 [file] [log] [blame]
Jason Molendaa7b5afa2013-11-15 00:17:32 +00001//===-- SystemRuntimeMacOSX.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_SystemRuntimeMacOSX_h_
11#define liblldb_SystemRuntimeMacOSX_h_
12
13// C Includes
14// C++ Includes
15#include <map>
16#include <vector>
17#include <string>
18
19// Other libraries and framework includes
20#include "llvm/Support/MachO.h"
21
22#include "lldb/Target/SystemRuntime.h"
23#include "lldb/Host/FileSpec.h"
24#include "lldb/Core/ConstString.h"
25#include "lldb/Core/ModuleList.h"
26#include "lldb/Core/UUID.h"
27#include "lldb/Host/Mutex.h"
28#include "lldb/Target/Process.h"
29
30class SystemRuntimeMacOSX : public lldb_private::SystemRuntime
31{
32public:
33 //------------------------------------------------------------------
34 // Static Functions
35 //------------------------------------------------------------------
36 static void
37 Initialize();
38
39 static void
40 Terminate();
41
42 static lldb_private::ConstString
43 GetPluginNameStatic();
44
45 static const char *
46 GetPluginDescriptionStatic();
47
48 static lldb_private::SystemRuntime *
49 CreateInstance (lldb_private::Process *process);
50
51 SystemRuntimeMacOSX (lldb_private::Process *process);
52
53 virtual
54 ~SystemRuntimeMacOSX ();
55
56 void
57 Clear (bool clear_process);
58
59 void
60 DidAttach ();
61
62 void
63 DidLaunch();
64
65 void
66 ModulesDidLoad (lldb_private::ModuleList &module_list);
67
68 const std::vector<lldb_private::ConstString> &
69 GetExtendedBacktraceTypes ();
70
71 lldb::ThreadSP
72 GetExtendedBacktraceThread (lldb::ThreadSP thread, lldb_private::ConstString type);
73
74 // REMOVE THE FOLLOWING 4
75 bool
76 SetItemEnqueuedBreakpoint ();
77
78 bool
79 DidSetItemEnqueuedBreakpoint () const;
80
81 static bool
82 ItemEnqueuedCallback (void *baton, lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
83
84 bool
85 ItemEnqueuedBreakpointHit (lldb_private::StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
86
87 //------------------------------------------------------------------
88 // PluginInterface protocol
89 //------------------------------------------------------------------
90 virtual lldb_private::ConstString
91 GetPluginName();
92
93 virtual uint32_t
94 GetPluginVersion();
95
96private:
97 struct ArchivedBacktrace {
98 uint32_t stop_id;
99 bool stop_id_is_valid;
100 lldb::queue_id_t libdispatch_queue_id; // LLDB_INVALID_QUEUE_ID if unavailable
101 std::vector<lldb::addr_t> pcs;
102 };
103
104 SystemRuntimeMacOSX::ArchivedBacktrace
105 GetLibdispatchExtendedBacktrace (lldb::ThreadSP thread);
106
107protected:
108 lldb::user_id_t m_break_id;
109 mutable lldb_private::Mutex m_mutex;
110
111private:
112
113 void
114 ParseLdiHeaders ();
115
116 bool
117 LdiHeadersInitialized ();
118
119 lldb::addr_t
120 GetQueuesHead ();
121
122 lldb::addr_t
123 GetItemsHead ();
124
125 lldb::addr_t
126 GetThreadCreatorItem (lldb::ThreadSP thread);
127
Jason Molenda8ee9cb52013-11-16 01:24:22 +0000128 lldb::tid_t
129 GetNewThreadUniquethreadID (lldb::ThreadSP original_thread_sp);
130
131 void
132 SetNewThreadThreadName (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);
133
Jason Molendaa7b5afa2013-11-15 00:17:32 +0000134 void
135 SetNewThreadQueueName (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);
136
137 void
138 SetNewThreadExtendedBacktraceToken (lldb::ThreadSP original_thread_sp, lldb::ThreadSP new_extended_thread_sp);
139
140 struct ldi_queue_offsets {
141 uint16_t next;
142 uint16_t prev;
143 uint16_t queue_id;
144 uint16_t current_item_ptr;
145 };
146
147 struct ldi_item_offsets {
148 uint16_t next;
149 uint16_t prev;
150 uint16_t type;
151 uint16_t identifier;
152 uint16_t stop_id;
153 uint16_t backtrace_length;
154 uint16_t backtrace_ptr;
155 uint16_t thread_name_ptr;
156 uint16_t queue_name_ptr;
157 uint16_t unique_thread_id;
158 uint16_t pthread_id;
159 uint16_t enqueueing_thread_dispatch_queue_t;
160 uint16_t enqueueing_thread_dispatch_block_ptr;
161 };
162
163 struct ldi_header {
164 uint16_t version;
165 uint16_t ldi_header_size;
166 uint16_t initialized; // 0 means uninitialized
167 uint16_t queue_size;
168 uint16_t item_size;
169 uint64_t queues_head_ptr_address; // Address of queues head structure
170 uint64_t items_head_ptr_address; // Address of items_head
171 struct ldi_queue_offsets queue_offsets;
172 struct ldi_item_offsets item_offsets;
173 };
174
175 struct ldi_header m_ldi_header;
176
177 DISALLOW_COPY_AND_ASSIGN (SystemRuntimeMacOSX);
178};
179
180#endif // liblldb_SystemRuntimeMacOSX_h_