Skip to content

Commit 68dafe4

Browse files
ktranlabath
authored andcommitted
[lldb] Use CompileUnit::ResolveSymbolContext in SymbolFileDWARF
SymbolFileDWARF::ResolveSymbolContext is currently unaware that in DWARF5 the primary file is specified at file index 0. As a result it misses to correctly resolve the symbol context for the primary file when DWARF5 debug data is used and the primary file is only specified at index 0. This change makes use of CompileUnit::ResolveSymbolContext to resolve the symbol context. The ResolveSymbolContext in CompileUnit has been previously already updated to reflect changes in DWARF5 and contains a more readable version. It can resolve more, but will also do a bit more work than SymbolFileDWARF::ResolveSymbolContext (getting the Module, and going through SymbolFileDWARF::ResolveSymbolContextForAddress), however, it's mostly directed by $resolve_scope what will be resolved, and ensures that code is easier to maintain if there's only one path. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D98619
1 parent f263418 commit 68dafe4

File tree

3 files changed

+135
-70
lines changed

3 files changed

+135
-70
lines changed

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

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,66 +1966,8 @@ uint32_t SymbolFileDWARF::ResolveSymbolContext(const FileSpec &file_spec,
19661966
bool file_spec_matches_cu_file_spec =
19671967
FileSpec::Match(file_spec, dc_cu->GetPrimaryFile());
19681968
if (check_inlines || file_spec_matches_cu_file_spec) {
1969-
SymbolContext sc(m_objfile_sp->GetModule());
1970-
sc.comp_unit = dc_cu;
1971-
uint32_t file_idx = UINT32_MAX;
1972-
1973-
// If we are looking for inline functions only and we don't find it
1974-
// in the support files, we are done.
1975-
if (check_inlines) {
1976-
file_idx =
1977-
sc.comp_unit->GetSupportFiles().FindFileIndex(1, file_spec, true);
1978-
if (file_idx == UINT32_MAX)
1979-
continue;
1980-
}
1981-
1982-
if (line != 0) {
1983-
LineTable *line_table = sc.comp_unit->GetLineTable();
1984-
1985-
if (line_table != nullptr && line != 0) {
1986-
// We will have already looked up the file index if we are
1987-
// searching for inline entries.
1988-
if (!check_inlines)
1989-
file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex(
1990-
1, file_spec, true);
1991-
1992-
if (file_idx != UINT32_MAX) {
1993-
uint32_t found_line;
1994-
uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex(
1995-
0, file_idx, line, false, &sc.line_entry);
1996-
found_line = sc.line_entry.line;
1997-
1998-
while (line_idx != UINT32_MAX) {
1999-
sc.function = nullptr;
2000-
sc.block = nullptr;
2001-
if (resolve_scope &
2002-
(eSymbolContextFunction | eSymbolContextBlock)) {
2003-
const lldb::addr_t file_vm_addr =
2004-
sc.line_entry.range.GetBaseAddress().GetFileAddress();
2005-
if (file_vm_addr != LLDB_INVALID_ADDRESS) {
2006-
ResolveFunctionAndBlock(
2007-
file_vm_addr, resolve_scope & eSymbolContextBlock, sc);
2008-
}
2009-
}
2010-
2011-
sc_list.Append(sc);
2012-
line_idx = line_table->FindLineEntryIndexByFileIndex(
2013-
line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2014-
}
2015-
}
2016-
} else if (file_spec_matches_cu_file_spec && !check_inlines) {
2017-
// only append the context if we aren't looking for inline call
2018-
// sites by file and line and if the file spec matches that of
2019-
// the compile unit
2020-
sc_list.Append(sc);
2021-
}
2022-
} else if (file_spec_matches_cu_file_spec && !check_inlines) {
2023-
// only append the context if we aren't looking for inline call
2024-
// sites by file and line and if the file spec matches that of
2025-
// the compile unit
2026-
sc_list.Append(sc);
2027-
}
2028-
1969+
dc_cu->ResolveSymbolContext(file_spec, line, check_inlines, false,
1970+
resolve_scope, sc_list);
20291971
if (!check_inlines)
20301972
break;
20311973
}

lldb/source/Symbol/CompileUnit.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,18 @@ void CompileUnit::ResolveSymbolContext(const FileSpec &file_spec,
248248
if (!file_spec_matches_cu_file_spec && !check_inlines)
249249
return;
250250

251+
SymbolContext sc(GetModule());
252+
sc.comp_unit = this;
253+
254+
if (line == 0) {
255+
if (file_spec_matches_cu_file_spec && !check_inlines) {
256+
// only append the context if we aren't looking for inline call sites by
257+
// file and line and if the file spec matches that of the compile unit
258+
sc_list.Append(sc);
259+
}
260+
return;
261+
}
262+
251263
uint32_t file_idx =
252264
GetSupportFiles().FindFileIndex(0, file_spec, true);
253265
while (file_idx != UINT32_MAX) {
@@ -259,23 +271,15 @@ void CompileUnit::ResolveSymbolContext(const FileSpec &file_spec,
259271
if (num_file_indexes == 0)
260272
return;
261273

262-
SymbolContext sc(GetModule());
263-
sc.comp_unit = this;
274+
LineTable *line_table = sc.comp_unit->GetLineTable();
264275

265-
if (line == 0) {
276+
if (line_table == nullptr) {
266277
if (file_spec_matches_cu_file_spec && !check_inlines) {
267-
// only append the context if we aren't looking for inline call sites by
268-
// file and line and if the file spec matches that of the compile unit
269278
sc_list.Append(sc);
270279
}
271280
return;
272281
}
273282

274-
LineTable *line_table = sc.comp_unit->GetLineTable();
275-
276-
if (line_table == nullptr)
277-
return;
278-
279283
uint32_t line_idx;
280284
LineEntry line_entry;
281285

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Test handling of DWARF5 file index 0.
2+
3+
# REQUIRES: x86
4+
5+
# RUN: llvm-mc -filetype=obj -o %t -triple x86_64-pc-linux %s
6+
# RUN: %lldb %t -o "image lookup -f hello.c -l 1" \
7+
# RUN: -o exit | FileCheck %s
8+
9+
# CHECK: 2 matches found in hello.c:1
10+
.text
11+
.Lfunc_begin0:
12+
.file 0 "." "hello.c"
13+
.loc 0 1 0 # hello.c:1:0
14+
nop
15+
.loc 0 1 13 prologue_end # hello.c:1:13
16+
nop
17+
.Lfunc_end0:
18+
.section .debug_abbrev,"",@progbits
19+
.byte 1 # Abbreviation Code
20+
.byte 17 # DW_TAG_compile_unit
21+
.byte 1 # DW_CHILDREN_yes
22+
.byte 37 # DW_AT_producer
23+
.byte 37 # DW_FORM_strx1
24+
.byte 19 # DW_AT_language
25+
.byte 5 # DW_FORM_data2
26+
.byte 3 # DW_AT_name
27+
.byte 37 # DW_FORM_strx1
28+
.byte 114 # DW_AT_str_offsets_base
29+
.byte 23 # DW_FORM_sec_offset
30+
.byte 16 # DW_AT_stmt_list
31+
.byte 23 # DW_FORM_sec_offset
32+
.byte 27 # DW_AT_comp_dir
33+
.byte 37 # DW_FORM_strx1
34+
.byte 17 # DW_AT_low_pc
35+
.byte 27 # DW_FORM_addrx
36+
.byte 18 # DW_AT_high_pc
37+
.byte 6 # DW_FORM_data4
38+
.byte 115 # DW_AT_addr_base
39+
.byte 23 # DW_FORM_sec_offset
40+
.byte 0 # EOM(1)
41+
.byte 0 # EOM(2)
42+
.byte 2 # Abbreviation Code
43+
.byte 46 # DW_TAG_subprogram
44+
.byte 0 # DW_CHILDREN_no
45+
.byte 17 # DW_AT_low_pc
46+
.byte 27 # DW_FORM_addrx
47+
.byte 18 # DW_AT_high_pc
48+
.byte 6 # DW_FORM_data4
49+
.byte 64 # DW_AT_frame_base
50+
.byte 24 # DW_FORM_exprloc
51+
.byte 3 # DW_AT_name
52+
.byte 37 # DW_FORM_strx1
53+
.byte 58 # DW_AT_decl_file
54+
.byte 11 # DW_FORM_data1
55+
.byte 59 # DW_AT_decl_line
56+
.byte 11 # DW_FORM_data1
57+
.byte 73 # DW_AT_type
58+
.byte 19 # DW_FORM_ref4
59+
.byte 63 # DW_AT_external
60+
.byte 25 # DW_FORM_flag_present
61+
.byte 0 # EOM(1)
62+
.byte 0 # EOM(2)
63+
.byte 3 # Abbreviation Code
64+
.byte 36 # DW_TAG_base_type
65+
.byte 0 # DW_CHILDREN_no
66+
.byte 3 # DW_AT_name
67+
.byte 37 # DW_FORM_strx1
68+
.byte 62 # DW_AT_encoding
69+
.byte 11 # DW_FORM_data1
70+
.byte 11 # DW_AT_byte_size
71+
.byte 11 # DW_FORM_data1
72+
.byte 0 # EOM(1)
73+
.byte 0 # EOM(2)
74+
.byte 0 # EOM(3)
75+
.section .debug_info,"",@progbits
76+
.Lcu_begin0:
77+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
78+
.Ldebug_info_start0:
79+
.short 5 # DWARF version number
80+
.byte 1 # DWARF Unit Type
81+
.byte 8 # Address Size (in bytes)
82+
.long .debug_abbrev # Offset Into Abbrev. Section
83+
.byte 1 # Abbrev [1] 0xc:0x2b DW_TAG_compile_unit
84+
.byte 0 # DW_AT_producer
85+
.short 12 # DW_AT_language
86+
.byte 1 # DW_AT_name
87+
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
88+
.long .Lline_table_start0 # DW_AT_stmt_list
89+
.byte 2 # DW_AT_comp_dir
90+
.byte 0 # DW_AT_low_pc
91+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
92+
.long .Laddr_table_base0 # DW_AT_addr_base
93+
.Ldebug_info_end0:
94+
.section .debug_str_offsets,"",@progbits
95+
.long 24 # Length of String Offsets Set
96+
.short 5
97+
.short 0
98+
.Lstr_offsets_base0:
99+
.section .debug_str,"MS",@progbits,1
100+
.Linfo_string0:
101+
.asciz "" # string offset=0
102+
.Linfo_string1:
103+
.asciz "hello.c" # string offset=101
104+
.Linfo_string2:
105+
.asciz "." # string offset=109
106+
.section .debug_str_offsets,"",@progbits
107+
.long .Linfo_string0
108+
.long .Linfo_string1
109+
.long .Linfo_string2
110+
.section .debug_addr,"",@progbits
111+
.Ldebug_addr_start0:
112+
.short 5 # DWARF version number
113+
.byte 8 # Address size
114+
.byte 0 # Segment selector size
115+
.Laddr_table_base0:
116+
.quad .Lfunc_begin0
117+
.Ldebug_addr_end0:
118+
.section .debug_line,"",@progbits
119+
.Lline_table_start0:

0 commit comments

Comments
 (0)