From 8398ad9cb21736dc57ee4dd766bd0859ef9bd000 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 31 Jul 2024 09:57:10 -0700 Subject: [lldb] Unify the way we get the Target in CommandObject (#101208) Currently, CommandObjects are obtaining a target in a variety of ways. Often the command incorrectly operates on the selected target. As an example, when a breakpoint command is running, the current target is passed into the command but the target that hit the breakpoint is not the selected target. In other places we use the CommandObject's execution context, which is frozen during the execution of the command, and comes with its own limitations. Finally, we often want to fall back to the dummy target if no real target is available. Instead of having to guess how to get the target, this patch introduces one helper function in CommandObject to get the most relevant target. In order of priority, that's the target from the command object's execution context, from the interpreter's execution context, the selected target or the dummy target. rdar://110846511 --- lldb/source/Commands/CommandObjectFrame.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'lldb/source/Commands/CommandObjectFrame.cpp') diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index 3f4178c..29e460f 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -687,7 +687,7 @@ protected: m_cmd_name); // Increment statistics. - TargetStats &target_stats = GetSelectedOrDummyTarget().GetStatistics(); + TargetStats &target_stats = GetTarget().GetStatistics(); if (result.Succeeded()) target_stats.GetFrameVariableStats().NotifySuccess(); else @@ -874,13 +874,13 @@ void CommandObjectFrameRecognizerAdd::DoExecute(Args &command, RegularExpressionSP(new RegularExpression(m_options.m_module)); auto func = RegularExpressionSP(new RegularExpression(m_options.m_symbols.front())); - GetSelectedOrDummyTarget().GetFrameRecognizerManager().AddRecognizer( + GetTarget().GetFrameRecognizerManager().AddRecognizer( recognizer_sp, module, func, m_options.m_first_instruction_only); } else { auto module = ConstString(m_options.m_module); std::vector symbols(m_options.m_symbols.begin(), m_options.m_symbols.end()); - GetSelectedOrDummyTarget().GetFrameRecognizerManager().AddRecognizer( + GetTarget().GetFrameRecognizerManager().AddRecognizer( recognizer_sp, module, symbols, m_options.m_first_instruction_only); } #endif @@ -898,9 +898,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - GetSelectedOrDummyTarget() - .GetFrameRecognizerManager() - .RemoveAllRecognizers(); + GetTarget().GetFrameRecognizerManager().RemoveAllRecognizers(); result.SetStatus(eReturnStatusSuccessFinishResult); } }; @@ -922,7 +920,7 @@ public: if (request.GetCursorIndex() != 0) return; - GetSelectedOrDummyTarget().GetFrameRecognizerManager().ForEach( + GetTarget().GetFrameRecognizerManager().ForEach( [&request](uint32_t rid, std::string rname, std::string module, llvm::ArrayRef symbols, bool regexp) { @@ -953,9 +951,7 @@ protected: return; } - GetSelectedOrDummyTarget() - .GetFrameRecognizerManager() - .RemoveAllRecognizers(); + GetTarget().GetFrameRecognizerManager().RemoveAllRecognizers(); result.SetStatus(eReturnStatusSuccessFinishResult); return; } @@ -973,9 +969,8 @@ protected: return; } - if (!GetSelectedOrDummyTarget() - .GetFrameRecognizerManager() - .RemoveRecognizerWithID(recognizer_id)) { + if (!GetTarget().GetFrameRecognizerManager().RemoveRecognizerWithID( + recognizer_id)) { result.AppendErrorWithFormat("'%s' is not a valid recognizer id.\n", command.GetArgumentAtIndex(0)); return; @@ -996,7 +991,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { bool any_printed = false; - GetSelectedOrDummyTarget().GetFrameRecognizerManager().ForEach( + GetTarget().GetFrameRecognizerManager().ForEach( [&result, &any_printed]( uint32_t recognizer_id, std::string name, std::string module, llvm::ArrayRef symbols, bool regexp) { @@ -1073,9 +1068,8 @@ protected: return; } - auto recognizer = GetSelectedOrDummyTarget() - .GetFrameRecognizerManager() - .GetRecognizerForFrame(frame_sp); + auto recognizer = + GetTarget().GetFrameRecognizerManager().GetRecognizerForFrame(frame_sp); Stream &output_stream = result.GetOutputStream(); output_stream.Printf("frame %d ", frame_index); -- cgit v1.1