Debugger.h revision c833295baeec641086f536e78050388af36784f8
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/Core/Communication.h"
21#include "lldb/Core/Listener.h"
22#include "lldb/Core/StreamFile.h"
23#include "lldb/Core/SourceManager.h"
24#include "lldb/Core/UserID.h"
25#include "lldb/Target/ExecutionContext.h"
26#include "lldb/Target/TargetList.h"
27
28namespace lldb_private {
29
30//----------------------------------------------------------------------
31/// @class Debugger Debugger.h "lldb/Core/Debugger.h"
32/// @brief A class to manage flag bits.
33///
34/// Provides a global root objects for the debugger core.
35//----------------------------------------------------------------------
36class Debugger :
37    public UserID
38{
39public:
40
41    static lldb::DebuggerSP
42    CreateInstance ();
43
44    static lldb::TargetSP
45    FindTargetWithProcessID (lldb::pid_t pid);
46
47    static void
48    Initialize ();
49
50    static void
51    Terminate ();
52
53    ~Debugger ();
54
55    lldb::DebuggerSP
56    GetSP ();
57
58    bool
59    GetAsyncExecution ();
60
61    void
62    SetAsyncExecution (bool async);
63
64    void
65    SetInputFileHandle (FILE *fh, bool tranfer_ownership);
66
67    void
68    SetOutputFileHandle (FILE *fh, bool tranfer_ownership);
69
70    void
71    SetErrorFileHandle (FILE *fh, bool tranfer_ownership);
72
73    FILE *
74    GetInputFileHandle ();
75
76    FILE *
77    GetOutputFileHandle ();
78
79    FILE *
80    GetErrorFileHandle ();
81
82    Stream&
83    GetOutputStream ()
84    {
85        return m_output_file;
86    }
87
88    Stream&
89    GetErrorStream ()
90    {
91        return m_error_file;
92    }
93
94    CommandInterpreter &
95    GetCommandInterpreter ();
96
97    Listener &
98    GetListener ();
99
100    SourceManager &
101    GetSourceManager ();
102
103    lldb::TargetSP
104    GetSelectedTarget ();
105
106    ExecutionContext
107    GetSelectedExecutionContext();
108    //------------------------------------------------------------------
109    /// Get accessor for the target list.
110    ///
111    /// The target list is part of the global debugger object. This
112    /// the single debugger shared instance to control where targets
113    /// get created and to allow for tracking and searching for targets
114    /// based on certain criteria.
115    ///
116    /// @return
117    ///     A global shared target list.
118    //------------------------------------------------------------------
119    TargetList&
120    GetTargetList ();
121
122    void
123    DispatchInput (const char *bytes, size_t bytes_len);
124
125    void
126    WriteToDefaultReader (const char *bytes, size_t bytes_len);
127
128    void
129    PushInputReader (const lldb::InputReaderSP& reader_sp);
130
131    bool
132    PopInputReader (const lldb::InputReaderSP& reader_sp);
133
134    ExecutionContext &
135    GetExecutionContext()
136    {
137        return m_exe_ctx;
138    }
139
140
141    void
142    UpdateExecutionContext (ExecutionContext *override_context);
143
144    static lldb::DebuggerSP
145    FindDebuggerWithID (lldb::user_id_t id);
146
147protected:
148
149    static void
150    DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len);
151
152    void
153    ActivateInputReader (const lldb::InputReaderSP &reader_sp);
154
155    bool
156    CheckIfTopInputReaderIsDone ();
157
158    void
159    DisconnectInput();
160
161    Communication m_input_comm;
162    StreamFile m_input_file;
163    StreamFile m_output_file;
164    StreamFile m_error_file;
165    TargetList m_target_list;
166    Listener m_listener;
167    SourceManager m_source_manager;
168    std::auto_ptr<CommandInterpreter> m_command_interpreter_ap;
169    ExecutionContext m_exe_ctx;
170
171    std::stack<lldb::InputReaderSP> m_input_readers;
172    std::string m_input_reader_data;
173
174private:
175
176    // Use Debugger::CreateInstance() to get a shared pointer to a new
177    // debugger object
178    Debugger ();
179
180
181
182    DISALLOW_COPY_AND_ASSIGN (Debugger);
183};
184
185} // namespace lldb_private
186
187#endif  // #if defined(__cplusplus)
188#endif  // liblldb_Debugger_h_
189