diff options
Diffstat (limited to 'lldb/source/Commands/CommandObjectCommands.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectCommands.cpp | 130 |
1 files changed, 106 insertions, 24 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 737a449..3e46041 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -22,10 +22,12 @@ #include "lldb/Core/InputReaderEZ.h" #include "lldb/Core/StringList.h" #include "lldb/Interpreter/Args.h" +#include "lldb/Interpreter/CommandHistory.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandObjectRegexCommand.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionValueBoolean.h" +#include "lldb/Interpreter/OptionValueUInt64.h" #include "lldb/Interpreter/Options.h" #include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Interpreter/ScriptInterpreterPython.h" @@ -64,7 +66,11 @@ protected: public: CommandOptions (CommandInterpreter &interpreter) : - Options (interpreter) + Options (interpreter), + m_start_idx(0), + m_stop_idx(0), + m_count(0), + m_wipe(false) { } @@ -76,27 +82,27 @@ protected: { Error error; const int short_option = m_getopt_table[option_idx].val; - bool success; switch (short_option) { case 'c': - m_end_idx = Args::StringToUInt32(option_arg, UINT_MAX, 0, &success); - if (!success) - error.SetErrorStringWithFormat("invalid value for count: %s", option_arg); - if (m_end_idx != 0) - m_end_idx--; - m_start_idx = 0; + error = m_count.SetValueFromCString(option_arg,eVarSetOperationAssign); + break; + case 's': + if (option_arg && strcmp("end", option_arg) == 0) + { + m_start_idx.SetCurrentValue(UINT64_MAX); + m_start_idx.SetOptionWasSet(); + } + else + error = m_start_idx.SetValueFromCString(option_arg,eVarSetOperationAssign); break; case 'e': - m_end_idx = Args::StringToUInt32(option_arg, 0, 0, &success); - if (!success) - error.SetErrorStringWithFormat("invalid value for end index: %s", option_arg); + error = m_stop_idx.SetValueFromCString(option_arg,eVarSetOperationAssign); break; - case 's': - m_start_idx = Args::StringToUInt32(option_arg, 0, 0, &success); - if (!success) - error.SetErrorStringWithFormat("invalid value for start index: %s", option_arg); + case 'w': + m_wipe.SetCurrentValue(true); + m_wipe.SetOptionWasSet(); break; default: error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); @@ -109,8 +115,10 @@ protected: void OptionParsingStarting () { - m_start_idx = 0; - m_end_idx = UINT_MAX; + m_start_idx.Clear(); + m_stop_idx.Clear(); + m_count.Clear(); + m_wipe.Clear(); } const OptionDefinition* @@ -125,17 +133,90 @@ protected: // Instance variables to hold the values for command options. - uint32_t m_start_idx; - uint32_t m_end_idx; + OptionValueUInt64 m_start_idx; + OptionValueUInt64 m_stop_idx; + OptionValueUInt64 m_count; + OptionValueBoolean m_wipe; }; bool DoExecute (Args& command, CommandReturnObject &result) { - - m_interpreter.DumpHistory (result.GetOutputStream(), - m_options.m_start_idx, - m_options.m_end_idx); + if (m_options.m_wipe.GetCurrentValue() && m_options.m_wipe.OptionWasSet()) + { + m_interpreter.GetCommandHistory().Clear(); + result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult); + } + else + { + if (m_options.m_start_idx.OptionWasSet() && m_options.m_stop_idx.OptionWasSet() && m_options.m_count.OptionWasSet()) + { + result.AppendError("--count, --start-index and --end-index cannot be all specified in the same invocation"); + result.SetStatus(lldb::eReturnStatusFailed); + } + else + { + std::pair<bool,uint64_t> start_idx = {m_options.m_start_idx.OptionWasSet(),m_options.m_start_idx.GetCurrentValue()}; + std::pair<bool,uint64_t> stop_idx = {m_options.m_stop_idx.OptionWasSet(),m_options.m_stop_idx.GetCurrentValue()}; + std::pair<bool,uint64_t> count = {m_options.m_count.OptionWasSet(),m_options.m_count.GetCurrentValue()}; + + const CommandHistory& history(m_interpreter.GetCommandHistory()); + + if (start_idx.first && start_idx.second == UINT64_MAX) + { + if (count.first) + { + start_idx.second = history.GetSize() - count.second; + stop_idx.second = history.GetSize() - 1; + } + else if (stop_idx.first) + { + start_idx.second = stop_idx.second; + stop_idx.second = history.GetSize() - 1; + } + else + { + start_idx.second = 0; + stop_idx.second = history.GetSize() - 1; + } + } + else + { + if (!start_idx.first && !stop_idx.first && !count.first) + { + start_idx.second = 0; + stop_idx.second = history.GetSize() - 1; + } + else if (start_idx.first) + { + if (count.first) + { + stop_idx.second = start_idx.second + count.second - 1; + } + else if (!stop_idx.first) + { + stop_idx.second = history.GetSize() - 1; + } + } + else if (stop_idx.first) + { + if (count.first) + { + if (stop_idx.second >= count.second) + start_idx.second = stop_idx.second - count.second + 1; + else + start_idx.second = 0; + } + } + else /* if (count.first) */ + { + start_idx.second = 0; + stop_idx.second = count.second - 1; + } + } + history.Dump(result.GetOutputStream(), start_idx.second, stop_idx.second); + } + } return result.Succeeded(); } @@ -147,8 +228,9 @@ OptionDefinition CommandObjectCommandsHistory::CommandOptions::g_option_table[] = { { LLDB_OPT_SET_1, false, "count", 'c', required_argument, NULL, 0, eArgTypeUnsignedInteger, "How many history commands to print."}, -{ LLDB_OPT_SET_1, false, "start-index", 's', required_argument, NULL, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands."}, +{ LLDB_OPT_SET_1, false, "start-index", 's', required_argument, NULL, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)."}, { LLDB_OPT_SET_1, false, "end-index", 'e', required_argument, NULL, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands."}, +{ LLDB_OPT_SET_2, false, "wipe", 'w', no_argument, NULL, 0, eArgTypeBoolean, "Clears the current command history."}, { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } }; |