]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/API/SBCommandInterpreter.h
Merge ^/head r293280 through r293429.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / API / SBCommandInterpreter.h
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/SBDefines.h"
20 #include "lldb/API/SBDebugger.h"
21
22 namespace lldb {
23
24 class LLDB_API SBCommandInterpreterRunOptions
25 {
26 friend class SBDebugger;
27 friend class SBCommandInterpreter;
28
29 public:
30     SBCommandInterpreterRunOptions();
31     ~SBCommandInterpreterRunOptions();
32
33     bool
34     GetStopOnContinue () const;
35
36     void
37     SetStopOnContinue (bool);
38
39     bool
40     GetStopOnError () const;
41
42     void
43     SetStopOnError (bool);
44
45     bool
46     GetStopOnCrash () const;
47
48     void
49     SetStopOnCrash (bool);
50
51     bool
52     GetEchoCommands () const;
53
54     void
55     SetEchoCommands (bool);
56
57     bool
58     GetPrintResults () const;
59
60     void
61     SetPrintResults (bool);
62
63     bool
64     GetAddToHistory () const;
65
66     void
67     SetAddToHistory (bool);
68
69 private:
70     lldb_private::CommandInterpreterRunOptions *
71     get () const;
72
73     lldb_private::CommandInterpreterRunOptions &
74     ref () const;
75
76     // This is set in the constructor and will always be valid.
77     mutable std::unique_ptr<lldb_private::CommandInterpreterRunOptions> m_opaque_up;
78 };
79
80 class SBCommandInterpreter
81 {
82 public:
83     enum
84     {
85         eBroadcastBitThreadShouldExit       = (1 << 0),
86         eBroadcastBitResetPrompt            = (1 << 1),
87         eBroadcastBitQuitCommandReceived    = (1 << 2),           // User entered quit 
88         eBroadcastBitAsynchronousOutputData = (1 << 3),
89         eBroadcastBitAsynchronousErrorData  = (1 << 4)
90     };
91
92     SBCommandInterpreter (const lldb::SBCommandInterpreter &rhs);
93     
94     ~SBCommandInterpreter ();
95
96     const lldb::SBCommandInterpreter &
97     operator = (const lldb::SBCommandInterpreter &rhs);
98
99     static const char * 
100     GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type);
101     
102     static const char *
103     GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type);
104
105     static bool
106     EventIsCommandInterpreterEvent (const lldb::SBEvent &event);
107     
108     bool
109     IsValid() const;
110
111     bool
112     CommandExists (const char *cmd);
113
114     bool
115     AliasExists (const char *cmd);
116
117     lldb::SBBroadcaster
118     GetBroadcaster ();
119     
120     static const char *
121     GetBroadcasterClass ();
122
123     bool
124     HasCommands ();
125
126     bool
127     HasAliases ();
128
129     bool
130     HasAliasOptions ();
131
132     lldb::SBProcess
133     GetProcess ();
134     
135     lldb::SBDebugger
136     GetDebugger ();
137     
138     lldb::SBCommand
139     AddMultiwordCommand (const char* name, const char* help);
140     
141     lldb::SBCommand
142     AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help);
143
144     void
145     SourceInitFileInHomeDirectory (lldb::SBCommandReturnObject &result);
146
147     void
148     SourceInitFileInCurrentWorkingDirectory (lldb::SBCommandReturnObject &result);
149
150     lldb::ReturnStatus
151     HandleCommand (const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history = false);
152
153     lldb::ReturnStatus
154     HandleCommand (const char *command_line, SBExecutionContext &exe_ctx, SBCommandReturnObject &result, bool add_to_history = false);
155
156     void
157     HandleCommandsFromFile (lldb::SBFileSpec &file,
158                             lldb::SBExecutionContext &override_context,
159                             lldb::SBCommandInterpreterRunOptions &options,
160                             lldb::SBCommandReturnObject result);
161
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...
164     
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.
173     
174     int
175     HandleCompletion (const char *current_line,
176                       const char *cursor,
177                       const char *last_char,
178                       int match_start_point,
179                       int max_return_elements,
180                       lldb::SBStringList &matches);
181
182     int
183     HandleCompletion (const char *current_line,
184                       uint32_t cursor_pos,
185                       int match_start_point,
186                       int max_return_elements,
187                       lldb::SBStringList &matches);
188
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
192     bool
193     SetCommandOverrideCallback (const char *command_name,
194                                 lldb::CommandOverrideCallback callback,
195                                 void *baton);
196     
197     SBCommandInterpreter(lldb_private::CommandInterpreter *interpreter_ptr = nullptr);   // Access using SBDebugger::GetCommandInterpreter();
198     
199     //----------------------------------------------------------------------
200     /// Return true if the command interpreter is the active IO handler.
201     ///
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     //----------------------------------------------------------------------
206     bool
207     IsActive ();
208     
209     //----------------------------------------------------------------------
210     /// Get the string that needs to be written to the debugger stdin file
211     /// handle when a control character is typed.
212     ///
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
216     /// functionality.
217     ///
218     /// @param[in] ch
219     ///     The character that was typed along with the control key
220     ///
221     /// @return
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     //----------------------------------------------------------------------
226     const char *
227     GetIOHandlerControlSequence(char ch);
228
229     bool
230     GetPromptOnQuit();
231
232     void
233     SetPromptOnQuit(bool b);
234
235     //----------------------------------------------------------------------
236     /// Resolve the command just as HandleCommand would, expanding abbreviations
237     /// and aliases.  If successful, result->GetOutput has the full expansion.
238     //----------------------------------------------------------------------
239     void
240     ResolveCommand(const char *command_line, SBCommandReturnObject &result);
241
242 protected:
243     lldb_private::CommandInterpreter &
244     ref ();
245
246     lldb_private::CommandInterpreter *
247     get ();
248
249     void
250     reset (lldb_private::CommandInterpreter *);
251
252 private:
253     friend class SBDebugger;
254
255     static void
256     InitializeSWIG ();
257
258     lldb_private::CommandInterpreter *m_opaque_ptr;
259 };
260
261 class SBCommandPluginInterface
262 {
263 public:
264     virtual
265     ~SBCommandPluginInterface() = default;
266
267     virtual bool
268     DoExecute (lldb::SBDebugger /*debugger*/,
269                char** /*command*/,
270                lldb::SBCommandReturnObject & /*result*/)
271     {
272         return false;
273     }
274 };
275     
276 class SBCommand
277 {
278 public:
279     SBCommand ();
280     
281     bool
282     IsValid ();
283     
284     const char*
285     GetName ();
286     
287     const char*
288     GetHelp ();
289     
290     const char*
291     GetHelpLong ();
292     
293     void
294     SetHelp (const char*);
295     
296     void
297     SetHelpLong (const char*);
298     
299     uint32_t
300     GetFlags ();
301     
302     void
303     SetFlags (uint32_t flags);
304     
305     lldb::SBCommand
306     AddMultiwordCommand(const char* name, const char* help = nullptr);
307     
308     lldb::SBCommand
309     AddCommand(const char* name, lldb::SBCommandPluginInterface* impl, const char* help = nullptr);
310     
311 private:
312     friend class SBDebugger;
313     friend class SBCommandInterpreter;
314     
315     SBCommand (lldb::CommandObjectSP cmd_sp);
316     
317     lldb::CommandObjectSP m_opaque_sp;
318 };
319
320 } // namespace lldb
321
322 #endif // LLDB_SBCommandInterpreter_h_