This is an archive of the discontinued LLVM Phabricator instance.

[NativeSession] Add column numbers to NativeLineNumber.
ClosedPublic

Authored by akhuang on Jun 16 2020, 10:23 AM.

Details

Summary

This adds column numbers if they are present, and otherwise
sets the column number to be zero.

Bug: https://bugs.llvm.org/show_bug.cgi?id=41795

Diff Detail

Event Timeline

akhuang created this revision.Jun 16 2020, 10:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2020, 10:23 AM

This looks right, but I'd like to see a test.

llvm-pdbutil is used in a DIA test for line numbers (llvm\test\DebugInfo\PDB\DIA\pdbdump-linenumbers.test), so perhaps that could be the model for a native one that also checks the column numbers. That would require a tweak to llvm-pdbutil to make essentially the same change as you have here, to include column numbers in the output when they're present.

llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
476

As I understand it, the line numbers and column numbers are in parallel arrays (streams). So, for each line number you take the next column number (if there are column numbers at all).

Assuming that's right:

I don't see a need to change the for loop to use the line number iterators. Yeah, it creates some source code symmetry with the column number iterators, but I'm not sure that makes that more understandable here. I won't block on it, but I'd prefer the original for (const LineNumberEntry &LN : Group.LineNumbers).

481

It seems that if there is no column info, then ColIt would always equal ColsEnd, so perhaps that first part of the condition is not necessary. Perhaps, just before the loop, you could assert that either Lines.hasColumnInfo() or that ColIt is ColsEnd and then simplify the condition here.

The assertion would be a nice place to add a comment like

// If there are column numbers, then they are in a parallel stream to the line numbers.
akhuang marked 2 inline comments as done.Jun 17 2020, 2:45 PM

thanks for the comments! I added another llvm-symbolizer test with a pdb that contains column numbers.

It looks like llvm-pdbutil does already output column info, but I guess PDBs don't normally contain column info.

akhuang updated this revision to Diff 271493.Jun 17 2020, 2:45 PM

Add test case, and address other comments.

Very close now. It looks like the change I requested led to a bug. Once that's corrected, this'll look great.

Thanks for adding the test. Perhaps you could generate PDBs both with and without column info and then the test could check that it works either way (which should have caught the new bug). If there's already an existing test that catches the bug (skipping the line numbers whether there are no column numbers), that's sufficient.

Feel free to ping me if I've not been clear.

llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
470

Sorry, I wasn't clear enough before because it looks like I confused you. This if statement is unnecessary and, in fact, wrong. You still want to go through the line numbers in this group even if there's no column information.

When I said assert, I literally meant an assert like this:

llvm_assert(Lines.hasColumnInfo() || ColIt == ColsEnd);

Note that it's ||, not &&. If we have column info, great. If we don't, then ensure that the iterator alone makes that clear in order to use the simpler test in the loop.

akhuang marked an inline comment as done.Jun 25 2020, 9:28 AM
akhuang added inline comments.
llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
470

Makes sense. I was avoiding using asserts in case some section happened to be messed up, in which case we would just skip it instead of asserting. (Although I don't know if this is actually something that could happen.)

I think my if statement is just the inverse of your suggested assert? It continues if it claims there is column info and the column info is empty.

The original test case in llvm/test/tools/llvm-symbolizer/pdb/pdb-native.test doesn't have column info and passes.

akhuang updated this revision to Diff 274925.Jul 1 2020, 2:38 PM

Update loop per discussion.

amccarth accepted this revision.Jul 1 2020, 2:50 PM

LGTM

This revision is now accepted and ready to land.Jul 1 2020, 2:50 PM
This revision was automatically updated to reflect the committed changes.
nikic added a subscriber: nikic.Aug 2 2022, 1:28 AM

The test-columns.pdb file added here is 6MB large. Is it possible to reduce its size while preserving the spirit of the test?

Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 1:28 AM

The test-columns.pdb file added here is 6MB large. Is it possible to reduce its size while preserving the spirit of the test?

I think it can be built without the system headers, which would reduce the PDB size by a lot. I can make a patch for that.