This is an archive of the discontinued LLVM Phabricator instance.

[llvm-symbolizer] Introduce the -dsym-hint option.
ClosedPublic

Authored by glider on Oct 9 2014, 9:59 AM.

Details

Reviewers
samsonov
Summary

llvm-symbolizer will consult one of the .dSYM paths passed via -dsym-hint if it fails to find the .dSYM bundle at the default location.

Diff Detail

Event Timeline

glider retitled this revision from to [llvm-symbolizer] Introduce the -dsym-hint option. llvm-symbolizer will consult one of the .dSYM paths passed via -dsym-hint if it fails to find the .dSYM bundle at the default location..Oct 9 2014, 9:59 AM
glider updated this object.
glider edited the test plan for this revision. (Show Details)
glider added a reviewer: samsonov.
glider added a subscriber: Unknown Object (MLST).
glider updated this revision to Diff 14660.Oct 9 2014, 9:59 AM
glider retitled this revision from [llvm-symbolizer] Introduce the -dsym-hint option. llvm-symbolizer will consult one of the .dSYM paths passed via -dsym-hint if it fails to find the .dSYM bundle at the default location. to [llvm-symbolizer] Introduce the -dsym-hint option..
glider updated this object.
samsonov edited edge metadata.Oct 9 2014, 7:11 PM

Sorry, wasn't able to carefully review it today. Some early feedback.

