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"
14
15
#include " lldb/Interpreter/CommandInterpreter.h"
15
16
#include " lldb/Interpreter/CommandOptionArgumentTable.h"
16
17
#include " lldb/Interpreter/CommandReturnObject.h"
18
+ #include " lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
17
19
#include " lldb/Interpreter/OptionArgParser.h"
18
20
#include " lldb/Interpreter/ScriptInterpreter.h"
19
21
#include " lldb/Utility/Args.h"
@@ -127,9 +129,126 @@ class CommandObjectScriptingRun : public CommandObjectRaw {
127
129
CommandOptions m_options;
128
130
};
129
131
130
- #pragma mark CommandObjectMultiwordScripting
132
+ #define LLDB_OPTIONS_scripting_template_list
133
+ #include " CommandOptions.inc"
134
+
135
+ class CommandObjectScriptingTemplateList : public CommandObjectParsed {
136
+ public:
137
+ CommandObjectScriptingTemplateList (CommandInterpreter &interpreter)
138
+ : CommandObjectParsed(
139
+ interpreter, " scripting template list" ,
140
+ " List all the available scripting extension templates. " ,
141
+ " scripting template list [--language <scripting-language> --]" ) {}
142
+
143
+ ~CommandObjectScriptingTemplateList () override = default ;
144
+
145
+ Options *GetOptions () override { return &m_options; }
146
+
147
+ class CommandOptions : public Options {
148
+ public:
149
+ CommandOptions () = default ;
150
+ ~CommandOptions () override = default ;
151
+ Status SetOptionValue (uint32_t option_idx, llvm::StringRef option_arg,
152
+ ExecutionContext *execution_context) override {
153
+ Status error;
154
+ const int short_option = m_getopt_table[option_idx].val ;
131
155
132
- // CommandObjectMultiwordScripting
156
+ switch (short_option) {
157
+ case ' l' :
158
+ m_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum (
159
+ option_arg, GetDefinitions ()[option_idx].enum_values ,
160
+ eScriptLanguageNone, error);
161
+ if (!error.Success ())
162
+ error.SetErrorStringWithFormatv (
163
+ " unrecognized value for language '{0}'" , option_arg);
164
+ break ;
165
+ default :
166
+ llvm_unreachable (" Unimplemented option" );
167
+ }
168
+
169
+ return error;
170
+ }
171
+
172
+ void OptionParsingStarting (ExecutionContext *execution_context) override {
173
+ m_language = lldb::eScriptLanguageDefault;
174
+ }
175
+
176
+ llvm::ArrayRef<OptionDefinition> GetDefinitions () override {
177
+ return llvm::ArrayRef (g_scripting_template_list_options);
178
+ }
179
+
180
+ lldb::ScriptLanguage m_language = lldb::eScriptLanguageDefault;
181
+ };
182
+
183
+ protected:
184
+ void DoExecute (Args &command, CommandReturnObject &result) override {
185
+ Stream &s = result.GetOutputStream ();
186
+ s.Printf (" Available scripted extension templates:" );
187
+
188
+ auto print_field = [&s](llvm::StringRef key, llvm::StringRef value) {
189
+ if (!value.empty ()) {
190
+ s.IndentMore ();
191
+ s.Indent ();
192
+ s << key << " : " << value << ' \n ' ;
193
+ s.IndentLess ();
194
+ }
195
+ };
196
+
197
+ size_t num_listed_interface = 0 ;
198
+ size_t num_templates = PluginManager::GetNumScriptedInterfaces ();
199
+ for (size_t i = 0 ; i < num_templates; i++) {
200
+ llvm::StringRef plugin_name =
201
+ PluginManager::GetScriptedInterfaceNameAtIndex (i);
202
+ if (plugin_name.empty ())
203
+ break ;
204
+
205
+ lldb::ScriptLanguage lang =
206
+ PluginManager::GetScriptedInterfaceLanguageAtIndex (i);
207
+ if (lang != m_options.m_language )
208
+ continue ;
209
+
210
+ if (!num_listed_interface)
211
+ s.EOL ();
212
+
213
+ num_listed_interface++;
214
+
215
+ llvm::StringRef desc =
216
+ PluginManager::GetScriptedInterfaceDescriptionAtIndex (i);
217
+ ScriptedInterfaceUsages usages =
218
+ PluginManager::GetScriptedInterfaceUsagesAtIndex (i);
219
+
220
+ print_field (" Name" , plugin_name);
221
+ print_field (" Language" , ScriptInterpreter::LanguageToString (lang));
222
+ print_field (" Description" , desc);
223
+ usages.Dump (s, ScriptedInterfaceUsages::UsageKind::API);
224
+ usages.Dump (s, ScriptedInterfaceUsages::UsageKind::CommandInterpreter);
225
+
226
+ if (i != num_templates - 1 )
227
+ s.EOL ();
228
+ }
229
+
230
+ if (!num_listed_interface)
231
+ s << " None\n " ;
232
+ }
233
+
234
+ private:
235
+ CommandOptions m_options;
236
+ };
237
+
238
+ class CommandObjectMultiwordScriptingTemplate : public CommandObjectMultiword {
239
+ public:
240
+ CommandObjectMultiwordScriptingTemplate (CommandInterpreter &interpreter)
241
+ : CommandObjectMultiword(
242
+ interpreter, " scripting template" ,
243
+ " Commands for operating on the scripting templates." ,
244
+ " scripting template [<subcommand-options>]" ) {
245
+ LoadSubCommand (
246
+ " list" ,
247
+ CommandObjectSP (new CommandObjectScriptingTemplateList (interpreter)));
248
+ }
249
+
250
+ ~CommandObjectMultiwordScriptingTemplate () override = default ;
251
+ };
133
252
134
253
CommandObjectMultiwordScripting::CommandObjectMultiwordScripting (
135
254
CommandInterpreter &interpreter)
@@ -139,6 +258,9 @@ CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
139
258
" scripting <subcommand> [<subcommand-options>]" ) {
140
259
LoadSubCommand (" run" ,
141
260
CommandObjectSP (new CommandObjectScriptingRun (interpreter)));
261
+ LoadSubCommand (" template" ,
262
+ CommandObjectSP (
263
+ new CommandObjectMultiwordScriptingTemplate (interpreter)));
142
264
}
143
265
144
266
CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting () = default ;
0 commit comments