diff options
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp')
-rw-r--r-- | contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp | 136 |
1 files changed, 72 insertions, 64 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp index 8df8aca04e4a..a4929ea0d515 100644 --- a/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp +++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -9,6 +9,7 @@ #include "CommandObjectWatchpoint.h" #include "CommandObjectWatchpointCommand.h" +#include <memory> #include <vector> #include "llvm/ADT/StringRef.h" @@ -20,6 +21,7 @@ #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandOptionArgumentTable.h" #include "lldb/Interpreter/CommandReturnObject.h" +#include "lldb/Symbol/Function.h" #include "lldb/Symbol/Variable.h" #include "lldb/Symbol/VariableList.h" #include "lldb/Target/StackFrame.h" @@ -29,12 +31,12 @@ using namespace lldb; using namespace lldb_private; -static void AddWatchpointDescription(Stream *s, Watchpoint *wp, +static void AddWatchpointDescription(Stream &s, Watchpoint &wp, lldb::DescriptionLevel level) { - s->IndentMore(); - wp->GetDescription(s, level); - s->IndentLess(); - s->EOL(); + s.IndentMore(); + wp.GetDescription(&s, level); + s.IndentLess(); + s.EOL(); } static bool CheckTargetForWatchpointOperations(Target *target, @@ -209,13 +211,13 @@ protected: Target *target = &GetSelectedTarget(); if (target->GetProcessSP() && target->GetProcessSP()->IsAlive()) { - uint32_t num_supported_hardware_watchpoints; - Status error = target->GetProcessSP()->GetWatchpointSupportInfo( - num_supported_hardware_watchpoints); - if (error.Success()) + std::optional<uint32_t> num_supported_hardware_watchpoints = + target->GetProcessSP()->GetWatchpointSlotCount(); + + if (num_supported_hardware_watchpoints) result.AppendMessageWithFormat( "Number of supported hardware watchpoints: %u\n", - num_supported_hardware_watchpoints); + *num_supported_hardware_watchpoints); } const WatchpointList &watchpoints = target->GetWatchpointList(); @@ -237,8 +239,8 @@ protected: // No watchpoint selected; show info about all currently set watchpoints. result.AppendMessage("Current watchpoints:"); for (size_t i = 0; i < num_watchpoints; ++i) { - Watchpoint *wp = watchpoints.GetByIndex(i).get(); - AddWatchpointDescription(&output_stream, wp, m_options.m_level); + WatchpointSP watch_sp = watchpoints.GetByIndex(i); + AddWatchpointDescription(output_stream, *watch_sp, m_options.m_level); } result.SetStatus(eReturnStatusSuccessFinishNoResult); } else { @@ -252,9 +254,9 @@ protected: const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) { - Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get(); - if (wp) - AddWatchpointDescription(&output_stream, wp, m_options.m_level); + WatchpointSP watch_sp = watchpoints.FindByID(wp_ids[i]); + if (watch_sp) + AddWatchpointDescription(output_stream, *watch_sp, m_options.m_level); result.SetStatus(eReturnStatusSuccessFinishNoResult); } } @@ -289,9 +291,9 @@ public: void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override { - CommandCompletions::InvokeCommonCompletionCallbacks( - GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, - request, nullptr); + lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request, + nullptr); } protected: @@ -365,9 +367,9 @@ public: void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override { - CommandCompletions::InvokeCommonCompletionCallbacks( - GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, - request, nullptr); + lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request, + nullptr); } protected: @@ -446,9 +448,9 @@ public: void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override { - CommandCompletions::InvokeCommonCompletionCallbacks( - GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, - request, nullptr); + lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request, + nullptr); } Options *GetOptions() override { return &m_options; } @@ -569,9 +571,9 @@ public: void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override { - CommandCompletions::InvokeCommonCompletionCallbacks( - GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, - request, nullptr); + lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request, + nullptr); } Options *GetOptions() override { return &m_options; } @@ -694,9 +696,9 @@ public: void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override { - CommandCompletions::InvokeCommonCompletionCallbacks( - GetCommandInterpreter(), CommandCompletions::eWatchPointIDCompletion, - request, nullptr); + lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), lldb::eWatchpointIDCompletion, request, + nullptr); } Options *GetOptions() override { return &m_options; } @@ -758,8 +760,8 @@ protected: } if (command.GetArgumentCount() == 0) { - WatchpointSP wp_sp = target->GetLastCreatedWatchpoint(); - wp_sp->SetCondition(m_options.m_condition.c_str()); + WatchpointSP watch_sp = target->GetLastCreatedWatchpoint(); + watch_sp->SetCondition(m_options.m_condition.c_str()); result.SetStatus(eReturnStatusSuccessFinishNoResult); } else { // Particular watchpoints selected; set condition on them. @@ -773,9 +775,9 @@ protected: int count = 0; const size_t size = wp_ids.size(); for (size_t i = 0; i < size; ++i) { - WatchpointSP wp_sp = watchpoints.FindByID(wp_ids[i]); - if (wp_sp) { - wp_sp->SetCondition(m_options.m_condition.c_str()); + WatchpointSP watch_sp = watchpoints.FindByID(wp_ids[i]); + if (watch_sp) { + watch_sp->SetCondition(m_options.m_condition.c_str()); ++count; } } @@ -835,8 +837,7 @@ corresponding to the byte size of the data type."); m_arguments.push_back(arg); // Absorb the '-w' and '-s' options into our option group. - m_option_group.Append(&m_option_watchpoint, LLDB_OPT_SET_ALL, - LLDB_OPT_SET_1); + m_option_group.Append(&m_option_watchpoint, LLDB_OPT_SET_1, LLDB_OPT_SET_1); m_option_group.Finalize(); } @@ -847,9 +848,9 @@ corresponding to the byte size of the data type."); OptionElementVector &opt_element_vector) override { if (request.GetCursorIndex() != 0) return; - CommandCompletions::InvokeCommonCompletionCallbacks( - GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion, - request, nullptr); + lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks( + GetCommandInterpreter(), lldb::eVariablePathCompletion, request, + nullptr); } Options *GetOptions() override { return &m_option_group; } @@ -949,30 +950,34 @@ protected: uint32_t watch_type = m_option_watchpoint.watch_type; error.Clear(); - Watchpoint *wp = - target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error) - .get(); - if (wp) { - wp->SetWatchSpec(command.GetArgumentAtIndex(0)); - wp->SetWatchVariable(true); - if (var_sp && var_sp->GetDeclaration().GetFile()) { + WatchpointSP watch_sp = + target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error); + if (!watch_sp) { + result.AppendErrorWithFormat( + "Watchpoint creation failed (addr=0x%" PRIx64 ", size=%" PRIu64 + ", variable expression='%s').\n", + addr, static_cast<uint64_t>(size), command.GetArgumentAtIndex(0)); + if (const char *error_message = error.AsCString(nullptr)) + result.AppendError(error_message); + return result.Succeeded(); + } + + watch_sp->SetWatchSpec(command.GetArgumentAtIndex(0)); + watch_sp->SetWatchVariable(true); + if (var_sp) { + if (var_sp->GetDeclaration().GetFile()) { StreamString ss; // True to show fullpath for declaration file. var_sp->GetDeclaration().DumpStopContext(&ss, true); - wp->SetDeclInfo(std::string(ss.GetString())); + watch_sp->SetDeclInfo(std::string(ss.GetString())); } - output_stream.Printf("Watchpoint created: "); - wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); - output_stream.EOL(); - result.SetStatus(eReturnStatusSuccessFinishResult); - } else { - result.AppendErrorWithFormat( - "Watchpoint creation failed (addr=0x%" PRIx64 ", size=%" PRIu64 - ", variable expression='%s').\n", - addr, (uint64_t)size, command.GetArgumentAtIndex(0)); - if (error.AsCString(nullptr)) - result.AppendError(error.AsCString()); + if (var_sp->GetScope() == eValueTypeVariableLocal) + watch_sp->SetupVariableWatchpointDisabler(m_exe_ctx.GetFrameSP()); } + output_stream.Printf("Watchpoint created: "); + watch_sp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); + output_stream.EOL(); + result.SetStatus(eReturnStatusSuccessFinishResult); return result.Succeeded(); } @@ -991,6 +996,7 @@ public: : CommandObjectRaw( interpreter, "watchpoint set expression", "Set a watchpoint on an address by supplying an expression. " + "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. " @@ -1084,6 +1090,8 @@ protected: options.SetKeepInMemory(false); options.SetTryAllThreads(true); options.SetTimeout(std::nullopt); + if (m_option_watchpoint.language_type != eLanguageTypeUnknown) + options.SetLanguage(m_option_watchpoint.language_type); ExpressionResults expr_result = target->EvaluateExpression(expr, frame, valobj_sp, options); @@ -1117,13 +1125,13 @@ protected: CompilerType compiler_type(valobj_sp->GetCompilerType()); Status error; - Watchpoint *wp = - target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error) - .get(); - if (wp) { + WatchpointSP watch_sp = + target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error); + if (watch_sp) { + watch_sp->SetWatchSpec(std::string(expr)); Stream &output_stream = result.GetOutputStream(); output_stream.Printf("Watchpoint created: "); - wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); + watch_sp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); output_stream.EOL(); result.SetStatus(eReturnStatusSuccessFinishResult); } else { |