llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[llvm-symbolizer] Improve output for addresses with no line correspondence

Open bd1976bris opened this issue 2 years ago • 2 comments

My understanding is that the convention for addresses with no line correspondence is to associate them with line 0.

From the DWARF 5 spec section 6.2.2 State Machine Registers from the entry on the meaning of the line register:

An unsigned integer indicating a source line number. Lines are numbered beginning at 1. The compiler may emit the value 0 in cases where an instruction cannot be attributed to any source line

We should improve the tool behavior for such addresses to avoid confusion to users.

Suggestions for improvement:

1. Print <unknown> rather than line 0 for such addresses:

Current output:

llvm-symbolizer.exe --obj=main.elf 0x0000000000000177 f3 main.c:0:0

Proposed:

llvm-symbolizer.exe --obj=main.elf 0x0000000000000177 f3 main.c:<unknown> *Warning: no line correspondence for address. Please try a nearby address or use --skip-line-zero(#82240) *

Although, perhaps it isn't even possible to give a reasonable file for such addresses (compiler inlining scenarios etc) - in which case perhaps only printing the function name would be preferable?

2. Do not show context lines:

I noticed that for --print-source-context-lines for line zero addresses you currently get very confusing output where the lines around line zero are displayed:

Current output:

llvm-symbolizer.exe 0x0000000000000156 --obj=main.elf --print-source-context-lines=3 f3 main.c:0:0 1 : static int gvar1 = 0; 2 : static int gvar2 = 0; 3 : static int gvar3 = 0;

Proposed:

llvm-symbolizer.exe 0x0000000000000156 --obj=main.elf --print-source-context-lines=3 f3 main.c:<unknown> *Warning: no line correspondence for address so no context displayed. Please try a nearby address or use --skip-line-zero(#82240) *

Other notes:

  • Might be worth checking the interaction with --no-use-symbol-table (https://github.com/llvm/llvm-project/pull/71008)?
  • Perhaps we should enhance the documentation to add some notes on line zero behaviour?

bd1976bris avatar May 16 '24 14:05 bd1976bris

@llvm/issue-subscribers-tools-llvm-symbolizer

Author: bd1976bris (bd1976bris)

My understanding is that the convention for addresses with no line correspondence is to associate them with line 0.

We should improve the tool behavior for such addresses to avoid confusion to users.

Suggestions for improvement:

1. Print &lt;unknown&gt; rather than line 0 for such addresses:

Current output: >llvm-symbolizer.exe --obj=main.elf 0x0000000000000177 f3 main.c:0:0

Proposed: >llvm-symbolizer.exe --obj=main.elf 0x0000000000000177 f3 main.c:&lt;unknown&gt; *Warning: no line correspondence for address. Please try a nearby address or use --skip-line-zero(#82240) *

Although, perhaps it isn't even possible to give a reasonable file for such addresses (compiler inlining scenarios etc) - in which case perhaps only printing the function name would be preferable?

2. Do not show context lines:

I noticed that for --print-source-context-lines for line zero addresses you currently get very confusing output where the lines around line zero are displayed:

Current output: >llvm-symbolizer.exe 0x0000000000000156 --obj=main.elf --print-source-context-lines=3 f3 main.c:0:0 1 : static int gvar1 = 0; 2 : static int gvar2 = 0; 3 : static int gvar3 = 0;

Proposed: >llvm-symbolizer.exe 0x0000000000000156 --obj=main.elf --print-source-context-lines=3 f3 main.c:&lt;unknown&gt; *Warning: no line correspondence for address so no context displayed. Please try a nearby address or use --skip-line-zero(#82240) *

Other notes:

  • Might be worth checking the interaction with --no-use-symbol-table (https://github.com/llvm/llvm-project/pull/71008)?

llvmbot avatar May 16 '24 14:05 llvmbot

Note: I noticed that column information is printed for line 0 lines (tried a contrived hand-crafted example). I think that line zero implies no column information.

bd1976bris avatar Jul 26 '24 13:07 bd1976bris