Index: packages/Python/lldbsuite/test/linux/add-symbols/Makefile =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/linux/add-symbols/Makefile @@ -0,0 +1,8 @@ +all: clean + mkdir debug_binaries + $(CC) -g main.c + cp a.out debug_binaries + strip --strip-debug --remove-section=.note.gnu.build-id a.out + +clean: + rm -rf a.out debug_binaries Index: packages/Python/lldbsuite/test/linux/add-symbols/TestTargetSymbolsAddCommand.py =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/linux/add-symbols/TestTargetSymbolsAddCommand.py @@ -0,0 +1,52 @@ +""" Testing explicit symbol loading via target symbols add. """ +import os +import time +import lldb +import sys +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TargetSymbolsAddCommand(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + self.source = 'main.c' + + @no_debug_info_test # Prevent the genaration of the dwarf version of this test + @skipUnlessPlatform(['linux']) + def test_target_symbols_add(self): + """Test that 'target symbols add' can load the symbols + even if gnu.build-id and gnu_debuglink are not present in the module. + Similar to test_add_dsym_mid_execution test for macos.""" + self.build(clean=True) + exe = os.path.join(os.getcwd(), "a.out") + + self.target = self.dbg.CreateTarget(exe) + self.assertTrue(self.target, VALID_TARGET) + + main_bp = self.target.BreakpointCreateByName("main", "a.out") + self.assertTrue(main_bp, VALID_BREAKPOINT) + + self.process = self.target.LaunchSimple( + None, None, self.get_process_working_directory()) + self.assertTrue(self.process, PROCESS_IS_VALID) + + # The stop reason of the thread should be breakpoint. + self.assertTrue(self.process.GetState() == lldb.eStateStopped, + STOPPED_DUE_TO_BREAKPOINT) + + exe_module = self.target.GetModuleAtIndex(0) + uuid = exe_module.GetUUIDString() + + # Check that symbols are not loaded and main.c is not know to be + # the source file. + self.expect("frame select", substrs=['main.c'], matching=False) + + self.runCmd("target symbols add -u %s -s debug_binaries/a.out" % uuid) + + # Check that symbols are now loaded and main.c is in the output. + self.expect("frame select", substrs=['main.c']) Index: packages/Python/lldbsuite/test/linux/add-symbols/main.c =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/linux/add-symbols/main.c @@ -0,0 +1,6 @@ +#include +static int var = 5; +int main() { + printf("%p is %d\n", &var, var); + return ++var; +} Index: source/Commands/CommandObjectTarget.cpp =================================================================== --- source/Commands/CommandObjectTarget.cpp +++ source/Commands/CommandObjectTarget.cpp @@ -4236,26 +4236,30 @@ error_set = true; } } else { - if (uuid_option_set) { - module_spec.GetUUID() = - m_uuid_option_group.GetOptionValue().GetCurrentValue(); - success |= module_spec.GetUUID().IsValid(); - } else if (file_option_set) { + if (file_option_set) { module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue(); - ModuleSP module_sp( - target->GetImages().FindFirstModule(module_spec)); - if (module_sp) { - module_spec.GetFileSpec() = module_sp->GetFileSpec(); - module_spec.GetPlatformFileSpec() = - module_sp->GetPlatformFileSpec(); - module_spec.GetUUID() = module_sp->GetUUID(); - module_spec.GetArchitecture() = module_sp->GetArchitecture(); - } else { + if (uuid_option_set) { + module_spec.GetUUID() = + m_uuid_option_group.GetOptionValue().GetCurrentValue(); module_spec.GetArchitecture() = target->GetArchitecture(); + } else { + ModuleSP module_sp( + target->GetImages().FindFirstModule(module_spec)); + if (module_sp) { + module_spec.GetFileSpec() = module_sp->GetFileSpec(); + module_spec.GetPlatformFileSpec() = + module_sp->GetPlatformFileSpec(); + module_spec.GetUUID() = module_sp->GetUUID(); + module_spec.GetArchitecture() = module_sp->GetArchitecture(); + } } success |= module_spec.GetUUID().IsValid() || module_spec.GetFileSpec().Exists(); + } else if (uuid_option_set) { + module_spec.GetUUID() = + m_uuid_option_group.GetOptionValue().GetCurrentValue(); + success |= module_spec.GetUUID().IsValid(); } } Index: source/Host/common/Symbols.cpp =================================================================== --- source/Host/common/Symbols.cpp +++ source/Host/common/Symbols.cpp @@ -308,8 +308,12 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec, bool force_lookup) { - // Fill in the module_spec.GetFileSpec() for the object file and/or the - // module_spec.GetSymbolFileSpec() for the debug symbols file. + // Unlike on Apple there is no smart way to download symbol files. + // Simply try using module file spec if it is specified and exists. + if (module_spec.GetFileSpec() && module_spec.GetFileSpec().Exists()) { + module_spec.GetSymbolFileSpec() = module_spec.GetFileSpec(); + return true; + } return false; }