@@ -1591,24 +1591,24 @@ class CommandObjectProcessHandle : public CommandObjectParsed {
1591
1591
1592
1592
Options *GetOptions () override { return &m_options; }
1593
1593
1594
- bool VerifyCommandOptionValue (const std::string &option, int &real_value) {
1595
- bool okay = true ;
1594
+ std::optional<bool > VerifyCommandOptionValue (const std::string &option) {
1595
+ if (option.empty ())
1596
+ return std::nullopt;
1597
+
1596
1598
bool success = false ;
1597
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;
1598
1607
1599
- if (success && tmp_value)
1600
- real_value = 1 ;
1601
- else if (success && !tmp_value)
1602
- real_value = 0 ;
1603
- else {
1604
- // If the value isn't 'true' or 'false', it had better be 0 or 1.
1605
- if (!llvm::to_integer (option, real_value))
1606
- real_value = 3 ;
1607
- if (real_value != 0 && real_value != 1 )
1608
- okay = false ;
1608
+ return parsed_value == 0 ? false : true ;
1609
1609
}
1610
1610
1611
- return okay ;
1611
+ return std::nullopt ;
1612
1612
}
1613
1613
1614
1614
void PrintSignalHeader (Stream &str) {
@@ -1666,33 +1666,31 @@ class CommandObjectProcessHandle : public CommandObjectParsed {
1666
1666
// the user's options.
1667
1667
ProcessSP process_sp = target.GetProcessSP ();
1668
1668
1669
- int stop_action = -1 ; // -1 means leave the current setting alone
1670
- int pass_action = -1 ; // -1 means leave the current setting alone
1671
- int notify_action = -1 ; // -1 means leave the current setting alone
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 );
1672
1673
1673
- if (!m_options.stop .empty () &&
1674
- !VerifyCommandOptionValue (m_options.stop , stop_action)) {
1674
+ if (!m_options.stop .empty () && !stop_action.has_value ()) {
1675
1675
result.AppendError (" Invalid argument for command option --stop; must be "
1676
1676
" true or false.\n " );
1677
1677
return ;
1678
1678
}
1679
1679
1680
- if (!m_options.notify .empty () &&
1681
- !VerifyCommandOptionValue (m_options.notify , notify_action)) {
1682
- result.AppendError (" Invalid argument for command option --notify; must "
1683
- " be true or false.\n " );
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 " );
1684
1683
return ;
1685
1684
}
1686
1685
1687
- if (!m_options.pass .empty () &&
1688
- !VerifyCommandOptionValue (m_options.pass , pass_action)) {
1689
- result.AppendError (" Invalid argument for command option --pass; must be "
1690
- " true or false.\n " );
1686
+ 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 " );
1691
1689
return ;
1692
1690
}
1693
1691
1694
- bool no_actions = (stop_action == - 1 && pass_action == - 1
1695
- && notify_action == - 1 );
1692
+ bool no_actions = (! stop_action. has_value () && ! pass_action. has_value () &&
1693
+ !notify_action. has_value () );
1696
1694
if (m_options.only_target_values && !no_actions) {
1697
1695
result.AppendError (" -t is for reporting, not setting, target values." );
1698
1696
return ;
@@ -1732,14 +1730,14 @@ class CommandObjectProcessHandle : public CommandObjectParsed {
1732
1730
if (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1733
1731
// Casting the actions as bools here should be okay, because
1734
1732
// VerifyCommandOptionValue guarantees the value is either 0 or 1.
1735
- if (stop_action != - 1 )
1736
- signals_sp->SetShouldStop (signo, stop_action);
1737
- if (pass_action != - 1 ) {
1738
- bool suppress = !pass_action;
1733
+ if (stop_action. has_value () )
1734
+ signals_sp->SetShouldStop (signo, * stop_action);
1735
+ if (pass_action. has_value () ) {
1736
+ bool suppress = !* pass_action;
1739
1737
signals_sp->SetShouldSuppress (signo, suppress);
1740
1738
}
1741
- if (notify_action != - 1 )
1742
- signals_sp->SetShouldNotify (signo, notify_action);
1739
+ if (notify_action. has_value () )
1740
+ signals_sp->SetShouldNotify (signo, * notify_action);
1743
1741
++num_signals_set;
1744
1742
} else {
1745
1743
result.AppendErrorWithFormat (" Invalid signal name '%s'\n " ,
@@ -1759,40 +1757,35 @@ class CommandObjectProcessHandle : public CommandObjectParsed {
1759
1757
}
1760
1758
num_signals_set = num_args;
1761
1759
}
1762
- auto set_lazy_bool = [] (int action) -> LazyBool {
1763
- LazyBool lazy;
1764
- if (action == -1 )
1765
- lazy = eLazyBoolCalculate;
1766
- else if (action)
1767
- lazy = eLazyBoolYes;
1768
- else
1769
- lazy = eLazyBoolNo;
1770
- return lazy;
1760
+ auto set_lazy_bool = [](std::optional<bool > action) -> LazyBool {
1761
+ if (!action.has_value ())
1762
+ return eLazyBoolCalculate;
1763
+ return (*action) ? eLazyBoolYes : eLazyBoolNo;
1771
1764
};
1772
1765
1773
1766
// If there were no actions, we're just listing, don't add the dummy:
1774
1767
if (!no_actions)
1775
- target.AddDummySignal (arg.ref (),
1776
- set_lazy_bool (pass_action),
1777
- set_lazy_bool (notify_action),
1778
- set_lazy_bool (stop_action));
1768
+ target.AddDummySignal (arg.ref (), set_lazy_bool (pass_action),
1769
+ set_lazy_bool (notify_action),
1770
+ set_lazy_bool (stop_action));
1779
1771
}
1780
1772
} else {
1781
1773
// No signal specified, if any command options were specified, update ALL
1782
1774
// signals. But we can't do this without a process since we don't know
1783
1775
// all the possible signals that might be valid for this target.
1784
- if (((notify_action != -1 ) || (stop_action != -1 ) || (pass_action != -1 ))
1785
- && process_sp) {
1776
+ if ((notify_action.has_value () || stop_action.has_value () ||
1777
+ pass_action.has_value ()) &&
1778
+ process_sp) {
1786
1779
if (m_interpreter.Confirm (
1787
1780
" Do you really want to update all the signals?" , false )) {
1788
1781
int32_t signo = signals_sp->GetFirstSignalNumber ();
1789
1782
while (signo != LLDB_INVALID_SIGNAL_NUMBER) {
1790
- if (notify_action != - 1 )
1791
- signals_sp->SetShouldNotify (signo, notify_action);
1792
- if (stop_action != - 1 )
1793
- signals_sp->SetShouldStop (signo, stop_action);
1794
- if (pass_action != - 1 ) {
1795
- bool suppress = !pass_action;
1783
+ if (notify_action. has_value () )
1784
+ signals_sp->SetShouldNotify (signo, * notify_action);
1785
+ if (stop_action. has_value () )
1786
+ signals_sp->SetShouldStop (signo, * stop_action);
1787
+ if (pass_action. has_value () ) {
1788
+ bool suppress = !* pass_action;
1796
1789
signals_sp->SetShouldSuppress (signo, suppress);
1797
1790
}
1798
1791
signo = signals_sp->GetNextSignalNumber (signo);
0 commit comments