diff options
author | Enrico Granata <egranata@apple.com> | 2012-12-11 22:42:19 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2012-12-11 22:42:19 +0000 |
commit | 9d14084b45320a1b4ff75eec7ede88b15ac3389c (patch) | |
tree | 0ee1659d40003336d7b4228117abd670039f5292 /lldb/source/Interpreter | |
parent | 496970f6eec7697dbda6d02fc4f8dc595a24145f (diff) | |
download | bcm5719-llvm-9d14084b45320a1b4ff75eec7ede88b15ac3389c.tar.gz bcm5719-llvm-9d14084b45320a1b4ff75eec7ede88b15ac3389c.zip |
Adding a validation callback mechanism to OptionValueString (such a feature might theoretically be added to the general OptionValue base class should the need arise)
Using this mechanism, making sure that the options to pass a summary string or a named summary to frame variable do not have invalid values
<rdar://problem/11576143>
llvm-svn: 169927
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r-- | lldb/source/Interpreter/OptionGroupVariable.cpp | 23 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionValueString.cpp | 62 |
2 files changed, 80 insertions, 5 deletions
diff --git a/lldb/source/Interpreter/OptionGroupVariable.cpp b/lldb/source/Interpreter/OptionGroupVariable.cpp index 5f1c271525b..e98ff56ec7c 100644 --- a/lldb/source/Interpreter/OptionGroupVariable.cpp +++ b/lldb/source/Interpreter/OptionGroupVariable.cpp @@ -15,6 +15,8 @@ // C++ Includes // Other libraries and framework includes // Project includes +#include "lldb/Core/DataVisualization.h" +#include "lldb/Core/Error.h" #include "lldb/Target/Target.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Utility/Utils.h" @@ -39,7 +41,22 @@ g_option_table[] = OptionGroupVariable::OptionGroupVariable (bool show_frame_options) : OptionGroup(), - include_frame_options (show_frame_options) + include_frame_options (show_frame_options), + summary([] (const char* str,void*)->Error + { + if (!str || !str[0]) + return Error("must specify a valid named summary"); + TypeSummaryImplSP summary_sp; + if (DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(str), summary_sp) == false) + return Error("must specify a valid named summary"); + return Error(); + }), + summary_string([] (const char* str, void*)->Error + { + if (!str || !str[0]) + return Error("must specify a non-empty summary string"); + return Error(); + }) { } @@ -67,10 +84,10 @@ OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter, show_scope = true; break; case 'y': - summary.SetCurrentValue(option_arg); + error = summary.SetCurrentValue(option_arg); break; case 'z': - summary_string.SetCurrentValue(option_arg); + error = summary_string.SetCurrentValue(option_arg); break; default: error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); diff --git a/lldb/source/Interpreter/OptionValueString.cpp b/lldb/source/Interpreter/OptionValueString.cpp index 696e62b78e7..91a980340ad 100644 --- a/lldb/source/Interpreter/OptionValueString.cpp +++ b/lldb/source/Interpreter/OptionValueString.cpp @@ -61,20 +61,36 @@ OptionValueString::SetValueFromCString (const char *value_cstr, case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: case eVarSetOperationRemove: + if (m_validator) + { + error = m_validator(value_cstr,m_validator_baton); + if (error.Fail()) + return error; + } error = OptionValue::SetValueFromCString (value_cstr, op); break; case eVarSetOperationAppend: + { + std::string new_value(m_current_value); if (value_cstr && value_cstr[0]) { if (m_options.Test (eOptionEncodeCharacterEscapeSequences)) { std::string str; Args::EncodeEscapeSequences (value_cstr, str); - m_current_value += str; + new_value.append(str); } else - m_current_value += value_cstr; + new_value.append(value_cstr); + } + if (m_validator) + { + error = m_validator(new_value.c_str(),m_validator_baton); + if (error.Fail()) + return error; + } + m_current_value.assign(new_value); } break; @@ -84,6 +100,12 @@ OptionValueString::SetValueFromCString (const char *value_cstr, case eVarSetOperationReplace: case eVarSetOperationAssign: + if (m_validator) + { + error = m_validator(value_cstr,m_validator_baton); + if (error.Fail()) + return error; + } m_value_was_set = true; if (m_options.Test (eOptionEncodeCharacterEscapeSequences)) { @@ -104,3 +126,39 @@ OptionValueString::DeepCopy () const { return OptionValueSP(new OptionValueString(*this)); } + +Error +OptionValueString::SetCurrentValue (const char *value) +{ + if (m_validator) + { + Error error(m_validator(value,m_validator_baton)); + if (error.Fail()) + return error; + } + if (value && value[0]) + m_current_value.assign (value); + else + m_current_value.clear(); + return Error(); +} + +Error +OptionValueString::AppendToCurrentValue (const char *value) +{ + if (value && value[0]) + { + if (m_validator) + { + std::string new_value(m_current_value); + new_value.append(value); + Error error(m_validator(value,m_validator_baton)); + if (error.Fail()) + return error; + m_current_value.assign(new_value); + } + else + m_current_value.append (value); + } + return Error(); +} |