This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add support to cache a PDB's global scope and fix a bug in getting the source file name for a compiland
ClosedPublic

Authored by asmith on Dec 19 2017, 8:50 PM.

Details

Summary

This commit is a combination of the following changes:

  • Cache PDB's global scope (executable) in SymbolFilePDB
  • Change naming of cu to compiland which is PDB specific
  • Change ParseCompileUnitForSymIndex to ParseCompileUnitForUID. Prefer using a common name UID instead of PDB's System Index Adding one more argument index to this method, which is used to specify the index of the compile unit in a cached compile unit array
  • Add GetPDBCompilandByUID method to simply code
  • Fix a bug in getting the source file name for a PDB compiland. For some reason, PDBSymbolCompiland::getSourceFileName() could return an empty name, so if that is true, we have to walk through all source files of this compiland and determine the right source file used to generate this compiland based on language indicated.

    The previous implementation called PDBSession::findOneSourceFile method to get its name for the compiland. This is not accurate since the one source file found could be a header other than source file.

Diff Detail

Repository
rL LLVM

Event Timeline

asmith created this revision.Dec 19 2017, 8:50 PM

Since it seems like you're going to be doing some work in here, it would be great if you could update lldb-test to dump PDB symbol information. This would allow us to easily test all sorts of things in here. For example, you could find a PDB that returned an empty source file name, and then have the tool dump something like:

Compiland: {foo}, Source File: {bar}

then we could just grep this output against FileCheck.

source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
367–370

Is it DIA that is returning the empty name?

371

Can you do an early return here?

382–389

This would probably be shorter as:

llvm::is_contained({"cpp", "c", "cc", "cxx"}, file_extension.GetStringRef().lower());
683

Early return here.

763

nit: .get() shouldn't be necessary

767

Same here.

source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
197

Is this a performance win or just a convenience? I assumed the session itself would cache the global scope, but maybe that assumption was wrong.

asmith updated this revision to Diff 128312.Dec 28 2017, 6:02 PM

These changes will fix this crash in the current mainline:

lldb-test.exe symbols (path-to-your-lldb-exe)

Can you add a test with REQUIRES: windows that builds a simple program using clang-cl, generates a PDB, and then uses lldb-test to check part of the output against that executable? It can be a one line check, basically just proving that it doesn't crash, and we can add more specific tests for certain types of symbols and types later.

asmith updated this revision to Diff 129747.Jan 12 2018, 10:01 PM

Added a lit unit test

zturner accepted this revision.Jan 12 2018, 10:15 PM

It's nice that this turned out so easy. Didn't even require modifying lldb-test.

lit/SymbolFile/PDB/compilands.test
9 ↗(On Diff #129747)

If there's only one line then CHECK-DAG is equivalent to CHECK.

This revision is now accepted and ready to land.Jan 12 2018, 10:15 PM
asmith updated this revision to Diff 129750.Jan 12 2018, 10:56 PM
asmith retitled this revision from [lldb] This commit adds support to cache a PDB's global scope and fixes a bug in getting the source file name for a compiland to [lldb] Add support to cache a PDB's global scope and fix a bug in getting the source file name for a compiland.
asmith edited the summary of this revision. (Show Details)

Cleaned up some comments before commit

asmith closed this revision.Jan 12 2018, 10:59 PM