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