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