Skip to content

Commit 8e78455

Browse files
committed
[lldb] Remove VerifyCommandOptionValue entirely
1 parent a93faa9 commit 8e78455

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,26 +1591,6 @@ class CommandObjectProcessHandle : public CommandObjectParsed {
15911591

15921592
Options *GetOptions() override { return &m_options; }
15931593

1594-
std::optional<bool> VerifyCommandOptionValue(const std::string &option) {
1595-
if (option.empty())
1596-
return std::nullopt;
1597-
1598-
bool success = false;
1599-
bool tmp_value = OptionArgParser::ToBoolean(option, false, &success);
1600-
if (success)
1601-
return tmp_value;
1602-
1603-
int parsed_value = -1;
1604-
if (llvm::to_integer(option, parsed_value)) {
1605-
if (parsed_value != 0 && parsed_value != 1)
1606-
return std::nullopt;
1607-
1608-
return parsed_value == 0 ? false : true;
1609-
}
1610-
1611-
return std::nullopt;
1612-
}
1613-
16141594
void PrintSignalHeader(Stream &str) {
16151595
str.Printf("NAME PASS STOP NOTIFY\n");
16161596
str.Printf("=========== ===== ===== ======\n");
@@ -1666,27 +1646,48 @@ class CommandObjectProcessHandle : public CommandObjectParsed {
16661646
// the user's options.
16671647
ProcessSP process_sp = target.GetProcessSP();
16681648

1669-
std::optional<bool> stop_action = VerifyCommandOptionValue(m_options.stop);
1670-
std::optional<bool> pass_action = VerifyCommandOptionValue(m_options.pass);
1671-
std::optional<bool> notify_action =
1672-
VerifyCommandOptionValue(m_options.notify);
1649+
std::optional<bool> stop_action = {};
1650+
std::optional<bool> pass_action = {};
1651+
std::optional<bool> notify_action = {};
16731652

1674-
if (!m_options.stop.empty() && !stop_action.has_value()) {
1675-
result.AppendError("Invalid argument for command option --stop; must be "
1676-
"true or false.\n");
1677-
return;
1653+
if (!m_options.stop.empty()) {
1654+
bool success = false;
1655+
bool value = OptionArgParser::ToBoolean(m_options.stop, false, &success);
1656+
if (!success) {
1657+
result.AppendError(
1658+
"Invalid argument for command option --stop; must be "
1659+
"true or false.\n");
1660+
return;
1661+
}
1662+
1663+
stop_action = value;
16781664
}
16791665

1680-
if (!m_options.pass.empty() && !pass_action.has_value()) {
1681-
result.AppendError("Invalid argument for command option --pass; must be "
1682-
"true or false.\n");
1683-
return;
1666+
if (!m_options.pass.empty()) {
1667+
bool success = false;
1668+
bool value = OptionArgParser::ToBoolean(m_options.pass, false, &success);
1669+
if (!success) {
1670+
result.AppendError(
1671+
"Invalid argument for command option --pass; must be "
1672+
"true or false.\n");
1673+
return;
1674+
}
1675+
pass_action = value;
1676+
}
1677+
1678+
if (!m_options.notify.empty()) {
1679+
bool success = false;
1680+
bool value =
1681+
OptionArgParser::ToBoolean(m_options.notify, false, &success);
1682+
if (!success) {
1683+
result.AppendError("Invalid argument for command option --notify; must "
1684+
"be true or false.\n");
1685+
return;
1686+
}
1687+
notify_action = value;
16841688
}
16851689

16861690
if (!m_options.notify.empty() && !notify_action.has_value()) {
1687-
result.AppendError("Invalid argument for command option --notify; must "
1688-
"be true or false.\n");
1689-
return;
16901691
}
16911692

16921693
bool no_actions = (!stop_action.has_value() && !pass_action.has_value() &&
@@ -1728,8 +1729,6 @@ class CommandObjectProcessHandle : public CommandObjectParsed {
17281729
if (signals_sp) {
17291730
int32_t signo = signals_sp->GetSignalNumberFromName(arg.c_str());
17301731
if (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1731-
// Casting the actions as bools here should be okay, because
1732-
// VerifyCommandOptionValue guarantees the value is either 0 or 1.
17331732
if (stop_action.has_value())
17341733
signals_sp->SetShouldStop(signo, *stop_action);
17351734
if (pass_action.has_value()) {

0 commit comments

Comments
 (0)