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