[Lldb-commits] [lldb] Make ValueObjectPrinter's handling of its ValueObject pointers more principled (NFC) (PR #81314)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri Feb 9 12:51:51 PST 2024


================
@@ -121,8 +135,10 @@ class ValueObjectPrinter {
 private:
   bool ShouldShowName() const;
 
-  ValueObject *m_orig_valobj;
-  ValueObject *m_valobj;
+  ValueObject &m_orig_valobj;
+  ValueObject *m_cached_valobj; /// Cache the current "most specialized" value.
----------------
clayborg wrote:

I wonder if we should start using `std::weak_ptr<ValueObject>` instead of raw pointers. Someone is storing a shared pointer to the object somewhere in the value object tree, so having a weak pointer could help us to catch these things as we can ask `if (m_cached_valobj_wp.expired() == true)` and this would tell us that this was assigned to a valid object at one point, but it has been freed. The expired call will return false if the weak pointer was never set or if the weak pointer was cleared.

https://github.com/llvm/llvm-project/pull/81314


More information about the lldb-commits mailing list