Debugger.h revision 535f53c8795b3592ce835804af5cef89be39ceea
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#include <unistd.h>
17
18#include <stack>
19
20#include "lldb/lldb-public.h"
21
22#include "lldb/API/SBDefines.h"
23
24#include "lldb/Core/Broadcaster.h"
25#include "lldb/Core/Communication.h"
26#include "lldb/Core/InputReaderStack.h"
27#include "lldb/Core/Listener.h"
28#include "lldb/Core/StreamFile.h"
29#include "lldb/Core/SourceManager.h"
30#include "lldb/Core/UserID.h"
31#include "lldb/Core/UserSettingsController.h"
32#include "lldb/DataFormatters/FormatManager.h"
33#include "lldb/Host/Terminal.h"
34#include "lldb/Interpreter/OptionValueProperties.h"
35#include "lldb/Target/ExecutionContext.h"
36#include "lldb/Target/Platform.h"
37#include "lldb/Target/TargetList.h"
38
39namespace lldb_private {
40
41//----------------------------------------------------------------------
42/// @class Debugger Debugger.h "lldb/Core/Debugger.h"
43/// @brief A class to manage flag bits.
44///
45/// Provides a global root objects for the debugger core.
46//----------------------------------------------------------------------
47
48
49class Debugger :
50    public STD_ENABLE_SHARED_FROM_THIS(Debugger),
51    public UserID,
52    public Properties,
53    public BroadcasterManager
54{
55friend class SourceManager;  // For GetSourceFileCache.
56
57public:
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 ();
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
164public:
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                  const char **end,
240                  ValueObject* valobj = NULL);
241
242
243    void
244    CleanUpInputReaders ();
245
246    static int
247    TestDebuggerRefCount ();
248
249    bool
250    GetCloseInputOnEOF () const;
251
252    void
253    SetCloseInputOnEOF (bool b);
254
255    bool
256    EnableLog (const char *channel, const char **categories, const char *log_file, uint32_t log_options, Stream &error_stream);
257
258    void
259    SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
260
261
262    //----------------------------------------------------------------------
263    // Properties Functions
264    //----------------------------------------------------------------------
265    enum StopDisassemblyType
266    {
267        eStopDisassemblyTypeNever = 0,
268        eStopDisassemblyTypeNoSource,
269        eStopDisassemblyTypeAlways
270    };
271
272    virtual Error
273    SetPropertyValue (const ExecutionContext *exe_ctx,
274                      VarSetOperationType op,
275                      const char *property_path,
276                      const char *value);
277
278    bool
279    GetAutoConfirm () const;
280
281    const char *
282    GetFrameFormat() const;
283
284    const char *
285    GetThreadFormat() const;
286
287    lldb::ScriptLanguage
288    GetScriptLanguage() const;
289
290    bool
291    SetScriptLanguage (lldb::ScriptLanguage script_lang);
292
293    uint32_t
294    GetTerminalWidth () const;
295
296    bool
297    SetTerminalWidth (uint32_t term_width);
298
299    const char *
300    GetPrompt() const;
301
302    void
303    SetPrompt(const char *p);
304
305    bool
306    GetUseExternalEditor () const;
307
308    bool
309    SetUseExternalEditor (bool use_external_editor_p);
310
311    uint32_t
312    GetStopSourceLineCount (bool before) const;
313
314    StopDisassemblyType
315    GetStopDisassemblyDisplay () const;
316
317    uint32_t
318    GetDisassemblyLineCount () const;
319
320    bool
321    GetNotifyVoid () const;
322
323
324    const ConstString &
325    GetInstanceName()
326    {
327        return m_instance_name;
328    }
329
330    typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
331
332    bool
333    LoadPlugin (const FileSpec& spec);
334
335protected:
336
337    static void
338    DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len);
339
340    lldb::InputReaderSP
341    GetCurrentInputReader ();
342
343    void
344    ActivateInputReader (const lldb::InputReaderSP &reader_sp);
345
346    bool
347    CheckIfTopInputReaderIsDone ();
348
349    SourceManager::SourceFileCache &
350    GetSourceFileCache ()
351    {
352        return m_source_file_cache;
353    }
354    Communication m_input_comm;
355    StreamFile m_input_file;
356    StreamFile m_output_file;
357    StreamFile m_error_file;
358    TerminalState m_terminal_state;
359    TargetList m_target_list;
360    PlatformList m_platform_list;
361    Listener m_listener;
362    std::auto_ptr<SourceManager> m_source_manager_ap;    // This is a scratch source manager that we return if we have no targets.
363    SourceManager::SourceFileCache m_source_file_cache; // All the source managers for targets created in this debugger used this shared
364                                                        // source file cache.
365    std::auto_ptr<CommandInterpreter> m_command_interpreter_ap;
366
367    InputReaderStack m_input_reader_stack;
368    std::string m_input_reader_data;
369    typedef std::map<std::string, lldb::StreamWP> LogStreamMap;
370    LogStreamMap m_log_streams;
371    lldb::StreamSP m_log_callback_stream_sp;
372    ConstString m_instance_name;
373    typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList;
374    LoadedPluginsList m_loaded_plugins;
375
376    void
377    InstanceInitialize ();
378
379private:
380
381    // Use Debugger::CreateInstance() to get a shared pointer to a new
382    // debugger object
383    Debugger (lldb::LogOutputCallback m_log_callback, void *baton);
384
385    DISALLOW_COPY_AND_ASSIGN (Debugger);
386
387};
388
389} // namespace lldb_private
390
391#endif  // #if defined(__cplusplus)
392#endif  // liblldb_Debugger_h_
393