Skip to content

Commit 82d134f

Browse files
author
Kevin Frei
committed
Reapply "DebugInfoD tests + fixing issues exposed by tests (llvm#85693)"
This reverts commit 7fc2fbb.
1 parent 790db0c commit 82d134f

File tree

10 files changed

+144
-22
lines changed

10 files changed

+144
-22
lines changed

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
5151
#
5252
# GNUWin32 uname gives "windows32" or "server version windows32" while
5353
# some versions of MSYS uname return "MSYS_NT*", but most environments
54-
# standardize on "Windows_NT", so we'll make it consistent here.
54+
# standardize on "Windows_NT", so we'll make it consistent here.
5555
# When running tests from Visual Studio, the environment variable isn't
5656
# inherited all the way down to the process spawned for make.
5757
#----------------------------------------------------------------------
@@ -210,6 +210,12 @@ else
210210
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
211211
DSYM = $(EXE).debug
212212
endif
213+
214+
ifeq "$(MAKE_DWP)" "YES"
215+
MAKE_DWO := YES
216+
DWP_NAME = $(EXE).dwp
217+
DYLIB_DWP_NAME = $(DYLIB_NAME).dwp
218+
endif
213219
endif
214220

215221
LIMIT_DEBUG_INFO_FLAGS =
@@ -358,6 +364,7 @@ ifneq "$(OS)" "Darwin"
358364

359365
OBJCOPY ?= $(call replace_cc_with,objcopy)
360366
ARCHIVER ?= $(call replace_cc_with,ar)
367+
DWP ?= $(call replace_cc_with,dwp)
361368
override AR = $(ARCHIVER)
362369
endif
363370

@@ -528,6 +535,10 @@ ifneq "$(CXX)" ""
528535
endif
529536
endif
530537

538+
ifeq "$(GEN_GNU_BUILD_ID)" "YES"
539+
LDFLAGS += -Wl,--build-id
540+
endif
541+
531542
#----------------------------------------------------------------------
532543
# DYLIB_ONLY variable can be used to skip the building of a.out.
533544
# See the sections below regarding dSYM file as well as the building of
@@ -566,11 +577,25 @@ else
566577
endif
567578
else
568579
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
580+
ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
581+
cp "$(EXE)" "$(EXE).unstriped""
582+
endif
569583
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
570584
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
571585
endif
586+
ifeq "$(MAKE_DWP)" "YES"
587+
$(DWP) -o "$(DWP_NAME)" $(DWOS)
588+
endif
572589
endif
573590

591+
592+
#----------------------------------------------------------------------
593+
# Support emitting the content of the GNU build-id into a file
594+
# This needs to be used in conjunction with GEN_GNU_BUILD_ID := YES
595+
#----------------------------------------------------------------------
596+
$(EXE).uuid : $(EXE)
597+
$(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
598+
574599
#----------------------------------------------------------------------
575600
# Make the dylib
576601
#----------------------------------------------------------------------
@@ -611,9 +636,15 @@ endif
611636
else
612637
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
613638
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
639+
ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
640+
cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).unstripped"
641+
endif
614642
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
615643
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
616644
endif
645+
ifeq "$(MAKE_DWP)" "YES"
646+
$(DWP) -o $(DYLIB_DWP_FILE) $(DYLIB_DWOS)
647+
endif
617648
endif
618649

