Skip to content

Commit 51d691f

Browse files
author
Kevin Frei
committed
Continuing to pick my changes apart a little bit
1 parent 4ad67e7 commit 51d691f

27 files changed

+1893
-13
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "lldb/Interpreter/OptionValueProperties.h"
4040

4141
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
42+
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
4243
#include "Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h"
4344
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
4445
#include "lldb/Symbol/Block.h"
@@ -4347,6 +4348,23 @@ SymbolFileDWARFDebugMap *SymbolFileDWARF::GetDebugMapSymfile() {
43474348
return m_debug_map_symfile;
43484349
}
43494350

4351+
bool SymbolFileDWARF::IsDwpSymbolFile(const lldb::ModuleSP &module_sp,
4352+
const FileSpec &file_spec) {
4353+
DataBufferSP dwp_file_data_sp;
4354+
lldb::offset_t dwp_file_data_offset = 0;
4355+
// Try to create an ObjectFileELF frorm the filespace
4356+
ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
4357+
module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
4358+
dwp_file_data_sp, dwp_file_data_offset);
4359+
if (!ObjectFileELF::classof(dwp_obj_file.get()))
4360+
return false;
4361+
static ConstString sect_name_debug_cu_index(".debug_cu_index");
4362+
if (!dwp_obj_file || !dwp_obj_file->GetSectionList()->FindSectionByName(
4363+
sect_name_debug_cu_index))
4364+
return false;
4365+
return true;
4366+
}
4367+
43504368
const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
43514369
llvm::call_once(m_dwp_symfile_once_flag, [this]() {
43524370
// Create a list of files to try and append .dwp to.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ class SymbolFileDWARF : public SymbolFileCommon {
280280

281281
DWARFContext &GetDWARFContext() { return m_context; }
282282

283+
static bool IsDwpSymbolFile(const lldb::ModuleSP &module_sp,
284+
const FileSpec &file_spec);
285+
283286
const std::shared_ptr<SymbolFileDWARFDwo> &GetDwpSymbolFile();
284287

285288
FileSpec GetFile(DWARFUnit &unit, size_t file_idx);

lldb/source/Plugins/SymbolLocator/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
# Order matters here, as the first symbol locator will prevent further
2+
# searching. For DWARF binaries that are both stripped & split, the Default
3+
# plugin will return the stripped binary when asked for the ObjectFile,
4+
# preventing an unstripped binary from being requested from the Debuginfod
5+
# provider
6+
add_subdirectory(Debuginfod)
17
add_subdirectory(Default)
28
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
39
add_subdirectory(DebugSymbols)
410
endif()
5-
add_subdirectory(Debuginfod)

lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ class PluginProperties : public Properties {
9696
Args m_server_urls;
9797
};
9898

99-
} // namespace
100-
101-
static PluginProperties &GetGlobalPluginProperties() {
99+
PluginProperties &GetGlobalPluginProperties() {
102100
static PluginProperties g_settings;
103101
return g_settings;
104102
}
105103

104+
} // namespace
105+
106106
SymbolLocatorDebuginfod::SymbolLocatorDebuginfod() : SymbolLocator() {}
107107

108108
void SymbolLocatorDebuginfod::Initialize() {

lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <cstring>
1212

1313
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
14+
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
1415
#include "lldb/Core/Module.h"
1516
#include "lldb/Core/ModuleSpec.h"
1617
#include "lldb/Core/PluginManager.h"
@@ -87,8 +88,16 @@ SymbolVendorELF::CreateInstance(const lldb::ModuleSP &module_sp,
8788
FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
8889
FileSpec dsym_fspec =
8990
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
90-
if (!dsym_fspec)
91-
return nullptr;
91+
if (!dsym_fspec ||
92+
plugin::dwarf::SymbolFileDWARF::IsDwpSymbolFile(module_sp, dsym_fspec)) {
93+
// If we have a stripped binary or if we got a DWP file, we should prefer
94+
// symbols in the executable acquired through a plugin.
95+
ModuleSpec unstripped_spec =
96+
PluginManager::LocateExecutableObjectFile(module_spec);
97+
if (!unstripped_spec)
98+
return nullptr;
99+
dsym_fspec = unstripped_spec.GetFileSpec();
100+
}
92101

93102
DataBufferSP dsym_file_data_sp;
94103
lldb::offset_t dsym_file_data_offset = 0;
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_EXEC
6+
Machine: EM_X86_64
7+
Entry: 0x401030
8+
ProgramHeaders:
9+
- Type: PT_LOAD
10+
Flags: [ PF_R ]
11+
FirstSec: .note.gnu.build-id
12+
LastSec: .note.gnu.build-id
13+
VAddr: 0x400000
14+
Align: 0x1000
15+
Offset: 0x0
16+
- Type: PT_LOAD
17+
Flags: [ PF_X, PF_R ]
18+
FirstSec: .text
19+
LastSec: .text
20+
VAddr: 0x401000
21+
Align: 0x1000
22+
Offset: 0x1000
23+
- Type: PT_LOAD
24+
Flags: [ PF_R ]
25+
FirstSec: .rodata
26+
LastSec: .eh_frame
27+
VAddr: 0x402000
28+
Align: 0x1000
29+
Offset: 0x1000
30+
- Type: PT_LOAD
31+
Flags: [ PF_W, PF_R ]
32+
FirstSec: .data.rel.ro
33+
LastSec: .data.rel.ro
34+
VAddr: 0x403FF8
35+
Align: 0x1000
36+
Offset: 0x1FF8
37+
- Type: PT_NOTE
38+
Flags: [ PF_R ]
39+
FirstSec: .note.gnu.build-id
40+
LastSec: .note.gnu.build-id
41+
VAddr: 0x4001C8
42+
Align: 0x4
43+
Offset: 0x1C8
44+
- Type: PT_GNU_STACK
45+
Flags: [ PF_W, PF_R ]
46+
Align: 0x10
47+
Offset: 0x0
48+
- Type: PT_GNU_RELRO
49+
Flags: [ PF_R ]
50+
FirstSec: .data.rel.ro
51+
LastSec: .data.rel.ro
52+
VAddr: 0x403FF8
53+
Offset: 0x1FF8
54+
Sections:
55+
- Name: .note.gnu.build-id
56+
Type: SHT_NOTE
57+
Flags: [ SHF_ALLOC ]
58+
Address: 0x4001C8
59+
AddressAlign: 0x4
60+
Notes:
61+
- Name: GNU
62+
Desc: B4927EA09A08EE63313299CF347043010D03CC5E
63+
Type: NT_PRPSINFO
64+
- Name: .text
65+
Type: SHT_NOBITS
66+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
67+
Address: 0x401000
68+
AddressAlign: 0x10
69+
Offset: 0x1000
70+
Size: 0x64
71+
- Name: .rodata
72+
Type: SHT_NOBITS
73+
Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
74+
Address: 0x402000
75+
AddressAlign: 0x1
76+
EntSize: 0x1
77+
Size: 0x1
78+
- Name: .eh_frame
79+
Type: SHT_NOBITS
80+
Flags: [ SHF_ALLOC ]
81+
Address: 0x402008
82+
AddressAlign: 0x8
83+
Size: 0x54
84+
- Name: .data.rel.ro
85+
Type: SHT_NOBITS
86+
Flags: [ SHF_WRITE, SHF_ALLOC ]
87+
Address: 0x403FF8
88+
AddressAlign: 0x8
89+
Offset: 0x1FF8
90+
Size: 0x8
91+
- Name: .comment
92+
Type: SHT_PROGBITS
93+
Flags: [ SHF_MERGE, SHF_STRINGS ]
94+
AddressAlign: 0x1
95+
EntSize: 0x1
96+
Content: 46616365626F6F6B20636C616E672076657273696F6E2031352E302E302028676974406769746875622E636F6D3A6B6576696E667265692F6C6C766D2E67697420393336636262353533363366386363363236643061303336666138343065383737313335373264392900
97+
- Name: .debug_info
98+
Type: SHT_PROGBITS
99+
AddressAlign: 0x1
100+
Content: 9A000000050001080000000001001D0001080000000000000002016400000008000000022D000000004C02A1000339000000043D0000000100050306010604080707012800000001560500447E0000000802917C0800447E00000008029170090044820000000009023400000001560700480A02770809004C9100000000050605040B870000000B8C0000000C390000000387000000043D000000010000
101+
- Name: .debug_abbrev
102+
Type: SHT_PROGBITS
103+
AddressAlign: 0x1
104+
Content: 011101252513050325721710171B25111B12067317000002340049133A0B3B0B02180000030101491300000421004913370B000005240003253E0B0B0B000006240003250B0B3E0B0000072E01111B1206401803253A0B3B0B271949133F190000080500021803253A0B3B0B49130000092E01111B1206401803253A0B3B0B27193F1900000A3400021803253A0B3B0B491300000B0F00491300000C26004913000000
105+
- Name: .debug_line
106+
Type: SHT_PROGBITS
107+
AddressAlign: 0x1
108+
Content: 7B0000000500080037000000010101FB0E0D00010101010000000100000101011F010000000003011F020F051E013D000000004F0B089C0626CBD8AB443134CFE6DD950400000902001040000000000003C30001050B0AAD0510063C05183C0526E405153C05030B3C050006A1050F0ABE050BBB0503065806770210000101
109+
- Name: .debug_line_str
110+
Type: SHT_PROGBITS
111+
Flags: [ SHF_MERGE, SHF_STRINGS ]
112+
AddressAlign: 0x1
113+
EntSize: 0x1
114+
Content: 2F686F6D652F667265696B2F6C6C766D2D73616E642F6C6C766D2F6C6C64622F746573742F5368656C6C2F4465627567696E666F642F496E70757473006D61696E2E6300
115+
- Name: .debug_str_offsets
116+
Type: SHT_PROGBITS
117+
AddressAlign: 0x1
118+
Content: 2C00000005000000000000006B00000072000000AF000000B4000000C8000000CD000000D1000000D8000000DD000000
119+
Symbols:
120+
- Name: .note.gnu.build-id
121+
Type: STT_SECTION
122+
Section: .note.gnu.build-id
123+
Value: 0x4001C8
124+
- Name: .text
125+
Type: STT_SECTION
126+
Section: .text
127+
Value: 0x401000
128+
- Name: .rodata
129+
Type: STT_SECTION
130+
Section: .rodata
131+
Value: 0x402000
132+
- Name: .eh_frame
133+
Type: STT_SECTION
134+
Section: .eh_frame
135+
Value: 0x402008
136+
- Name: .data.rel.ro
137+
Type: STT_SECTION
138+
Section: .data.rel.ro
139+
Value: 0x403FF8
140+
- Name: .comment
141+
Type: STT_SECTION
142+
Section: .comment
143+
- Name: .debug_info
144+
Type: STT_SECTION
145+
Section: .debug_info
146+
- Name: .debug_abbrev
147+
Type: STT_SECTION
148+
Section: .debug_abbrev
149+
- Name: .debug_line
150+
Type: STT_SECTION
151+
Section: .debug_line
152+
- Name: .debug_str
153+
Type: STT_SECTION
154+
Section: .debug_str
155+
- Name: .debug_addr
156+
Type: STT_SECTION
157+
Section: .debug_addr
158+
- Name: .debug_line_str
159+
Type: STT_SECTION
160+
Section: .debug_line_str
161+
- Name: .debug_str_offsets
162+
Type: STT_SECTION
163+
Section: .debug_str_offsets
164+
- Name: main.c
165+
Type: STT_FILE
166+
Index: SHN_ABS
167+
- Name: _start
168+
Type: STT_FUNC
169+
Section: .text
170+
Binding: STB_GLOBAL
171+
Value: 0x401030
172+
Size: 0x34
173+
- Name: __bss_start
174+
Section: .data.rel.ro
175+
Binding: STB_GLOBAL
176+
Value: 0x404000
177+
- Name: func
178+
Type: STT_FUNC
179+
Section: .text
180+
Binding: STB_GLOBAL
181+
Value: 0x401000
182+
Size: 0x28
183+
- Name: _edata
184+
Section: .data.rel.ro
185+
Binding: STB_GLOBAL
186+
Value: 0x404000
187+
- Name: _end
188+
Section: .data.rel.ro
189+
Binding: STB_GLOBAL
190+
Value: 0x404000
191+
DWARF:
192+
debug_str:
193+
- 'Facebook clang version 15.0.0 ([email protected]:kevinfrei/llvm.git 936cbb55363f8cc626d0a036fa840e87713572d9)'
194+
- main.c
195+
- '/home/freik/llvm-sand/llvm/lldb/test/Shell/Debuginfod/Inputs'
196+
- char
197+
- __ARRAY_SIZE_TYPE__
198+
- func
199+
- int
200+
- _start
201+
- argc
202+
- argv
203+
debug_addr:
204+
- Length: 0x1C
205+
Version: 0x5
206+
AddressSize: 0x8
207+
Entries:
208+
- Address: 0x402000
209+
- Address: 0x401000
210+
- Address: 0x401030
211+
...
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_REL
6+
Machine: EM_X86_64
7+
SectionHeaderStringTable: .strtab
8+
Sections:
9+
- Name: .debug_abbrev.dwo
10+
Type: SHT_PROGBITS
11+
Flags: [ SHF_EXCLUDE ]
12+
AddressAlign: 0x1
13+
Content: 0111012525130503257625000002340049133A0B3B0B02180000030101491300000421004913370B000005240003253E0B0B0B000006240003250B0B3E0B0000072E01111B1206401803253A0B3B0B271949133F190000080500021803253A0B3B0B49130000092E015523401803253A0B3B0B27193F1900000A3400021803253A0B3B0B491300000B0F00491300000C26004913000000
14+
- Name: .debug_rnglists.dwo
15+
Type: SHT_PROGBITS
16+
Flags: [ SHF_EXCLUDE ]
17+
AddressAlign: 0x1
18+
Content: '1000000005000800010000000400000004306400'
19+
- Name: .debug_str.dwo
20+
Type: SHT_PROGBITS
21+
Flags: [ SHF_EXCLUDE, SHF_MERGE, SHF_STRINGS ]
22+
AddressAlign: 0x1
23+
EntSize: 0x1
24+
Content: 63686172005F5F41525241595F53495A455F545950455F5F0066756E6300696E74005F7374617274006172676300617267760046616365626F6F6B20636C616E672076657273696F6E2031352E302E302028676974406769746875622E636F6D3A6B6576696E667265692F6C6C766D2E676974203933366362623535333633663863633632366430613033366661383430653837373133353732643929006D61696E2E630067656E2F6D61696E2D73706C69742E64776F00
25+
- Name: .debug_str_offsets.dwo
26+
Type: SHT_PROGBITS
27+
Flags: [ SHF_EXCLUDE ]
28+
AddressAlign: 0x1
29+
Content: 2C000000050000000000000005000000190000001E00000022000000290000002E000000330000009E000000A5000000
30+
- Name: .debug_info.dwo
31+
Type: SHT_PROGBITS
32+
Flags: [ SHF_EXCLUDE ]
33+
AddressAlign: 0x1
34+
Content: 8D00000005000508000000008094E89A08DB62C101071D0008090224000000004C02A10003300000000434000000010005000601060108070701280000000156020044710000000802917C05004471000000080291700600447500000000090001560400480A02770806004C8400000000050305040B7A0000000B7F0000000C30000000037A0000000434000000010000
35+
- Name: .debug_cu_index
36+
Type: SHT_PROGBITS
37+
AddressAlign: 0x1
38+
Content: 050000000400000001000000020000008094E89A08DB62C100000000000000000100000000000000010000000300000006000000080000000000000000000000000000000000000091000000970000003000000014000000
39+
- Type: SectionHeaderTable
40+
Sections:
41+
- Name: .strtab
42+
- Name: .debug_abbrev.dwo
43+
- Name: .debug_rnglists.dwo
44+
- Name: .debug_str.dwo
45+
- Name: .debug_str_offsets.dwo
46+
- Name: .debug_info.dwo
47+
- Name: .debug_cu_index
48+
- Name: .symtab
49+
Symbols: []
50+
...

0 commit comments

Comments
 (0)