Author: Adrian Prantl Date: 2020-08-06T13:30:17-07:00 New Revision: 0fa520af6734c5f1fab80629337e3f08fd8770db
URL: https://github.com/llvm/llvm-project/commit/0fa520af6734c5f1fab80629337e3f08fd8770db DIFF: https://github.com/llvm/llvm-project/commit/0fa520af6734c5f1fab80629337e3f08fd8770db.diff LOG: Unify the code that updates the ArchSpec after finding a fat binary with how it is done for a lean binary In particular this affects how target create --arch is handled — it allowed us to override the deployment target (a useful feature for the expression evaluator), but the fat binary case didn't. rdar://problem/66024437 Differential Revision: https://reviews.llvm.org/D85049 (cherry picked from commit 470bdd3caaab0b6e0ffed4da304244be40b78668) Added: Modified: lldb/source/Target/TargetList.cpp lldb/test/API/macosx/universal/Makefile lldb/test/API/macosx/universal/TestUniversal.py Removed: ################################################################################ diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index 7e243e5ed338..d4d3740286b7 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -104,6 +104,15 @@ Status TargetList::CreateTargetInternal( } bool prefer_platform_arch = false; + auto update_platform_arch = [&](const ArchSpec &module_arch) { + // If the OS or vendor weren't specified, then adopt the module's + // architecture so that the platform matching can be more accurate. + if (!platform_arch.TripleOSWasSpecified() || + !platform_arch.TripleVendorWasSpecified()) { + prefer_platform_arch = true; + platform_arch = module_arch; + } + }; if (!user_exe_path.empty()) { ModuleSpec module_spec(FileSpec(user_exe_path, FileSpec::Style::native)); @@ -129,11 +138,7 @@ Status TargetList::CreateTargetInternal( // If the OS or vendor weren't specified, then adopt the module's // architecture so that the platform matching can be more // accurate. - if (!platform_arch.TripleOSWasSpecified() || - !platform_arch.TripleVendorWasSpecified()) { - prefer_platform_arch = true; - platform_arch = matching_module_spec.GetArchitecture(); - } + update_platform_arch(matching_module_spec.GetArchitecture()); } else { StreamString platform_arch_strm; StreamString module_arch_strm; @@ -155,16 +160,14 @@ Status TargetList::CreateTargetInternal( } } } else if (arch.IsValid()) { - // A (valid) architecture was specified. + // Fat binary. A (valid) architecture was specified. module_spec.GetArchitecture() = arch; if (module_specs.FindMatchingModuleSpec(module_spec, - matching_module_spec)) { - prefer_platform_arch = true; - platform_arch = matching_module_spec.GetArchitecture(); - } + matching_module_spec)) + update_platform_arch(matching_module_spec.GetArchitecture()); } else { - // No architecture specified, check if there is only one platform for - // all of the architectures. + // Fat binary. No architecture specified, check if there is + // only one platform for all of the architectures. PlatformSP host_platform_sp = Platform::GetHostPlatform(); std::vector<PlatformSP> platforms; for (size_t i = 0; i < num_specs; ++i) { @@ -251,7 +254,7 @@ Status TargetList::CreateTargetInternal( // If we have a valid architecture, make sure the current platform is // compatible with that architecture. if (!prefer_platform_arch && arch.IsValid()) { - if (!platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) { + if (!platform_sp->IsCompatibleArchitecture(arch, false, nullptr)) { platform_sp = Platform::GetPlatformForArchitecture(arch, &platform_arch); if (!is_dummy_target && platform_sp) debugger.GetPlatformList().SetSelectedPlatform(platform_sp); @@ -260,8 +263,7 @@ Status TargetList::CreateTargetInternal( // If "arch" isn't valid, yet "platform_arch" is, it means we have an // executable file with a single architecture which should be used. ArchSpec fixed_platform_arch; - if (!platform_sp->IsCompatibleArchitecture(platform_arch, false, - &fixed_platform_arch)) { + if (!platform_sp->IsCompatibleArchitecture(platform_arch, false, nullptr)) { platform_sp = Platform::GetPlatformForArchitecture(platform_arch, &fixed_platform_arch); if (!is_dummy_target && platform_sp) diff --git a/lldb/test/API/macosx/universal/Makefile b/lldb/test/API/macosx/universal/Makefile index a6926557015d..8712fdecf566 100644 --- a/lldb/test/API/macosx/universal/Makefile +++ b/lldb/test/API/macosx/universal/Makefile @@ -8,13 +8,13 @@ testit: testit.x86_64h testit.x86_64 lipo -create -o testit $^ testit.x86_64h: testit.x86_64h.o - $(CC) -isysroot $(SDKROOT) -arch x86_64h -o testit.x86_64h $< + $(CC) -isysroot $(SDKROOT) -target x86_64h-apple-macosx10.9 -o testit.x86_64h $< testit.x86_64: testit.x86_64.o - $(CC) -isysroot $(SDKROOT) -arch x86_64 -o testit.x86_64 $< + $(CC) -isysroot $(SDKROOT) -target x86_64-apple-macosx10.9 -o testit.x86_64 $< testit.x86_64h.o: main.c - $(CC) -isysroot $(SDKROOT) -g -O0 -arch x86_64h -c -o testit.x86_64h.o $< + $(CC) -isysroot $(SDKROOT) -g -O0 -target x86_64h-apple-macosx10.9-apple-macosx10.9-apple-macosx10.9-apple-macosx10.9 -c -o testit.x86_64h.o $< testit.x86_64.o: main.c - $(CC) -isysroot $(SDKROOT) -g -O0 -arch x86_64 -c -o testit.x86_64.o $< + $(CC) -isysroot $(SDKROOT) -g -O0 -target x86_64-apple-macosx10.9 -c -o testit.x86_64.o $< diff --git a/lldb/test/API/macosx/universal/TestUniversal.py b/lldb/test/API/macosx/universal/TestUniversal.py index 94a056762a2c..e3ae675e1602 100644 --- a/lldb/test/API/macosx/universal/TestUniversal.py +++ b/lldb/test/API/macosx/universal/TestUniversal.py @@ -1,7 +1,3 @@ -"""Test aspects of lldb commands on universal binaries.""" - - - import unittest2 import os import lldb @@ -14,6 +10,7 @@ def haswellOrLater(): return "AVX2" in features.split() class UniversalTestCase(TestBase): + """Test aspects of lldb commands on universal binaries.""" NO_DEBUG_INFO_TESTCASE = True mydir = TestBase.compute_mydir(__file__) @@ -39,9 +36,10 @@ def test_sbdebugger_create_target_with_file_and_target_triple(self): # Create a target by the debugger. target = self.dbg.CreateTargetWithFileAndTargetTriple( - exe, "x86_64-apple-macosx") + exe, "x86_64-apple-macosx10.10") self.assertTrue(target, VALID_TARGET) - self.expect("image list -A -b", substrs=["x86_64 testit"]) + self.expect("image list -t -b", substrs=["x86_64-apple-macosx10.9.0 testit"]) + self.expect("target list", substrs=["testit", "arch=x86_64-apple-macosx10.10"]) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits