8
8
9
9
#include " CommandObjectScripting.h"
10
10
#include " lldb/Core/Debugger.h"
11
+ #include " lldb/Core/PluginManager.h"
11
12
#include " lldb/DataFormatters/DataVisualization.h"
12
13
#include " lldb/Host/Config.h"
13
14
#include " lldb/Host/OptionParser.h"
21
22
using namespace lldb ;
22
23
using namespace lldb_private ;
23
24
25
+ #pragma mark CommandObjectScriptingExecute
26
+
24
27
#define LLDB_OPTIONS_scripting_execute
25
28
#include " CommandOptions.inc"
26
29
@@ -114,6 +117,159 @@ void CommandObjectScriptingExecute::DoExecute(llvm::StringRef command,
114
117
result.SetStatus (eReturnStatusFailed);
115
118
}
116
119
120
+ #pragma mark CommandObjectScriptingTemplateList
121
+
122
+ #define LLDB_OPTIONS_scripting_template_list
123
+ #include " CommandOptions.inc"
124
+
125
+ Status CommandObjectScriptingTemplateList::CommandOptions::SetOptionValue (
126
+ uint32_t option_idx, llvm::StringRef option_arg,
127
+ ExecutionContext *execution_context) {
128
+ Status error;
129
+ const int short_option = m_getopt_table[option_idx].val ;
130
+
131
+ switch (short_option) {
132
+ case ' l' :
133
+ language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum (
134
+ option_arg, GetDefinitions ()[option_idx].enum_values ,
135
+ eScriptLanguageNone, error);
136
+ if (!error.Success ())
137
+ error.SetErrorStringWithFormat (" unrecognized value for language '%s'" ,
138
+ option_arg.str ().c_str ());
139
+ break ;
140
+ default :
141
+ llvm_unreachable (" Unimplemented option" );
142
+ }
143
+
144
+ return error;
145
+ }
146
+
147
+ void CommandObjectScriptingTemplateList::CommandOptions::OptionParsingStarting (
148
+ ExecutionContext *execution_context) {
149
+ language = lldb::eScriptLanguageNone;
150
+ }
151
+
152
+ llvm::ArrayRef<OptionDefinition>
153
+ CommandObjectScriptingTemplateList::CommandOptions::GetDefinitions () {
154
+ return llvm::ArrayRef (g_scripting_execute_options);
155
+ }
156
+
157
+ CommandObjectScriptingTemplateList::CommandObjectScriptingTemplateList (
158
+ CommandInterpreter &interpreter)
159
+ : CommandObjectParsed(
160
+ interpreter, " scripting template list" ,
161
+ " List all the available scripting affordances templates. " ,
162
+ " scripting template list [--language <scripting-language> --]" ) {}
163
+
164
+ CommandObjectScriptingTemplateList::~CommandObjectScriptingTemplateList () =
165
+ default ;
166
+
167
+ void CommandObjectScriptingTemplateList::DoExecute (
168
+ Args &command, CommandReturnObject &result) {
169
+ lldb::ScriptLanguage language =
170
+ (m_options.language == lldb::eScriptLanguageNone)
171
+ ? m_interpreter.GetDebugger ().GetScriptLanguage ()
172
+ : m_options.language ;
173
+
174
+ if (language == lldb::eScriptLanguageNone) {
175
+ result.AppendError (
176
+ " the script-lang setting is set to none - scripting not available" );
177
+ return ;
178
+ }
179
+
180
+ ScriptInterpreter *script_interpreter =
181
+ GetDebugger ().GetScriptInterpreter (true , language);
182
+
183
+ if (script_interpreter == nullptr ) {
184
+ result.AppendError (" no script interpreter" );
185
+ return ;
186
+ }
187
+
188
+ Stream &s = result.GetOutputStream ();
189
+ s.Printf (" Available scripted affordances:\n " );
190
+
191
+ auto print_field = [&s](llvm::StringRef key, llvm::StringRef value,
192
+ bool check_validy = false ) {
193
+ if (!check_validy || !value.empty ()) {
194
+ s.IndentMore ();
195
+ s.Indent ();
196
+ s << key << " : " << value << ' \n ' ;
197
+ s.IndentLess ();
198
+ }
199
+ };
200
+ auto print_usages = [&s](llvm::StringRef usage_kind,
201
+ std::vector<llvm::StringRef> &usages) {
202
+ s.IndentMore ();
203
+ s.Indent ();
204
+ s << usage_kind << " Usages:" ;
205
+ if (usages.empty ())
206
+ s << " No usages.\n " ;
207
+ else if (usages.size () == 1 )
208
+ s << " " << usages.front () << ' \n ' ;
209
+ else {
210
+ s << ' \n ' ;
211
+ for (llvm::StringRef usage : usages) {
212
+ s.IndentMore ();
213
+ s.Indent ();
214
+ s << usage << ' \n ' ;
215
+ s.IndentLess ();
216
+ }
217
+ }
218
+ s.IndentLess ();
219
+ };
220
+
221
+ size_t i = 0 ;
222
+ for (llvm::StringRef plugin_name =
223
+ PluginManager::GetScriptedInterfaceNameAtIndex (i);
224
+ !plugin_name.empty ();) {
225
+
226
+ llvm::StringRef desc =
227
+ PluginManager::GetScriptedInterfaceDescriptionAtIndex (i);
228
+ lldb::ScriptLanguage lang =
229
+ PluginManager::GetScriptedInterfaceLanguageAtIndex (i);
230
+ std::vector<llvm::StringRef> ci_usages =
231
+ PluginManager::GetScriptedInterfaceCommandInterpreterUsagesAtIndex (i);
232
+ std::vector<llvm::StringRef> api_usages =
233
+ PluginManager::GetScriptedInterfaceAPIUsagesAtIndex (i);
234
+
235
+ print_field (" Name" , plugin_name);
236
+ switch (lang) {
237
+ case eScriptLanguagePython:
238
+ print_field (" Language" , " Python" );
239
+ break ;
240
+ case eScriptLanguageLua:
241
+ print_field (" Language" , " Lua" );
242
+ break ;
243
+ default :
244
+ break ;
245
+ }
246
+ print_field (" Description" , desc);
247
+ print_usages (" Command Interpreter" , ci_usages);
248
+ print_usages (" API" , api_usages);
249
+
250
+ plugin_name = PluginManager::GetScriptedInterfaceNameAtIndex (++i);
251
+ if (!plugin_name.empty ())
252
+ s.EOL ();
253
+ }
254
+ }
255
+
256
+ #pragma mark CommandObjectMultiwordScriptingTemplate
257
+
258
+ // CommandObjectMultiwordScriptingTemplate
259
+
260
+ CommandObjectMultiwordScriptingTemplate::
261
+ CommandObjectMultiwordScriptingTemplate (CommandInterpreter &interpreter)
262
+ : CommandObjectMultiword(
263
+ interpreter, " scripting template" ,
264
+ " Commands for operating on the scripting templates." ,
265
+ " scripting template [<subcommand-options>]" ) {
266
+ LoadSubCommand (" list" , CommandObjectSP (new CommandObjectScriptingTemplateList (
267
+ interpreter)));
268
+ }
269
+
270
+ CommandObjectMultiwordScriptingTemplate::
271
+ ~CommandObjectMultiwordScriptingTemplate () = default ;
272
+
117
273
#pragma mark CommandObjectMultiwordScripting
118
274
119
275
// CommandObjectMultiwordScripting
@@ -126,6 +282,9 @@ CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
126
282
" scripting <subcommand> [<subcommand-options>]" ) {
127
283
LoadSubCommand (" execute" , CommandObjectSP (new CommandObjectScriptingExecute (
128
284
interpreter)));
285
+ LoadSubCommand (" template" ,
286
+ CommandObjectSP (
287
+ new CommandObjectMultiwordScriptingTemplate (interpreter)));
129
288
}
130
289
131
290
CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting () = default ;
0 commit comments