diff --git a/lldb/include/lldb/Target/StackFrameRecognizer.h b/lldb/include/lldb/Target/StackFrameRecognizer.h --- a/lldb/include/lldb/Target/StackFrameRecognizer.h +++ b/lldb/include/lldb/Target/StackFrameRecognizer.h @@ -125,7 +125,6 @@ private: struct RegisteredEntry { uint32_t recognizer_id; - bool deleted; lldb::StackFrameRecognizerSP recognizer; bool is_regexp; ConstString module; diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -999,9 +999,14 @@ return false; } - GetSelectedOrDummyTarget() - .GetFrameRecognizerManager() - .RemoveRecognizerWithID(recognizer_id); + if (!GetSelectedOrDummyTarget() + .GetFrameRecognizerManager() + .RemoveRecognizerWithID(recognizer_id)) { + result.AppendErrorWithFormat("'%s' is not a valid recognizer id.\n", + command.GetArgumentAtIndex(0)); + result.SetStatus(eReturnStatusFailed); + return false; + } result.SetStatus(eReturnStatusSuccessFinishResult); return result.Succeeded(); } diff --git a/lldb/source/Target/StackFrameRecognizer.cpp b/lldb/source/Target/StackFrameRecognizer.cpp --- a/lldb/source/Target/StackFrameRecognizer.cpp +++ b/lldb/source/Target/StackFrameRecognizer.cpp @@ -50,17 +50,17 @@ void StackFrameRecognizerManager::AddRecognizer( StackFrameRecognizerSP recognizer, ConstString module, llvm::ArrayRef symbols, bool first_instruction_only) { - m_recognizers.push_front({(uint32_t)m_recognizers.size(), false, recognizer, - false, module, RegularExpressionSP(), symbols, + m_recognizers.push_front({(uint32_t)m_recognizers.size(), recognizer, false, + module, RegularExpressionSP(), symbols, RegularExpressionSP(), first_instruction_only}); } void StackFrameRecognizerManager::AddRecognizer( StackFrameRecognizerSP recognizer, RegularExpressionSP module, RegularExpressionSP symbol, bool first_instruction_only) { - m_recognizers.push_front( - {(uint32_t)m_recognizers.size(), false, recognizer, true, ConstString(), - module, std::vector(), symbol, first_instruction_only}); + m_recognizers.push_front({(uint32_t)m_recognizers.size(), recognizer, true, + ConstString(), module, std::vector(), + symbol, first_instruction_only}); } void StackFrameRecognizerManager::ForEach( @@ -90,9 +90,13 @@ uint32_t recognizer_id) { if (recognizer_id >= m_recognizers.size()) return false; - if (m_recognizers[recognizer_id].deleted) + auto found = + llvm::find_if(m_recognizers, [recognizer_id](const RegisteredEntry &e) { + return e.recognizer_id == recognizer_id; + }); + if (found == m_recognizers.end()) return false; - m_recognizers[recognizer_id].deleted = true; + m_recognizers.erase(found); return true; } @@ -116,8 +120,6 @@ Address current_addr = frame->GetFrameCodeAddress(); for (auto entry : m_recognizers) { - if (entry.deleted) - continue; if (entry.module) if (entry.module != module_name) continue; diff --git a/lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py b/lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py --- a/lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py +++ b/lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py @@ -44,8 +44,24 @@ self.runCmd("frame recognizer delete 0") + # Test that it deleted the recognizer with id 0. self.expect("frame recognizer list", substrs=['1: recognizer.MyOtherFrameRecognizer, module a.out, symbol bar (regexp)']) + self.expect("frame recognizer list", matching=False, + substrs=['MyFrameRecognizer']) + + # Test that an invalid index and deleting the same index again + # is an error and doesn't do any changes. + self.expect("frame recognizer delete 2", error=True, + substrs=["error: '2' is not a valid recognizer id."]) + self.expect("frame recognizer delete 0", error=True, + substrs=["error: '0' is not a valid recognizer id."]) + # Recognizers should have the same state as above. + self.expect("frame recognizer list", + substrs=['1: recognizer.MyOtherFrameRecognizer, module a.out, symbol bar (regexp)']) + self.expect("frame recognizer list", matching=False, + substrs=['MyFrameRecognizer']) + self.runCmd("frame recognizer clear")