Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp +++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp @@ -148,11 +148,20 @@ uint32_t i; if (UpdateSDKDirectoryInfosIfNeeded()) { const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); - - // Check to see if the user specified a build string. If they did, then be - // sure to match it. std::vector check_sdk_info(num_sdk_infos, true); - ConstString build(m_sdk_build); + + // Prefer the user SDK build string. + ConstString build = GetSDKBuild(); + + // Fall back to the platform's build string. + if (!build) { + if (llvm::Optional os_build_str = GetOSBuildString()) { + build = ConstString(*os_build_str); + } + } + + // If we have a build string, only check platforms for which the build + // string matches. if (build) { for (i = 0; i < num_sdk_infos; ++i) check_sdk_info[i] = m_sdk_directory_infos[i].build == build; @@ -163,14 +172,14 @@ llvm::VersionTuple version = GetOSVersion(); if (!version.empty()) { if (UpdateSDKDirectoryInfosIfNeeded()) { - // First try for an exact match of major, minor and update + // First try for an exact match of major, minor and update. for (i = 0; i < num_sdk_infos; ++i) { if (check_sdk_info[i]) { if (m_sdk_directory_infos[i].version == version) return &m_sdk_directory_infos[i]; } } - // First try for an exact match of major and minor + // Try for an exact match of major and minor. for (i = 0; i < num_sdk_infos; ++i) { if (check_sdk_info[i]) { if (m_sdk_directory_infos[i].version.getMajor() == @@ -181,7 +190,7 @@ } } } - // Lastly try to match of major version only.. + // Lastly try to match of major version only. for (i = 0; i < num_sdk_infos; ++i) { if (check_sdk_info[i]) { if (m_sdk_directory_infos[i].version.getMajor() == @@ -192,7 +201,7 @@ } } } else if (build) { - // No version, just a build number, search for the first one that matches + // No version, just a build number, return the first one that matches. for (i = 0; i < num_sdk_infos; ++i) if (check_sdk_info[i]) return &m_sdk_directory_infos[i]; Index: lldb/test/API/macosx/rosetta/Makefile =================================================================== --- /dev/null +++ lldb/test/API/macosx/rosetta/Makefile @@ -0,0 +1,4 @@ +C_SOURCES := main.c +override ARCH = x86_64 + +include Makefile.rules Index: lldb/test/API/macosx/rosetta/TestRosetta.py =================================================================== --- /dev/null +++ lldb/test/API/macosx/rosetta/TestRosetta.py @@ -0,0 +1,36 @@ +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * + + +def apple_silicon(test): + return platform.system() == 'Darwin' and test.getArchitecture() in [ + 'arm64', 'arm64e' + ] + + +class TestRosetta(TestBase): + + NO_DEBUG_INFO_TESTCASE = True + + def no_apple_silicon(self): + if not apple_silicon(self): + return "Rosetta requires Apple Silicon" + return None + + @skipTestIfFn(no_apple_silicon) + def test_rosetta(self): + """There can be many tests in a test case - describe this test here.""" + self.build() + self.main_source_file = lldb.SBFileSpec("main.c") + + broadcaster = self.dbg.GetBroadcaster() + listener = lldbutil.start_listening_from( + broadcaster, lldb.SBDebugger.eBroadcastBitWarning) + + target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( + self, "Set a breakpoint here", self.main_source_file) + + event = lldb.SBEvent() + self.assertFalse(listener.GetNextEvent(event)) Index: lldb/test/API/macosx/rosetta/main.c =================================================================== --- /dev/null +++ lldb/test/API/macosx/rosetta/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + int i = 0; // Set a breakpoint here + return i; +}