Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ bool lldb_private::formatters::LibcxxSmartPointerSummaryProvider(
if (!success)
return false;

// std::shared_ptr releases the underlying resource when the
// __shared_owners_ count hits -1. So `__shared_owners_ == 0` indicates 1
// owner. Hence add +1 here.
stream.Printf(" strong=%" PRIu64, count + 1);
}

Expand All @@ -187,7 +190,9 @@ bool lldb_private::formatters::LibcxxSmartPointerSummaryProvider(
if (!success)
return false;

stream.Printf(" weak=%" PRIu64, count + 1);
// Unlike __shared_owners_, __shared_weak_owners_ indicates the exact
// std::weak_ptr reference count.
stream.Printf(" weak=%" PRIu64, count);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_shared_ptr_variables(self):
"""Test `frame variable` output for `std::shared_ptr` types."""
self.build()

lldbutil.run_to_source_breakpoint(
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp")
)

Expand All @@ -37,23 +37,23 @@ def test_shared_ptr_variables(self):
type="std::shared_ptr<int>",
children=[ValueCheck(name="__ptr_")],
)
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=1$")
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=0$")
self.assertNotEqual(valobj.child[0].unsigned, 0)

valobj = self.expect_var_path(
"sp_int_ref",
type="std::shared_ptr<int> &",
children=[ValueCheck(name="__ptr_")],
)
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=1$")
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=0$")
self.assertNotEqual(valobj.child[0].unsigned, 0)

valobj = self.expect_var_path(
"sp_int_ref_ref",
type="std::shared_ptr<int> &&",
children=[ValueCheck(name="__ptr_")],
)
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=1$")
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=0$")
self.assertNotEqual(valobj.child[0].unsigned, 0)

if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
Expand All @@ -68,12 +68,12 @@ def test_shared_ptr_variables(self):
type="std::shared_ptr<" + string_type + ">",
children=[ValueCheck(name="__ptr_", summary='"hello"')],
)
self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=0$')

valobj = self.expect_var_path("sp_user", type="std::shared_ptr<User>")
self.assertRegex(
valobj.summary,
"^std(::__[^:]*)?::shared_ptr<User>::element_type @ 0x0*[1-9a-f][0-9a-f]+( strong=1)? weak=1",
"^std(::__[^:]*)?::shared_ptr<User>::element_type @ 0x0*[1-9a-f][0-9a-f]+( strong=1)? weak=0",
)
self.assertNotEqual(valobj.child[0].unsigned, 0)

Expand All @@ -91,11 +91,23 @@ def test_shared_ptr_variables(self):
self.expect_var_path("sp_user->name", type="std::string", summary='"steph"')

valobj = self.expect_var_path(
"si", type="std::shared_ptr<int>", summary="47 strong=2 weak=1"
"si", type="std::shared_ptr<int>", summary="47 strong=2 weak=0"
)

valobj = self.expect_var_path(
"sie", type="std::shared_ptr<int>", summary="nullptr strong=2 weak=1"
"sie", type="std::shared_ptr<int>", summary="nullptr strong=2 weak=0"
)

lldbutil.continue_to_breakpoint(process, bkpt)

valobj = self.expect_var_path(
"si", type="std::shared_ptr<int>", summary="47 strong=2 weak=2"
)
valobj = self.expect_var_path(
"sie", type="std::shared_ptr<int>", summary="nullptr strong=2 weak=2"
)
valobj = self.expect_var_path(
"wie", type="std::weak_ptr<int>", summary="nullptr strong=2 weak=2"
)

self.runCmd("settings set target.experimental.use-DIL true")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cstdio>
#include <memory>
#include <string>

Expand Down Expand Up @@ -26,5 +27,12 @@ int main() {
std::shared_ptr<int> si(new int(47));
std::shared_ptr<int> sie(si, nullptr);

return 0; // break here
std::puts("// break here");

std::weak_ptr<int> wie = sie;
std::weak_ptr<int> wie2 = sie;

std::puts("// break here");

return 0;
}
Loading