This is an archive of the discontinued LLVM Phabricator instance.

[lldb/DWARF] Make manual dwarf index deterministic
ClosedPublic

Authored by labath on Jan 26 2022, 7:44 AM.

Details

Summary

Currently, running the test suite with LLVM_ENABLE_EXPENSIVE_CHECKS=On
causes a couple of tests to fail. This happens because they expect a
certain order of variables (all of them happen to use the "target
variable" command, but other lookup functions should suffer from the
same issues), all of which have the same name. Sort algorithms often
preserve the order of equivalent elements (in this case the entries in
the NameToDIE map), but that not guaranteed, and
LLVM_ENABLE_EXPENSIVE_CHECKS stresses that by pre-shuffling all inputs
before sorting.

While this could easily be fixed by relaxing the test expectations,
having a deterministic output seems like a worthwhile goal,
particularly, as this could have bigger consequences than just a
different print order -- in some cases we just pick the first entry that
we find, whatever that is. Therefore this patch makes the sort
deterministic by introducing another sort key -- UniqueCString::Sort
gets a value comparator functor, which can be used to sort elements with
the same name -- in the DWARF case we use DIERef::operator<, which
roughly equals the order in which the entries appear in the debug info,
and matches the current "accidental" order.

Using a extra functor seemed preferable to using stable_sort, as the
latter allocates extra O(n) of temporary memory.

I observed no difference in debug info parsing speed with this patch
applied.

Diff Detail

Event Timeline

labath created this revision.Jan 26 2022, 7:44 AM
labath requested review of this revision.Jan 26 2022, 7:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2022, 7:44 AM
This revision is now accepted and ready to land.Jan 26 2022, 11:00 AM
clayborg accepted this revision.Jan 26 2022, 4:06 PM
This revision was automatically updated to reflect the committed changes.