Note that you will need tests in test/DebugInfo/ (add actual .dSYM bundles and macho files you're trying to symbolize under test/DebugInfo/, preferrably with sources and comments describing how to build them).

LLVMSymbolize.cpp
215

Why all this complexity? Can you just change this function to take .dSYM bundle, and call it either on file from .dSYM hints argument, or from PathToExe + ".dSYM"?

329

This can be a static helper, pass Opts.DynamicHints here.
Output parameters ("Paths") should better go last in argument list.

llvm-symbolizer.cpp
34

Please update docs/CommandGuide/llvm-symbolizer.rst

130

Additional method looks like an overkill. Opts is a struct, you can just call

Opts.DsymHints.assign(ClDsymHint.begin(), ClDsymHint.end());

Don't you think the tests for commandline args should go into tets/tools/llvm-symbolizer instead?

LLVMSymbolize.cpp
215

We probably don't want to try those paths from -dsym-hints that don't end with ".dSYM"

329

Agreed.

llvm-symbolizer.cpp
34

Done

130

Done

glider updated this revision to Diff 14727.Oct 10 2014, 7:10 AM
glider edited edge metadata.

Updated the diff. Haven't finished the tests yet though.

glider added inline comments.Oct 10 2014, 7:31 AM
LLVMSymbolize.cpp
215

Hmm, the following workflow still doesn't work:

$ clang foo.c -g -c && clang foo.o -g -o foo
$ dsymutil foo -o bar.dSYM

Turns out the DWARF binary for foo is at bar.dSYM/Contents/Resources/DWARF/foo.

329

Actually, no. This function needs Opts.DsymHints.

Sorry the last comment has been lost in time. The updated diff fixes the problem mentioned in http://reviews.llvm.org/D5705?id=14660#inline-47195

I'm not sure if adding user-facing Verbosity option is a good idea, in this patch it looks merely like a debugging aid.

If we decide to introduce it, I'd prefer a separate patch, with a careful audit of all existing code and reasonable decisions of what and when to print (for instance, it makes sense to print our steps in attempt to resolve .gnu_debuglink).

docs/CommandGuide/llvm-symbolizer.rst
18 ↗(On Diff #14727)

Existing options are already listed below (after EXAMPLE)

31 ↗(On Diff #14727)

Please specify that this flag may be provided multiple times and that it's relevant only for Mac OS.

tools/llvm-symbolizer/LLVMSymbolize.cpp
216 ↗(On Diff #14727)

Looks like unfinished sentence.

303 ↗(On Diff #14727)

Looks like this routine is generally usable and should reside somewhere in libLLVMObject. At the very least, add a FIXME about it.

304 ↗(On Diff #14727)

dyn_cast may return null. Either handle this, or take MachOObjectFile as an input argument.

319 ↗(On Diff #14727)

static

328 ↗(On Diff #14727)

I still think this should be a static helper, which should take Opts.DsymHints as an argument. Also, consider checking --dsym_hint values in the main binary (probably, even reporting an error is incorrect value is passed there), so that "Opts.DsymHints" are always reasonable.

330 ↗(On Diff #14727)

Variable names should start with capital letter.

334 ↗(On Diff #14727)

const auto &path

345 ↗(On Diff #14727)

DsymPaths

361 ↗(On Diff #14727)

just use "else if" here.

367 ↗(On Diff #14727)

You can use EC.message() - this can be a different kind of error.

379 ↗(On Diff #14727)

Please get rid of Bin/DbgBin here, use local variables with small scope where appropriate instead.

387 ↗(On Diff #14727)

So, you have this sequence scattered throughout the code (at least three times):

OwningBinary<Binary> B = std::move(BinaryOrErr.get());
Bin = B.getBinary().get();
Obj = getObjectFileFromBinary(Bin, ArchName);

Can it be simplified or moved to a function?

394 ↗(On Diff #14727)

if (!DbgObj) ?

tools/llvm-symbolizer/LLVMSymbolize.h
67 ↗(On Diff #14727)

BinaryPair is unused now.

99 ↗(On Diff #14727)

typedef is not really needed now in C++11 world. ObjectPairForPathArchTy::iterator can be replaced with auto.

Addressed the comments.
WDYT is better: a) commit the binaries and .dSYM files for testing to the repository, or b) generate them on the fly?

docs/CommandGuide/llvm-symbolizer.rst
18 ↗(On Diff #14727)

Indeed. Sorry, I've missed those.

31 ↗(On Diff #14727)

Done.

tools/llvm-symbolizer/LLVMSymbolize.cpp
216 ↗(On Diff #14727)

Good catch, fixed.

303 ↗(On Diff #14727)
304 ↗(On Diff #14727)

Done

319 ↗(On Diff #14727)

Done

328 ↗(On Diff #14727)

I've moved the check for ".dSYM" extension to the main binary, so this function has become really small now.
I think it's ok to make it a private member, or otherwise I can move it into lookUpDsymFile.

330 ↗(On Diff #14727)

Done (hope I've fixed them all)

334 ↗(On Diff #14727)

done

345 ↗(On Diff #14727)

done

361 ↗(On Diff #14727)

Removed Opts.Verbose instead.

367 ↗(On Diff #14727)

Ok, but I've removed Opts.Verbose.

379 ↗(On Diff #14727)

Moved them 1-2 scopes down.

387 ↗(On Diff #14727)

I've tried to compactify these a bit.
But moving just these three lines into a separate function doesn't work because B is passed to addOwningBinary() later.
However it's not always correct to include addOwningBinary() into that function, because the former isn't called after every sequence you're talking about.
We won't get much from moving two of these three lines into a function OTOH.

394 ↗(On Diff #14727)

Fixed

tools/llvm-symbolizer/LLVMSymbolize.h
67 ↗(On Diff #14727)

Removed.

99 ↗(On Diff #14727)

Removed typedefs except for ObjectPair which is used in several class members' declarations.

glider updated this revision to Diff 14804.Oct 13 2014, 9:47 AM

Addressed Alexey's comments

I think we should check in .dSYM binaries - IIUC we can't generate these files unless we have dsymutil installed in the system (and we certainly don't have it on Linux).

test/tools/llvm-symbolizer/Inputs/dsym-test.c
1 ↗(On Diff #14804)

Please provide a comment with sequence of compiler / dsymutil invocations yielding the all the binaries you check in to Inputs/

samsonov added inline comments.Oct 13 2014, 12:14 PM
test/tools/llvm-symbolizer/Inputs/dsym-test.c
2 ↗(On Diff #14804)

Do you need to add lit.local.cfg to this directory to exclude .c files from testsuite?

tools/llvm-symbolizer/LLVMSymbolize.cpp
101 ↗(On Diff #14804)

SymbolIterator

327 ↗(On Diff #14804)

Is it OK for a binary to not have UUID command? I think that if the object is well-formed, but doesn't have UUID command, you shouldn't use error() wrapper, as it prints error messages to stderr.

334 ↗(On Diff #14804)

Probably it's ok to even sink this function down to lookUpDsymFile (I don't see how it can be generally useful).

337 ↗(On Diff #14804)

ResourcePath (or just get rid of local variable).

347 ↗(On Diff #14804)

This variable is not used.

383 ↗(On Diff #14804)

Please check that the code works if Obj is nullptr

386 ↗(On Diff #14804)
if (auto MachObj = dyn_cast<const MachOObjectFile>(Obj))
  DbgObj = ...;
tools/llvm-symbolizer/LLVMSymbolize.h
95 ↗(On Diff #14804)

Thanks for the typedef cleanup. You may want to commit it separately as a cleanup change before the main patch.

130 ↗(On Diff #14804)

Please define each member on a separate line.

tools/llvm-symbolizer/llvm-symbolizer.cpp
132 ↗(On Diff #14804)

You may want to print the invalid flag value here.

glider added inline comments.Oct 14 2014, 8:12 AM
test/tools/llvm-symbolizer/Inputs/dsym-test.c
1 ↗(On Diff #14804)

Done

2 ↗(On Diff #14804)

I think no, lit doesn't attempt to run this file.

tools/llvm-symbolizer/LLVMSymbolize.cpp
101 ↗(On Diff #14804)

Fixed in r219682.

327 ↗(On Diff #14804)

No, it's not ok. However this code has changed in the latest version of the patch.

334 ↗(On Diff #14804)

Done

337 ↗(On Diff #14804)

Done

347 ↗(On Diff #14804)

Removed.

383 ↗(On Diff #14804)

It should. I've inserted a return statement just for the case.

386 ↗(On Diff #14804)

Done

tools/llvm-symbolizer/LLVMSymbolize.h
95 ↗(On Diff #14804)

Done in r219682.

130 ↗(On Diff #14804)

Fixed in r219682.

tools/llvm-symbolizer/llvm-symbolizer.cpp
132 ↗(On Diff #14804)

Done.

glider updated this revision to Diff 14868.Oct 14 2014, 8:16 AM

Addressed the comments.

samsonov accepted this revision.Oct 14 2014, 11:25 AM
samsonov edited edge metadata.

LGTM, once the following minor comments are addressed.

Please run the patch through clang-format-diff before submitting. Thanks for working on this!

tools/llvm-symbolizer/LLVMSymbolize.cpp
320 ↗(On Diff #14868)

s/path/Path

356 ↗(On Diff #14868)

We still need to cache (nullptr, nullptr) pair in ObjectPairForPathArch. For example, if the path is invalid and provided 50 times, we don't want to print diagnostics 50 times in error() function. So, at least in the way the code is structured now, we'll have to increase the indentation.

358 ↗(On Diff #14868)

Do you need this check now? Looks like it's enough to check that Obj is a MachOObjectFile (and you won't need "Bin" variable in this case).

This revision is now accepted and ready to land.Oct 14 2014, 11:25 AM
glider added inline comments.Oct 16 2014, 5:12 PM
tools/llvm-symbolizer/LLVMSymbolize.cpp
320 ↗(On Diff #14868)

Done

356 ↗(On Diff #14868)

Added code that puts (nullptr, nullptr) into the map. Don't think increasing the indentation is better here.

358 ↗(On Diff #14868)

Removed the check.

glider updated this revision to Diff 15055.Oct 16 2014, 5:15 PM
glider edited edge metadata.

Fixed the comments.

glider closed this revision.Oct 16 2014, 6:00 PM

r220004, thank you!