619650
#----------------------------------------------------------------------

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,26 +4299,38 @@ const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
42994299
FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
43004300
ModuleSpec module_spec;
43014301
module_spec.GetFileSpec() = m_objfile_sp->GetFileSpec();
4302+
FileSpec dwp_filespec;
43024303
for (const auto &symfile : symfiles.files()) {
43034304
module_spec.GetSymbolFileSpec() =
43044305
FileSpec(symfile.GetPath() + ".dwp", symfile.GetPathStyle());
43054306
LLDB_LOG(log, "Searching for DWP using: \"{0}\"",
43064307
module_spec.GetSymbolFileSpec());
4307-
FileSpec dwp_filespec =
4308+
dwp_filespec =
43084309
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
43094310
if (FileSystem::Instance().Exists(dwp_filespec)) {
4310-
LLDB_LOG(log, "Found DWP file: \"{0}\"", dwp_filespec);
4311-
DataBufferSP dwp_file_data_sp;
4312-
lldb::offset_t dwp_file_data_offset = 0;
4313-
ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
4314-
GetObjectFile()->GetModule(), &dwp_filespec, 0,
4315-
FileSystem::Instance().GetByteSize(dwp_filespec), dwp_file_data_sp,
4316-
dwp_file_data_offset);
4317-
if (dwp_obj_file) {
4318-
m_dwp_symfile = std::make_shared<SymbolFileDWARFDwo>(
4319-
*this, dwp_obj_file, DIERef::k_file_index_mask);
4320-
break;
4321-
}
4311+
break;
4312+
}
4313+
}
4314+
if (!FileSystem::Instance().Exists(dwp_filespec)) {
4315+
LLDB_LOG(log, "No DWP file found locally");
4316+
// Fill in the UUID for the module we're trying to match for, so we can
4317+
// find the correct DWP file, as the Debuginfod plugin uses *only* this
4318+
// data to correctly match the DWP file with the binary.
4319+
module_spec.GetUUID() = m_objfile_sp->GetUUID();
4320+
dwp_filespec =
4321+
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
4322+
}
4323+
if (FileSystem::Instance().Exists(dwp_filespec)) {
4324+
LLDB_LOG(log, "Found DWP file: \"{0}\"", dwp_filespec);
4325+
DataBufferSP dwp_file_data_sp;
4326+
lldb::offset_t dwp_file_data_offset = 0;
4327+
ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
4328+
GetObjectFile()->GetModule(), &dwp_filespec, 0,
4329+
FileSystem::Instance().GetByteSize(dwp_filespec), dwp_file_data_sp,
4330+
dwp_file_data_offset);
4331+
if (dwp_obj_file) {
4332+
m_dwp_symfile = std::make_shared<SymbolFileDWARFDwo>(
4333+
*this, dwp_obj_file, DIERef::k_file_index_mask);
43224334
}
43234335
}
43244336
if (!m_dwp_symfile) {

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: the first symbol locator prevents further searching.
2+
# For DWARF binaries that are both stripped and split, the Default plugin
3+
# will return the stripped binary when asked for the ObjectFile, which then
4+
# prevents 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/SymbolVendor/ELF/SymbolVendorELF.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ static bool IsDwpSymbolFile(const lldb::ModuleSP &module_sp,
5555
dwp_file_data_sp, dwp_file_data_offset);
5656
// The presence of a debug_cu_index section is the key identifying feature of
5757
// a DWP file. Make sure we don't fill in the section list on dwp_obj_file
58-
// (by calling GetSectionList(false)) as this is invoked before we may have
59-
// all the symbol files collected and available.
58+
// (by calling GetSectionList(false)) as this function could be called before
59+
// we may have all the symbol files collected and available.
6060
return dwp_obj_file && ObjectFileELF::classof(dwp_obj_file.get()) &&
6161
dwp_obj_file->GetSectionList(false)->FindSectionByType(
6262
eSectionTypeDWARFDebugCuIndex, false);
@@ -105,8 +105,15 @@ SymbolVendorELF::CreateInstance(const lldb::ModuleSP &module_sp,
105105
FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
106106
FileSpec dsym_fspec =
107107
PluginManager::LocateExecutableSymbolFile(module_spec, search_paths);
108-
if (!dsym_fspec)
109-
return nullptr;
108+
if (!dsym_fspec || IsDwpSymbolFile(module_sp, dsym_fspec)) {
109+
// If we have a stripped binary or if we got a DWP file, we should prefer
110+
// symbols in the executable acquired through a plugin.
111+
ModuleSpec unstripped_spec =
112+
PluginManager::LocateExecutableObjectFile(module_spec);
113+
if (!unstripped_spec)
114+
return nullptr;
115+
dsym_fspec = unstripped_spec.GetFileSpec();
116+
}
110117

111118
DataBufferSP dsym_file_data_sp;
112119
lldb::offset_t dsym_file_data_offset = 0;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
C_SOURCES := main.c
2+
3+
# For normal (non DWP) Debuginfod tests, we need:
4+
5+
# * The "full" binary: a.out.debug
6+
# Produced by Makefile.rules with KEEP_FULL_DEBUG_BINARY set to YES and
7+
# SPLIT_DEBUG_SYMBOLS set to YES
8+
9+
# * The stripped binary (a.out)
10+
# Produced by Makefile.rules with SPLIT_DEBUG_SYMBOLS set to YES
11+
12+
# * The 'only-keep-debug' binary (a.out.dbg)
13+
# Produced below
14+
15+
# * The .uuid file (for a little easier testing code)
16+
# Produced below
17+
18+
# Don't strip the debug info from a.out:
19+
SPLIT_DEBUG_SYMBOLS := YES
20+
SAVE_FULL_DEBUG_BINARY := YES
21+
GEN_GNU_BUILD_ID := YES
22+
23+
all: a.out.uuid a.out
24+
25+
include Makefile.rules

lldb/test/API/debuginfod/Normal/TestDebuginfod.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def test_debuginfod_symbols(self):
6363
Test behavior with the full binary available from Debuginfod as
6464
'debuginfo' from the plug-in.
6565
"""
66-
test_root = self.config_test(["a.out"], "a.out.full")
66+
test_root = self.config_test(["a.out"], "a.out.unstripped")
6767
self.try_breakpoint(True)
6868

6969
def test_debuginfod_executable(self):
7070
"""
7171
Test behavior with the full binary available from Debuginfod as
7272
'executable' from the plug-in.
7373
"""
74-
test_root = self.config_test(["a.out"], None, "a.out.full")
74+
test_root = self.config_test(["a.out"], None, "a.out.unstripped")
7575
self.try_breakpoint(True)
7676

7777
def test_debuginfod_okd_symbols(self):
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This is a dump little pair of test files
2+
3+
int func(int argc, const char *argv[]) {
4+
return (argc + 1) * (argv[argc][0] + 2);
5+
}
6+
7+
int main(int argc, const char *argv[]) { return func(0, argv); }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
C_SOURCES := main.c
2+
3+
# For split-dwarf Debuginfod tests, we need:
4+
5+
# * A .DWP file (a.out.dwp)
6+
# Produced by Makefile.rules with MAKE_DWO and MERGE_DWOS both set to YES
7+
8+
# * The "full" binary: it's missing things that live in .dwo's (a.out.debug)
9+
# Produced by Makefile.rules with KEEP_FULL_DEBUG_BINARY set to YES and
10+
# SPLIT_DEBUG_SYMBOLS set to YES
11+
12+
# * The stripped binary (a.out)
13+
# Produced by Makefile.rules
14+
15+
# * The 'only-keep-debug' binary (a.out.dbg)
16+
# Produced below
17+
18+
# * The .uuid file (for a little easier testing code)
19+
# Produced here in the rule below
20+
21+
MAKE_DWP := YES
22+
SPLIT_DEBUG_SYMBOLS := YES
23+
SAVE_FULL_DEBUG_BINARY := YES
24+
GEN_GNU_BUILD_ID := YES
25+
26+
all: a.out.uuid a.out
27+
28+
include Makefile.rules

lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_debuginfod_both_symfiles_from_service(self):
8080
Test behavior with a stripped binary, with the unstripped binary and
8181
dwp symbols from Debuginfod.
8282
"""
83-
self.config_test(["a.out"], "a.out.dwp", "a.out.full")
83+
self.config_test(["a.out"], "a.out.dwp", "a.out.unstripped")
8484
self.try_breakpoint(True)
8585

8686
def test_debuginfod_both_okd_symfiles_from_service(self):
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This is a dump little pair of test files
2+
3+
int func(int argc, const char *argv[]) {
4+
return (argc + 1) * (argv[argc][0] + 2);
5+
}
6+
7+
int main(int argc, const char *argv[]) { return func(0, argv); }

0 commit comments

Comments
 (0)