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 CommandObjectScriptingRun
26
+
24
27
#define LLDB_OPTIONS_scripting_run
25
28
#include " CommandOptions.inc"
26
29
@@ -127,6 +130,157 @@ class CommandObjectScriptingRun : public CommandObjectRaw {
127
130
CommandOptions m_options;
128
131
};
129
132
133
+ #pragma mark CommandObjectScriptingTemplateList
134
+
135
+ #define LLDB_OPTIONS_scripting_template_list
136
+ #include " CommandOptions.inc"
137
+
138
+ class CommandObjectScriptingTemplateList : public CommandObjectParsed {
139
+ public:
140
+ CommandObjectScriptingTemplateList (CommandInterpreter &interpreter)
141
+ : CommandObjectParsed(
142
+ interpreter, " scripting template list" ,
143
+ " List all the available scripting affordances templates. " ,
144
+ " scripting template list [--language <scripting-language> --]" ) {}
145
+
146
+ ~CommandObjectScriptingTemplateList () override = default ;
147
+
148
+ Options *GetOptions () override { return &m_options; }
149
+
150
+ class CommandOptions : public Options {
151
+ public:
152
+ CommandOptions () = default ;
153
+ ~CommandOptions () override = default ;
154
+ Status SetOptionValue (uint32_t option_idx, llvm::StringRef option_arg,
155
+ ExecutionContext *execution_context) override {
156
+ Status error;
157
+ const int short_option = m_getopt_table[option_idx].val ;
158
+
159
+ switch (short_option) {
160
+ case ' l' :
161
+ m_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum (
162
+ option_arg, GetDefinitions ()[option_idx].enum_values ,
163
+ eScriptLanguageNone, error);
164
+ if (!error.Success ())
165
+ error.SetErrorStringWithFormat (" unrecognized value for language '%s'" ,
166
+ option_arg.str ().c_str ());
167
+ break ;
168
+ default :
169
+ llvm_unreachable (" Unimplemented option" );
170
+ }
171
+
172
+ return error;
173
+ }
174
+
175
+ void OptionParsingStarting (ExecutionContext *execution_context) override {
176
+ m_language = lldb::eScriptLanguageDefault;
177
+ }
178
+
179
+ llvm::ArrayRef<OptionDefinition> GetDefinitions () override {
180
+ return llvm::ArrayRef (g_scripting_template_list_options);
181
+ }
182
+
183
+ lldb::ScriptLanguage m_language = lldb::eScriptLanguageDefault;
184
+ };
185
+
186
+ protected:
187
+ void DoExecute (Args &command, CommandReturnObject &result) override {
188
+ Stream &s = result.GetOutputStream ();
189
+ s.Printf (" Available scripted extension templates:" );
190
+
191
+ auto print_field = [&s](llvm::StringRef key, llvm::StringRef value,
192
+ bool check_validity = false ) {
193
+ if (!check_validity || !value.empty ()) {
194
+ s.IndentMore ();
195
+ s.Indent ();
196
+ s << key << " : " << value << ' \n ' ;
197
+ s.IndentLess ();
198
+ }
199
+ };
200
+
201
+ auto print_usages = [&s](llvm::StringRef usage_kind,
202
+ std::vector<llvm::StringRef> &usages) {
203
+ s.IndentMore ();
204
+ s.Indent ();
205
+ s << usage_kind << " Usages:" ;
206
+ if (usages.empty ())
207
+ s << " None\n " ;
208
+ else if (usages.size () == 1 )
209
+ s << " " << usages.front () << ' \n ' ;
210
+ else {
211
+ s << ' \n ' ;
212
+ for (llvm::StringRef usage : usages) {
213
+ s.IndentMore ();
214
+ s.Indent ();
215
+ s << usage << ' \n ' ;
216
+ s.IndentLess ();
217
+ }
218
+ }
219
+ s.IndentLess ();
220
+ };
221
+
222
+ size_t num_listed_interface = 0 ;
223
+ size_t num_templates = PluginManager::GetNumScriptedInterfaces ();
224
+ for (size_t i = 0 ; i < num_templates; i++) {
225
+ llvm::StringRef plugin_name =
226
+ PluginManager::GetScriptedInterfaceNameAtIndex (i);
227
+ if (plugin_name.empty ())
228
+ break ;
229
+
230
+ lldb::ScriptLanguage lang =
231
+ PluginManager::GetScriptedInterfaceLanguageAtIndex (i);
232
+ if (lang != m_options.m_language )
233
+ continue ;
234
+
235
+ if (!num_listed_interface)
236
+ s.EOL ();
237
+
238
+ num_listed_interface++;
239
+
240
+ llvm::StringRef desc =
241
+ PluginManager::GetScriptedInterfaceDescriptionAtIndex (i);
242
+ std::vector<llvm::StringRef> ci_usages =
243
+ PluginManager::GetScriptedInterfaceCommandInterpreterUsagesAtIndex (i);
244
+ std::vector<llvm::StringRef> api_usages =
245
+ PluginManager::GetScriptedInterfaceAPIUsagesAtIndex (i);
246
+
247
+ print_field (" Name" , plugin_name);
248
+ print_field (" Language" , ScriptInterpreter::LanguageToString (lang));
249
+ print_field (" Description" , desc);
250
+ print_usages (" Command Interpreter" , ci_usages);
251
+ print_usages (" API" , api_usages);
252
+
253
+ if (i != num_templates - 1 )
254
+ s.EOL ();
255
+ }
256
+
257
+ if (!num_listed_interface)
258
+ s << " None\n " ;
259
+ }
260
+
261
+ private:
262
+ CommandOptions m_options;
263
+ };
264
+
265
+ #pragma mark CommandObjectMultiwordScriptingTemplate
266
+
267
+ // CommandObjectMultiwordScriptingTemplate
268
+
269
+ class CommandObjectMultiwordScriptingTemplate : public CommandObjectMultiword {
270
+ public:
271
+ CommandObjectMultiwordScriptingTemplate (CommandInterpreter &interpreter)
272
+ : CommandObjectMultiword(
273
+ interpreter, " scripting template" ,
274
+ " Commands for operating on the scripting templates." ,
275
+ " scripting template [<subcommand-options>]" ) {
276
+ LoadSubCommand (
277
+ " list" ,
278
+ CommandObjectSP (new CommandObjectScriptingTemplateList (interpreter)));
279
+ }
280
+
281
+ ~CommandObjectMultiwordScriptingTemplate () override = default ;
282
+ };
283
+
130
284
#pragma mark CommandObjectMultiwordScripting
131
285
132
286
// CommandObjectMultiwordScripting
@@ -139,6 +293,9 @@ CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
139
293
" scripting <subcommand> [<subcommand-options>]" ) {
140
294
LoadSubCommand (" run" ,
141
295
CommandObjectSP (new CommandObjectScriptingRun (interpreter)));
296
+ LoadSubCommand (" template" ,
297
+ CommandObjectSP (
298
+ new CommandObjectMultiwordScriptingTemplate (interpreter)));
142
299
}
143
300
144
301
CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting () = default ;
0 commit comments