This is an archive of the discontinued LLVM Phabricator instance.

[llvm-symbolizer] Add llvm-addr2line
ClosedPublic

Authored by ikudrin on Apr 1 2019, 7:06 AM.

Details

Summary

llvm-symbolizer, with the latest updates, works very similarly to GNU's addr2line. The main difference is in the defaults both tools use. In particular:

  • llvm-symbolizer has "-I", "-f" and "-C" options ON by default;
  • llvm-symbolizer prints line and column while addr2line prints only a line.
  • With "-f -i=0", llvm-symbolizer replaces the name of an inlined function with the name from the symbol table, i. e., the top caller function in the inlining chain. addr2line preserves the name of the inlined function.

This patch adds an alias for llvm-symbolizer which is tuned to follow the behavior of addr2line better.

Diff Detail

Event Timeline

ikudrin created this revision.Apr 1 2019, 7:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2019, 7:06 AM
Herald added a subscriber: mgorny. · View Herald Transcript
rupprecht added a subscriber: Quolyk.

(adding a few others that may be interested)

include/llvm/DebugInfo/Symbolize/DIPrinter.h
33 ↗(On Diff #193076)

This should be the enum itself, not a bool

lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
230–231 ↗(On Diff #193076)

I don't really understand this bit... would it make more sense to have this happen a level up? i.e. make the caller of this check UseSymbolTableForInlinedFunctions and call the right method instead?

test/tools/llvm-symbolizer/addr2line.test
21 ↗(On Diff #193076)

nit: include a newline at the end

tools/llvm-symbolizer/llvm-symbolizer.cpp
274

The parameter should be commented, i.e. /*UseSymbolTableForInlinedFunctions=*/!IsAddr2Line

jhenderson added inline comments.Apr 2 2019, 4:24 AM
test/tools/llvm-symbolizer/addr2line.test
1 ↗(On Diff #193076)

Rather than adding a test that tests each of the places where llvm-addr2line is different to llvm-symbolizer, I think it would make a lot more sense to add test cases using llvm-addr2line to the existing llvm-symbolizer tests, where the behaviour is different.

tools/llvm-symbolizer/llvm-symbolizer.cpp
97–100

This change should be separated out into a different patch, as it affects llvm-symbolizer behaviour too.

149

Test cases for this new option?

266

Maybe worth having a basic test that shows that the usage text is correct for both tools.

jhenderson added inline comments.Apr 2 2019, 7:43 AM
lib/DebugInfo/Symbolize/DIPrinter.cpp
85–86 ↗(On Diff #193076)

Thinking about it, it might be nice if this was under a new dedicated switch, that can be individually be enabled and disabled, so that llvm-addr2line users can print that without changing the other defaults.

ikudrin updated this revision to Diff 194687.Apr 11 2019, 8:05 AM
ikudrin edited the summary of this revision. (Show Details)
  • Rebased the patch to the current tip;
  • Moved the code which handles differences in printing source positions in llvm-symbolizer.cpp;
  • Reworked tests.

I guess it's not considered a common practice, but i think it would be a really good idea to add a docs page for the new tool at the same time. Else it will be forgotten, much like for half of other tools..

I guess it's not considered a common practice, but i think it would be a really good idea to add a docs page for the new tool at the same time. Else it will be forgotten, much like for half of other tools..

I agree, although it's worth noting that llvm-symbolizer DOES have this documentation, so it may be worth piggy-backing on that rather than writing an entirely new doc.

Overall, I'm basically happy with this change. One of the major points brought up at the BoF and round table for LLVM binutils at the just-gone Euro LLVM Developers' Meeting was that we might want to consider a machine-readable output style in the future. If we do that, we will likely need to refactor how this all works (i.e. how LLVM style, GNU style and machine-readable style get printed), but that's probably beyond the scope of this change. Getting the new tool in allows people to start using it now.

test/tools/llvm-symbolizer/sym.test
64

You should add a {{$}} to the end of this line as it would also match "inctwo".

tools/llvm-symbolizer/llvm-symbolizer.cpp
236

suites -> suits

ikudrin updated this revision to Diff 194849.Apr 12 2019, 5:39 AM
  • Added a doc page for llvm-addr2line. I'll really appreciate any corrections.
  • Addressed other review comments.
ikudrin updated this revision to Diff 194854.Apr 12 2019, 5:43 AM
  • Fixed a typo.
jhenderson accepted this revision.Apr 12 2019, 6:29 AM

LGTM, but it would be worth getting a second pair of eyes on the documentation who is more familiar with how the markup works, to make sure it is correct.

This revision is now accepted and ready to land.Apr 12 2019, 6:29 AM
rupprecht requested changes to this revision.Apr 15 2019, 1:49 AM

(requesting changes for one small bit, otherwise lgtm)

docs/CommandGuide/llvm-addr2line.rst
7 ↗(On Diff #194854)

I think this should be [*options*] (e.g. see llvm-objdump.rst)

tools/llvm-symbolizer/llvm-symbolizer.cpp
230

I think this should be else if (ClOutputStyle == OutputStyle::GNU), if someone wants to use llvm-symbolizer directly but still have GNU addr2line compatability.

This revision now requires changes to proceed.Apr 15 2019, 1:49 AM

LGTM, but it would be worth getting a second pair of eyes on the documentation who is more familiar with how the markup works, to make sure it is correct.

I don't speak rst, but I'm pretty familiar with markdown, and there was a thread last year that received positive support for switching rst to markdown [1][2], so I think people are in favor of it. But I'm fine checking this in now as .rst for consistency. Worst case scenario, it doesn't render, and someone can commit a patch to fix it. Nothing will stop compiling :)
(We can/should do a rst->md conversion for all the binutils/command guide docs as a whole, in a separate patch)

Also: looks like the llvm website definitely supports markdown for other docs, e.g. see this page: http://llvm.org/docs/TestSuiteGuide.html (generated from docs/TestSuiteGuide.md)

[1] https://lists.llvm.org/pipermail/llvm-dev/2018-March/122234.html
[2] http://lists.llvm.org/pipermail/llvm-dev/2018-April/122304.html

But I'm fine checking this in now as .rst for consistency. Worst case scenario, it doesn't render, and someone can commit a patch to fix it. Nothing will stop compiling :)

FWIW, there is actually a build bot that does the conversion, and it fails if the syntax is bad, so we should aim to get it right first time if possible.

ikudrin updated this revision to Diff 195127.Apr 15 2019, 4:29 AM
  • rst -> md.
  • Made printing of an empty line depend on the -output-style option instead of the tool name.
ikudrin marked an inline comment as done.Apr 15 2019, 4:40 AM
ikudrin added inline comments.
tools/llvm-symbolizer/llvm-symbolizer.cpp
230

I'm not sure. Output style should define the way the information is displayed, but not affect the information itself. It'd be a bit unexpected, I think.

jhenderson requested changes to this revision.Apr 15 2019, 4:49 AM
jhenderson added inline comments.
tools/llvm-symbolizer/llvm-symbolizer.cpp
230

I actually agree with Jordan, so I'm retracting my LGTM.

We should try to have a consistent strategy between the tools. llvm-readobj already has an --elf-output-style switch, which switches the printing style between LLVM and GNU (and could be used for others in the future). llvm-readelf changes the default of that switch, but is otherwise essentially identical. There are other differences to do with command-line parsing, that are solely driven by the tool name.

The same should exist for llvm-symbolizer/llvm-addr2line. The tool's output style should be configured via the switch, with defaults of LLVM and GNU respectively. In some cases with might allow overriding of some behaviours. The command-line behaviour will still be driven by the tool name.

This revision now requires changes to proceed.Apr 15 2019, 4:49 AM
ikudrin updated this revision to Diff 195163.Apr 15 2019, 5:59 AM

OK, let be it.

rupprecht accepted this revision.Apr 15 2019, 7:02 AM

But I'm fine checking this in now as .rst for consistency. Worst case scenario, it doesn't render, and someone can commit a patch to fix it. Nothing will stop compiling :)

FWIW, there is actually a build bot that does the conversion, and it fails if the syntax is bad, so we should aim to get it right first time if possible.

Ok, but it's still just a build bot, not real code :p
It would be good to check the build bot status after submitting to make sure it handles the new file correctly. It looks fine when I throw it at an md viewer, but I'm not sure what the build bot does to parse it.

Thanks for adding this!

Could we have a test case that shows that llvm-symbolizer --output-style=GNU produces the same as llvm-addr2line for the inlining stuff, please?

It looks like the changes for --output-style should go into a separate patch with the corresponding tests.

ikudrin updated this revision to Diff 195356.Apr 16 2019, 5:11 AM
  • Extracted the changes for --output-style into a separate patch, D60770.

Code all looks good, but you should talk about the effect of --output-style on the output for both llvm-symbolizer and llvm-addr2line as appropriate.

Code all looks good, but you should talk about the effect of --output-style on the output for both llvm-symbolizer and llvm-addr2line as appropriate.

Do you want this option to be added to the documentation about llvm-symbolizer or something else? Or you meant other places where this info should be added?

Code all looks good, but you should talk about the effect of --output-style on the output for both llvm-symbolizer and llvm-addr2line as appropriate.

Do you want this option to be added to the documentation about llvm-symbolizer or something else? Or you meant other places where this info should be added?

It would be good to have it in the llvm-symbolizer document (if it doesn't already exist there), documenting the style differences. I think it should also be explicitly mentioned in the llvm-addr2line document (but just saying the default is different is fine for that).

ikudrin updated this revision to Diff 195543.Apr 17 2019, 5:14 AM
ikudrin retitled this revision from [llvm-symbolizer] Add llvm-addr2line. to [llvm-symbolizer] Add llvm-addr2line.
  • Rebased on top of D60816; updated the documentation accordingly.
This revision is now accepted and ready to land.Apr 17 2019, 5:23 AM
This revision was automatically updated to reflect the committed changes.