This is an archive of the discontinued LLVM Phabricator instance.

[PDB] Print section contributions and section map
ClosedPublic

Authored by zturner on Jun 1 2016, 12:51 PM.

Details

Summary

I'm not sure how to interpret either of these arrays, but at least we understand the format.

I suspect that the section map is used for determining RVAs of relocated fields, but I don't know how to do the calculation, and none of the fields of OMFSegMapDesc are documented in Microsoft headers (aside from printing their values, which is how I arrived at the layout) so the meaning is unclear.

Diff Detail

Event Timeline

zturner updated this revision to Diff 59266.Jun 1 2016, 12:51 PM
zturner retitled this revision from to [PDB] Print section contributions and section map.
zturner updated this object.
zturner added reviewers: ruiu, majnemer, rnk.
zturner added a subscriber: llvm-commits.

So apparently entries in the SectionMap correspond to the symbols of type COFF Group and Section. For example, if you look at the Entry field in the section map which has Section=2, and then you go up to the Symbol section and look for all the COFF Group entries with Segment=2 and add up their lengths, you will see that they match. I'm still not sure what to use the fields of the section map entries for though. I assume those Flags are important, but unfortunately they are undocumented.

zturner updated this revision to Diff 59268.Jun 1 2016, 1:28 PM

Also print out image section characteristics of the COFF Group and COFF Section symbols that appear in the modules' symbol tables.

rnk added inline comments.Jun 1 2016, 1:41 PM
include/llvm/DebugInfo/CodeView/EnumTables.h
28

These shouldn't live in headers, they'll be duplicated in all TUs that use them. Probably the best way to expose this would be to declare a function that returns an ArrayRef of register names, and then implement that in the .cpp file, given that we don't want to duplicate the size of the array in the header. Keep the prototypes in the SymbolDumper.h header.

include/llvm/DebugInfo/PDB/Raw/RawTypes.h
32

Is Contr short for Contribution? Maybe Contrib instead of Contr?

45

This isn't "standard layout" unfortunately:
http://en.cppreference.com/w/cpp/concept/StandardLayoutType

ASan actually has a mode that inserts additional padding between fields of non-standard layout types, but it was never productionized. Instead of using inheritance, I'd have the first member be the normal SectionContrib type.

zturner updated this revision to Diff 59282.Jun 1 2016, 2:41 PM

Updated based on suggestions

ruiu added inline comments.Jun 1 2016, 2:57 PM
tools/llvm-pdbdump/llvm-pdbdump.cpp
143

section-contribs?

510

I'd do s/contr/contrib/g to all files in this patch.

519

Define this class outside of this function.

Also this class definition made me think of the visitor design choice. Currently visitor's callback is a class with visit() member function. But it can be just a std::function, no? We can create a lambda here and pass it to visitSectionContributions function.

540

Why do you have to call flush?

zturner added inline comments.Jun 1 2016, 3:02 PM
tools/llvm-pdbdump/llvm-pdbdump.cpp
510

A little tricky since that will catch Contrib too, but anyway I'll fix up the rest of the instances.

519

The problem is we don't know whether it will be called back with a SectionContrib or a SectionContrib2. If it were possible to make a "multi lambda" or something that supported overloads, then yes we could do that. Of course, I could raise the logic outside and use a switch statement, but in general I like the pattern of handling variant-data with a visitor.

Is there a reason to prefer defining the class outside the function? This is effectively a lambda with an overload, so just like your lambda would be scoped to the function, I wrote the class the same way.

540

Not strictly necessary, other dump functions do this as well, I guess because it's nice to be able to see the output in a debugger if you're stepping through

ruiu added inline comments.Jun 1 2016, 3:15 PM
tools/llvm-pdbdump/llvm-pdbdump.cpp
519

OK, if there's a chance for the class to have more than two callback functions, using a class makes sense to me. But currently it has only one callback function, so I'd do with a simple lambda rather than a class to avoid overdesining. I guess it's your call.

No particular reason to not avoid defining classes inside functions, but it is at least rather unusual in LLVM. If it is a deliberate choice and if you like this, it's OK to me.

zturner added inline comments.Jun 1 2016, 3:20 PM
tools/llvm-pdbdump/llvm-pdbdump.cpp
519

It already has 2 functions. visit is overloaded to take a const SectionContrib & and a const SectionContrib2 &. See below this function, where the overload delegates to this version of the function and then prints out additional data.

zturner updated this revision to Diff 59300.Jun 1 2016, 4:13 PM

Figured out the flags and documented the field descriptions, also cleaned up enum tables and made them more consistent.

rnk accepted this revision.Jun 1 2016, 4:23 PM
rnk edited edge metadata.

lgtm with nits

include/llvm/DebugInfo/PDB/Raw/DbiStream.h
74

s/Contr/Contrib/?

lib/DebugInfo/PDB/Raw/EnumTables.cpp
32–34

A less fragile way to do this is to declare it like:

ArrayRef<EnumEntry<uint16_t>> llvm::pdb::getOMFSegMapDescFlagNames() { ...
This revision is now accepted and ready to land.Jun 1 2016, 4:23 PM
ruiu accepted this revision.Jun 1 2016, 4:26 PM
ruiu edited edge metadata.

LGTM

majnemer added inline comments.Jun 1 2016, 4:30 PM
test/DebugInfo/PDB/pdbdump-headers.test
1189

Can we pretty print these flags?

zturner added inline comments.Jun 1 2016, 4:34 PM
test/DebugInfo/PDB/pdbdump-headers.test
1189

Already done in this revision (see llvm-pdbdump.cpp), I just forgot to update the test. It's working locally.

Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r271488.