This is an archive of the discontinued LLVM Phabricator instance.

Get rid of DWARFFormValue::getFixedFormSizes(uint8_t AddrSize, uint16_t Version).
AbandonedPublic

Authored by clayborg on Nov 10 2016, 10:47 AM.

Details

Summary

In preparation for a follow on patch that improves DWARF parsing speed, clean up DWARFFormValue so that we have can get the fixed byte size of a form value given a DWARFUnit or given the version, address byte size and dwarf32/64.

This patch cleans up code so that everyone is using one of the new DWARFFormValue functions:

static Optional<uint8_t> DWARFFormValue::getFixedByteSize(dwarf::Form Form, const DWARFUnit *U = nullptr);
static Optional<uint8_t> DWARFFormValue::getFixedByteSize(dwarf::Form Form, uint16_t Version, uint8_t AddrSize, bool Dwarf32);

This patch changes DWARFFormValue::skipValue() to rely on the output of DWARFFormValue::getFixedByteSize(...) instead of duplicating the numbers here. This will reduce the number of changes we need to make to DWARF to fewer places in DWARFFormValue when we add support for new form.

This patch also starts to support DWARF64 so that we can get correct byte sizes for forms that vary according the DWARF 32/64.

Diff Detail

Event Timeline

clayborg updated this revision to Diff 77512.Nov 10 2016, 10:47 AM
clayborg retitled this revision from to Get rid of DWARFFormValue::getFixedFormSizes(uint8_t AddrSize, uint16_t Version). .
clayborg updated this object.
dblaikie edited edge metadata.Nov 10 2016, 11:16 AM

Just a few drive-by comments.

include/llvm/DebugInfo/DWARF/DWARFFormValue.h
149

Might be worth having an enum for this, for readability.

lib/DebugInfo/DWARF/DWARFFormValue.cpp
130

prefer llvm_unreachable over assert(false) (& there's no need for the return afterwards)

459–460

It's pretty common in LLVM to roll a variable declaration into the condition where possible:

if (Optional<uint8_t> FixedByteSize = getFixedByteSize(form, U)) {
  ...
}

(similar feedback elsewhere)

aprantl added inline comments.Nov 10 2016, 11:34 AM
include/llvm/DebugInfo/DWARF/DWARFFormValue.h
128
135

///

140

Could you use the opportunity and document what the bool return value indicates? It's not clear to me from reading the function.

lib/DebugInfo/DWARF/DWARFFormValue.cpp
57

Would it make sense / be possible to encode this tabular data (at least for the majority of values) in the macros in Dwarf.def?

361–363

I know it was like this in the original source, but while you are editing it, we could use the opportunity fix the variable names to start with uppercase (http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly). Up to you.

421

Should this really be an assertion, in the sense of that it indicates a programming error in the caller? Or can this situation be triggered by malformed DWARF input and should we return an Error instead?

tools/llvm-dwp/llvm-dwp.cpp
138

Comment what this magic indicator does?

Will update according to comments.

lib/DebugInfo/DWARF/DWARFFormValue.cpp
57

Not sure how you would do this since many don't have a byte size. Zero is a valid DW_FORM size, so you can't use zero for items that don't have byte sizes. I wouldn't want to have a signed integer as the size either where -1 would indicate that there is no size. So since there is no easy way to encode an optional value with no value into the table, I would vote against this. Agains, this is the only function that needs to be updated.

361–363

I desire to keep this patch small so the extra diffs don't cloud our ability to see changes. I will do a follow up patch where I do nothing but case changing.

421

This function is internal to this file and is designed to only be called for variable length forms. The callers of this function both do:

if (Optional<uint8_t> FixedByteSize = getFixedByteSize(form, U)) {
  *offset_ptr += *FixedByteSize;
  return true;
}
return skipVariableLengthValue(...);

I turned this into an llvm_unreachable().

clayborg updated this revision to Diff 77540.Nov 10 2016, 12:51 PM
clayborg edited edge metadata.

Addresses issues from dblaike and aprantl

clayborg marked 7 inline comments as done.Nov 10 2016, 12:53 PM

Marked things as Done.

dblaikie added inline comments.Nov 10 2016, 12:55 PM
lib/DebugInfo/DWARF/DWARFFormValue.cpp
419–420

This is still a branche-to-unreachable, which should probably just be an assert instead:

assert(indirect && "Form must ...");
if (Optional<uint8_t> ...) {
  ...
}
aprantl added inline comments.Nov 10 2016, 1:22 PM
include/llvm/DebugInfo/DWARF/DWARFUnit.h
195

I think the llvm:: namespace is redundant here.

207

Up to taste, maybe write this as:

switch (getFormat()) {
  case dwarf::DwarfFormat::Dwarf32: return 4;
  case dwarf::DwarfFormat::Dwarf64: return 8;
}
include/llvm/Support/Dwarf.h
438

Maybe call this DWARF32 and DWARF64 since that is the correct spelling?

lib/DebugInfo/DWARF/DWARFFormValue.cpp
363

Should we make this const DWARFUnit *U = nullptr since you're using it that way later on?

clayborg abandoned this revision.Nov 10 2016, 2:26 PM

Looking as some of the comments made me think if a nicer way to fix some of the redundant code in DWARFFormValue.cpp and also clear up some of the questions that Adrian had about the fixed sized forms having the assertion in skipVariableLengthValue() in the cases where the fixed sized forms were happening. I am going to abandon this revision and open another otherwise all of the inlined comments won't make sense since a lot will have changed, but for the better.