@@ -1152,13 +1152,13 @@ class CommandObjectPythonFunction : public CommandObjectRaw {
1152
1152
// / This class implements a "raw" scripted command. lldb does no parsing of the
1153
1153
// / command line, instead passing the line unaltered (except for backtick
1154
1154
// / substitution).
1155
- class CommandObjectScriptingObject : public CommandObjectRaw {
1155
+ class CommandObjectScriptingObjectRaw : public CommandObjectRaw {
1156
1156
public:
1157
- CommandObjectScriptingObject (CommandInterpreter &interpreter,
1158
- std::string name,
1159
- StructuredData::GenericSP cmd_obj_sp,
1160
- ScriptedCommandSynchronicity synch,
1161
- CompletionType completion_type)
1157
+ CommandObjectScriptingObjectRaw (CommandInterpreter &interpreter,
1158
+ std::string name,
1159
+ StructuredData::GenericSP cmd_obj_sp,
1160
+ ScriptedCommandSynchronicity synch,
1161
+ CompletionType completion_type)
1162
1162
: CommandObjectRaw(interpreter, name), m_cmd_obj_sp(cmd_obj_sp),
1163
1163
m_synchro (synch), m_fetched_help_short(false ),
1164
1164
m_fetched_help_long(false ), m_completion_type(completion_type) {
@@ -1169,7 +1169,7 @@ class CommandObjectScriptingObject : public CommandObjectRaw {
1169
1169
GetFlags ().Set (scripter->GetFlagsForCommandObject (cmd_obj_sp));
1170
1170
}
1171
1171
1172
- ~CommandObjectScriptingObject () override = default ;
1172
+ ~CommandObjectScriptingObjectRaw () override = default ;
1173
1173
1174
1174
void
1175
1175
HandleArgumentCompletion (CompletionRequest &request,
@@ -1304,32 +1304,30 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1304
1304
void OptionParsingStarting (ExecutionContext *execution_context) override {
1305
1305
ScriptInterpreter *scripter =
1306
1306
m_interpreter.GetDebugger ().GetScriptInterpreter ();
1307
- if (!scripter) {
1307
+ if (!scripter || !m_cmd_obj_sp)
1308
1308
return ;
1309
- }
1310
- if (!m_cmd_obj_sp) {
1311
- return ;
1312
- }
1309
+
1313
1310
scripter->OptionParsingStartedForCommandObject (m_cmd_obj_sp);
1314
- };
1311
+ }
1315
1312
1316
1313
llvm::ArrayRef<OptionDefinition> GetDefinitions () override {
1317
1314
if (!m_options_definition_up)
1318
1315
return {};
1319
1316
return llvm::ArrayRef (m_options_definition_up.get (), m_num_options);
1320
1317
}
1321
1318
1322
- static bool ParseUsageMaskFromArray (StructuredData::ObjectSP obj_sp,
1323
- size_t counter, uint32_t &usage_mask, Status &error ) {
1319
+ static Status ParseUsageMaskFromArray (StructuredData::ObjectSP obj_sp,
1320
+ size_t counter, uint32_t &usage_mask) {
1324
1321
// If the usage entry is not provided, we use LLDB_OPT_SET_ALL.
1325
1322
// If the usage mask is a UINT, the option belongs to that group.
1326
1323
// If the usage mask is a vector of UINT's, the option belongs to all the
1327
1324
// groups listed.
1328
1325
// If a subelement of the vector is a vector of two ints, then the option
1329
1326
// belongs to the inclusive range from the first to the second element.
1327
+ Status error;
1330
1328
if (!obj_sp) {
1331
1329
usage_mask = LLDB_OPT_SET_ALL;
1332
- return true ;
1330
+ return error ;
1333
1331
}
1334
1332
1335
1333
usage_mask = 0 ;
@@ -1342,17 +1340,17 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1342
1340
if (value == 0 ) {
1343
1341
error.SetErrorStringWithFormatv (
1344
1342
" 0 is not a valid group for option {0}" , counter);
1345
- return false ;
1343
+ return error ;
1346
1344
}
1347
1345
usage_mask = (1 << (value - 1 ));
1348
- return true ;
1346
+ return error ;
1349
1347
}
1350
1348
// Otherwise it has to be an array:
1351
1349
StructuredData::Array *array_val = obj_sp->GetAsArray ();
1352
1350
if (!array_val) {
1353
1351
error.SetErrorStringWithFormatv (
1354
1352
" required field is not a array for option {0}" , counter);
1355
- return false ;
1353
+ return error ;
1356
1354
}
1357
1355
// This is the array ForEach for accumulating a group usage mask from
1358
1356
// an array of string descriptions of groups.
@@ -1408,11 +1406,13 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1408
1406
}
1409
1407
return true ;
1410
1408
};
1411
- return array_val->ForEach (groups_accumulator);
1409
+ array_val->ForEach (groups_accumulator);
1410
+ return error;
1412
1411
}
1413
1412
1414
1413
1415
- Status SetOptionsFromArray (StructuredData::Array &options, Status &error) {
1414
+ Status SetOptionsFromArray (StructuredData::Array &options) {
1415
+ Status error;
1416
1416
m_num_options = options.GetSize ();
1417
1417
m_options_definition_up.reset (new OptionDefinition[m_num_options]);
1418
1418
// We need to hand out pointers to contents of these vectors; we reserve
@@ -1447,8 +1447,8 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1447
1447
// Usage Mask:
1448
1448
StructuredData::ObjectSP obj_sp = opt_dict->GetValueForKey (" groups" );
1449
1449
if (obj_sp) {
1450
- ParseUsageMaskFromArray (obj_sp, counter, option_def. usage_mask ,
1451
- error );
1450
+ error = ParseUsageMaskFromArray (obj_sp, counter,
1451
+ option_def. usage_mask );
1452
1452
if (error.Fail ())
1453
1453
return false ;
1454
1454
}
@@ -1694,6 +1694,34 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1694
1694
};
1695
1695
1696
1696
public:
1697
+ static CommandObjectSP Create (CommandInterpreter &interpreter,
1698
+ std::string name,
1699
+ StructuredData::GenericSP cmd_obj_sp,
1700
+ ScriptedCommandSynchronicity synch,
1701
+ CommandReturnObject &result) {
1702
+ CommandObjectSP new_cmd_sp (new CommandObjectScriptingObjectParsed (
1703
+ interpreter, name, cmd_obj_sp, synch));
1704
+
1705
+ CommandObjectScriptingObjectParsed *parsed_cmd
1706
+ = static_cast <CommandObjectScriptingObjectParsed *>(new_cmd_sp.get ());
1707
+ // Now check all the failure modes, and report if found.
1708
+ Status opt_error = parsed_cmd->GetOptionsError ();
1709
+ Status arg_error = parsed_cmd->GetArgsError ();
1710
+
1711
+ if (opt_error.Fail ())
1712
+ result.AppendErrorWithFormat (" failed to parse option definitions: %s" ,
1713
+ opt_error.AsCString ());
1714
+ if (arg_error.Fail ())
1715
+ result.AppendErrorWithFormat (" %sfailed to parse argument definitions: %s" ,
1716
+ opt_error.Fail () ? " , also " : " " ,
1717
+ arg_error.AsCString ());
1718
+
1719
+ if (!result.Succeeded ())
1720
+ return {};
1721
+
1722
+ return new_cmd_sp;
1723
+ }
1724
+
1697
1725
CommandObjectScriptingObjectParsed (CommandInterpreter &interpreter,
1698
1726
std::string name,
1699
1727
StructuredData::GenericSP cmd_obj_sp,
@@ -1720,7 +1748,7 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1720
1748
StructuredData::Array *options_array = options_object_sp->GetAsArray ();
1721
1749
// but if it exists, it has to be an array.
1722
1750
if (options_array) {
1723
- m_options.SetOptionsFromArray (*(options_array), m_options_error );
1751
+ m_options_error = m_options.SetOptionsFromArray (*(options_array));
1724
1752
// If we got an error don't bother with the arguments...
1725
1753
if (m_options_error.Fail ())
1726
1754
return ;
@@ -1804,8 +1832,8 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1804
1832
1805
1833
// Usage Mask:
1806
1834
obj_sp = arg_dict->GetValueForKey (" groups" );
1807
- CommandOptions::ParseUsageMaskFromArray (obj_sp, counter ,
1808
- arg_opt_set_association, m_args_error );
1835
+ m_args_error = CommandOptions::ParseUsageMaskFromArray (obj_sp,
1836
+ counter, arg_opt_set_association );
1809
1837
this_entry.emplace_back (arg_type, arg_repetition,
1810
1838
arg_opt_set_association);
1811
1839
elem_counter++;
@@ -1879,7 +1907,7 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1879
1907
1880
1908
1881
1909
protected:
1882
- bool DoExecute (Args &args,
1910
+ void DoExecute (Args &args,
1883
1911
CommandReturnObject &result) override {
1884
1912
ScriptInterpreter *scripter = GetDebugger ().GetScriptInterpreter ();
1885
1913
@@ -1900,8 +1928,6 @@ class CommandObjectScriptingObjectParsed : public CommandObjectParsed {
1900
1928
result.SetStatus (eReturnStatusSuccessFinishResult);
1901
1929
}
1902
1930
}
1903
-
1904
- return result.Succeeded ();
1905
1931
}
1906
1932
1907
1933
private:
@@ -2306,17 +2332,12 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
2306
2332
}
2307
2333
2308
2334
if (m_options.m_parsed_command ) {
2309
- new_cmd_sp.reset (new CommandObjectScriptingObjectParsed (
2310
- m_interpreter, m_cmd_name, cmd_obj_sp, m_synchronicity));
2311
- Status options_error
2312
- = static_cast <CommandObjectScriptingObjectParsed *>(new_cmd_sp.get ())->GetOptionsError ();
2313
- if (options_error.Fail ()) {
2314
- result.AppendErrorWithFormat (" failed to parse option definitions: %s" ,
2315
- options_error.AsCString ());
2316
- return false ;
2317
- }
2335
+ new_cmd_sp = CommandObjectScriptingObjectParsed::Create (m_interpreter,
2336
+ m_cmd_name, cmd_obj_sp, m_synchronicity, result);
2337
+ if (!result.Succeeded ())
2338
+ return ;
2318
2339
} else
2319
- new_cmd_sp.reset (new CommandObjectScriptingObject (
2340
+ new_cmd_sp.reset (new CommandObjectScriptingObjectRaw (
2320
2341
m_interpreter, m_cmd_name, cmd_obj_sp, m_synchronicity,
2321
2342
m_completion_type));
2322
2343
}
0 commit comments