]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/llvm/tools/lldb/tools/driver/Driver.h
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / contrib / llvm / tools / lldb / tools / driver / Driver.h
1 //===-- Driver.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 lldb_Driver_h_
11 #define lldb_Driver_h_
12
13 #include "lldb/Utility/PseudoTerminal.h"
14
15 #include <set>
16 #include <bitset>
17 #include <string>
18 #include <vector>
19
20 #include "lldb/API/SBDefines.h"
21 #include "lldb/API/SBBroadcaster.h"
22 #include "lldb/API/SBDebugger.h"
23 #include "lldb/API/SBError.h"
24 #include "lldb/API/SBInputReader.h"
25
26 #define ASYNC true
27 #define NO_ASYNC false
28
29 class IOChannel;
30
31 namespace lldb
32 {
33     class SBInputReader;
34 }
35
36
37 class Driver : public lldb::SBBroadcaster
38 {
39 public:
40     enum {
41         eBroadcastBitReadyForInput    = (1 << 0),
42         eBroadcastBitThreadShouldExit = (1 << 1)
43     };
44
45     Driver ();
46
47     virtual
48     ~Driver ();
49
50     void
51     MainLoop ();
52
53     void
54     PutSTDIN (const char *src, size_t src_len);
55
56     void
57     GetFromMaster (const char *src, size_t src_len);
58
59     bool
60     HandleIOEvent (const lldb::SBEvent &event);
61
62     void
63     HandleProcessEvent (const lldb::SBEvent &event);
64
65     void
66     HandleBreakpointEvent (const lldb::SBEvent &event);
67
68     void
69     HandleThreadEvent (const lldb::SBEvent &event);
70
71     lldb::SBError
72     ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &do_exit);
73
74     const char *
75     GetFilename() const;
76
77     const char *
78     GetCrashLogFilename() const;
79
80     const char *
81     GetArchName() const;
82
83     lldb::ScriptLanguage
84     GetScriptLanguage() const;
85
86     size_t
87     GetNumSourceCommandFiles () const;
88
89     const char *
90     GetSourceCommandFileAtIndex (uint32_t idx) const;
91
92     bool
93     GetDebugMode() const;
94
95
96     class OptionData
97     {
98     public:
99         OptionData ();
100        ~OptionData ();
101
102         void
103         Clear();
104
105         //static OptionDefinition m_cmd_option_table[];
106
107         std::vector<std::string> m_args;
108         lldb::ScriptLanguage m_script_lang;
109         std::string m_core_file;
110         std::string m_crash_log;
111         std::vector<std::string> m_source_command_files;
112         bool m_debug_mode;
113         bool m_print_version;
114         bool m_print_python_path;
115         bool m_print_help;
116         bool m_wait_for;
117         std::string m_process_name;
118         lldb::pid_t m_process_pid;
119         bool m_use_external_editor;  // FIXME: When we have set/show variables we can remove this from here.
120         typedef std::set<char> OptionSet;
121         OptionSet m_seen_options;
122     };
123
124
125     static lldb::SBError
126     SetOptionValue (int option_idx,
127                     const char *option_arg,
128                     Driver::OptionData &data);
129
130
131     lldb::SBDebugger &
132     GetDebugger()
133     {
134         return m_debugger;
135     }
136     
137     bool
138     EditlineReaderIsTop ()
139     {
140         return m_debugger.InputReaderIsTopReader (m_editline_reader);
141     }
142
143     bool
144     GetIsDone () const
145     {
146         return m_done;
147     }
148
149     void
150     SetIsDone ()
151     {
152         m_done = true;
153     }
154     
155     void
156     ResizeWindow (unsigned short col);
157
158 private:
159     lldb::SBDebugger m_debugger;
160     lldb_utility::PseudoTerminal m_editline_pty;
161     FILE *m_editline_slave_fh;
162     lldb::SBInputReader m_editline_reader;
163     std::unique_ptr<IOChannel> m_io_channel_ap;
164     OptionData m_option_data;
165     bool m_executing_user_command;
166     bool m_waiting_for_command;
167     bool m_done;
168
169     void
170     ResetOptionValues ();
171
172     size_t
173     GetProcessSTDOUT ();
174
175     size_t
176     GetProcessSTDERR ();
177
178     void
179     UpdateSelectedThread ();
180
181     void
182     CloseIOChannelFile ();
183
184     static size_t
185     EditLineInputReaderCallback (void *baton, 
186                                  lldb::SBInputReader *reader, 
187                                  lldb::InputReaderAction notification,
188                                  const char *bytes, 
189                                  size_t bytes_len);
190
191     static void
192     ReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
193
194     static void
195     MasterThreadBytesReceived (void *baton, const void *src, size_t src_len);
196     
197     void
198     ReadyForCommand ();
199 };
200
201 #endif // lldb_Driver_h_