This is an archive of the discontinued LLVM Phabricator instance.

[pdb, lld] Write CodeView line tables to PDB.
AbandonedPublic

Authored by zturner on Apr 27 2017, 12:39 PM.

Details

Reviewers
ruiu
inglorion
rnk
Summary

In the global DBI stream, there is a list of module descriptors, one for each compiland. These descriptors contain a StreamIndex field, and if it is set to something valid, this stream index contains much more debug info about the module, such as symbols and codeview line info.

Prior to this patch, we were not writing the CodeView line information portion of this stream. This patch adds support for it. The way to use the new functionality is as follows:

PdbFileBuilder Pdb;
auto &Dbi = Pdb.getDbiBuilder();
auto &StringTable = Pdb.getStringTable();

auto &Module = Dbi.addModuleInfo("foo.obj");

StringTable.insert("foo.cpp");
auto &Source = Dbi.addModuleSourceFile("foo.obj", "foo.cpp");

auto Lines = llvm::make_unique<codeview::ModuleDebugLineFragment>();
auto Checksums = llvm::make_unique<codeview::ModuleDebugChecksumFragment>();

// All line contributions for foo.cpp

// Line Number Name Offsets refer to the Dbi string.
Lines->createBlock("foo.cpp", Dbi.getNameIndex("foo.cpp"));
Lines->addLineInfo(CodeOffset, LineNumber);
Lines->addLineInfo(CodeOffset2, LineNumber2);

// All line contributions for foo.h
Lines->createBlock("foo.h", Dbi.getNameIndex("foo.h"));
Lines->addLineInfo(CodeOffset3, LineNumber3);

// File checkum NameOffsets refer to the global string table.
Checksums->addChecksum(StringTable.getNameIndex("foo.cpp"), FileChecksumKind::MD5, llvm::md5(getFileContents("foo.cpp")));

Module.setC13LineInfo(std::move(Lines));
Module.setC13ChecksumInfo(std::move(Checksums));

Pdb.commit("out.pdb");

Diff Detail

Event Timeline

zturner created this revision.Apr 27 2017, 12:39 PM
zturner updated this revision to Diff 97020.Apr 27 2017, 4:43 PM

Fixed an issue where the YAML output and the raw output were different. One was printing the End Delta as the absolute end line, and the other was printing as the delta. Made this consistent, in both cases it is now a delta.

zturner updated this revision to Diff 97032.Apr 27 2017, 5:59 PM

Made this CL a little smaller by committing a portion of it independently. This is the rebased patch with only the portion that is still uncommitted.

inglorion edited edge metadata.Apr 27 2017, 6:13 PM

It seems a little awkward to me that we're passing both a filename and an index for the same filename to createBlock. Looking through the code, I get the impression that we don't actually need the StringRef, only the index. If so, could you remove the StringRef?

llvm/include/llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h
1

Can you change this to "ModuleDebugFileChecksumFragment.h" while you're at it?

zturner updated this revision to Diff 97108.Apr 28 2017, 9:08 AM

Fixed suggestions from inglorion@

ruiu added inline comments.Apr 28 2017, 10:22 AM
llvm/include/llvm/DebugInfo/CodeView/CodeView.h
550–552

Is k prefix hangarian?

llvm/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h
64

What is this for?

zturner added inline comments.Apr 28 2017, 10:25 AM
llvm/include/llvm/DebugInfo/CodeView/CodeView.h
550–552

My bad, I should have called this LF_None and LF_HaveColumns. I'll fix in a follow up

llvm/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h
64

Good question, I should remove this.

zturner updated this revision to Diff 97132.Apr 28 2017, 11:38 AM

Fixed suggestions from ruiu

Please also update the example in the summary, e.g. createBlock() now only takes one argument.

inglorion added inline comments.Apr 28 2017, 1:38 PM
llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
507

This no longer takes the filename, right?

It turns out the way I'm translating file names is all wrong, and it's not that easy to fix. The work here is mostly done but I'm going to try to fix this up and re-upload. In the meantime, I'll try to see if I can break up certain parts of this change into smaller pieces and submit them, so that when I'm finally done fixing the root of the problem, the resulting CL will be smaller than this one.