Skip to content

Commit 3dc24bc

Browse files
committed
[LLDB] Re-land: Use path relative to binary for finding .dwo files.
DWARF allows .dwo file paths to be relative rather than absolute. When they are relative, DWARF uses DW_AT_comp_dir to find the .dwo file. DW_AT_comp_dir can also be relative, making the entire search patch for the .dwo file relative. In this case, LLDB currently searches relative to its current working directory, i.e. the directory from which the debugger was launched. This is not right, as the compiler, which generated the relative paths, can have no idea where the debugger will be launched. The correct thing is to search relative to the location of the executable binary. That is what this patch does. Differential Revision: https://reviews.llvm.org/D97786
1 parent 59437cb commit 3dc24bc

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,13 @@ SymbolFileDWARF::GetDwoSymbolFileForCompileUnit(
16511651
return nullptr;
16521652

16531653
dwo_file.SetFile(comp_dir, FileSpec::Style::native);
1654+
if (dwo_file.IsRelative()) {
1655+
// if DW_AT_comp_dir is relative, it should be relative to the location
1656+
// of the executable, not to the location from which the debugger was
1657+
// launched.
1658+
dwo_file.PrependPathComponent(
1659+
m_objfile_sp->GetFileSpec().GetDirectory().GetStringRef());
1660+
}
16541661
FileSystem::Instance().Resolve(dwo_file);
16551662
dwo_file.AppendPathComponent(dwo_name);
16561663
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Test to verify LLDB searches for dwos with relative paths relative to the
2+
# binary location, not relative to LLDB's launch location.
3+
4+
# RUN: llvm-mc --filetype=obj --triple x86_64-pc-linux %s -o %t.o
5+
# RUN: llvm-objcopy --split-dwo=%T/dwo-relative-path.dwo %t.o
6+
7+
# RUN: cd ../..
8+
9+
# RUN: %lldb %t.o -o "target var x" -b 2>&1 | FileCheck %s
10+
11+
# CHECK: x = 10
12+
13+
.file "dwo-relative-path.cpp"
14+
.file 0 "." "dwo-relative-path.cpp" md5 0xadc61d242247514c5d402d62db34b825
15+
.type x,@object # @x
16+
.data
17+
.globl x
18+
.p2align 2
19+
x:
20+
.long 10 # 0xa
21+
.size x, 4
22+
23+
.section .debug_abbrev,"",@progbits
24+
.byte 1 # Abbreviation Code
25+
.byte 74 # DW_TAG_skeleton_unit
26+
.byte 0 # DW_CHILDREN_no
27+
.byte 16 # DW_AT_stmt_list
28+
.byte 23 # DW_FORM_sec_offset
29+
.byte 114 # DW_AT_str_offsets_base
30+
.byte 23 # DW_FORM_sec_offset
31+
.byte 27 # DW_AT_comp_dir
32+
.byte 37 # DW_FORM_strx1
33+
.ascii "\264B" # DW_AT_GNU_pubnames
34+
.byte 25 # DW_FORM_flag_present
35+
.byte 118 # DW_AT_dwo_name
36+
.byte 37 # DW_FORM_strx1
37+
.byte 115 # DW_AT_addr_base
38+
.byte 23 # DW_FORM_sec_offset
39+
.byte 0 # EOM(1)
40+
.byte 0 # EOM(2)
41+
.byte 0 # EOM(3)
42+
.section .debug_info,"",@progbits
43+
.Lcu_begin0:
44+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
45+
.Ldebug_info_start0:
46+
.short 5 # DWARF version number
47+
.byte 4 # DWARF Unit Type
48+
.byte 8 # Address Size (in bytes)
49+
.long .debug_abbrev # Offset Into Abbrev. Section
50+
.quad 3752513468363206953
51+
.byte 1 # Abbrev [1] 0x14:0x14 DW_TAG_skeleton_unit
52+
.long .Lline_table_start0 # DW_AT_stmt_list
53+
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
54+
.byte 0 # DW_AT_comp_dir
55+
# DW_AT_GNU_pubnames
56+
.byte 1 # DW_AT_dwo_name
57+
.long .Laddr_table_base0 # DW_AT_addr_base
58+
.Ldebug_info_end0:
59+
.section .debug_str_offsets,"",@progbits
60+
.long 12 # Length of String Offsets Set
61+
.short 5
62+
.short 0
63+
.Lstr_offsets_base0:
64+
.section .debug_str,"MS",@progbits,1
65+
.Lskel_string0:
66+
.asciz "." # string offset=0
67+
.Lskel_string1:
68+
.asciz "dwo-relative-path.dwo" # string offset=2
69+
.section .debug_str_offsets,"",@progbits
70+
.long .Lskel_string0
71+
.long .Lskel_string1
72+
.section .debug_str_offsets.dwo,"e",@progbits
73+
.long 24 # Length of String Offsets Set
74+
.short 5
75+
.short 0
76+
.section .debug_str.dwo,"eMS",@progbits,1
77+
.Linfo_string0:
78+
.asciz "x"
79+
.Linfo_string1:
80+
.asciz "int"
81+
.Linfo_string2:
82+
.asciz "clang version 13.0.0 (https://chromium.googlesource.com/external/github.com/llvm/llvm-project 6666e0d7a29c639df7a1652b6d3bf16f28edd45a)"
83+
.Linfo_string3:
84+
.asciz "dwo-relative-path.cpp"
85+
.Linfo_string10:
86+
.asciz "dwo-relative-path.dwo"
87+
.section .debug_str_offsets.dwo,"e",@progbits
88+
.long .Linfo_string0-.debug_str.dwo
89+
.long .Linfo_string1-.debug_str.dwo
90+
.long .Linfo_string2-.debug_str.dwo
91+
.long .Linfo_string3-.debug_str.dwo
92+
.section .debug_info.dwo,"e",@progbits
93+
.long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit
94+
.Ldebug_info_dwo_start0:
95+
.short 5 # DWARF version number
96+
.byte 5 # DWARF Unit Type
97+
.byte 8 # Address Size (in bytes)
98+
.long 0 # Offset Into Abbrev. Section
99+
.quad 3752513468363206953
100+
.byte 1 # Abbrev [1] 0x14:0x65 DW_TAG_compile_unit
101+
.byte 8 # DW_AT_producer
102+
.short 33 # DW_AT_language
103+
.byte 9 # DW_AT_name
104+
.byte 10 # DW_AT_dwo_name
105+
.byte 2 # Abbrev [2] 0x1a:0xb DW_TAG_variable
106+
.byte 0 # DW_AT_name
107+
.long 37 # DW_AT_type
108+
# DW_AT_external
109+
.byte 0 # DW_AT_decl_file
110+
.byte 11 # DW_AT_decl_line
111+
.byte 2 # DW_AT_location
112+
.byte 161
113+
.byte 0
114+
.byte 3 # Abbrev [3] 0x25:0x4 DW_TAG_base_type
115+
.byte 1 # DW_AT_name
116+
.byte 5 # DW_AT_encoding
117+
.byte 4 # DW_AT_byte_size
118+
.byte 0 # End Of Children Mark
119+
.Ldebug_info_dwo_end0:
120+
.section .debug_abbrev.dwo,"e",@progbits
121+
.byte 1 # Abbreviation Code
122+
.byte 17 # DW_TAG_compile_unit
123+
.byte 1 # DW_CHILDREN_yes
124+
.byte 37 # DW_AT_producer
125+
.byte 37 # DW_FORM_strx1
126+
.byte 19 # DW_AT_language
127+
.byte 5 # DW_FORM_data2
128+
.byte 3 # DW_AT_name
129+
.byte 37 # DW_FORM_strx1
130+
.byte 118 # DW_AT_dwo_name
131+
.byte 37 # DW_FORM_strx1
132+
.byte 0 # EOM(1)
133+
.byte 0 # EOM(2)
134+
.byte 2 # Abbreviation Code
135+
.byte 52 # DW_TAG_variable
136+
.byte 0 # DW_CHILDREN_no
137+
.byte 3 # DW_AT_name
138+
.byte 37 # DW_FORM_strx1
139+
.byte 73 # DW_AT_type
140+
.byte 19 # DW_FORM_ref4
141+
.byte 63 # DW_AT_external
142+
.byte 25 # DW_FORM_flag_present
143+
.byte 58 # DW_AT_decl_file
144+
.byte 11 # DW_FORM_data1
145+
.byte 59 # DW_AT_decl_line
146+
.byte 11 # DW_FORM_data1
147+
.byte 2 # DW_AT_location
148+
.byte 24 # DW_FORM_exprloc
149+
.byte 0 # EOM(1)
150+
.byte 0 # EOM(2)
151+
.byte 3 # Abbreviation Code
152+
.byte 36 # DW_TAG_base_type
153+
.byte 0 # DW_CHILDREN_no
154+
.byte 3 # DW_AT_name
155+
.byte 37 # DW_FORM_strx1
156+
.byte 62 # DW_AT_encoding
157+
.byte 11 # DW_FORM_data1
158+
.byte 11 # DW_AT_byte_size
159+
.byte 11 # DW_FORM_data1
160+
.byte 0 # EOM(1)
161+
.byte 0 # EOM(2)
162+
.byte 0 # EOM(3)
163+
.section .debug_addr,"",@progbits
164+
.long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
165+
.Ldebug_addr_start0:
166+
.short 5 # DWARF version number
167+
.byte 8 # Address size
168+
.byte 0 # Segment selector size
169+
.Laddr_table_base0:
170+
.quad x
171+
.Ldebug_addr_end0:
172+
.section .debug_line,"",@progbits
173+
.Lline_table_start0:

0 commit comments

Comments
 (0)