Page MenuHomePhabricator

Make llvm-symbolizer work on Windows.

Authored by zturner on Apr 23 2015, 2:39 PM.



This is a rework of my original patch which introduced a new class hierarchy into llvm-symbolizer. Now that DIContext has moved to a common layer, this patch simply uses DIContext, resulting in much nicer code in llvm-symbolizer.

Inline frames are not yet supported, so we fall back to just pretending like the option wasn't specified whenever a PDBContext is in use. Test program:

Here is some program output showing that it works:

d:\testexe>cat test.c
  void foo() {

int main() {

d:\testexe>dumpbin /DISASM test.exe | grep "_foo:\|_main:" --after-context=1
  00401020: 55                 push        ebp
  00401030: 55                 push        ebp

d:\testexe>d:\src\llvmbuild\ninja\bin\llvm-symbolizer.exe --obj test.exe


Diff Detail


Event Timeline

zturner updated this revision to Diff 24335.Apr 23 2015, 2:39 PM
zturner retitled this revision from to Make llvm-symbolizer work on Windows..
zturner updated this object.
zturner edited the test plan for this revision. (Show Details)
zturner added reviewers: samsonov, timurrrr.
zturner updated this object.
zturner added a subscriber: Unknown Object (MLST).
samsonov added inline comments.Apr 23 2015, 6:12 PM
10 ↗(On Diff #24335)

Header guard looks wrong.

30 ↗(On Diff #24335)

Will these be implicitly deleted anyway?

37 ↗(On Diff #24335)

Note that ImageBase may be uninitialized at this point.

60 ↗(On Diff #24335)

Can LineInfo be nullptr at this point?

169 ↗(On Diff #24335)

The code has assumption that ModuleInfo::symbolizeInlinedCode() always returns *some* frames (at least one empty) - see the special case for InlinedContext.getNumberOfFrames() == 0. Hence, the assert in LLVMSymbolizer::symbolizeCode().

I think, that's a wrong place to add a fallback - instead you can make PDBContext::getInliningInfoForAddress() return a DIInliningInfo with a single frame, obtained from PDBContext::getLineInfoForAddress().

131 ↗(On Diff #24335)

Can you create RAII object that would call CoInitializeEx in ctor and CoUninitialize in dtor (and use it in applicable tools - for now llvm-symbolizer / llvm-dwarfdump)? It can have empty implementation on non-Windows platforms.

timurrrr edited edge metadata.Apr 24 2015, 10:03 AM

It's great to see how small the changes to the symbolizer code are!

I'll defer to Alexey for the review as I'm not at all familiar with the code.

23 ↗(On Diff #24335)

nit: s/pdb/PDB/

78 ↗(On Diff #24335)

can this return nullptr?

472 ↗(On Diff #24335)

if (X *x = dyn_cast<X>(...)) { (1)
is not consistent with the other parts of the change where you use
if (auto x = dyn_cast<X>(...)) {

Personally I like the former (1) more.

zturner updated this revision to Diff 24406.Apr 24 2015, 11:26 AM
zturner edited edge metadata.

I've addressed all of the comments except for the RAII com initialization comment. I think that can happen as a separate CL, since it will need to undergo review from others to make sure they're comfortable with the way we're introducing it (since COM is kind of a platform-specific thing, it has to be done carefully).

samsonov edited edge metadata.Apr 24 2015, 12:05 PM

Can you add tests for this functionality (proper handling of invalid addresses etc.)? For DWARF, we just check in small binaries with debug information (see test/DebugInfo/llvm-symbolizer.test).

10 ↗(On Diff #24406)


(yep, I've just noticed that header guards in include/llvm/DebugInfo/DWARF/* files are wrong, I will probably fix that.

44 ↗(On Diff #24406)

What if Symbol is nullptr? Probably you should bail out early in this case.

57 ↗(On Diff #24406)

You can reduce indentation with

if (Length == 0)
  return Result;
61 ↗(On Diff #24406)

if LineInfo can't be nullptr, can we assert on this?

87 ↗(On Diff #24406)

Looks like you can move copying the contents of LineInfo (from IPDBEnumLineNumbers) to DILineInfo into a helper function.

94 ↗(On Diff #24406)

Should this be dyn_cast_or_null ?

zturner updated this revision to Diff 24415.Apr 24 2015, 2:37 PM
zturner edited edge metadata.

Fix remaining issues and added a test.

samsonov accepted this revision.Apr 24 2015, 3:39 PM
samsonov edited edge metadata.

LGTM. There are a few minor comments below, feel free to land after addressing them. Thank you!

1 ↗(On Diff #24415)

Probably filename should reflect that these are addresses in test.exe

4 ↗(On Diff #24415)

missing newline?

1 ↗(On Diff #24415)

Could you provide comment with brief instruction on how to build test.exe / test.pdf from it?

9 ↗(On Diff #24415)

missing newline

20 ↗(On Diff #24415)

config.h is probably not needed now?

This revision is now accepted and ready to land.Apr 24 2015, 3:39 PM
This revision was automatically updated to reflect the committed changes.