[lld] [llvm] [Symbolizer] Support for Missing Line Numbers. (PR #82240)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 03:36:33 PDT 2024


================
@@ -0,0 +1,240 @@
+##  Test the "--skip-line-zero" option.
+##
+##  This test uses handcrafted assembly to produce the following line table:
+##  Address            Line   Column File   ISA Discriminator OpIndex Flags
+##  ------------------ ------ ------ ------ --- ------------- ------- -------------
+##  0x0000000000001710      1      0      1   0             0       0
+##  0x0000000000001714      0      0      1   0             0       0
+##  0x0000000000001719      1      2      1   0             0       0
+##  0x000000000000171b      1      2      1   0             0       0  end_sequence
+##  0x00000000000016c0      0      0      1   0             0       0
+##  0x00000000000016cf      2      0      1   0             0       0
+##  0x00000000000016d4      0      0      1   0             0       0
+##  0x00000000000016d9      0      0      1   0             0       0
+##  0x00000000000016df      0      0      1   0             0       0  end_sequence
+
+# REQUIRES: x86-registered-target
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+
+## Check that without '--skip-line-zero', line zero is displayed for a line-table entry which has no source correspondence.
+# RUN: llvm-symbolizer --obj=%t.o 0x16d4 | FileCheck --strict-whitespace --match-full-lines --check-prefix=DISABLE %s
+
+# DISABLE:main
+# DISABLE-NEXT:main.c:0:0
+
+## Check that the '--skip-line-zero' does not cross sequence boundaries.
+## If it fails to find in the current sequence then line zero is returned for the queried address.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x16c0 | FileCheck --strict-whitespace --match-full-lines --check-prefix=FAIL-ACROSS-SEQ %s
+
+# FAIL-ACROSS-SEQ:main
+# FAIL-ACROSS-SEQ-NEXT:main.c:0:0
+
+## Check that with '--skip-line-zero', the last non-zero line in the current sequence is displayed.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x1717 | FileCheck --strict-whitespace --match-full-lines --check-prefix=WITHIN-SEQ %s
+
+# WITHIN-SEQ:foo
+# WITHIN-SEQ-NEXT:main.c:1:0 (approximate)
+
+## Check that with '--skip-line-zero', multiple line zero rows are skipped within the current sequence.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x16d9 | FileCheck --strict-whitespace --match-full-lines --check-prefix=MULTIPLE-ROWS %s
+
+# MULTIPLE-ROWS:main
+# MULTIPLE-ROWS-NEXT:main.c:2:0 (approximate)
+
+## Check that '--skip-line-zero' only affects the line zero addresses when more than one address is specified.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero 0x16d4 0x1719 | FileCheck --strict-whitespace --match-full-lines --check-prefixes=ENABLE,NO-APPROX %s
+
+# ENABLE:main
+# ENABLE-NEXT:main.c:2:0 (approximate)
+# NO-APPROX:foo
+# NO-APPROX-NEXT:main.c:1:2
+
+## Check to ensure that '--skip-line-zero' with '--verbose' enabled displays approximate flag in verbose ouptut.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --verbose 0x1717 | FileCheck --strict-whitespace --match-full-lines --check-prefix=VERBOSE %s
+
+# VERBOSE:foo
+# VERBOSE-NEXT:  Filename: main.c
+# VERBOSE-NEXT:  Function start filename: main.c
+# VERBOSE-NEXT:  Function start line: 1
+# VERBOSE-NEXT:  Function start address: 0x1710
+# VERBOSE-NEXT:  Line: 1
+# VERBOSE-NEXT:  Column: 0
+# VERBOSE-NEXT:  Approximate: true
+
+## Check to ensure that '--skip-line-zero' with '--output-style=JSON' displays approximate flag in JSON output.
+# RUN: llvm-symbolizer --obj=%t.o --skip-line-zero --output-style=JSON 0x1717 | FileCheck --strict-whitespace --match-full-lines --check-prefix=JSON %s
+
+# JSON:[{"Address":"0x1717","ModuleName":"{{.*}}{{[/|\]+}}test{{[/|\]+}}tools{{[/|\]+}}llvm-symbolizer{{[/|\]+}}Output{{[/|\]+}}skip-line-zero.s.tmp.o","Symbol":[{"Approximate":true,"Column":0,"Discriminator":0,"FileName":"main.c","FunctionName":"foo","Line":1,"StartAddress":"0x1710","StartFileName":"main.c","StartLine":1}]}]
+
+## main.c
+## __attribute__((section("def"))) int foo() { return 1234; }
+## int main(void) { return foo()+5678; }
+##
+## Generated using
+## clang -S -gdwarf-4 --target=x86_64-pc-linux -fdebug-prefix-map=/tmp="" main.c -o main.s
+##
+## Sections belonging to code segment(.text) are removed. Sections related to debug information(other than .debug_line) are modified. Section .debug_line is handwritten.
+
+	.section	.debug_abbrev,"", at progbits
----------------
ampandey-1995 wrote:

Sorry, I couldn't shorter anything from here. See here in this lit test we have 4 DIE's.
- DW_TAG_compile_unit(total 1, children 3)
- DW_TAG_subprogram(total 2 ) {represents two functions (foo,main)}
- DW_TAG_base_type(total 1) {represents the base fundamental type of function return type}

Excluding DW_TAG_subprogram and DW_TAG_base_type DIE's would break the object file itself when llvm-dwarfdump is invoked and also llvm-symbolizer will misbehave with the object file. 

It's not that information stored in the non-CU DIE's are not used. We are explicitly storing function offsets(foo{0x1710,0x171b},main{0x16c0,0x16df}) in those DIE's(DW_TAG_subprogram). Explicit offsets are required here because of two sequences(as by default they chose to start at offset zero which is altogether again affect the llvm-symbolizer o/p).

If I remove the DW_TAG_subprogram and DW_TAG_base_type from the .debug_abbrev and the corresponding information from .debug_info, then this is the symbolizer o/p.

```
~$ llvm-symbolizer --obj=skip-line-zero.o 0x1719 --skip-line-zero
??
main.c:1:2
```
It's not that it is functionally misbehaving , as you see we are losing function name which I believe other reviewers dosen't want.


https://github.com/llvm/llvm-project/pull/82240


More information about the llvm-commits mailing list