This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add tests which simulate the various std::string layouts
ClosedPublic

Authored by labath on Apr 21 2022, 2:22 AM.

Details

Summary

Checking whether a formatter change does not break some of the supported
string layouts is difficult because it requires tracking down and/or
building different versions and build configurations of the library.

The purpose of this patch is to avoid that by providing an in-tree
simulation of the string class. It is a reduced version of the real
string class, obtained by elimitating all non-trivial code, leaving
just the internal data structures used by the data formatter. Different
versions of the class can be simulated through preprocessor defines.

The test (ab)uses the fact that our formatters kick in for any
double-underscore sub-namespace of std, so it avoids colliding with
the real string class by declaring the test class in the std::__lldb
namespace.

I do not consider this to be a replacement for the existing data
formatter tests, as producing this kind of a test is not trivial, and it
is easy to make a mistake in the process. However, it's also not
realistic to expect that every person changing the data formatter will
test it against all versions of the real class, so I think it can be
useful as a first line of defence.

Adding support for new layouts can become particularly unwieldy, but
this complexity will also be reflected in the actual code, so if we find
ourselves needing to support too many variants, we may need to start
dropping support for old ones, or come up with a completely different
strategy.

Diff Detail

Event Timeline

labath created this revision.Apr 21 2022, 2:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 21 2022, 2:22 AM
labath requested review of this revision.Apr 21 2022, 2:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 21 2022, 2:22 AM
labath updated this revision to Diff 424131.Apr 21 2022, 2:23 AM

remove the stray binary

philnik accepted this revision.Apr 21 2022, 3:40 AM

LGTM, but you probably want to wait for someone from the LLDB team to approve too.

This revision is now accepted and ready to land.Apr 21 2022, 3:40 AM
This revision was landed with ongoing or failed builds.Jun 30 2022, 11:12 PM
This revision was automatically updated to reflect the committed changes.