]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Debugger.h
MFC r258884: Update LLDB to upstream r196259 snapshot
[FreeBSD/stable/10.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/InputReaderStack.h"
23 #include "lldb/Core/Listener.h"
24 #include "lldb/Core/StreamFile.h"
25 #include "lldb/Core/SourceManager.h"
26 #include "lldb/Core/UserID.h"
27 #include "lldb/Core/UserSettingsController.h"
28 #include "lldb/DataFormatters/FormatManager.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 lldb_private {
36
37 //----------------------------------------------------------------------
38 /// @class Debugger Debugger.h "lldb/Core/Debugger.h"
39 /// @brief A class to manage flag bits.
40 ///
41 /// Provides a global root objects for the debugger core.
42 //----------------------------------------------------------------------
43
44
45 class Debugger :
46     public std::enable_shared_from_this<Debugger>,
47     public UserID,
48     public Properties,
49     public BroadcasterManager
50 {
51 friend class SourceManager;  // For GetSourceFileCache.
52
53 public:
54
55     typedef lldb::DynamicLibrarySP (*LoadPluginCallbackType) (const lldb::DebuggerSP &debugger_sp,
56                                                               const FileSpec& spec,
57                                                               Error& error);
58
59     static lldb::DebuggerSP
60     CreateInstance (lldb::LogOutputCallback log_callback = NULL, void *baton = NULL);
61
62     static lldb::TargetSP
63     FindTargetWithProcessID (lldb::pid_t pid);
64     
65     static lldb::TargetSP
66     FindTargetWithProcess (Process *process);
67
68     static void
69     Initialize (LoadPluginCallbackType load_plugin_callback);
70     
71     static void 
72     Terminate ();
73     
74     static void
75     SettingsInitialize ();
76     
77     static void
78     SettingsTerminate ();
79     
80     static void
81     Destroy (lldb::DebuggerSP &debugger_sp);
82
83     virtual
84     ~Debugger ();
85     
86     void Clear();
87
88     bool
89     GetAsyncExecution ();
90
91     void
92     SetAsyncExecution (bool async);
93
94     File &
95     GetInputFile ()
96     {
97         return m_input_file.GetFile();
98     }
99
100     File &
101     GetOutputFile ()
102     {
103         return m_output_file.GetFile();
104     }
105
106     File &
107     GetErrorFile ()
108     {
109         return m_error_file.GetFile();
110     }
111     
112     void
113     SetInputFileHandle (FILE *fh, bool tranfer_ownership);
114
115     void
116     SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
117
118     void
119     SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
120     
121     void
122     SaveInputTerminalState();
123     
124     void
125     RestoreInputTerminalState();
126
127     Stream&
128     GetOutputStream ()
129     {
130         return m_output_file;
131     }
132
133     Stream&
134     GetErrorStream ()
135     {
136         return m_error_file;
137     }
138
139     lldb::StreamSP
140     GetAsyncOutputStream ();
141     
142     lldb::StreamSP
143     GetAsyncErrorStream ();
144     
145     CommandInterpreter &
146     GetCommandInterpreter ()
147     {
148         assert (m_command_interpreter_ap.get());
149         return *m_command_interpreter_ap;
150     }
151
152     Listener &
153     GetListener ()
154     {
155         return m_listener;
156     }
157
158     // This returns the Debugger's scratch source manager.  It won't be able to look up files in debug
159     // information, but it can look up files by absolute path and display them to you.
160     // To get the target's source manager, call GetSourceManager on the target instead.
161     SourceManager &
162     GetSourceManager ();
163
164 public:
165     
166     lldb::TargetSP
167     GetSelectedTarget ()
168     {
169         return m_target_list.GetSelectedTarget ();
170     }
171
172     ExecutionContext
173     GetSelectedExecutionContext();
174     //------------------------------------------------------------------
175     /// Get accessor for the target list.
176     ///
177     /// The target list is part of the global debugger object. This
178     /// the single debugger shared instance to control where targets
179     /// get created and to allow for tracking and searching for targets
180     /// based on certain criteria.
181     ///
182     /// @return
183     ///     A global shared target list.
184     //------------------------------------------------------------------
185     TargetList &
186     GetTargetList ()
187     {
188         return m_target_list;
189     }
190
191     PlatformList &
192     GetPlatformList ()
193     {
194         return m_platform_list;
195     }
196
197     void
198     DispatchInputInterrupt ();
199
200     void
201     DispatchInputEndOfFile ();
202
203     void
204     DispatchInput (const char *bytes, size_t bytes_len);
205
206     void
207     WriteToDefaultReader (const char *bytes, size_t bytes_len);
208
209     void
210     PushInputReader (const lldb::InputReaderSP& reader_sp);
211
212     bool
213     PopInputReader (const lldb::InputReaderSP& reader_sp);
214
215     void
216     NotifyTopInputReader (lldb::InputReaderAction notification);
217
218     bool
219     InputReaderIsTopReader (const lldb::InputReaderSP& reader_sp);
220     
221     static lldb::DebuggerSP
222     FindDebuggerWithID (lldb::user_id_t id);
223     
224     static lldb::DebuggerSP
225     FindDebuggerWithInstanceName (const ConstString &instance_name);
226     
227     static size_t
228     GetNumDebuggers();
229     
230     static lldb::DebuggerSP
231     GetDebuggerAtIndex (size_t index);
232
233     static bool
234     FormatPrompt (const char *format,
235                   const SymbolContext *sc,
236                   const ExecutionContext *exe_ctx,
237                   const Address *addr,
238                   Stream &s,
239                   ValueObject* valobj = NULL);
240
241
242     void
243     CleanUpInputReaders ();
244
245     static int
246     TestDebuggerRefCount ();
247
248     bool
249     GetCloseInputOnEOF () const;
250     
251     void
252     SetCloseInputOnEOF (bool b);
253     
254     bool
255     EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
256
257     void
258     SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
259     
260
261     //----------------------------------------------------------------------
262     // Properties Functions
263     //----------------------------------------------------------------------
264     enum StopDisassemblyType
265     {
266         eStopDisassemblyTypeNever = 0,
267         eStopDisassemblyTypeNoSource,
268         eStopDisassemblyTypeAlways
269     };
270     
271     virtual Error
272     SetPropertyValue (const ExecutionContext *exe_ctx,
273                       VarSetOperationType op,
274                       const char *property_path,
275                       const char *value);
276
277     bool
278     GetAutoConfirm () const;
279     
280     const char *
281     GetFrameFormat() const;
282     
283     const char *
284     GetThreadFormat() const;
285     
286     lldb::ScriptLanguage
287     GetScriptLanguage() const;
288     
289     bool
290     SetScriptLanguage (lldb::ScriptLanguage script_lang);
291     
292     uint32_t
293     GetTerminalWidth () const;
294     
295     bool
296     SetTerminalWidth (uint32_t term_width);
297     
298     const char *
299     GetPrompt() const;
300     
301     void
302     SetPrompt(const char *p);
303     
304     bool
305     GetUseExternalEditor () const;
306     
307     bool
308     SetUseExternalEditor (bool use_external_editor_p);
309     
310     bool
311     GetUseColor () const;
312     
313     bool
314     SetUseColor (bool use_color);
315     
316     uint32_t
317     GetStopSourceLineCount (bool before) const;
318     
319     StopDisassemblyType
320     GetStopDisassemblyDisplay () const;
321     
322     uint32_t
323     GetDisassemblyLineCount () const;
324     
325     bool
326     GetAutoOneLineSummaries () const;
327     
328     bool
329     GetNotifyVoid () const;
330
331     
332     const ConstString &
333     GetInstanceName()
334     {
335         return m_instance_name;
336     }
337         
338     bool
339     LoadPlugin (const FileSpec& spec, Error& error);
340
341 protected:
342
343     static void
344     DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len);
345
346     lldb::InputReaderSP
347     GetCurrentInputReader ();
348     
349     void
350     ActivateInputReader (const lldb::InputReaderSP &reader_sp);
351
352     bool
353     CheckIfTopInputReaderIsDone ();
354     
355     SourceManager::SourceFileCache &
356     GetSourceFileCache ()
357     {
358         return m_source_file_cache;
359     }
360     Communication m_input_comm;
361     StreamFile m_input_file;
362     StreamFile m_output_file;
363     StreamFile m_error_file;
364     TerminalState m_terminal_state;
365     TargetList m_target_list;
366     PlatformList m_platform_list;
367     Listener m_listener;
368     std::unique_ptr<SourceManager> m_source_manager_ap;    // This is a scratch source manager that we return if we have no targets.
369     SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
370                                                         // source file cache.
371     std::unique_ptr<CommandInterpreter> m_command_interpreter_ap;
372
373     InputReaderStack m_input_reader_stack;
374     std::string m_input_reader_data;
375     typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
376     LogStreamMap m_log_streams;
377     lldb::StreamSP m_log_callback_stream_sp;
378     ConstString m_instance_name;
379     static LoadPluginCallbackType g_load_plugin_callback;
380     typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList;
381     LoadedPluginsList m_loaded_plugins;
382     
383     void
384     InstanceInitialize ();
385     
386 private:
387
388     // Use Debugger::CreateInstance() to get a shared pointer to a new
389     // debugger object
390     Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
391
392     DISALLOW_COPY_AND_ASSIGN (Debugger);
393     
394 };
395
396 } // namespace lldb_private
397
398 #endif  // #if defined(__cplusplus)
399 #endif  // liblldb_Debugger_h_