This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Make the libcxx unique_ptr prettyprinter support custom deleters.
ClosedPublic

Authored by jgorbe on Apr 18 2023, 2:31 PM.

Details

Summary

The unique_ptr prettyprinter calls GetValueOfLibCXXCompressedPair,
which looks for a __value_ child. However, when the second value in
the compressed pair is not an empty class, there are two __value_
children because __compressed_pair derives twice from
__compressed_pair_elem, one for each member of the pair. And then the
lookup fails because it's ambiguous.

This patch makes the following changes:

  • Rename GetValueOfLibCXXCompressedPair to GetFirstValueOfLibCXXCompressedPair, and add a similar function to get the second value. Put both functions in Plugin/Language/CPlusPlus/LibCxx.cpp because it seems inappropriate to have libcxx-specific helpers separate from all the libcxx-dependent code.
  • Read the second value of the __ptr_ pair and display a "deleter" child in the unique_ptr synthetic child provider, when available.
  • Add a test case for the non-empty deleter case.

Diff Detail

Event Timeline

jgorbe created this revision.Apr 18 2023, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2023, 2:31 PM
jgorbe requested review of this revision.Apr 18 2023, 2:31 PM
labath accepted this revision.Apr 28 2023, 4:02 AM
labath added a subscriber: labath.
labath added inline comments.
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
52

We should check that pair.GetChildAtIndex(0, true) returns a valid value before dereferencing it, so we don't crash if the definition of the comppressed_pair type is missing or something like

65

Similarly, here (I'm don't think that GetNumChildren()>1 actually guarantees that the GetChildAtIndex(1) will return a valid object).

731–739

unrelated, but it might be nice to give a better name to the pointed-to value as well.

This revision is now accepted and ready to land.Apr 28 2023, 4:02 AM
jgorbe updated this revision to Diff 518540.May 1 2023, 1:05 PM

Addressed review comments:

  • Check pair values before attempting to call GetChildMemberWithName on them
  • Rename first child from __value_ to pointer. This is friendlier and also matches the name used by the libstdcxx unique_ptr prettyprinter.
jgorbe marked 2 inline comments as done.May 1 2023, 1:07 PM
This revision was landed with ongoing or failed builds.May 1 2023, 1:08 PM
This revision was automatically updated to reflect the committed changes.
aprantl added a subscriber: aprantl.May 1 2023, 2:06 PM

Looks like this broke on the Darwin incremental bot:

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/54508/

Can you please take a look and revert in the mean time?

jgorbe added a comment.May 1 2023, 2:12 PM

Sure, I'll revert. Thanks for notifying me of the problem.

jgorbe added a comment.May 1 2023, 4:21 PM

Landed again, with a fix for the test that was failing on Darwin, as https://github.com/llvm/llvm-project/commit/d69518b4e52d527b3f8fcc41e90ae21f1f234555. I'll keep an eye on the build bot.

Thanks for the quick response!