[Lldb-commits] [PATCH] D30272: Improve data formatter for libstdcpp unique_ptr

Tamas Berghammer via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 23 04:48:38 PST 2017


tberghammer added a comment.

My original plan was to add it to the synthetic child provider but after some thoughts and experimenting I concluded it doesn't really belongs to there because it should be responsible for generating new children while here we are modifying the way the parent object is printed. Also for this reason the implementation of it would be fairly complex because we would have to execute the synthetic child providers when the parent is referenced instead of when a child of it is queried. Also I think it won't be a good idea to add a new method to the synthetic child provider called "IsPointerLike" as it seems like introducing a very specific method to an interface what is currently quite generic. On the other hand I see the need for making the list of pointer like objects easily extensible from python.

One solution I can possibly see (haven't tried it out) is to add the following 2 new method to the value object:

- IsDeceremntPointerDepth: By default returns true for pointers and references and will return true for children generated for smart pointers
- IsDereferenceOfParent: By default returns false and will return true for the first child of the smart pointers

If we add these methods then the synthetic child provider can create a child where they will be returning true and then rely on them to implement this functionality. I think this solution would be a fairly clean design but would introduce a lot of new API for a small amount of extra functionality.

The third possible option is to somehow put the IsPointerLikeObject method into the summary provider as I think that would be the best place for it but I am not sure how to do it as it currently takes a ValueObject and then returns a string without too much flexibility. Saying that it should just flip some bit on the ValueObject itself seems like a quite big hack and would make the API hard to maintain so I don't really like this implementation.

What do you think?



================
Comment at: source/DataFormatters/ValueObjectPrinter.cpp:515
   const bool is_ptr = IsPtr();
+  const bool is_ref_or_ptr_like = IsRef() || IsPointerLikeObject();
   const bool is_uninit = IsUninitialized();
----------------
labath wrote:
> Is there are reason you are bundling the is-pointer-like with the is-ref flag instead of the is-ptr one (which would be more logical)? If there is one it certainly isn't obvious.
Because I want to treat a unique_ptr the same way as a reference so if you just write so it is automatically dereferenced at the root level while not at other levels (we don't dereference pointers by default at any level). I can split it out to a separate bool if you think that helps


https://reviews.llvm.org/D30272





More information about the lldb-commits mailing list