-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[GSYM] Use debug line offsets during GSYM creation #129196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This change adds support for using the `DW_AT_LLVM_stmt_sequence` attribute in the GSYM DWARF transformer. When present, the attribute is used to help locate the correct line table entries for a function.
e114b27
to
32df7eb
Compare
@llvm/pr-subscribers-debuginfo Author: None (alx32) ChangesThis patch introduces support for the The Patch is 31.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/129196.diff 2 Files Affected:
diff --git a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
index 568af5ee8e3ae..ea989767d111c 100644
--- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
+++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
@@ -317,8 +317,20 @@ static void convertFunctionLineTable(OutputAggregator &Out, CUInfo &CUI,
const object::SectionedAddress SecAddress{
StartAddress, object::SectionedAddress::UndefSection};
+ // Attempt to retrieve DW_AT_LLVM_stmt_sequence if present.
+ std::optional<uint64_t> StmtSeqOffset;
+ if (auto StmtSeqAttr = Die.find(llvm::dwarf::DW_AT_LLVM_stmt_sequence)) {
+ // The `DW_AT_LLVM_stmt_sequence` attribute might be set to `UINT64_MAX`
+ // when it refers to an empty line sequence. In such cases, the DWARF linker
+ // will exclude the empty sequence from the final output and assign
+ // `UINT64_MAX` to the `DW_AT_LLVM_stmt_sequence` attribute.
+ auto StmtSeqVal = dwarf::toSectionOffset(StmtSeqAttr, UINT64_MAX);
+ if (StmtSeqVal != UINT32_MAX)
+ StmtSeqOffset = StmtSeqVal;
+ }
- if (!CUI.LineTable->lookupAddressRange(SecAddress, RangeSize, RowVector)) {
+ if (!CUI.LineTable->lookupAddressRange(SecAddress, RangeSize, RowVector,
+ StmtSeqOffset)) {
// If we have a DW_TAG_subprogram but no line entries, fall back to using
// the DW_AT_decl_file an d DW_AT_decl_line if we have both attributes.
std::string FilePath = Die.getDeclFile(
diff --git a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml
index bba92befc089b..968bffaab649b 100644
--- a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml
+++ b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml
@@ -53,39 +53,39 @@
### 0x00000001000003e8 =========================> 0x000000010000035c => 0x0000000100000340
# RUN: llvm-gsymutil %t/dwarf_call_sites_dSYM.gsym --merged-functions --address=0x00000001000003d0 | FileCheck --check-prefix=CHECK-C1 %s
-# CHECK-C1: 0x00000001000003d0: main + 32 @ /tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:63
+# CHECK-C1: 0x00000001000003d0: main + 32 @ /private/tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:63
# CHECK-C1-NEXT: CallSites: function2_copy2
# RUN: llvm-gsymutil %t/dwarf_call_sites_dSYM.gsym --merged-functions --address=0x000000010000037c --merged-functions-filter="function2_copy2" | FileCheck --check-prefix=CHECK-C2 %s
-# CHECK-C2: 0x000000010000037c: function_inlined + 8 @ /tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:35 [inlined]
-# CHECK-C2-NEXT: function2_copy2 + 16 @ /tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:48
+# CHECK-C2: 0x000000010000037c: function_inlined + 8 @ /private/tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:35 [inlined]
+# CHECK-C2-NEXT: function2_copy2 + 16 @ /private/tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:48
# CHECK-C2-NEXT: CallSites: function3_copy1
# RUN: llvm-gsymutil %t/dwarf_call_sites_dSYM.gsym --merged-functions --address=0x000000010000035c --merged-functions-filter="function3_copy1" | FileCheck --check-prefix=CHECK-C3 %s
# CHECK-C3: Found 1 function at address 0x000000010000035c:
-# CHECK-C3-NEXT: 0x000000010000035c: function3_copy1 + 16 @ /tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:{{.}}
+# CHECK-C3-NEXT: 0x000000010000035c: function3_copy1 + 16 @ /private/tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:21
# CHECK-C3-NEXT: CallSites: function4_copy1
# RUN: llvm-gsymutil %t/dwarf_call_sites_dSYM.gsym --merged-functions --address=0x0000000100000340 --merged-functions-filter="function4_copy1" | FileCheck --check-prefix=CHECK-C4 %s
# CHECK-C4: Found 1 function at address 0x0000000100000340:
-# CHECK-C4-NEXT: 0x0000000100000340: function4_copy1 + 8 @ /tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:{{.}}
+# CHECK-C4-NEXT: 0x0000000100000340: function4_copy1 + 8 @ /private/tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:7
### ----------------------------------------------------------------------------------------------------------------------------------
### Resolve the 2nd call stack - the 2nd and 3rd addresses are the same but they resolve to a different function because of the filter
# RUN: llvm-gsymutil %t/dwarf_call_sites_dSYM.gsym --address=0x00000001000003e8 --merged-functions | FileCheck --check-prefix=CHECK-C5 %s
# CHECK-C5: Found 1 function at address 0x00000001000003e8:
-# CHECK-C5-NEXT: 0x00000001000003e8: main + 56 @ /tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:64
+# CHECK-C5-NEXT: 0x00000001000003e8: main + 56 @ /private/tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:64
# CHECK-C5-NEXT: CallSites: function3_copy2
# RUN: llvm-gsymutil %t/dwarf_call_sites_dSYM.gsym --merged-functions --address=0x000000010000035c --merged-functions-filter="function3_copy2" | FileCheck --check-prefix=CHECK-C6 %s
# CHECK-C6: Found 1 function at address 0x000000010000035c:
-# CHECK-C6-NEXT: 0x000000010000035c: function3_copy2 + 16 @ /tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:{{.}}
+# CHECK-C6-NEXT: 0x000000010000035c: function3_copy2 + 16 @ /private/tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:28
# CHECK-C6-NEXT: CallSites: function4_copy2
# RUN: llvm-gsymutil %t/dwarf_call_sites_dSYM.gsym --merged-functions --merged-functions-filter="function4_copy2" --address=0x0000000100000340 | FileCheck --check-prefix=CHECK-C7 %s
# CHECK-C7: Found 1 function at address 0x0000000100000340:
-# CHECK-C7-NEXT: 0x0000000100000340: function4_copy2 + 8 @ /tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:{{.}}
+# CHECK-C7-NEXT: 0x0000000100000340: function4_copy2 + 8 @ /private/tmp/tst{{[/\\]}}out/merged_funcs_test.cpp:14
#--- merged_funcs_test.cpp
@@ -228,7 +228,7 @@ FileHeader:
LoadCommands:
- cmd: LC_UUID
cmdsize: 24
- uuid: 4C4C442F-5555-3144-A1E4-99C5508F990D
+ uuid: 4C4C44F6-5555-3144-A1E3-14AF19709811
- cmd: LC_BUILD_VERSION
cmdsize: 24
platform: 1
@@ -276,7 +276,7 @@ LoadCommands:
reserved1: 0x0
reserved2: 0x0
reserved3: 0x0
- content: CFFAEDFE0C000001000000000A00000008000000C005000000000000000000001B000000180000004C4C442F55553144A1E499C5508F990D32000000180000000100000000000B0000000B00000000000200000018000000001000000A000000A01000009C00000019000000480000005F5F504147455A45524F00000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000019000000980000005F5F54455854000000000000000000000000000001000000
+ content: CFFAEDFE0C000001000000000A00000008000000C005000000000000000000001B000000180000004C4C44F655553144A1E314AF1970981132000000180000000100000000000B0000000B00000000000200000018000000001000000A000000A01000009C00000019000000480000005F5F504147455A45524F00000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000019000000980000005F5F54455854000000000000000000000000000001000000
- cmd: LC_SEGMENT_64
cmdsize: 152
segname: __DATA
@@ -318,7 +318,7 @@ LoadCommands:
vmaddr: 4295004160
vmsize: 4096
fileoff: 8192
- filesize: 3640
+ filesize: 3526
maxprot: 7
initprot: 3
nsects: 11
@@ -327,7 +327,7 @@ LoadCommands:
- sectname: __debug_line
segname: __DWARF
addr: 0x100009000
- size: 327
+ size: 323
offset: 0x2000
align: 0
reloff: 0x0
@@ -338,9 +338,9 @@ LoadCommands:
reserved3: 0x0
- sectname: __debug_aranges
segname: __DWARF
- addr: 0x100009147
+ addr: 0x100009143
size: 48
- offset: 0x2147
+ offset: 0x2143
align: 0
reloff: 0x0
nreloc: 0
@@ -350,9 +350,9 @@ LoadCommands:
reserved3: 0x0
- sectname: __debug_loc
segname: __DWARF
- addr: 0x100009177
+ addr: 0x100009173
size: 1026
- offset: 0x2177
+ offset: 0x2173
align: 0
reloff: 0x0
nreloc: 0
@@ -360,12 +360,12 @@ LoadCommands:
reserved1: 0x0
reserved2: 0x0
reserved3: 0x0
- content: 00000000000000000800000000000000010050080000000000000014000000000000000400A301509F0000000000000000000000000000000004000000000000000C0000000000000001005800000000000000000000000000000000080000000000000014000000000000000100500000000000000000000000000000000000000000000000000800000000000000010050080000000000000014000000000000000400A301509F0000000000000000000000000000000004000000000000000C0000000000000001005800000000000000000000000000000000080000000000000014000000000000000100500000000000000000000000000000000014000000000000002000000000000000010050200000000000000034000000000000000400A301509F00000000000000000000000000000000240000000000000034000000000000000100500000000000000000000000000000000014000000000000002000000000000000010050200000000000000034000000000000000400A301509F00000000000000000000000000000000240000000000000034000000000000000100500000000000000000000000000000000034000000000000004000000000000000010050400000000000000058000000000000000400A301509F000000000000000000000000000000003C0000000000000040000000000000000300707E9F000000000000000000000000000000004400000000000000580000000000000001005000000000000000000000000000000000340000000000000040000000000000000300707E9F00000000000000000000000000000000440000000000000058000000000000000100500000000000000000000000000000000034000000000000004000000000000000010050400000000000000058000000000000000400A301509F000000000000000000000000000000003C0000000000000040000000000000000300707E9F000000000000000000000000000000004400000000000000580000000000000001005000000000000000000000000000000000340000000000000040000000000000000300707E9F00000000000000000000000000000000440000000000000058000000000000000100500000000000000000000000000000000058000000000000006400000000000000010050640000000000000078000000000000000400A301509F00000000000000000000000000000000680000000000000078000000000000000100500000000000000000000000000000000084000000000000009000000000000000030011009F90000000000000009C000000000000000100639C00000000000000A800000000000000010064B800000000000000C00000000000000001006300000000000000000000000000000000
+ content: 00000000000000000800000000000000010050080000000000000014000000000000000400A301509F0000000000000000000000000000000004000000000000000C0000000000000001005800000000000000000000000000000000080000000000000014000000000000000100500000000000000000000000000000000000000000000000000800000000000000010050080000000000000014000000000000000400A301509F0000000000000000000000000000000004000000000000000C0000000000000001005800000000000000000000000000000000080000000000000014000000000000000100500000000000000000000000000000000014000000000000002000000000000000010050200000000000000034000000000000000400A301509F00000000000000000000000000000000240000000000000034000000000000000100500000000000000000000000000000000014000000000000002000000000000000010050200000000000000034000000000000000400A301509F00000000000000000000000000000000240000000000000034000000000000000100500000000000000000000000000000000034000000000000004000000000000000010050400000000000000058000000000000000400A301509F000000000000000000000000000000003C0000000000000040000000000000000300707E9F000000000000000000000000000000004400000000000000580000000000000001005000000000000000000000000000000000340000000000000040000000000000000300707E9F00000000000000000000000000000000440000000000000058000000000000000100500000000000000000000000000000000034000000000000004000000000000000010050400000000000000058000000000000000400A301509F000000000000000000000000000000003C0000000000000040000000000000000300707E9F00000000000000000000000000000000440000000000000058000000000000000100500000000000000000000000000000000058000000000000006400000000000000010050640000000000000078000000000000000400A301509F00000000000000000000000000000000680000000000000078000000000000000100500000000000000000000000000000000084000000000000009000000000000000030011009F90000000000000009C000000000000000100639C00000000000000A800000000000000010064B800000000000000C00000000000000001006300000000000000000000000000000000
- sectname: __debug_info
segname: __DWARF
- addr: 0x100009579
+ addr: 0x100009575
size: 923
- offset: 0x2579
+ offset: 0x2575
align: 0
reloff: 0x0
nreloc: 0
@@ -375,9 +375,9 @@ LoadCommands:
reserved3: 0x0
- sectname: __debug_frame
segname: __DWARF
- addr: 0x100009914
+ addr: 0x100009910
size: 272
- offset: 0x2914
+ offset: 0x2910
align: 0
reloff: 0x0
nreloc: 0
@@ -388,9 +388,9 @@ LoadCommands:
content: 14000000FFFFFFFF0400080001781E0C1F000000000000001400000000000000380300000100000014000000000000001400000000000000380300000100000014000000000000001C000000000000004C030000010000002000000000000000480C1D109E019D021C000000000000004C030000010000002000000000000000480C1D109E019D021C000000000000006C030000010000002400000000000000480C1D109E019D021C000000000000006C030000010000002400000000000000480C1D109E019D021C0000000000000090030000010000002000000000000000480C1D109E019D022400000000000000B00300000100000058000000000000004C0C1D109E019D029303940400000000
- sectname: __debug_abbrev
segname: __DWARF
- addr: 0x100009A24
+ addr: 0x100009A20
size: 260
- offset: 0x2A24
+ offset: 0x2A20
align: 0
reloff: 0x0
nreloc: 0
@@ -400,9 +400,9 @@ LoadCommands:
reserved3: 0x0
- sectname: __debug_str
segname: __DWARF
- addr: 0x100009B28
- size: 317
- offset: 0x2B28
+ addr: 0x100009B24
+ size: 207
+ offset: 0x2B24
align: 0
reloff: 0x0
nreloc: 0
@@ -412,9 +412,9 @@ LoadCommands:
reserved3: 0x0
- sectname: __apple_namespac
segname: __DWARF
- addr: 0x100009C65
+ addr: 0x100009BF3
size: 36
- offset: 0x2C65
+ offset: 0x2BF3
align: 0
reloff: 0x0
nreloc: 0
@@ -425,9 +425,9 @@ LoadCommands:
content: 485341480100000001000000000000000C000000000000000100000001000600FFFFFFFF
- sectname: __apple_names
segname: __DWARF
- addr: 0x100009C89
+ addr: 0x100009C17
size: 316
- offset: 0x2C89
+ offset: 0x2C17
align: 0
reloff: 0x0
nreloc: 0
@@ -435,12 +435,12 @@ LoadCommands:
reserved1: 0x0
reserved2: 0x0
reserved3: 0x0
- content: 48534148010000000A0000000A0000000C0000000000000001000000010006000000000002000000030000000400000006000000FFFFFFFF0800000009000000FFFFFFFFFFFFFFFF88CB36CFF4B03BD389CB36CF0A452B694908311C0B452B694A08311CDC41AB586A7F9A7CAD7ED75898000000A8000000B8000000C8000000D8000000E8000000F80000000801000018010000280100000A01000001000000BB010000000000009C000000010000002E000000000000001A010000010000003A02000000000000AE000000010000004F00000000000000D900000001000000E500000000000000C9000000010000009A00000000000000E90000000100000039010000000000002A01000001000000B90200000000000034010000010000000D03000000000000F900000002000000050200008402000000000000
+ content: 48534148010000000A0000000A0000000C0000000000000001000000010006000000000002000000030000000400000006000000FFFFFFFF0800000009000000FFFFFFFFFFFFFFFF88CB36CFF4B03BD389CB36CF0A452B694908311C0B452B694A08311CDC41AB586A7F9A7CAD7ED75898000000A8000000B8000000C8000000D8000000E8000000F80000000801000018010000280100009C00000001000000BB010000000000002E000000010000002E00000000000000AC000000010000003A0200000000000040000000010000004F000000000000006B00000001000000E5000000000000005B000000010000009A000000000000007B000000010000003901000000000000BC00000001000000B902000000000000C6000000010000000D030000000000008B00000002000000050200008402000000000000
- sectname: __apple_types
segname: __DWARF
- addr: 0x100009DC5
+ addr: 0x100009D53
size: 79
- offset: 0x2DC5
+ offset: 0x2D53
align: 0
reloff: 0x0
nreloc: 0
@@ -448,12 +448,12 @@ LoadCommands:
reserved1: 0x0
reserved2: 0x0
reserved3: 0x0
- content: 48534148010000000100000001000000180000000000000004000000010006000300050005000B0006000600000000003080880B38000000AA0000000100000048000000240000A4283A0C00000000
+ content: 48534148010000000100000001000000180000000000000004000000010006000300050005000B0006000600000000003080880B380000003C0000000100000048000000240000A4283A0C00000000
- sectname: __apple_objc
segname: __DWARF
- addr: 0x100009E14
+ addr: 0x100009DA2
size: 36
- offset: 0x2E14
+ offset: 0x2DA2
align: 0
reloff: 0x0
nreloc: 0
@@ -530,10 +530,9 @@ LinkEditData:
DWARF:
debug_str:
- ''
- - 'clang version 20.0.0git (https://github.com/alx32/llvm-project.git 92a15dd7482ff4e1fae7a07f888564e5b1d53eee)'
- - '/tmp/tst/out/merged_funcs_test.cpp'
+ - merged_funcs_test.cpp
- '/'
- - '/tmp/tst'
+ - '/private/tmp/tst/out'
- global_result
- int
- function4_copy1
@@ -803,18 +802,18 @@ DWARF:
Entries:
- AbbrCode: 0x1
Values:
- - Value: 0x1
+ - Value: 0x0
- Value: 0x21
- - Value: 0x6E
- - Value: 0x91
+ - Value: 0x1
+ - Value: 0x17
- Value: 0x0
- - Value: 0x93
+ - Value: 0x19
- Value: 0x1
- Value: 0x100000338
- Value: 0xD0
- AbbrCode: 0x2
Values:
- - Value: 0x9C
+ - Value: 0x2E
- Value: 0x43
- Value: 0x1
- Value: 0x1
@@ -827,7 +826,7 @@ DWARF:
- Value: 0x48
- AbbrCode: 0x4
Values:
- - Value: 0xAA
+ - Value: 0x3C
- Value: 0x5
- Value: 0x4
- AbbrCode: 0x5
@@ -835,11 +834,11 @@ DWARF:
- Value: 0x100000338
- Value: 0x14
- Value: 0x1
- - Value: 0x3B
+ - Value: 0x54
- Value: 0x1
BlockData: [ 0x6F ]
- Value: 0x1
- - Value: 0xAE
+ - Value: 0x40
- Value: 0x1
- Value: 0x4
- Value: 0x48
@@ -848,21 +847,21 @@ DWARF:
- AbbrCode: 0x6
Values:
- Value: 0x0
- - Value: ...
[truncated]
|
// will exclude the empty sequence from the final output and assign | ||
// `UINT64_MAX` to the `DW_AT_LLVM_stmt_sequence` attribute. | ||
auto StmtSeqVal = dwarf::toSectionOffset(StmtSeqAttr, UINT64_MAX); | ||
if (StmtSeqVal != UINT32_MAX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC:
if (StmtSeqVal != UINT32_MAX) | |
if (StmtSeqVal != UINT64_MAX) |
There is a bug in `llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp` where `StmtSeqVal` was being compared against `UINT32_MAX` rather than the correct `UINT64_MAX` - thanks @nocchijiang for [pointing this out](#129196 (comment)). We correct the issue with this patch. For testing - the issue would show when we have a correct offset of value `UINT32_MAX` - but constructing such a test is impractical.
There is a bug in `llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp` where `StmtSeqVal` was being compared against `UINT32_MAX` rather than the correct `UINT64_MAX` - thanks @nocchijiang for [pointing this out](llvm/llvm-project#129196 (comment)). We correct the issue with this patch. For testing - the issue would show when we have a correct offset of value `UINT32_MAX` - but constructing such a test is impractical.
This patch introduces support for the `DW_AT_LLVM_stmt_sequence` attribute in the GSYM DWARF transformer. With this change, the DWARF GSYM creation process can now accurately associate debug information with the correct functions, even when multiple functions have been merged together. The `macho-gsym-merged-callsites-dsym.yaml` test data is regenerated to include the fixes in the DWARF linker (llvm#128953) and the test is updated to check that debug data is correctly associated for merged functions.
This patch introduces support for the
DW_AT_LLVM_stmt_sequence
attribute in the GSYM DWARF transformer. With this change, the DWARF GSYM creation process can now accurately associate debug information with the correct functions, even when multiple functions have been merged together.The
macho-gsym-merged-callsites-dsym.yaml
test data is regenerated to include the fixes in the DWARF linker (#128953) and the test is updated to check that debug data is correctly associated for merged functions.