LLDB API Documentation

SBCommandInterpreter.h
Go to the documentation of this file.
1 //===-- SBCommandInterpreter.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_SBCommandInterpreter_h_
11 #define LLDB_SBCommandInterpreter_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <memory>
16 
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/API/SBDebugger.h"
20 #include "lldb/API/SBDefines.h"
21 
22 namespace lldb {
23 
25  friend class SBDebugger;
26  friend class SBCommandInterpreter;
27 
28 public:
31 
32  bool GetStopOnContinue() const;
33 
34  void SetStopOnContinue(bool);
35 
36  bool GetStopOnError() const;
37 
38  void SetStopOnError(bool);
39 
40  bool GetStopOnCrash() const;
41 
42  void SetStopOnCrash(bool);
43 
44  bool GetEchoCommands() const;
45 
46  void SetEchoCommands(bool);
47 
48  bool GetPrintResults() const;
49 
50  void SetPrintResults(bool);
51 
52  bool GetAddToHistory() const;
53 
54  void SetAddToHistory(bool);
55 
56 private:
57  lldb_private::CommandInterpreterRunOptions *get() const;
58 
59  lldb_private::CommandInterpreterRunOptions &ref() const;
60 
61  // This is set in the constructor and will always be valid.
62  mutable std::unique_ptr<lldb_private::CommandInterpreterRunOptions>
63  m_opaque_up;
64 };
65 
67 public:
68  enum {
71  eBroadcastBitQuitCommandReceived = (1 << 2), // User entered quit
74  };
75 
77 
79 
82 
83  static const char *
84  GetArgumentTypeAsCString(const lldb::CommandArgumentType arg_type);
85 
86  static const char *
87  GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type);
88 
89  static bool EventIsCommandInterpreterEvent(const lldb::SBEvent &event);
90 
91  bool IsValid() const;
92 
93  bool CommandExists(const char *cmd);
94 
95  bool AliasExists(const char *cmd);
96 
98 
99  static const char *GetBroadcasterClass();
100 
101  bool HasCommands();
102 
103  bool HasAliases();
104 
105  bool HasAliasOptions();
106 
108 
110 
111  lldb::SBCommand AddMultiwordCommand(const char *name, const char *help);
112 
113  lldb::SBCommand AddCommand(const char *name,
115  const char *help);
116 
117  lldb::SBCommand AddCommand(const char *name,
119  const char *help, const char *syntax);
120 
122 
123  void
125 
126  lldb::ReturnStatus HandleCommand(const char *command_line,
128  bool add_to_history = false);
129 
130  lldb::ReturnStatus HandleCommand(const char *command_line,
131  SBExecutionContext &exe_ctx,
132  SBCommandReturnObject &result,
133  bool add_to_history = false);
134 
136  lldb::SBExecutionContext &override_context,
139 
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...
143 
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.
159 
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);
163 
164  int HandleCompletion(const char *current_line, uint32_t cursor_pos,
165  int match_start_point, int max_return_elements,
166  lldb::SBStringList &matches);
167 
168  // Catch commands before they execute by registering a callback that will
169  // get called when the command gets executed. This allows GUI or command
170  // line interfaces to intercept a command and stop it from happening
171  bool SetCommandOverrideCallback(const char *command_name,
172  lldb::CommandOverrideCallback callback,
173  void *baton);
174 
176  lldb_private::CommandInterpreter *interpreter_ptr =
177  nullptr); // Access using SBDebugger::GetCommandInterpreter();
178 
179  //----------------------------------------------------------------------
180  /// Return true if the command interpreter is the active IO handler.
181  ///
182  /// This indicates that any input coming into the debugger handles will
183  /// go to the command interpreter and will result in LLDB command line
184  /// commands being executed.
185  //----------------------------------------------------------------------
186  bool IsActive();
187 
188  //----------------------------------------------------------------------
189  /// Get the string that needs to be written to the debugger stdin file
190  /// handle when a control character is typed.
191  ///
192  /// Some GUI programs will intercept "control + char" sequences and want
193  /// to have them do what normally would happen when using a real
194  /// terminal, so this function allows GUI programs to emulate this
195  /// functionality.
196  ///
197  /// @param[in] ch
198  /// The character that was typed along with the control key
199  ///
200  /// @return
201  /// The string that should be written into the file handle that is
202  /// feeding the input stream for the debugger, or nullptr if there is
203  /// no string for this control key.
204  //----------------------------------------------------------------------
205  const char *GetIOHandlerControlSequence(char ch);
206 
207  bool GetPromptOnQuit();
208 
209  void SetPromptOnQuit(bool b);
210 
211  //----------------------------------------------------------------------
212  /// Resolve the command just as HandleCommand would, expanding abbreviations
213  /// and aliases. If successful, result->GetOutput has the full expansion.
214  //----------------------------------------------------------------------
215  void ResolveCommand(const char *command_line, SBCommandReturnObject &result);
216 
217 protected:
218  lldb_private::CommandInterpreter &ref();
219 
220  lldb_private::CommandInterpreter *get();
221 
222  void reset(lldb_private::CommandInterpreter *);
223 
224 private:
225  friend class SBDebugger;
226 
227  static void InitializeSWIG();
228 
229  lldb_private::CommandInterpreter *m_opaque_ptr;
230 };
231 
233 public:
234  virtual ~SBCommandPluginInterface() = default;
235 
236  virtual bool DoExecute(lldb::SBDebugger /*debugger*/, char ** /*command*/,
237  lldb::SBCommandReturnObject & /*result*/) {
238  return false;
239  }
240 };
241 
242 class SBCommand {
243 public:
244  SBCommand();
245 
246  bool IsValid();
247 
248  const char *GetName();
249 
250  const char *GetHelp();
251 
252  const char *GetHelpLong();
253 
254  void SetHelp(const char *);
255 
256  void SetHelpLong(const char *);
257 
258  uint32_t GetFlags();
259 
260  void SetFlags(uint32_t flags);
261 
262  lldb::SBCommand AddMultiwordCommand(const char *name,
263  const char *help = nullptr);
264 
265  lldb::SBCommand AddCommand(const char *name,
267  const char *help = nullptr);
268 
269  lldb::SBCommand AddCommand(const char *name,
271  const char *help, const char *syntax);
272 
273 private:
274  friend class SBDebugger;
275  friend class SBCommandInterpreter;
276 
277  SBCommand(lldb::CommandObjectSP cmd_sp);
278 
279  lldb::CommandObjectSP m_opaque_sp;
280 };
281 
282 } // namespace lldb
283 
284 #endif // LLDB_SBCommandInterpreter_h_
static bool EventIsCommandInterpreterEvent(const lldb::SBEvent &event)
lldb::SBProcess GetProcess()
static const char * GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type)
bool SetCommandOverrideCallback(const char *command_name, lldb::CommandOverrideCallback callback, void *baton)
bool AliasExists(const char *cmd)
SBCommandInterpreter(const lldb::SBCommandInterpreter &rhs)
static const char * GetBroadcasterClass()
bool CommandExists(const char *cmd)
class LLDB_API SBCommand
Definition: SBDefines.h:36
lldb::SBCommand AddCommand(const char *name, lldb::SBCommandPluginInterface *impl, const char *help)
lldb::ReturnStatus HandleCommand(const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history=false)
class LLDB_API SBCommandInterpreterRunOptions
Definition: SBDefines.h:38
void HandleCommandsFromFile(lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context, lldb::SBCommandInterpreterRunOptions &options, lldb::SBCommandReturnObject result)
int HandleCompletion(const char *current_line, const char *cursor, const char *last_char, int match_start_point, int max_return_elements, lldb::SBStringList &matches)
void ResolveCommand(const char *command_line, SBCommandReturnObject &result)
lldb::SBDebugger GetDebugger()
const char * GetIOHandlerControlSequence(char ch)
virtual bool DoExecute(lldb::SBDebugger, char **, lldb::SBCommandReturnObject &)
void SourceInitFileInHomeDirectory(lldb::SBCommandReturnObject &result)
lldb::SBCommand AddMultiwordCommand(const char *name, const char *help)
static const char * GetArgumentTypeAsCString(const lldb::CommandArgumentType arg_type)
void SourceInitFileInCurrentWorkingDirectory(lldb::SBCommandReturnObject &result)
void reset(lldb_private::CommandInterpreter *)
lldb::SBBroadcaster GetBroadcaster()
lldb_private::CommandInterpreter & ref()
const lldb::SBCommandInterpreter & operator=(const lldb::SBCommandInterpreter &rhs)