diff --git a/lldb/include/lldb/Target/BoundsSafetyTrapFrameRecognizer.h b/lldb/include/lldb/Target/BoundsSafetyTrapFrameRecognizer.h deleted file mode 100644 index d4ede8e8f033f..0000000000000 --- a/lldb/include/lldb/Target/BoundsSafetyTrapFrameRecognizer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* TO_UPSTREAM(BoundsSafety) ON */ -//===-- BoundsSafetyTrapFrameRecognizer.h -------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_BoundsSafetyTrapFrameRegognizer_h_ -#define liblldb_BoundsSafetyTrapFrameRegognizer_h_ - -#include "lldb/Target/StackFrameRecognizer.h" - -namespace lldb_private { - -void RegisterBoundsSafetyTrapFrameRecognizer(Process &process); - -/// Holds the stack frame that caused the BoundsSafety trap and the inlined stop -/// reason message. -class BoundsSafetyTrapRecognizedStackFrame : public RecognizedStackFrame { -public: - BoundsSafetyTrapRecognizedStackFrame(lldb::StackFrameSP most_relevant_frame_sp, - llvm::StringRef stop_desc); - lldb::StackFrameSP GetMostRelevantFrame() override; - -private: - lldb::StackFrameSP m_most_relevant_frame; -}; - -/// When a thread stops, it checks the current frame contains a BoundsSafety Trap -/// diagnostic. If so, it returns a \a -/// BoundsSafetyTrapRecognizedStackFrame holding the diagnostic a stop reason -/// description with and the parent frame as the most relavant frame. -class BoundsSafetyTrapFrameRecognizer : public StackFrameRecognizer { -public: - std::string GetName() override { - return "Pointer Check Trap StackFrame Recognizer"; - } - lldb::RecognizedStackFrameSP - RecognizeFrame(lldb::StackFrameSP frame) override; -}; - -} // namespace lldb_private - -#endif // liblldb_BoundsSafetyTrapFrameRegognizer_h_ -/* TO_UPSTREAM(BoundsSafety) OFF */ \ No newline at end of file diff --git a/lldb/source/Target/BoundsSafetyTrapFrameRecognizer.cpp b/lldb/source/Target/BoundsSafetyTrapFrameRecognizer.cpp deleted file mode 100644 index 6f15c1e29be76..0000000000000 --- a/lldb/source/Target/BoundsSafetyTrapFrameRecognizer.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* TO_UPSTREAM(BoundsSafety) ON */ -#include "lldb/Core/Module.h" -#include "lldb/Symbol/Function.h" -#include "lldb/Symbol/SymbolContext.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" - -#include "lldb/Utility/LLDBLog.h" -#include "lldb/Utility/Log.h" - -#include "lldb/Target/BoundsSafetyTrapFrameRecognizer.h" - -using namespace llvm; -using namespace lldb; -using namespace lldb_private; - -BoundsSafetyTrapRecognizedStackFrame::BoundsSafetyTrapRecognizedStackFrame( - StackFrameSP most_relevant_frame_sp, StringRef stop_desc) - : m_most_relevant_frame(most_relevant_frame_sp) { - m_stop_desc = std::string(stop_desc); -} - -lldb::RecognizedStackFrameSP -BoundsSafetyTrapFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) { - if (frame_sp->GetFrameIndex()) - return {}; - - ThreadSP thread_sp = frame_sp->GetThread(); - ProcessSP process_sp = thread_sp->GetProcess(); - - StackFrameSP most_relevant_frame_sp = thread_sp->GetStackFrameAtIndex(1); - - if (!most_relevant_frame_sp) { - Log *log = GetLog(LLDBLog::Unwind); - LLDB_LOG( - log, - "Bounds check failed Recognizer: Hit unwinding bound (1 frame)!"); - return {}; - } - - SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextEverything); - - if (!sc.block) - return {}; - - // The runtime error is set as the function name in the inlined function info - // of frame #0 by the compiler - const InlineFunctionInfo *inline_info = nullptr; - Block *inline_block = sc.block->GetContainingInlinedBlock(); - - if (!inline_block) - return {}; - - inline_info = sc.block->GetInlinedFunctionInfo(); - - if (!inline_info) - return {}; - - StringRef runtime_error = inline_info->GetName().AsCString(); - - if (runtime_error.empty()) - return {}; - - return lldb::RecognizedStackFrameSP(new BoundsSafetyTrapRecognizedStackFrame( - most_relevant_frame_sp, runtime_error)); -} - -lldb::StackFrameSP BoundsSafetyTrapRecognizedStackFrame::GetMostRelevantFrame() { - return m_most_relevant_frame; -} - -namespace lldb_private { - -void RegisterBoundsSafetyTrapFrameRecognizer(Process &process) { - RegularExpressionSP module_regex_sp = nullptr; - // TODO(dliew): rdar://90866345 - // `Pointer Check runtime failure` is the legacy trap prefix. - RegularExpressionSP symbol_regex_sp( - new RegularExpression("(Bounds check failed)|(Pointer Check runtime failure)")); - - StackFrameRecognizerSP srf_recognizer_sp = - std::make_shared(); - - process.GetTarget().GetFrameRecognizerManager().AddRecognizer( - srf_recognizer_sp, module_regex_sp, symbol_regex_sp, - Mangled::NamePreference::ePreferDemangled, false); -} - -} // namespace lldb_private -/* TO_UPSTREAM(BoundsSafety) ON */ diff --git a/lldb/source/Target/CMakeLists.txt b/lldb/source/Target/CMakeLists.txt index 53f51afcfbdb5..6bbc4d0b6c32a 100644 --- a/lldb/source/Target/CMakeLists.txt +++ b/lldb/source/Target/CMakeLists.txt @@ -12,7 +12,6 @@ add_lldb_library(lldbTarget AssertFrameRecognizer.cpp DynamicRegisterInfo.cpp ExecutionContext.cpp - BoundsSafetyTrapFrameRecognizer.cpp InstrumentationRuntime.cpp InstrumentationRuntimeStopInfo.cpp JITLoader.cpp diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 01f178de5ad23..96f718466504c 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -43,9 +43,6 @@ #include "lldb/Target/ABI.h" #include "lldb/Target/AssertFrameRecognizer.h" #include "lldb/Target/DynamicLoader.h" -/* TO_UPSTREAM(BoundsSafety) ON */ -#include "lldb/Target/BoundsSafetyTrapFrameRecognizer.h" -/* TO_UPSTREAM(BoundsSafety) OFF */ #include "lldb/Target/InstrumentationRuntime.h" #include "lldb/Target/JITLoader.h" #include "lldb/Target/JITLoaderList.h" @@ -546,9 +543,6 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp, // common C LanguageRuntime plugin. RegisterAssertFrameRecognizer(this); RegisterVerboseTrapFrameRecognizer(*this); - /* TO_UPSTREAM(BoundsSafety) ON */ - RegisterBoundsSafetyTrapFrameRecognizer(*this); - /* TO_UPSTREAM(BoundsSafety) OFF */ } Process::~Process() { diff --git a/lldb/source/Target/VerboseTrapFrameRecognizer.cpp b/lldb/source/Target/VerboseTrapFrameRecognizer.cpp index d7f3d0925d2d4..34ce557533972 100644 --- a/lldb/source/Target/VerboseTrapFrameRecognizer.cpp +++ b/lldb/source/Target/VerboseTrapFrameRecognizer.cpp @@ -148,8 +148,11 @@ namespace lldb_private { void RegisterVerboseTrapFrameRecognizer(Process &process) { RegularExpressionSP module_regex_sp = nullptr; + // Older -fbounds-safety versions didn't have a ClangTrapPrefix, so the name + // of the frame was just the bounds-check failure message. This regex supports + // the old and new style of frames. auto symbol_regex_sp = std::make_shared( - llvm::formatv("^{0}", ClangTrapPrefix).str()); + llvm::formatv("^({0}|Bounds check failed|Pointer Check runtime failure)", ClangTrapPrefix).str()); StackFrameRecognizerSP srf_recognizer_sp = std::make_shared(); diff --git a/lldb/test/API/lang/BoundsSafety/out_of_bounds_pointer/TestOutOfBoundsPointer.py b/lldb/test/API/lang/BoundsSafety/out_of_bounds_pointer/TestOutOfBoundsPointer.py index 27bb0a1c35bca..d89952f13d0a7 100644 --- a/lldb/test/API/lang/BoundsSafety/out_of_bounds_pointer/TestOutOfBoundsPointer.py +++ b/lldb/test/API/lang/BoundsSafety/out_of_bounds_pointer/TestOutOfBoundsPointer.py @@ -80,12 +80,9 @@ def partial_oob(self, type_name): def overflow_oob(self, type_name): return self.get_idx_var_regex(oob_kind=OOBKind.Overflow, type_name=type_name) - def setUp(self): - TestBase.setUp(self) - if _get_bool_config("ios_disclosed", fail_value=False): - self.build() - def test_bidi_known_type_size(self): + self.build() + (_, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint( self, r"// break here:.+", lldb.SBFileSpec("bidi_check_known_type_size.c") ) @@ -154,6 +151,8 @@ def test_bidi_known_type_size(self): self.expect("frame variable fams2", patterns=[self.bidi_full_oob("FAMS_t *")]) def test_bidi_unknown_type_size(self): + self.build() + (_, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint( self, r"// break here:.+", lldb.SBFileSpec("bidi_check_unknown_type_size.c") ) @@ -203,6 +202,8 @@ def test_bidi_unknown_type_size(self): self.expect("frame variable oob_null", patterns=[self.bidi_full_oob("void *")]) def test_idx_known_type_size(self): + self.build() + (_, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint( self, r"// break here:.+", lldb.SBFileSpec("idx_check_known_type_size.c") ) @@ -252,6 +253,8 @@ def test_idx_known_type_size(self): self.expect("frame variable fams2", patterns=[self.full_oob("FAMS_t *")]) def test_idx_unknown_type_size(self): + self.build() + (_, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint( self, r"// break here:.+", lldb.SBFileSpec("idx_check_unknown_type_size.c") )