]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/include/lldb/API/SBCommandInterpreter.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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 #include "lldb/API/SBDefines.h"
14 #include "lldb/API/SBDebugger.h"
15
16 namespace lldb {
17
18 class SBCommandInterpreter
19 {
20 public:
21     enum
22     {
23         eBroadcastBitThreadShouldExit       = (1 << 0),
24         eBroadcastBitResetPrompt            = (1 << 1),
25         eBroadcastBitQuitCommandReceived    = (1 << 2),           // User entered quit 
26         eBroadcastBitAsynchronousOutputData = (1 << 3),
27         eBroadcastBitAsynchronousErrorData  = (1 << 4)
28     };
29
30     SBCommandInterpreter (const lldb::SBCommandInterpreter &rhs);
31     
32     const lldb::SBCommandInterpreter &
33     operator = (const lldb::SBCommandInterpreter &rhs);
34
35     ~SBCommandInterpreter ();
36
37     static const char * 
38     GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type);
39     
40     static const char *
41     GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type);
42     
43     bool
44     IsValid() const;
45
46     bool
47     CommandExists (const char *cmd);
48
49     bool
50     AliasExists (const char *cmd);
51
52     lldb::SBBroadcaster
53     GetBroadcaster ();
54     
55     static const char *
56     GetBroadcasterClass ();
57
58     bool
59     HasCommands ();
60
61     bool
62     HasAliases ();
63
64     bool
65     HasAliasOptions ();
66
67     lldb::SBProcess
68     GetProcess ();
69     
70     lldb::SBDebugger
71     GetDebugger ();
72     
73     lldb::SBCommand
74     AddMultiwordCommand (const char* name, const char* help);
75     
76     lldb::SBCommand
77     AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help);
78
79     void
80     SourceInitFileInHomeDirectory (lldb::SBCommandReturnObject &result);
81
82     void
83     SourceInitFileInCurrentWorkingDirectory (lldb::SBCommandReturnObject &result);
84
85     lldb::ReturnStatus
86     HandleCommand (const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history = false);
87
88     // The pointer based interface is not useful in SWIG, since the cursor & last_char arguments are string pointers INTO current_line
89     // and you can't do that in a scripting language interface in general...
90     
91     // In either case, the way this works is that the you give it a line and cursor position in the line.  The function
92     // will return the number of completions.  The matches list will contain number_of_completions + 1 elements.  The first
93     // element is the common substring after the cursor position for all the matches.  The rest of the elements are the
94     // matches.  The first element is useful if you are emulating the common shell behavior where the tab completes
95     // to the string that is common among all the matches, then you should first check if the first element is non-empty,
96     // and if so just insert it and move the cursor to the end of the insertion.  The next tab will return an empty
97     // common substring, and a list of choices (if any), at which point you should display the choices and let the user
98     // type further to disambiguate.
99     
100     int
101     HandleCompletion (const char *current_line,
102                       const char *cursor,
103                       const char *last_char,
104                       int match_start_point,
105                       int max_return_elements,
106                       lldb::SBStringList &matches);
107
108     int
109     HandleCompletion (const char *current_line,
110                       uint32_t cursor_pos,
111                       int match_start_point,
112                       int max_return_elements,
113                       lldb::SBStringList &matches);
114
115     // Catch commands before they execute by registering a callback that will
116     // get called when the command gets executed. This allows GUI or command
117     // line interfaces to intercept a command and stop it from happening
118     bool
119     SetCommandOverrideCallback (const char *command_name,
120                                 lldb::CommandOverrideCallback callback,
121                                 void *baton);
122     
123     SBCommandInterpreter (lldb_private::CommandInterpreter *interpreter_ptr = NULL);   // Access using SBDebugger::GetCommandInterpreter();
124     
125     //----------------------------------------------------------------------
126     /// Return true if the command interpreter is the active IO handler.
127     ///
128     /// This indicates that any input coming into the debugger handles will
129     /// go to the command interpreter and will result in LLDB command line
130     /// commands being executed.
131     //----------------------------------------------------------------------
132     bool
133     IsActive ();
134     
135     //----------------------------------------------------------------------
136     /// Get the string that needs to be written to the debugger stdin file
137     /// handle when a control character is typed.
138     ///
139     /// Some GUI programs will intercept "control + char" sequences and want
140     /// to have them do what normally would happen when using a real
141     /// terminal, so this function allows GUI programs to emulate this
142     /// functionality.
143     ///
144     /// @param[in] ch
145     ///     The character that was typed along with the control key
146     ///
147     /// @return
148     ///     The string that should be written into the file handle that is
149     ///     feeding the input stream for the debugger, or NULL if there is
150     ///     no string for this control key.
151     //----------------------------------------------------------------------
152     const char *
153     GetIOHandlerControlSequence(char ch);
154
155 protected:
156
157     lldb_private::CommandInterpreter &
158     ref ();
159
160     lldb_private::CommandInterpreter *
161     get ();
162
163     void
164     reset (lldb_private::CommandInterpreter *);
165 private:
166     friend class SBDebugger;
167
168     static void
169     InitializeSWIG ();
170
171     lldb_private::CommandInterpreter *m_opaque_ptr;
172 };
173
174 class SBCommandPluginInterface
175 {
176 public:
177     virtual bool
178     DoExecute (lldb::SBDebugger debugger,
179                char** command,
180                lldb::SBCommandReturnObject &result)
181     {
182         return false;
183     }
184     
185     virtual
186     ~SBCommandPluginInterface ()
187     {}
188 };
189     
190 class SBCommand
191 {
192 public:
193     
194     SBCommand ();
195     
196     bool
197     IsValid ();
198     
199     const char*
200     GetName ();
201     
202     const char*
203     GetHelp ();
204     
205     lldb::SBCommand
206     AddMultiwordCommand (const char* name, const char* help = NULL);
207     
208     lldb::SBCommand
209     AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help = NULL);
210     
211 private:
212     
213     friend class SBDebugger;
214     friend class SBCommandInterpreter;
215     
216     SBCommand (lldb::CommandObjectSP cmd_sp);
217     
218     lldb::CommandObjectSP m_opaque_sp;
219 };
220
221 } // namespace lldb
222
223 #endif // LLDB_SBCommandInterpreter_h_