1 //===-- SBCommandInterpreter.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_SBCommandInterpreter_h_
11 #define LLDB_SBCommandInterpreter_h_
17 // Other libraries and framework includes
19 #include "lldb/API/SBDebugger.h"
20 #include "lldb/API/SBDefines.h"
24 class LLDB_API SBCommandInterpreterRunOptions {
25 friend class SBDebugger;
26 friend class SBCommandInterpreter;
29 SBCommandInterpreterRunOptions();
30 ~SBCommandInterpreterRunOptions();
32 bool GetStopOnContinue() const;
34 void SetStopOnContinue(bool);
36 bool GetStopOnError() const;
38 void SetStopOnError(bool);
40 bool GetStopOnCrash() const;
42 void SetStopOnCrash(bool);
44 bool GetEchoCommands() const;
46 void SetEchoCommands(bool);
48 bool GetPrintResults() const;
50 void SetPrintResults(bool);
52 bool GetAddToHistory() const;
54 void SetAddToHistory(bool);
57 lldb_private::CommandInterpreterRunOptions *get() const;
59 lldb_private::CommandInterpreterRunOptions &ref() const;
61 // This is set in the constructor and will always be valid.
62 mutable std::unique_ptr<lldb_private::CommandInterpreterRunOptions>
66 class SBCommandInterpreter {
69 eBroadcastBitThreadShouldExit = (1 << 0),
70 eBroadcastBitResetPrompt = (1 << 1),
71 eBroadcastBitQuitCommandReceived = (1 << 2), // User entered quit
72 eBroadcastBitAsynchronousOutputData = (1 << 3),
73 eBroadcastBitAsynchronousErrorData = (1 << 4)
76 SBCommandInterpreter(const lldb::SBCommandInterpreter &rhs);
78 ~SBCommandInterpreter();
80 const lldb::SBCommandInterpreter &
81 operator=(const lldb::SBCommandInterpreter &rhs);
84 GetArgumentTypeAsCString(const lldb::CommandArgumentType arg_type);
87 GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type);
89 static bool EventIsCommandInterpreterEvent(const lldb::SBEvent &event);
93 bool CommandExists(const char *cmd);
95 bool AliasExists(const char *cmd);
97 lldb::SBBroadcaster GetBroadcaster();
99 static const char *GetBroadcasterClass();
105 bool HasAliasOptions();
107 lldb::SBProcess GetProcess();
109 lldb::SBDebugger GetDebugger();
111 lldb::SBCommand AddMultiwordCommand(const char *name, const char *help);
113 lldb::SBCommand AddCommand(const char *name,
114 lldb::SBCommandPluginInterface *impl,
117 lldb::SBCommand AddCommand(const char *name,
118 lldb::SBCommandPluginInterface *impl,
119 const char *help, const char *syntax);
121 void SourceInitFileInHomeDirectory(lldb::SBCommandReturnObject &result);
124 SourceInitFileInCurrentWorkingDirectory(lldb::SBCommandReturnObject &result);
126 lldb::ReturnStatus HandleCommand(const char *command_line,
127 lldb::SBCommandReturnObject &result,
128 bool add_to_history = false);
130 lldb::ReturnStatus HandleCommand(const char *command_line,
131 SBExecutionContext &exe_ctx,
132 SBCommandReturnObject &result,
133 bool add_to_history = false);
135 void HandleCommandsFromFile(lldb::SBFileSpec &file,
136 lldb::SBExecutionContext &override_context,
137 lldb::SBCommandInterpreterRunOptions &options,
138 lldb::SBCommandReturnObject result);
140 // The pointer based interface is not useful in SWIG, since the cursor &
141 // last_char arguments are string pointers INTO current_line
142 // and you can't do that in a scripting language interface in general...
144 // In either case, the way this works is that the you give it a line and
145 // cursor position in the line. The function
146 // will return the number of completions. The matches list will contain
147 // number_of_completions + 1 elements. The first
148 // element is the common substring after the cursor position for all the
149 // matches. The rest of the elements are the
150 // matches. The first element is useful if you are emulating the common shell
151 // behavior where the tab completes
152 // to the string that is common among all the matches, then you should first
153 // check if the first element is non-empty,
154 // and if so just insert it and move the cursor to the end of the insertion.
155 // The next tab will return an empty
156 // common substring, and a list of choices (if any), at which point you should
157 // display the choices and let the user
158 // type further to disambiguate.
160 int HandleCompletion(const char *current_line, const char *cursor,
161 const char *last_char, int match_start_point,
162 int max_return_elements, lldb::SBStringList &matches);
164 int HandleCompletion(const char *current_line, uint32_t cursor_pos,
165 int match_start_point, int max_return_elements,
166 lldb::SBStringList &matches);
168 bool WasInterrupted() const;
170 // Catch commands before they execute by registering a callback that will
171 // get called when the command gets executed. This allows GUI or command
172 // line interfaces to intercept a command and stop it from happening
173 bool SetCommandOverrideCallback(const char *command_name,
174 lldb::CommandOverrideCallback callback,
177 SBCommandInterpreter(
178 lldb_private::CommandInterpreter *interpreter_ptr =
179 nullptr); // Access using SBDebugger::GetCommandInterpreter();
181 //----------------------------------------------------------------------
182 /// Return true if the command interpreter is the active IO handler.
184 /// This indicates that any input coming into the debugger handles will
185 /// go to the command interpreter and will result in LLDB command line
186 /// commands being executed.
187 //----------------------------------------------------------------------
190 //----------------------------------------------------------------------
191 /// Get the string that needs to be written to the debugger stdin file
192 /// handle when a control character is typed.
194 /// Some GUI programs will intercept "control + char" sequences and want
195 /// to have them do what normally would happen when using a real
196 /// terminal, so this function allows GUI programs to emulate this
200 /// The character that was typed along with the control key
203 /// The string that should be written into the file handle that is
204 /// feeding the input stream for the debugger, or nullptr if there is
205 /// no string for this control key.
206 //----------------------------------------------------------------------
207 const char *GetIOHandlerControlSequence(char ch);
209 bool GetPromptOnQuit();
211 void SetPromptOnQuit(bool b);
213 //----------------------------------------------------------------------
214 /// Resolve the command just as HandleCommand would, expanding abbreviations
215 /// and aliases. If successful, result->GetOutput has the full expansion.
216 //----------------------------------------------------------------------
217 void ResolveCommand(const char *command_line, SBCommandReturnObject &result);
220 lldb_private::CommandInterpreter &ref();
222 lldb_private::CommandInterpreter *get();
224 void reset(lldb_private::CommandInterpreter *);
227 friend class SBDebugger;
229 static void InitializeSWIG();
231 lldb_private::CommandInterpreter *m_opaque_ptr;
234 class SBCommandPluginInterface {
236 virtual ~SBCommandPluginInterface() = default;
238 virtual bool DoExecute(lldb::SBDebugger /*debugger*/, char ** /*command*/,
239 lldb::SBCommandReturnObject & /*result*/) {
250 const char *GetName();
252 const char *GetHelp();
254 const char *GetHelpLong();
256 void SetHelp(const char *);
258 void SetHelpLong(const char *);
262 void SetFlags(uint32_t flags);
264 lldb::SBCommand AddMultiwordCommand(const char *name,
265 const char *help = nullptr);
267 lldb::SBCommand AddCommand(const char *name,
268 lldb::SBCommandPluginInterface *impl,
269 const char *help = nullptr);
271 lldb::SBCommand AddCommand(const char *name,
272 lldb::SBCommandPluginInterface *impl,
273 const char *help, const char *syntax);
276 friend class SBDebugger;
277 friend class SBCommandInterpreter;
279 SBCommand(lldb::CommandObjectSP cmd_sp);
281 lldb::CommandObjectSP m_opaque_sp;
286 #endif // LLDB_SBCommandInterpreter_h_