diff options
author | Med Ismail Bennani <medismail.bennani@gmail.com> | 2019-12-28 14:47:51 +0100 |
---|---|---|
committer | Med Ismail Bennani <medismail.bennani@gmail.com> | 2020-01-04 03:11:15 +0100 |
commit | df71f92fbb7c96cfd36d247ae6fb6929cb9bce35 (patch) | |
tree | 9f5a580a7637de248c390bfb16e2a6d4832e58b1 /lldb/source/Commands | |
parent | 05a4cf26365f10ae0cb2ad76f2babfb5ed929fdc (diff) | |
download | bcm5719-llvm-df71f92fbb7c96cfd36d247ae6fb6929cb9bce35.tar.gz bcm5719-llvm-df71f92fbb7c96cfd36d247ae6fb6929cb9bce35.zip |
[lldb/Command] Add --force option for `watchpoint delete` command
Currently, there is no option to delete all the watchpoint without LLDB
asking for a confirmation. Besides making the watchpoint delete command
homogeneous with the breakpoint delete command, this option could also
become handy to trigger automated watchpoint deletion i.e. using
breakpoint actions.
rdar://42560586
Differential Revision: https://reviews.llvm.org/D72096
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/source/Commands')
-rw-r--r-- | lldb/source/Commands/CommandObjectWatchpoint.cpp | 83 | ||||
-rw-r--r-- | lldb/source/Commands/Options.td | 5 |
2 files changed, 69 insertions, 19 deletions
diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp index 1b1d59740c8..c965d354f73 100644 --- a/lldb/source/Commands/CommandObjectWatchpoint.cpp +++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -415,6 +415,10 @@ protected: }; // CommandObjectWatchpointDelete +#define LLDB_OPTIONS_watchpoint_delete +#include "CommandOptions.inc" + +// CommandObjectWatchpointDelete #pragma mark Delete class CommandObjectWatchpointDelete : public CommandObjectParsed { @@ -423,7 +427,8 @@ public: : CommandObjectParsed(interpreter, "watchpoint delete", "Delete the specified watchpoint(s). If no " "watchpoints are specified, delete them all.", - nullptr, eCommandRequiresTarget) { + nullptr, eCommandRequiresTarget), + m_options() { CommandArgumentEntry arg; CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); @@ -434,6 +439,41 @@ public: ~CommandObjectWatchpointDelete() override = default; + Options *GetOptions() override { return &m_options; } + + class CommandOptions : public Options { + public: + CommandOptions() : Options(), m_force(false) {} + + ~CommandOptions() override = default; + + Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, + ExecutionContext *execution_context) override { + const int short_option = m_getopt_table[option_idx].val; + + switch (short_option) { + case 'f': + m_force = true; + break; + default: + llvm_unreachable("Unimplemented option"); + } + + return {}; + } + + void OptionParsingStarting(ExecutionContext *execution_context) override { + m_force = false; + } + + llvm::ArrayRef<OptionDefinition> GetDefinitions() override { + return llvm::makeArrayRef(g_watchpoint_delete_options); + } + + // Instance variables to hold the values for command options. + bool m_force; + }; + protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); @@ -453,8 +493,9 @@ protected: return false; } - if (command.GetArgumentCount() == 0) { - if (!m_interpreter.Confirm( + if (command.empty()) { + if (!m_options.m_force && + !m_interpreter.Confirm( "About to delete all watchpoints, do you want to do that?", true)) { result.AppendMessage("Operation cancelled..."); @@ -465,27 +506,31 @@ protected: (uint64_t)num_watchpoints); } result.SetStatus(eReturnStatusSuccessFinishNoResult); - } else { - // Particular watchpoints selected; delete them. - std::vector<uint32_t> wp_ids; - if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( - target, command, wp_ids)) { - result.AppendError("Invalid watchpoints specification."); - result.SetStatus(eReturnStatusFailed); - return false; - } + return result.Succeeded(); + } - int count = 0; - const size_t size = wp_ids.size(); - for (size_t i = 0; i < size; ++i) - if (target->RemoveWatchpointByID(wp_ids[i])) - ++count; - result.AppendMessageWithFormat("%d watchpoints deleted.\n", count); - result.SetStatus(eReturnStatusSuccessFinishNoResult); + // Particular watchpoints selected; delete them. + std::vector<uint32_t> wp_ids; + if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, + wp_ids)) { + result.AppendError("Invalid watchpoints specification."); + result.SetStatus(eReturnStatusFailed); + return false; } + int count = 0; + const size_t size = wp_ids.size(); + for (size_t i = 0; i < size; ++i) + if (target->RemoveWatchpointByID(wp_ids[i])) + ++count; + result.AppendMessageWithFormat("%d watchpoints deleted.\n", count); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + return result.Succeeded(); } + +private: + CommandOptions m_options; }; // CommandObjectWatchpointIgnore diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index f53d1481f4e..850df133a42 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -1126,3 +1126,8 @@ let Command = "watchpoint command add" in { "to run as command for this watchpoint. Be sure to give a module name if " "appropriate.">; } + +let Command = "watchpoint delete" in { + def watchpoint_delete_force : Option<"force", "f">, Group<1>, + Desc<"Delete all watchpoints without querying for confirmation.">; +} |