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 15 #include "lldb/API/SBBroadcaster.h" 16 #include "lldb/API/SBDebugger.h" 17 #include "lldb/API/SBDefines.h" 18 #include "lldb/API/SBError.h" 19 20 #include "llvm/Option/Arg.h" 21 #include "llvm/Option/ArgList.h" 22 #include "llvm/Option/Option.h" 23 24 #include <set> 25 #include <string> 26 #include <vector> 27 28 class Driver : public lldb::SBBroadcaster { 29 public: 30 typedef enum CommandPlacement { 31 eCommandPlacementBeforeFile, 32 eCommandPlacementAfterFile, 33 eCommandPlacementAfterCrash, 34 } CommandPlacement; 35 36 Driver(); 37 38 virtual ~Driver(); 39 40 /// Runs the main loop. 41 /// 42 /// @return The exit code that the process should return. 43 int MainLoop(); 44 45 lldb::SBError ProcessArgs(const llvm::opt::InputArgList &args, bool &exiting); 46 47 const char *GetFilename() const; 48 49 const char *GetCrashLogFilename() const; 50 51 const char *GetArchName() const; 52 53 lldb::ScriptLanguage GetScriptLanguage() const; 54 55 void WriteCommandsForSourcing(CommandPlacement placement, 56 lldb::SBStream &strm); 57 58 bool GetDebugMode() const; 59 60 struct OptionData { 61 void AddLocalLLDBInit(); 62 void AddInitialCommand(std::string command, CommandPlacement placement, 63 bool is_file, lldb::SBError &error); 64 65 struct InitialCmdEntry { 66 InitialCmdEntry(std::string contents, bool in_is_file, 67 bool is_cwd_lldbinit_file_read, bool in_quiet = false) contentsOptionData::InitialCmdEntry68 : contents(std::move(contents)), is_file(in_is_file), 69 source_quietly(in_quiet), 70 is_cwd_lldbinit_file_read(is_cwd_lldbinit_file_read) {} 71 72 std::string contents; 73 bool is_file; 74 bool source_quietly; 75 76 /// Remember if this is reading the local lldbinit file so we can skip it 77 /// if not permitted. 78 bool is_cwd_lldbinit_file_read; 79 }; 80 81 std::vector<std::string> m_args; 82 83 lldb::ScriptLanguage m_script_lang = lldb::eScriptLanguageDefault; 84 lldb::LanguageType m_repl_lang = lldb::eLanguageTypeUnknown; 85 lldb::pid_t m_process_pid = LLDB_INVALID_PROCESS_ID; 86 87 std::string m_core_file; 88 std::string m_crash_log; 89 std::string m_repl_options; 90 std::string m_process_name; 91 92 std::vector<InitialCmdEntry> m_initial_commands; 93 std::vector<InitialCmdEntry> m_after_file_commands; 94 std::vector<InitialCmdEntry> m_after_crash_commands; 95 96 bool m_debug_mode = false; 97 bool m_source_quietly = false; 98 bool m_print_version = false; 99 bool m_print_python_path = false; 100 bool m_wait_for = false; 101 bool m_repl = false; 102 bool m_batch = false; 103 104 // FIXME: When we have set/show variables we can remove this from here. 105 bool m_use_external_editor = false; 106 107 using OptionSet = std::set<char>; 108 OptionSet m_seen_options; 109 }; 110 GetDebugger()111 lldb::SBDebugger &GetDebugger() { return m_debugger; } 112 113 void ResizeWindow(unsigned short col); 114 115 private: 116 lldb::SBDebugger m_debugger; 117 OptionData m_option_data; 118 }; 119 120 #endif // lldb_Driver_h_ 121