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