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