]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Debugger.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / include / lldb / Core / Debugger.h
1 //===-- Debugger.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_Debugger_h_
11 #define liblldb_Debugger_h_
12 #if defined(__cplusplus)
13
14
15 #include <stdint.h>
16
17 #include <stack>
18
19 #include "lldb/lldb-public.h"
20 #include "lldb/Core/Broadcaster.h"
21 #include "lldb/Core/Communication.h"
22 #include "lldb/Core/IOHandler.h"
23 #include "lldb/Core/Listener.h"
24 #include "lldb/Core/SourceManager.h"
25 #include "lldb/Core/UserID.h"
26 #include "lldb/Core/UserSettingsController.h"
27 #include "lldb/DataFormatters/FormatManager.h"
28 #include "lldb/Host/Terminal.h"
29 #include "lldb/Interpreter/OptionValueProperties.h"
30 #include "lldb/Target/ExecutionContext.h"
31 #include "lldb/Target/Platform.h"
32 #include "lldb/Target/TargetList.h"
33
34 namespace lldb_private {
35
36 //----------------------------------------------------------------------
37 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
38 /// @brief A class to manage flag bits.
39 ///
40 /// Provides a global root objects for the debugger core.
41 //----------------------------------------------------------------------
42
43
44 class Debugger :
45     public std::enable_shared_from_this<Debugger>,
46     public UserID,
47     public Properties,
48     public BroadcasterManager
49 {
50 friend class SourceManager;  // For GetSourceFileCache.
51
52 public:
53
54     typedef lldb::DynamicLibrarySP (*LoadPluginCallbackType) (const lldb::DebuggerSP &debugger_sp,
55                                                               const FileSpec& spec,
56                                                               Error& error);
57
58     static lldb::DebuggerSP
59     CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL);
60
61     static lldb::TargetSP
62     FindTargetWithProcessID (lldb::pid_t pid);
63     
64     static lldb::TargetSP
65     FindTargetWithProcess (Process *process);
66
67     static void
68     Initialize (LoadPluginCallbackType load_plugin_callback);
69     
70     static void 
71     Terminate ();
72     
73     static void
74     SettingsInitialize ();
75     
76     static void
77     SettingsTerminate ();
78     
79     static void
80     Destroy (lldb::DebuggerSP &debugger_sp);
81
82     virtual
83     ~Debugger ();
84     
85     void Clear();
86
87     bool
88     GetAsyncExecution ();
89
90     void
91     SetAsyncExecution (bool async);
92
93     lldb::StreamFileSP
94     GetInputFile ()
95     {
96         return m_input_file_sp;
97     }
98
99     lldb::StreamFileSP
100     GetOutputFile ()
101     {
102         return m_output_file_sp;
103     }
104
105     lldb::StreamFileSP
106     GetErrorFile ()
107     {
108         return m_error_file_sp;
109     }
110
111     
112     
113     void
114     SetInputFileHandle (FILE *fh, bool tranfer_ownership);
115
116     void
117     SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
118
119     void
120     SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
121     
122     void
123     SaveInputTerminalState();
124     
125     void
126     RestoreInputTerminalState();
127
128     lldb::StreamSP
129     GetAsyncOutputStream ();
130     
131     lldb::StreamSP
132     GetAsyncErrorStream ();
133     
134     CommandInterpreter &
135     GetCommandInterpreter ()
136     {
137         assert (m_command_interpreter_ap.get());
138         return *m_command_interpreter_ap;
139     }
140
141     Listener &
142     GetListener ()
143     {
144         return m_listener;
145     }
146
147     // This returns the Debugger's scratch source manager.  It won't be able to look up files in debug
148     // information, but it can look up files by absolute path and display them to you.
149     // To get the target's source manager, call GetSourceManager on the target instead.
150     SourceManager &
151     GetSourceManager ();
152
153 public:
154     
155     lldb::TargetSP
156     GetSelectedTarget ()
157     {
158         return m_target_list.GetSelectedTarget ();
159     }
160
161     ExecutionContext
162     GetSelectedExecutionContext();
163     //------------------------------------------------------------------
164     /// Get accessor for the target list.
165     ///
166     /// The target list is part of the global debugger object. This
167     /// the single debugger shared instance to control where targets
168     /// get created and to allow for tracking and searching for targets
169     /// based on certain criteria.
170     ///
171     /// @return
172     ///     A global shared target list.
173     //------------------------------------------------------------------
174     TargetList &
175     GetTargetList ()
176     {
177         return m_target_list;
178     }
179
180     PlatformList &
181     GetPlatformList ()
182     {
183         return m_platform_list;
184     }
185
186     void
187     DispatchInputInterrupt ();
188
189     void
190     DispatchInputEndOfFile ();
191
192     //------------------------------------------------------------------
193     // If any of the streams are not set, set them to the in/out/err
194     // stream of the top most input reader to ensure they at least have
195     // something
196     //------------------------------------------------------------------
197     void
198     AdoptTopIOHandlerFilesIfInvalid (lldb::StreamFileSP &in,
199                                      lldb::StreamFileSP &out,
200                                      lldb::StreamFileSP &err);
201
202     void
203     PushIOHandler (const lldb::IOHandlerSP& reader_sp);
204
205     bool
206     PopIOHandler (const lldb::IOHandlerSP& reader_sp);
207     
208     // Synchronously run an input reader until it is done
209     void
210     RunIOHandler (const lldb::IOHandlerSP& reader_sp);
211     
212     bool
213     IsTopIOHandler (const lldb::IOHandlerSP& reader_sp);
214
215     ConstString
216     GetTopIOHandlerControlSequence(char ch);
217
218     bool
219     HideTopIOHandler();
220
221     void
222     RefreshTopIOHandler();
223
224     static lldb::DebuggerSP
225     FindDebuggerWithID (lldb::user_id_t id);
226     
227     static lldb::DebuggerSP
228     FindDebuggerWithInstanceName (const ConstString &instance_name);
229     
230     static size_t
231     GetNumDebuggers();
232     
233     static lldb::DebuggerSP
234     GetDebuggerAtIndex (size_t index);
235
236     static bool
237     FormatPrompt (const char *format,
238                   const SymbolContext *sc,
239                   const ExecutionContext *exe_ctx,
240                   const Address *addr,
241                   Stream &s,
242                   ValueObject* valobj = NULL);
243
244
245     void
246     ClearIOHandlers ();
247
248     static int
249     TestDebuggerRefCount ();
250
251     bool
252     GetCloseInputOnEOF () const;
253     
254     void
255     SetCloseInputOnEOF (bool b);
256     
257     bool
258     EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
259
260     void
261     SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
262     
263
264     //----------------------------------------------------------------------
265     // Properties Functions
266     //----------------------------------------------------------------------
267     enum StopDisassemblyType
268     {
269         eStopDisassemblyTypeNever = 0,
270         eStopDisassemblyTypeNoSource,
271         eStopDisassemblyTypeAlways
272     };
273     
274     virtual Error
275     SetPropertyValue (const ExecutionContext *exe_ctx,
276                       VarSetOperationType op,
277                       const char *property_path,
278                       const char *value);
279
280     bool
281     GetAutoConfirm () const;
282     
283     const char *
284     GetFrameFormat() const;
285     
286     const char *
287     GetThreadFormat() const;
288     
289     lldb::ScriptLanguage
290     GetScriptLanguage() const;
291     
292     bool
293     SetScriptLanguage (lldb::ScriptLanguage script_lang);
294     
295     uint32_t
296     GetTerminalWidth () const;
297     
298     bool
299     SetTerminalWidth (uint32_t term_width);
300     
301     const char *
302     GetPrompt() const;
303     
304     void
305     SetPrompt(const char *p);
306     
307     bool
308     GetUseExternalEditor () const;
309     
310     bool
311     SetUseExternalEditor (bool use_external_editor_p);
312     
313     bool
314     GetUseColor () const;
315     
316     bool
317     SetUseColor (bool use_color);
318     
319     uint32_t
320     GetStopSourceLineCount (bool before) const;
321     
322     StopDisassemblyType
323     GetStopDisassemblyDisplay () const;
324     
325     uint32_t
326     GetDisassemblyLineCount () const;
327     
328     bool
329     GetAutoOneLineSummaries () const;
330     
331     bool
332     GetNotifyVoid () const;
333
334     
335     const ConstString &
336     GetInstanceName()
337     {
338         return m_instance_name;
339     }
340         
341     bool
342     LoadPlugin (const FileSpec& spec, Error& error);
343
344     void
345     ExecuteIOHanders();
346     
347     bool
348     IsForwardingEvents ();
349
350     void
351     EnableForwardEvents (const lldb::ListenerSP &listener_sp);
352
353     void
354     CancelForwardEvents (const lldb::ListenerSP &listener_sp);
355 protected:
356
357     friend class CommandInterpreter;
358
359     bool
360     StartEventHandlerThread();
361
362     void
363     StopEventHandlerThread();
364
365     static lldb::thread_result_t
366     EventHandlerThread (lldb::thread_arg_t arg);
367
368     bool
369     StartIOHandlerThread();
370     
371     void
372     StopIOHandlerThread();
373     
374     static lldb::thread_result_t
375     IOHandlerThread (lldb::thread_arg_t arg);
376
377     void
378     DefaultEventHandler();
379
380     void
381     HandleBreakpointEvent (const lldb::EventSP &event_sp);
382     
383     void
384     HandleProcessEvent (const lldb::EventSP &event_sp);
385
386     void
387     HandleThreadEvent (const lldb::EventSP &event_sp);
388
389     size_t
390     GetProcessSTDOUT (Process *process, Stream *stream);
391     
392     size_t
393     GetProcessSTDERR (Process *process, Stream *stream);
394
395     SourceManager::SourceFileCache &
396     GetSourceFileCache ()
397     {
398         return m_source_file_cache;
399     }
400     lldb::StreamFileSP m_input_file_sp;
401     lldb::StreamFileSP m_output_file_sp;
402     lldb::StreamFileSP m_error_file_sp;
403     TerminalState m_terminal_state;
404     TargetList m_target_list;
405     PlatformList m_platform_list;
406     Listener m_listener;
407     std::unique_ptr<SourceManager> m_source_manager_ap;    // This is a scratch source manager that we return if we have no targets.
408     SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
409                                                         // source file cache.
410     std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
411
412     IOHandlerStack m_input_reader_stack;
413     typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
414     LogStreamMap m_log_streams;
415     lldb::StreamSP m_log_callback_stream_sp;
416     ConstString m_instance_name;
417     static LoadPluginCallbackType g_load_plugin_callback;
418     typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList;
419     LoadedPluginsList m_loaded_plugins;
420     lldb::thread_t m_event_handler_thread;
421     lldb::thread_t m_io_handler_thread;
422     lldb::ListenerSP m_forward_listener_sp;
423     bool m_event_handler_thread_alive;
424     void
425     InstanceInitialize ();
426     
427 private:
428
429     // Use Debugger::CreateInstance() to get a shared pointer to a new
430     // debugger object
431     Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
432
433     DISALLOW_COPY_AND_ASSIGN (Debugger);
434     
435 };
436
437 } // namespace lldb_private
438
439 #endif  // #if defined(__cplusplus)
440 #endif  // liblldb_Debugger_h_