diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp')
-rw-r--r-- | contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp | 140 |
1 files changed, 78 insertions, 62 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp index a4929ea0d515..c80868d33905 100644 --- a/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp +++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -207,7 +207,7 @@ public: }; protected: - bool DoExecute(Args &command, CommandReturnObject &result) override { + void DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); if (target->GetProcessSP() && target->GetProcessSP()->IsAlive()) { @@ -230,7 +230,7 @@ protected: if (num_watchpoints == 0) { result.AppendMessage("No watchpoints currently set."); result.SetStatus(eReturnStatusSuccessFinishNoResult); - return true; + return; } Stream &output_stream = result.GetOutputStream(); @@ -249,7 +249,7 @@ protected: if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); - return false; + return; } const size_t size = wp_ids.size(); @@ -260,8 +260,6 @@ protected: result.SetStatus(eReturnStatusSuccessFinishNoResult); } } - - return result.Succeeded(); } private: @@ -297,10 +295,10 @@ public: } protected: - bool DoExecute(Args &command, CommandReturnObject &result) override { + void DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); if (!CheckTargetForWatchpointOperations(target, result)) - return false; + return; std::unique_lock<std::recursive_mutex> lock; target->GetWatchpointList().GetListMutex(lock); @@ -311,7 +309,7 @@ protected: if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be enabled."); - return false; + return; } if (command.GetArgumentCount() == 0) { @@ -327,7 +325,7 @@ protected: if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); - return false; + return; } int count = 0; @@ -338,8 +336,6 @@ protected: result.AppendMessageWithFormat("%d watchpoints enabled.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); } - - return result.Succeeded(); } }; @@ -373,10 +369,10 @@ public: } protected: - bool DoExecute(Args &command, CommandReturnObject &result) override { + void DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); if (!CheckTargetForWatchpointOperations(target, result)) - return false; + return; std::unique_lock<std::recursive_mutex> lock; target->GetWatchpointList().GetListMutex(lock); @@ -386,7 +382,7 @@ protected: if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be disabled."); - return false; + return; } if (command.GetArgumentCount() == 0) { @@ -405,7 +401,7 @@ protected: if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); - return false; + return; } int count = 0; @@ -416,8 +412,6 @@ protected: result.AppendMessageWithFormat("%d watchpoints disabled.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); } - - return result.Succeeded(); } }; @@ -489,10 +483,10 @@ public: }; protected: - bool DoExecute(Args &command, CommandReturnObject &result) override { + void DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); if (!CheckTargetForWatchpointOperations(target, result)) - return false; + return; std::unique_lock<std::recursive_mutex> lock; target->GetWatchpointList().GetListMutex(lock); @@ -503,7 +497,7 @@ protected: if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be deleted."); - return false; + return; } if (command.empty()) { @@ -519,7 +513,7 @@ protected: (uint64_t)num_watchpoints); } result.SetStatus(eReturnStatusSuccessFinishNoResult); - return result.Succeeded(); + return; } // Particular watchpoints selected; delete them. @@ -527,7 +521,7 @@ protected: if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); - return false; + return; } int count = 0; @@ -537,8 +531,6 @@ protected: ++count; result.AppendMessageWithFormat("%d watchpoints deleted.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); - - return result.Succeeded(); } private: @@ -616,10 +608,10 @@ public: }; protected: - bool DoExecute(Args &command, CommandReturnObject &result) override { + void DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); if (!CheckTargetForWatchpointOperations(target, result)) - return false; + return; std::unique_lock<std::recursive_mutex> lock; target->GetWatchpointList().GetListMutex(lock); @@ -630,7 +622,7 @@ protected: if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be ignored."); - return false; + return; } if (command.GetArgumentCount() == 0) { @@ -645,7 +637,7 @@ protected: if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); - return false; + return; } int count = 0; @@ -656,8 +648,6 @@ protected: result.AppendMessageWithFormat("%d watchpoints ignored.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); } - - return result.Succeeded(); } private: @@ -742,10 +732,10 @@ public: }; protected: - bool DoExecute(Args &command, CommandReturnObject &result) override { + void DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); if (!CheckTargetForWatchpointOperations(target, result)) - return false; + return; std::unique_lock<std::recursive_mutex> lock; target->GetWatchpointList().GetListMutex(lock); @@ -756,7 +746,7 @@ protected: if (num_watchpoints == 0) { result.AppendError("No watchpoints exist to be modified."); - return false; + return; } if (command.GetArgumentCount() == 0) { @@ -769,7 +759,7 @@ protected: if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( target, command, wp_ids)) { result.AppendError("Invalid watchpoints specification."); - return false; + return; } int count = 0; @@ -784,8 +774,6 @@ protected: result.AppendMessageWithFormat("%d watchpoints modified.\n", count); result.SetStatus(eReturnStatusSuccessFinishNoResult); } - - return result.Succeeded(); } private: @@ -803,7 +791,7 @@ public: "Set a watchpoint on a variable. " "Use the '-w' option to specify the type of watchpoint and " "the '-s' option to specify the byte size to watch for. " - "If no '-w' option is specified, it defaults to write. " + "If no '-w' option is specified, it defaults to modify. " "If no '-s' option is specified, it defaults to the variable's " "byte size. " "Note that there are limited hardware resources for watchpoints. " @@ -866,7 +854,7 @@ protected: return variable_list.GetSize() - old_size; } - bool DoExecute(Args &command, CommandReturnObject &result) override { + void DoExecute(Args &command, CommandReturnObject &result) override { Target *target = GetDebugger().GetSelectedTarget().get(); StackFrame *frame = m_exe_ctx.GetFramePtr(); @@ -875,12 +863,12 @@ protected: if (command.GetArgumentCount() <= 0) { result.AppendError("required argument missing; " "specify your program variable to watch for"); - return false; + return; } - // If no '-w' is specified, default to '-w write'. + // If no '-w' is specified, default to '-w modify'. if (!m_option_watchpoint.watch_type_specified) { - m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite; + m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchModify; } // We passed the sanity check for the command. Proceed to set the @@ -895,7 +883,7 @@ protected: // A simple watch variable gesture allows only one argument. if (command.GetArgumentCount() != 1) { result.AppendError("specify exactly one variable to watch for"); - return false; + return; } // Things have checked out ok... @@ -930,9 +918,9 @@ protected: if (addr_type == eAddressTypeLoad) { // We're in business. // Find out the size of this variable. - size = m_option_watchpoint.watch_size == 0 + size = m_option_watchpoint.watch_size.GetCurrentValue() == 0 ? valobj_sp->GetByteSize().value_or(0) - : m_option_watchpoint.watch_size; + : m_option_watchpoint.watch_size.GetCurrentValue(); } compiler_type = valobj_sp->GetCompilerType(); } else { @@ -943,11 +931,27 @@ protected: result.AppendErrorWithFormat("unable to find any variable " "expression path that matches '%s'", command.GetArgumentAtIndex(0)); - return false; + return; } // Now it's time to create the watchpoint. - uint32_t watch_type = m_option_watchpoint.watch_type; + uint32_t watch_type = 0; + switch (m_option_watchpoint.watch_type) { + case OptionGroupWatchpoint::eWatchModify: + watch_type |= LLDB_WATCH_TYPE_MODIFY; + break; + case OptionGroupWatchpoint::eWatchRead: + watch_type |= LLDB_WATCH_TYPE_READ; + break; + case OptionGroupWatchpoint::eWatchReadWrite: + watch_type |= LLDB_WATCH_TYPE_READ | LLDB_WATCH_TYPE_WRITE; + break; + case OptionGroupWatchpoint::eWatchWrite: + watch_type |= LLDB_WATCH_TYPE_WRITE; + break; + case OptionGroupWatchpoint::eWatchInvalid: + break; + }; error.Clear(); WatchpointSP watch_sp = @@ -959,7 +963,7 @@ protected: addr, static_cast<uint64_t>(size), command.GetArgumentAtIndex(0)); if (const char *error_message = error.AsCString(nullptr)) result.AppendError(error_message); - return result.Succeeded(); + return; } watch_sp->SetWatchSpec(command.GetArgumentAtIndex(0)); @@ -978,8 +982,6 @@ protected: watch_sp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); output_stream.EOL(); result.SetStatus(eReturnStatusSuccessFinishResult); - - return result.Succeeded(); } private: @@ -999,7 +1001,7 @@ public: "Use the '-l' option to specify the language of the expression. " "Use the '-w' option to specify the type of watchpoint and " "the '-s' option to specify the byte size to watch for. " - "If no '-w' option is specified, it defaults to write. " + "If no '-w' option is specified, it defaults to modify. " "If no '-s' option is specified, it defaults to the target's " "pointer byte size. " "Note that there are limited hardware resources for watchpoints. " @@ -1013,7 +1015,7 @@ public: R"( Examples: -(lldb) watchpoint set expression -w write -s 1 -- foo + 32 +(lldb) watchpoint set expression -w modify -s 1 -- foo + 32 Watches write access for the 1-byte region pointed to by the address 'foo + 32')"); @@ -1045,7 +1047,7 @@ Examples: Options *GetOptions() override { return &m_option_group; } protected: - bool DoExecute(llvm::StringRef raw_command, + void DoExecute(llvm::StringRef raw_command, CommandReturnObject &result) override { auto exe_ctx = GetCommandInterpreter().GetExecutionContext(); m_option_group.NotifyOptionParsingStarting( @@ -1061,19 +1063,19 @@ protected: if (args.HasArgs()) if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group, exe_ctx)) - return false; + return; // If no argument is present, issue an error message. There's no way to // set a watchpoint. if (raw_command.trim().empty()) { result.AppendError("required argument missing; specify an expression " "to evaluate into the address to watch for"); - return false; + return; } // If no '-w' is specified, default to '-w write'. if (!m_option_watchpoint.watch_type_specified) { - m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite; + m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchModify; } // We passed the sanity check for the command. Proceed to set the @@ -1100,7 +1102,7 @@ protected: result.AppendErrorWithFormat("expression evaluated: \n%s", expr.data()); if (valobj_sp && !valobj_sp->GetError().Success()) result.AppendError(valobj_sp->GetError().AsCString()); - return false; + return; } // Get the address to watch. @@ -1108,16 +1110,32 @@ protected: addr = valobj_sp->GetValueAsUnsigned(0, &success); if (!success) { result.AppendError("expression did not evaluate to an address"); - return false; + return; } - if (m_option_watchpoint.watch_size != 0) - size = m_option_watchpoint.watch_size; + if (m_option_watchpoint.watch_size.GetCurrentValue() != 0) + size = m_option_watchpoint.watch_size.GetCurrentValue(); else size = target->GetArchitecture().GetAddressByteSize(); // Now it's time to create the watchpoint. - uint32_t watch_type = m_option_watchpoint.watch_type; + uint32_t watch_type; + switch (m_option_watchpoint.watch_type) { + case OptionGroupWatchpoint::eWatchRead: + watch_type = LLDB_WATCH_TYPE_READ; + break; + case OptionGroupWatchpoint::eWatchWrite: + watch_type = LLDB_WATCH_TYPE_WRITE; + break; + case OptionGroupWatchpoint::eWatchModify: + watch_type = LLDB_WATCH_TYPE_MODIFY; + break; + case OptionGroupWatchpoint::eWatchReadWrite: + watch_type = LLDB_WATCH_TYPE_READ | LLDB_WATCH_TYPE_WRITE; + break; + default: + watch_type = LLDB_WATCH_TYPE_MODIFY; + } // Fetch the type from the value object, the type of the watched object is // the pointee type @@ -1141,8 +1159,6 @@ protected: if (error.AsCString(nullptr)) result.AppendError(error.AsCString()); } - - return result.Succeeded(); } private: |