This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFCI] Replace dw_form_t with llvm::dwarf::Form
ClosedPublic

Authored by bulbazord on May 9 2023, 2:41 PM.

Details

Summary

LLDB currently defines dw_form_t as a uint16_t which makes sense.
However, LLVM also defines a similar type llvm::dwarf::Form which is
an enum backed by a uint16_t. Switching to the llvm implementation
means that we can more easily interoperate with the LLVM DWARF code.

Additionally, we get some type checking out of this: I found that
DWARFAttribute had a method called FormAtIndex that returned a
dw_attr_t. Although dw_attr_t is also a uint16_t under the hood,
the type checking benefits here are undeniable: If this had returned a
something of different signedness/width, we could have had some bad
bugs.

Diff Detail

Event Timeline

bulbazord created this revision.May 9 2023, 2:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 2:41 PM
bulbazord requested review of this revision.May 9 2023, 2:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 2:41 PM
rastogishubham accepted this revision.May 9 2023, 2:42 PM

Great refactoring!

This revision is now accepted and ready to land.May 9 2023, 2:42 PM
jingham added a subscriber: jingham.May 9 2023, 3:03 PM

Apparently a similar change was made with dw_tag_t, in the line below your first deletion I see:

typedef llvm::dwarf::Tag dw_tag_t;

It seems weird to have dw_tag_t but lvm::dwarf::Form. If there's a good reason to use the more verbose form, we should probably do the same with the Tag for consistency. Otherwise, you can just play the same re-typedef-ing as was done for tag, right?

Apparently a similar change was made with dw_tag_t, in the line below your first deletion I see:

typedef llvm::dwarf::Tag dw_tag_t;

It seems weird to have dw_tag_t but lvm::dwarf::Form. If there's a good reason to use the more verbose form, we should probably do the same with the Tag for consistency. Otherwise, you can just play the same re-typedef-ing as was done for tag, right?

Yes, Jonas did that work in 7fa72881d4cbf. I intentionally chose to not typedef here as a matter of personal preference, I prefer the explicitness of the full type. I do agree that we should be consistent here though. I don't think it quite matters which solution we go with, but do you (or anybody else) have strong opinions about this?

bulbazord updated this revision to Diff 520853.May 9 2023, 4:07 PM

Do a typedef in dwarf.h (like llvm::dwarf::Tag) instead of explicitly writing the type out everywhere

bulbazord updated this revision to Diff 520854.May 9 2023, 4:08 PM

Remove unused include in header

aprantl accepted this revision.May 9 2023, 5:44 PM
fdeazeve accepted this revision.May 10 2023, 5:08 AM

LGTM! I like how the static_cast now is explicit about the fact that some truncation is going on from the ULEB reading.

Do you have plans to do something similar for the attribute typedef?

Do you have plans to do something similar for the attribute typedef?

Yes I would like to do that too! :)

Fix a warning in HashedNameToDIE

This revision was automatically updated to reflect the committed changes.