[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:50 PST 2024


https://github.com/clayborg commented:

See inlined comments, but maybe we need to start storing a `std::weak_ptr<ValueObject>` instead of raw pointers to things, and possibly always passsing a `ValueObjectSP` object into the `ValueObjectPrinter` so it holds a strong reference to the value object while printing. I could see dead pointers causing problems and crashes.

It would be nice to also not crash, right now we do things like:
```
assert(valobj);
valobj->CrashNow();
```
If we use `std::weak_ptr<ValueObject>` instead of raw pointers or references, we can then call the `bool std::weak_ptr<T>::expired() const` function to see if the weak pointer was valid before, but the main shared pointer keeping it alive has been freed. This will allow us to detect issues where our backing object has been freed.

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


More information about the lldb-commits mailing list