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