This is an archive of the discontinued LLVM Phabricator instance.

[dwarf] Unify unknown dwarf enum formatting code
ClosedPublic

Authored by labath on Mar 16 2018, 8:27 AM.

Details

Summary

We have at least three pieces of code (in DWARFAbbreviationDeclaration,
DWARFAcceleratorTable and DWARFDie) that have hand-rolled support for
dumping unknown dwarf enum values. While not terrible, they are a bit
distracting and enable small differences to creep in (Unknown_ffff vs.
Unknown_0xffff). I ended up needing to add a fourth place
(DWARFVerifier), so I though it would be a good time to centralize.

This patch creates an alternative to the XXXString dumping functions in
the BinaryFormat library, which formats an unknown value as
DW_TYPE_Unknown_1234, instead of just an empty string. It is based on
the formatv function, as that allows us to avoid materializing the
string for unknown values (and because this way I don't have to invent a
name for the new functions :P).

Right now, I just demonstrate the principle with DW_TAG constants, but
other enums could be handled the same way as well.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Mar 16 2018, 8:27 AM
JDevlieghere added inline comments.Mar 16 2018, 8:33 AM
include/llvm/BinaryFormat/Dwarf.h
597 ↗(On Diff #138715)

Is the capitalization of Unknown on purpose (to differentiate with valid enum values)?

labath added inline comments.Mar 16 2018, 8:36 AM
include/llvm/BinaryFormat/Dwarf.h
597 ↗(On Diff #138715)

That's what the existing code was doing. I personally have no preference for either..

JDevlieghere added inline comments.Mar 16 2018, 8:58 AM
include/llvm/BinaryFormat/Dwarf.h
597 ↗(On Diff #138715)

I lean slightly towards lowercase because it's more consistent.

labath updated this revision to Diff 139115.Mar 20 2018, 6:32 AM
  • changed "Unknown" to "unknown". I have checked GNU readelf output, they format unknown values completely differently (Unknown TAG value: 0x3e), so this doesn't make the compatibility story worse.
  • added FORM, IDX, and AT format providers. These are the ones that are in use currently. Adding the rest is straight-forward.
  • I did *not* add the ATOM format provider. To achieve this, we first need to create a separate enum for the DW_ATOM constants, so I left that for a follow-up patch.
This revision is now accepted and ready to land.Mar 20 2018, 1:27 PM
This revision was automatically updated to reflect the committed changes.