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/SBDefines.h"
20 #include "lldb/API/SBDebugger.h"
24 class LLDB_API SBCommandInterpreterRunOptions
26 friend class SBDebugger;
27 friend class SBCommandInterpreter;
30 SBCommandInterpreterRunOptions();
31 ~SBCommandInterpreterRunOptions();
34 GetStopOnContinue () const;
37 SetStopOnContinue (bool);
40 GetStopOnError () const;
43 SetStopOnError (bool);
46 GetStopOnCrash () const;
49 SetStopOnCrash (bool);
52 GetEchoCommands () const;
55 SetEchoCommands (bool);
58 GetPrintResults () const;
61 SetPrintResults (bool);
64 GetAddToHistory () const;
67 SetAddToHistory (bool);
70 lldb_private::CommandInterpreterRunOptions *
73 lldb_private::CommandInterpreterRunOptions &
76 // This is set in the constructor and will always be valid.
77 mutable std::unique_ptr<lldb_private::CommandInterpreterRunOptions> m_opaque_up;
80 class SBCommandInterpreter
85 eBroadcastBitThreadShouldExit = (1 << 0),
86 eBroadcastBitResetPrompt = (1 << 1),
87 eBroadcastBitQuitCommandReceived = (1 << 2), // User entered quit
88 eBroadcastBitAsynchronousOutputData = (1 << 3),
89 eBroadcastBitAsynchronousErrorData = (1 << 4)
92 SBCommandInterpreter (const lldb::SBCommandInterpreter &rhs);
94 ~SBCommandInterpreter ();
96 const lldb::SBCommandInterpreter &
97 operator = (const lldb::SBCommandInterpreter &rhs);
100 GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type);
103 GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type);
106 EventIsCommandInterpreterEvent (const lldb::SBEvent &event);
112 CommandExists (const char *cmd);
115 AliasExists (const char *cmd);
121 GetBroadcasterClass ();
139 AddMultiwordCommand (const char* name, const char* help);
142 AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help);
145 SourceInitFileInHomeDirectory (lldb::SBCommandReturnObject &result);
148 SourceInitFileInCurrentWorkingDirectory (lldb::SBCommandReturnObject &result);
151 HandleCommand (const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history = false);
154 HandleCommand (const char *command_line, SBExecutionContext &exe_ctx, SBCommandReturnObject &result, bool add_to_history = false);
157 HandleCommandsFromFile (lldb::SBFileSpec &file,
158 lldb::SBExecutionContext &override_context,
159 lldb::SBCommandInterpreterRunOptions &options,
160 lldb::SBCommandReturnObject result);
162 // The pointer based interface is not useful in SWIG, since the cursor & last_char arguments are string pointers INTO current_line
163 // and you can't do that in a scripting language interface in general...
165 // In either case, the way this works is that the you give it a line and cursor position in the line. The function
166 // will return the number of completions. The matches list will contain number_of_completions + 1 elements. The first
167 // element is the common substring after the cursor position for all the matches. The rest of the elements are the
168 // matches. The first element is useful if you are emulating the common shell behavior where the tab completes
169 // to the string that is common among all the matches, then you should first check if the first element is non-empty,
170 // and if so just insert it and move the cursor to the end of the insertion. The next tab will return an empty
171 // common substring, and a list of choices (if any), at which point you should display the choices and let the user
172 // type further to disambiguate.
175 HandleCompletion (const char *current_line,
177 const char *last_char,
178 int match_start_point,
179 int max_return_elements,
180 lldb::SBStringList &matches);
183 HandleCompletion (const char *current_line,
185 int match_start_point,
186 int max_return_elements,
187 lldb::SBStringList &matches);
189 // Catch commands before they execute by registering a callback that will
190 // get called when the command gets executed. This allows GUI or command
191 // line interfaces to intercept a command and stop it from happening
193 SetCommandOverrideCallback (const char *command_name,
194 lldb::CommandOverrideCallback callback,
197 SBCommandInterpreter(lldb_private::CommandInterpreter *interpreter_ptr = nullptr); // Access using SBDebugger::GetCommandInterpreter();
199 //----------------------------------------------------------------------
200 /// Return true if the command interpreter is the active IO handler.
202 /// This indicates that any input coming into the debugger handles will
203 /// go to the command interpreter and will result in LLDB command line
204 /// commands being executed.
205 //----------------------------------------------------------------------
209 //----------------------------------------------------------------------
210 /// Get the string that needs to be written to the debugger stdin file
211 /// handle when a control character is typed.
213 /// Some GUI programs will intercept "control + char" sequences and want
214 /// to have them do what normally would happen when using a real
215 /// terminal, so this function allows GUI programs to emulate this
219 /// The character that was typed along with the control key
222 /// The string that should be written into the file handle that is
223 /// feeding the input stream for the debugger, or nullptr if there is
224 /// no string for this control key.
225 //----------------------------------------------------------------------
227 GetIOHandlerControlSequence(char ch);
233 SetPromptOnQuit(bool b);
235 //----------------------------------------------------------------------
236 /// Resolve the command just as HandleCommand would, expanding abbreviations
237 /// and aliases. If successful, result->GetOutput has the full expansion.
238 //----------------------------------------------------------------------
240 ResolveCommand(const char *command_line, SBCommandReturnObject &result);
243 lldb_private::CommandInterpreter &
246 lldb_private::CommandInterpreter *
250 reset (lldb_private::CommandInterpreter *);
253 friend class SBDebugger;
258 lldb_private::CommandInterpreter *m_opaque_ptr;
261 class SBCommandPluginInterface
265 ~SBCommandPluginInterface() = default;
268 DoExecute (lldb::SBDebugger /*debugger*/,
270 lldb::SBCommandReturnObject & /*result*/)
294 SetHelp (const char*);
297 SetHelpLong (const char*);
303 SetFlags (uint32_t flags);
306 AddMultiwordCommand(const char* name, const char* help = nullptr);
309 AddCommand(const char* name, lldb::SBCommandPluginInterface* impl, const char* help = nullptr);
312 friend class SBDebugger;
313 friend class SBCommandInterpreter;
315 SBCommand (lldb::CommandObjectSP cmd_sp);
317 lldb::CommandObjectSP m_opaque_sp;
322 #endif // LLDB_SBCommandInterpreter_h_