xref: /freebsd/contrib/llvm-project/lldb/tools/driver/Driver.h (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 //===-- Driver.h ------------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_TOOLS_DRIVER_DRIVER_H
10 #define LLDB_TOOLS_DRIVER_DRIVER_H
11 
12 #include "Platform.h"
13 
14 #include "lldb/API/SBBroadcaster.h"
15 #include "lldb/API/SBDebugger.h"
16 #include "lldb/API/SBDefines.h"
17 #include "lldb/API/SBError.h"
18 
19 #include "llvm/Option/Arg.h"
20 #include "llvm/Option/ArgList.h"
21 #include "llvm/Option/Option.h"
22 
23 #include <set>
24 #include <string>
25 #include <vector>
26 
27 class Driver : public lldb::SBBroadcaster {
28 public:
29   enum CommandPlacement {
30     eCommandPlacementBeforeFile,
31     eCommandPlacementAfterFile,
32     eCommandPlacementAfterCrash,
33   };
34 
35   Driver();
36 
37   virtual ~Driver();
38 
39   /// Runs the main loop.
40   ///
41   /// \return The exit code that the process should return.
42   int MainLoop();
43 
44   lldb::SBError ProcessArgs(const llvm::opt::InputArgList &args, bool &exiting);
45 
46   void WriteCommandsForSourcing(CommandPlacement placement,
47                                 lldb::SBStream &strm);
48 
49   struct OptionData {
50     void AddInitialCommand(std::string command, CommandPlacement placement,
51                            bool is_file, lldb::SBError &error);
52 
53     struct InitialCmdEntry {
54       InitialCmdEntry(std::string contents, bool in_is_file,
55                       bool in_quiet = false)
56           : contents(std::move(contents)), is_file(in_is_file),
57             source_quietly(in_quiet) {}
58 
59       std::string contents;
60       bool is_file;
61       bool source_quietly;
62     };
63 
64     std::vector<std::string> m_args;
65 
66     lldb::LanguageType m_repl_lang = lldb::eLanguageTypeUnknown;
67     lldb::pid_t m_process_pid = LLDB_INVALID_PROCESS_ID;
68 
69     std::string m_core_file;
70     std::string m_crash_log;
71     std::string m_repl_options;
72     std::string m_process_name;
73 
74     std::vector<InitialCmdEntry> m_initial_commands;
75     std::vector<InitialCmdEntry> m_after_file_commands;
76     std::vector<InitialCmdEntry> m_after_crash_commands;
77 
78     bool m_debug_mode = false;
79     bool m_source_quietly = false;
80     bool m_print_version = false;
81     bool m_print_python_path = false;
82     bool m_print_script_interpreter_info = false;
83     bool m_wait_for = false;
84     bool m_repl = false;
85     bool m_batch = false;
86 
87     // FIXME: When we have set/show variables we can remove this from here.
88     bool m_use_external_editor = false;
89 
90     using OptionSet = std::set<char>;
91     OptionSet m_seen_options;
92   };
93 
94   lldb::SBDebugger &GetDebugger() { return m_debugger; }
95 
96   void ResizeWindow(unsigned short col);
97 
98 private:
99   lldb::SBDebugger m_debugger;
100   OptionData m_option_data;
101 };
102 
103 #endif // LLDB_TOOLS_DRIVER_DRIVER_H
104