]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/SystemRuntime.h
Import to 0.6.1
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / SystemRuntime.h
1 //===-- SystemRuntime.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_SystemRuntime_h_
11 #define liblldb_SystemRuntime_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include <vector>
18
19 #include "lldb/lldb-public.h"
20 #include "lldb/Core/ConstString.h"
21 #include "lldb/Core/ModuleList.h"
22 #include "lldb/Core/PluginInterface.h"
23 #include "lldb/Core/StructuredData.h"
24 #include "lldb/Target/QueueList.h"
25 #include "lldb/Target/QueueItem.h"
26 #include "lldb/lldb-private.h"
27
28 namespace lldb_private {
29
30 //----------------------------------------------------------------------
31 /// @class SystemRuntime SystemRuntime.h "lldb/Target/SystemRuntime.h"
32 /// @brief A plug-in interface definition class for system runtimes.
33 ///
34 /// The system runtime plugins can collect information from the system
35 /// libraries during a Process' lifetime and provide information about
36 /// how objects/threads were originated.
37 ///
38 /// For instance, a system runtime plugin use a breakpoint when threads
39 /// are created to record the backtrace of where that thread was created.
40 /// Later, when backtracing the created thread, it could extend the backtrace
41 /// to show where it was originally created from.  
42 ///
43 /// The plugin will insert its own breakpoint when Created and start collecting
44 /// information.  Later when it comes time to augment a Thread, it can be
45 /// asked to provide that information.
46 ///
47 //----------------------------------------------------------------------
48
49 class SystemRuntime :
50     public PluginInterface
51 {
52 public:
53     //------------------------------------------------------------------
54     /// Find a system runtime plugin for a given process.
55     ///
56     /// Scans the installed SystemRuntime plugins and tries to find
57     /// an instance that can be used to track image changes in \a
58     /// process.
59     ///
60     /// @param[in] process
61     ///     The process for which to try and locate a system runtime
62     ///     plugin instance.
63     //------------------------------------------------------------------
64     static SystemRuntime* 
65     FindPlugin (Process *process);
66
67     //------------------------------------------------------------------
68     /// Construct with a process.
69     // -----------------------------------------------------------------
70     SystemRuntime(lldb_private::Process *process);
71
72     //------------------------------------------------------------------
73     /// Destructor.
74     ///
75     /// The destructor is virtual since this class is designed to be
76     /// inherited by the plug-in instance.
77     //------------------------------------------------------------------
78     ~SystemRuntime() override;
79
80     //------------------------------------------------------------------
81     /// Called after attaching to a process.
82     ///
83     /// Allow the SystemRuntime plugin to execute some code after attaching
84     /// to a process. 
85     //------------------------------------------------------------------
86     virtual void
87     DidAttach ();
88
89     //------------------------------------------------------------------
90     /// Called after launching a process.
91     ///
92     /// Allow the SystemRuntime plugin to execute some code after launching
93     /// a process. 
94     //------------------------------------------------------------------
95     virtual void
96     DidLaunch();
97
98     //------------------------------------------------------------------
99     /// Called when modules have been loaded in the process.
100     ///
101     /// Allow the SystemRuntime plugin to enable logging features in the
102     /// system runtime libraries.
103     //------------------------------------------------------------------
104     virtual void
105     ModulesDidLoad(lldb_private::ModuleList &module_list);
106
107     //------------------------------------------------------------------
108     /// Called before detaching from a process.
109     ///
110     /// This will give a SystemRuntime plugin a chance to free any resources
111     /// in the inferior process before we detach.
112     //------------------------------------------------------------------
113     virtual void
114     Detach ();
115
116     //------------------------------------------------------------------
117     /// Return a list of thread origin extended backtraces that may 
118     /// be available.
119     ///
120     /// A System Runtime may be able to provide a backtrace of when this
121     /// thread was originally created.  Furthermore, it may be able to 
122     /// provide that extended backtrace for different styles of creation.
123     /// On a system with both pthreads and libdispatch, aka Grand Central 
124     /// Dispatch, queues, the system runtime may be able to provide the
125     /// pthread creation of the thread and it may also be able to provide
126     /// the backtrace of when this GCD queue work block was enqueued.
127     /// The caller may request these different origins by name.
128     ///
129     /// The names will be provided in the order that they are most likely
130     /// to be requested.  For instance, a most natural order may be to 
131     /// request the GCD libdispatch queue origin.  If there is none, then 
132     /// request the pthread origin.
133     ///
134     /// @return
135     ///   A vector of ConstStrings with names like "pthread" or "libdispatch".
136     ///   An empty vector may be returned if no thread origin extended 
137     ///   backtrace capabilities are available.
138     //------------------------------------------------------------------
139     virtual const std::vector<ConstString> &
140     GetExtendedBacktraceTypes ();
141
142     //------------------------------------------------------------------
143     /// Return a Thread which shows the origin of this thread's creation.
144     ///
145     /// This likely returns a HistoryThread which shows how thread was
146     /// originally created (e.g. "pthread" type), or how the work that
147     /// is currently executing on it was originally enqueued (e.g. 
148     /// "libdispatch" type).
149     ///
150     /// There may be a chain of thread-origins; it may be informative to
151     /// the end user to query the returned ThreadSP for its origins as 
152     /// well.
153     ///
154     /// @param [in] thread
155     ///   The thread to examine.
156     ///
157     /// @param [in] type
158     ///   The type of thread origin being requested.  The types supported
159     ///   are returned from SystemRuntime::GetExtendedBacktraceTypes.
160     ///
161     /// @return
162     ///   A ThreadSP which will have a StackList of frames.  This Thread will
163     ///   not appear in the Process' list of current threads.  Normal thread 
164     ///   operations like stepping will not be available.  This is a historical
165     ///   view thread and may be only useful for showing a backtrace.
166     ///
167     ///   An empty ThreadSP will be returned if no thread origin is available.
168     //------------------------------------------------------------------
169     virtual lldb::ThreadSP
170     GetExtendedBacktraceThread (lldb::ThreadSP thread, ConstString type);
171
172     //------------------------------------------------------------------
173     /// Get the extended backtrace thread for a QueueItem
174     ///
175     /// A QueueItem represents a function/block that will be executed on
176     /// a libdispatch queue in the future, or it represents a function/block
177     /// that is currently executing on a thread.
178     ///
179     /// This method will report a thread backtrace of the function that 
180     /// enqueued it originally, if possible.
181     ///
182     /// @param [in] queue_item_sp
183     ///     The QueueItem that we are getting an extended backtrace for.
184     ///
185     /// @param [in] type
186     ///     The type of extended backtrace to fetch.  The types supported
187     ///     are returned from SystemRuntime::GetExtendedBacktraceTypes.
188     ///
189     /// @return
190     ///     If an extended backtrace is available, it is returned.  Else
191     ///     an empty ThreadSP is returned.
192     //------------------------------------------------------------------
193     virtual lldb::ThreadSP
194     GetExtendedBacktraceForQueueItem (lldb::QueueItemSP queue_item_sp, ConstString type)
195     {
196         return lldb::ThreadSP();
197     }
198
199     //------------------------------------------------------------------
200     /// Populate the Process' QueueList with libdispatch / GCD queues that exist.
201     ///
202     /// When process execution is paused, the SystemRuntime may be called to fill
203     /// in the list of Queues that currently exist.
204     ///
205     /// @param [out] queue_list
206     ///     This QueueList will be cleared, and any queues that currently exist
207     ///     will be added.  An empty QueueList will be returned if no queues
208     ///     exist or if this Systemruntime does not support libdispatch queues.
209     //------------------------------------------------------------------
210     virtual void
211     PopulateQueueList (lldb_private::QueueList &queue_list)
212     {
213     }
214
215     //------------------------------------------------------------------
216     /// Get the queue name for a thread given a thread's dispatch_qaddr.
217     ///
218     /// On systems using libdispatch queues, a thread may be associated with a queue.
219     /// There will be a call to get the thread's dispatch_qaddr.  At the dispatch_qaddr
220     /// we will find the address of this thread's dispatch_queue_t structure.
221     /// Given the address of the dispatch_queue_t structure for a thread,
222     /// get the queue name and return it.
223     ///
224     /// @param [in] dispatch_qaddr
225     ///     The address of the dispatch_qaddr pointer for this thread.
226     ///
227     /// @return
228     ///     The string of this queue's name.  An empty string is returned if the
229     ///     name could not be found.
230     //------------------------------------------------------------------
231     virtual std::string
232     GetQueueNameFromThreadQAddress (lldb::addr_t dispatch_qaddr)
233     {
234         return "";
235     }
236
237     //------------------------------------------------------------------
238     /// Get the QueueID for the libdispatch queue given the thread's dispatch_qaddr.
239     ///
240     /// On systems using libdispatch queues, a thread may be associated with a queue.
241     /// There will be a call to get the thread's dispatch_qaddr.  At the dispatch_qaddr
242     /// we will find the address of this thread's dispatch_queue_t structure.
243     /// Given the address of the dispatch_queue_t structure for a thread,
244     /// get the queue ID and return it.
245     /// 
246     /// @param [in] dispatch_qaddr
247     ///     The address of the dispatch_qaddr pointer for this thread.
248     ///
249     /// @return
250     ///     The queue ID, or if it could not be retrieved, LLDB_INVALID_QUEUE_ID.
251     //------------------------------------------------------------------
252     virtual lldb::queue_id_t
253     GetQueueIDFromThreadQAddress (lldb::addr_t dispatch_qaddr)
254     {
255         return LLDB_INVALID_QUEUE_ID;
256     }
257
258     //------------------------------------------------------------------
259     /// Get the libdispatch_queue_t address for the queue given the thread's dispatch_qaddr.
260     ///
261     /// On systems using libdispatch queues, a thread may be associated with a queue.
262     /// There will be a call to get the thread's dispatch_qaddr.  
263     /// Given the thread's dispatch_qaddr, find the libdispatch_queue_t address and
264     /// return it.
265     /// 
266     /// @param [in] dispatch_qaddr
267     ///     The address of the dispatch_qaddr pointer for this thread.
268     ///
269     /// @return
270     ///     The libdispatch_queue_t address, or LLDB_INVALID_ADDRESS if unavailable/not found.
271     //------------------------------------------------------------------
272     virtual lldb::addr_t
273     GetLibdispatchQueueAddressFromThreadQAddress (lldb::addr_t dispatch_qaddr)
274     {
275         return LLDB_INVALID_ADDRESS;
276     }
277
278
279     //------------------------------------------------------------------
280     /// Retrieve the Queue kind for the queue at a thread's dispatch_qaddr.
281     ///
282     /// Retrieve the Queue kind - either eQueueKindSerial or 
283     /// eQueueKindConcurrent, indicating that this queue processes work
284     /// items serially or concurrently.
285     ///
286     /// @return
287     ///     The Queue kind, if it could be read, else eQueueKindUnknown.
288     //------------------------------------------------------------------
289     virtual lldb::QueueKind
290     GetQueueKind (lldb::addr_t dispatch_qaddr)
291     {
292         return lldb::eQueueKindUnknown;
293     }
294
295     //------------------------------------------------------------------
296     /// Get the pending work items for a libdispatch Queue
297     ///
298     /// If this system/process is using libdispatch and the runtime can do so,
299     /// retrieve the list of pending work items for the specified Queue and
300     /// add it to the Queue.
301     ///
302     /// @param [in] queue
303     ///     The queue of interest.
304     //------------------------------------------------------------------
305     virtual void
306     PopulatePendingItemsForQueue (lldb_private::Queue *queue)
307     {
308     }
309
310     //------------------------------------------------------------------
311     /// Complete the fields in a QueueItem
312     ///
313     /// PopulatePendingItemsForQueue() may not fill in all of the QueueItem
314     /// details; when the remaining fields are needed, they will be
315     /// fetched by call this method.
316     ///
317     /// @param [in] queue_item
318     ///   The QueueItem that we will be completing.
319     ///
320     /// @param [in] item_ref
321     ///     The item_ref token that is needed to retrieve the rest of the
322     ///     information about the QueueItem.
323     //------------------------------------------------------------------
324     virtual void
325     CompleteQueueItem (lldb_private::QueueItem *queue_item, lldb::addr_t item_ref)
326     {
327     }
328
329     //------------------------------------------------------------------
330     /// Add key-value pairs to the StructuredData dictionary object with
331     /// information debugserver  may need when constructing the jThreadExtendedInfo 
332     /// packet.
333     ///
334     /// @param [out] dict
335     ///     Dictionary to which key-value pairs should be added; they will
336     ///     be sent to the remote gdb server stub as arguments in the 
337     ///     jThreadExtendedInfo request.
338     //------------------------------------------------------------------
339     virtual void
340     AddThreadExtendedInfoPacketHints (lldb_private::StructuredData::ObjectSP dict)
341     {
342     }
343
344     /// Determine whether it is safe to run an expression on a given thread
345     ///
346     /// If a system must not run functions on a thread in some particular state,
347     /// this method gives a way for it to flag that the expression should not be
348     /// run.
349     ///
350     /// @param [in] thread_sp
351     ///     The thread we want to run the expression on.
352     ///
353     /// @return
354     ///     True will be returned if there are no known problems with running an
355     ///     expression on this thread.  False means that the inferior function
356     ///     call should not be made on this thread.
357     //------------------------------------------------------------------
358     virtual bool
359     SafeToCallFunctionsOnThisThread (lldb::ThreadSP thread_sp)
360     {
361         return true;
362     }
363
364 protected:
365     //------------------------------------------------------------------
366     // Member variables.
367     //------------------------------------------------------------------
368     Process *m_process;
369
370     std::vector<ConstString> m_types;
371
372 private:
373
374     DISALLOW_COPY_AND_ASSIGN (SystemRuntime);
375 };
376
377 } // namespace lldb_private
378
379 #endif // liblldb_SystemRuntime_h_