summaryrefslogtreecommitdiff
path: root/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2025-11-20 16:45:11 -0800
committerGitHub <noreply@github.com>2025-11-20 16:45:11 -0800
commit06eac9feb92cba1d24e8a674c643aae1200d2bc8 (patch)
tree7acd1a4cc8ce631a5928c2deea7b3f95656777a8 /lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
parentac55d7859fc53d9ca8444a29a93fc45d16ecb26a (diff)
[lldb] Eliminate SupportFileSP nullptr derefs (#168624)
This patch fixes and eliminates the possibility of SupportFileSP ever being nullptr. The support file was originally treated like a value type, but became a polymorphic type and therefore has to be stored and passed around as a pointer. To avoid having all the callers check the validity of the pointer, I introduced the invariant that SupportFileSP is never null and always default constructed. However, without enforcement at the type level, that's fragile and indeed, we already identified two crashes where someone accidentally broke that invariant. This PR introduces a NonNullSharedPtr to prevent that. NonNullSharedPtr is a smart pointer wrapper around std::shared_ptr that guarantees the pointer is never null. If default-constructed, it creates a default-constructed instance of the contained type. Note that I'm using private inheritance because you shouldn't inherit from standard library classes due to the lack of virtual destructor. So while the new abstraction looks like a `std::shared_ptr`, it is in fact **not** a shared pointer. Given that our destructor is trivial, we could use public inheritance, but currently there's no need for it. rdar://164989579
Diffstat (limited to 'lldb/source/Breakpoint/BreakpointResolverFileLine.cpp')
-rw-r--r--lldb/source/Breakpoint/BreakpointResolverFileLine.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
index a94e9e23163d..cef1ef1b08fe 100644
--- a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
@@ -139,7 +139,7 @@ void BreakpointResolverFileLine::FilterContexts(SymbolContextList &sc_list) {
if (!sc.block)
continue;
- SupportFileSP file_sp;
+ SupportFileNSP file_sp = std::make_shared<SupportFile>();
uint32_t line;
const Block *inline_block = sc.block->GetContainingInlinedBlock();
if (inline_block) {