2022-01-26 20:40:24 +01:00
|
|
|
"""Test the SBDModule APIs."""
|
|
|
|
|
|
|
|
|
|
import lldb
|
|
|
|
|
from lldbsuite.test.decorators import *
|
|
|
|
|
from lldbsuite.test.lldbtest import *
|
|
|
|
|
from lldbsuite.test import lldbutil
|
|
|
|
|
|
|
|
|
|
import os, signal, subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SBModuleAPICase(TestBase):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
TestBase.setUp(self)
|
|
|
|
|
self.background_pid = None
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
TestBase.tearDown(self)
|
|
|
|
|
if self.background_pid:
|
|
|
|
|
os.kill(self.background_pid, signal.SIGKILL)
|
|
|
|
|
|
2025-08-19 14:24:10 -07:00
|
|
|
@skipIfRemote
|
|
|
|
|
def test_GetObjectName(self):
|
|
|
|
|
"""Test the SBModule::GetObjectName() method"""
|
|
|
|
|
self.build()
|
|
|
|
|
exe = self.getBuildArtifact("a.out")
|
|
|
|
|
libfoo_path = self.getBuildArtifact("libfoo.a")
|
|
|
|
|
target_exe = self.dbg.CreateTarget(exe)
|
|
|
|
|
self.assertTrue(target_exe.IsValid(), "Target for a.out is valid")
|
|
|
|
|
|
|
|
|
|
# Test that the executable module has no object name (usually the first module in the target)
|
|
|
|
|
exe_module = target_exe.GetModuleAtIndex(0)
|
|
|
|
|
self.assertTrue(exe_module.IsValid(), "Executable module is valid")
|
|
|
|
|
self.assertIsNone(
|
|
|
|
|
exe_module.GetObjectName(), "a.out should have no object name"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# check archive member names
|
|
|
|
|
module_specs = lldb.SBModuleSpecList.GetModuleSpecifications(libfoo_path)
|
|
|
|
|
self.assertGreater(
|
|
|
|
|
module_specs.GetSize(), 0, "Archive should have at least one module spec"
|
|
|
|
|
)
|
|
|
|
|
found = set()
|
|
|
|
|
expected = {"a.o", "b.o"}
|
|
|
|
|
for i in range(module_specs.GetSize()):
|
|
|
|
|
spec = module_specs.GetSpecAtIndex(i)
|
|
|
|
|
obj_name = spec.GetObjectName()
|
|
|
|
|
self.assertIsInstance(obj_name, str)
|
|
|
|
|
self.assertIn(obj_name, expected, f"Unexpected object name: {obj_name}")
|
|
|
|
|
# create a module from the arhive using the sepc
|
|
|
|
|
module = lldb.SBModule(spec)
|
|
|
|
|
self.assertTrue(module.IsValid(), "Module is valid")
|
|
|
|
|
self.assertTrue(module.IsValid(), f"Module for {obj_name} is valid")
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
module.GetObjectName(), obj_name, f"Object name for {obj_name} matches"
|
|
|
|
|
)
|
|
|
|
|
found.add(obj_name)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(found, expected, "Did not find all expected archive members")
|
|
|
|
|
|
2022-01-27 01:05:12 +01:00
|
|
|
@skipUnlessDarwin
|
2022-04-08 10:36:16 -07:00
|
|
|
@skipIfRemote
|
2022-01-26 20:40:24 +01:00
|
|
|
def test_module_is_file_backed(self):
|
|
|
|
|
"""Test the SBModule::IsFileBacked() method"""
|
|
|
|
|
self.build()
|
|
|
|
|
target, _, _, _ = lldbutil.run_to_source_breakpoint(
|
|
|
|
|
self, "// break here", lldb.SBFileSpec("main.c")
|
2023-05-25 08:48:57 -07:00
|
|
|
)
|
2022-01-26 20:40:24 +01:00
|
|
|
|
|
|
|
|
self.assertGreater(target.GetNumModules(), 0)
|
|
|
|
|
main_module = target.GetModuleAtIndex(0)
|
|
|
|
|
self.assertEqual(main_module.GetFileSpec().GetFilename(), "a.out")
|
|
|
|
|
self.assertTrue(
|
|
|
|
|
main_module.IsFileBacked(), "The module should be backed by a file on disk"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.dbg.DeleteTarget(target)
|
|
|
|
|
self.assertEqual(self.dbg.GetNumTargets(), 0)
|
|
|
|
|
|
|
|
|
|
exe = self.getBuildArtifact("a.out")
|
|
|
|
|
background_process = subprocess.Popen([exe])
|
|
|
|
|
self.assertTrue(background_process, "process is not valid")
|
|
|
|
|
self.background_pid = background_process.pid
|
|
|
|
|
os.unlink(exe)
|
|
|
|
|
|
|
|
|
|
target = self.dbg.CreateTarget("")
|
|
|
|
|
self.assertEqual(self.dbg.GetNumTargets(), 1)
|
|
|
|
|
error = lldb.SBError()
|
|
|
|
|
process = target.AttachToProcessWithID(
|
|
|
|
|
self.dbg.GetListener(), self.background_pid, error
|
|
|
|
|
)
|
2022-01-27 01:04:38 +01:00
|
|
|
self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
|
Reland "[lldb] Use just-built libcxx for tests when available"
This commit improves upon cc0b5ebf7fc8, which added support for
specifying which libcxx to use when testing LLDB. That patch honored
requests by tests that had `USE_LIBCPP=1` defined in their makefiles.
Now, we also use a non-default libcxx if all conditions below are true:
1. The test is not explicitly requesting the use of libstdcpp
(USE_LIBSTDCPP=1).
2. The test is not explicitly requesting the use of the system's
library (USE_SYSTEM_STDLIB=1).
3. A path to libcxx was either provided by the user through CMake flags
or libcxx was built together with LLDB.
Condition (2) is new and introduced in this patch in order to support
tests that are either:
* Cross-platform (such as API/macosx/macCatalyst and
API/tools/lldb-server). The just-built libcxx is usually not built for
platforms other than the host's.
* Cross-language (such as API/lang/objc/exceptions). In this case, the
Objective C runtime throws an exceptions that always goes through the
system's libcxx, instead of the just built libcxx. Fixing this would
require either changing the install-name of the just built libcxx in Mac
systems, or tuning the DYLD_LIBRARY_PATH variable at runtime.
Some other tests exposes limitations of LLDB when running with a debug
standard library. TestDbgInfoContentForwardLists had an assertion
removed, as it was checking for buggy LLDB behavior (which now
crashes). TestFixIts had a variable renamed, as the old name clashes
with a standard library name when debug info is present. This is a known
issue: https://github.com/llvm/llvm-project/issues/34391.
For `TestSBModule`, the way the "main" module is found was changed to
look for the "a.out" module, instead of relying on the index being 0. In
some systems, the index 0 is dyld when a custom standard library is
used.
Differential Revision: https://reviews.llvm.org/D132940
2022-08-30 09:28:14 -04:00
|
|
|
main_module = target.FindModule(lldb.SBFileSpec("a.out"))
|
2024-02-21 13:02:30 -06:00
|
|
|
self.assertIsNotNone(main_module)
|
2022-01-26 20:40:24 +01:00
|
|
|
self.assertFalse(
|
|
|
|
|
main_module.IsFileBacked(),
|
|
|
|
|
"The module should not be backed by a file on disk.",
|
|
|
|
|
)
|
|
|
|
|
|
2022-01-27 01:04:38 +01:00
|
|
|
error = process.Destroy()
|
2022-02-11 21:23:16 -08:00
|
|
|
self.assertSuccess(
|
|
|
|
|
error, "couldn't destroy process %s" % background_process.pid
|
|
|
|
|
)
|