[Lldb-commits] [PATCH] D153657: Don't allow ValueObject::Cast from a smaller type to a larger

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 23 11:54:02 PDT 2023


jingham created this revision.
jingham added reviewers: JDevlieghere, kastiglione, mib.
Herald added a project: All.
jingham requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

SBValue::Cast actually allows casting from a struct type to another struct type.  That's a little odd, C-family languages don't allow this, but we have done forever, so I don't want to remove the ability altogether.  However, we can't support casting from a small structure to a larger one because in some cases - e.g. all the ConstResult types used both for expression results and for many synthetic children - we don't know where we should fetch the extra bits from.  Just zero-filling them seems odd, and error seems like a better response.

This fixes a bug where when casting an expression result from a smaller type to a larger, lldb would present the memory in lldb after the ValueObject's data buffer as the value of the cast type.  Again, I could have fixed that bug by expanding the data buffer to match the larger size, but I wouldn't know what to fill it with.

There were two places in the C++ formatters that were using this cast from struct to struct type to change a C++ std typedef (e.g. std::shared_ptr<Foo>::element type *) to a type that is more useful to the user (pointer to the first template argument's type).  The cast from struct to struct in that case wasn't necessary, and looked weird since this really isn't an allowed C++ operation.  So I also changed those to case the pointer first, then dereference the cast value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153657

Files:
  lldb/include/lldb/Core/ValueObject.h
  lldb/include/lldb/Core/ValueObjectConstResult.h
  lldb/include/lldb/Core/ValueObjectConstResultCast.h
  lldb/include/lldb/Core/ValueObjectConstResultChild.h
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/Core/ValueObject.cpp
  lldb/source/Core/ValueObjectConstResult.cpp
  lldb/source/Core/ValueObjectConstResultCast.cpp
  lldb/source/Core/ValueObjectConstResultChild.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
  lldb/test/API/python_api/value/TestValueAPI.py
  lldb/test/API/python_api/value/main.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153657.534036.patch
Type: text/x-patch
Size: 9777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230623/10373059/attachment-0001.bin>


More information about the lldb-commits mailing list