This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator
ClosedPublic

Authored by Michael137 on Jul 8 2022, 4:51 AM.

Details

Summary

This patch adds a formatter for libcxx's std::unordered_map iterators.
The implementation follows a similar appraoch to the std::map iterator
formatter. I was hesistant about coupling the two into a common
implementation since the libcxx layouts might change for one of the
the containers but not the other.

All std::unordered_map iterators are covered with this patch:

  1. const/non-const key/value iterators
  2. const/non-const bucket iterators

Note that, we currently don't have a formatter for std::unordered_map.
This patch doesn't change that, we merely add support for its iterators,
because that's what Xcode users requested. One can still see contents
of std::unordered_map, whereas with iterators it's less ergonomic.

Testing

  • Added API test

Diff Detail

Event Timeline

Michael137 created this revision.Jul 8 2022, 4:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2022, 4:51 AM
Michael137 requested review of this revision.Jul 8 2022, 4:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2022, 4:51 AM
Michael137 updated this revision to Diff 443212.Jul 8 2022, 4:55 AM
  • Fixed class documentation
Michael137 updated this revision to Diff 443227.Jul 8 2022, 6:01 AM
  • Cleaned up documentation further
Michael137 updated this revision to Diff 443430.Jul 9 2022, 4:42 AM
  • Fixed test case for const bucket iterator
aprantl accepted this revision.Jul 12 2022, 12:56 AM

Nice! Few minor stylistic comments inside.

lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
404

Nit: This... and . at the end.

412

Does this get more readable if we assign this subexpression to an auto helper variable?

449

maybe invert the condition and convert to early exit?

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
14

just curious: what does the _with_run_command suffix mean? Or was this copied from another test?

This revision is now accepted and ready to land.Jul 12 2022, 12:56 AM
Michael137 marked 3 inline comments as done.
  • Address stylistic comments
  • Change test name
Michael137 marked an inline comment as done.Jul 12 2022, 2:01 AM
Michael137 added inline comments.
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
412

Definitely :)

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered_map/TestDataFormatterLibccUnorderedMap.py
14

Ah good catch. This was from at the map formatter test. Presumably the name refers to its usage of self.runCmd. I'll change it to something more meaningful