[llvm-symbolizer] Improve output for addresses with no line correspondence
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?
@llvm/issue-subscribers-tools-llvm-symbolizer
Author: bd1976bris (bd1976bris)
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)?
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.