Index: lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp =================================================================== --- lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -107,24 +107,24 @@ } } else { if (m_remote_platform_sp) { - error = - GetCachedExecutable(resolved_module_spec, exe_module_sp, - module_search_paths_ptr, *m_remote_platform_sp); - } else { - // We may connect to a process and use the provided executable (Don't use - // local $PATH). + return GetCachedExecutable(resolved_module_spec, exe_module_sp, + module_search_paths_ptr, + *m_remote_platform_sp); + } - // Resolve any executable within a bundle on MacOSX - Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); + // We may connect to a process and use the provided executable (Don't use + // local $PATH). - if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) - error.Clear(); - else - error.SetErrorStringWithFormat("the platform is not currently " - "connected, and '%s' doesn't exist in " - "the system root.", - exe_path); - } + // Resolve any executable within a bundle on MacOSX + Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec()); + + if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) + error.Clear(); + else + error.SetErrorStringWithFormat("the platform is not currently " + "connected, and '%s' doesn't exist in " + "the system root.", + exe_path); } if (error.Success()) { @@ -133,8 +133,8 @@ module_search_paths_ptr, nullptr, nullptr); if (error.Fail()) { // If we failed, it may be because the vendor and os aren't known. If - // that is the case, try setting them to the host architecture and give - // it another try. + // that is the case, try setting them to the host architecture and give + // it another try. llvm::Triple &module_triple = resolved_module_spec.GetArchitecture().GetTriple(); bool is_vendor_specified = Index: lldb/source/Target/TargetList.cpp =================================================================== --- lldb/source/Target/TargetList.cpp +++ lldb/source/Target/TargetList.cpp @@ -398,6 +398,8 @@ if (user_exe_path_is_bundle) exe_module_sp->GetFileSpec().GetPath(resolved_bundle_exe_path, sizeof(resolved_bundle_exe_path)); + if (target_sp->GetPreloadSymbols()) + exe_module_sp->PreloadSymbols(); } } else { // No file was specified, just create an empty target with any arch if a Index: lldb/unittests/Platform/CMakeLists.txt =================================================================== --- lldb/unittests/Platform/CMakeLists.txt +++ lldb/unittests/Platform/CMakeLists.txt @@ -1,8 +1,2 @@ -add_lldb_unittest(LLDBPlatformTests - PlatformDarwinTest.cpp - - LINK_LIBS - lldbPluginPlatformMacOSX - LINK_COMPONENTS - Support - ) +add_subdirectory(Darwin) +add_subdirectory(POSIX) \ No newline at end of file Index: lldb/unittests/Platform/Darwin/CMakeLists.txt =================================================================== --- /dev/null +++ lldb/unittests/Platform/Darwin/CMakeLists.txt @@ -0,0 +1,8 @@ +add_lldb_unittest(LLDBPlatformTests + PlatformDarwinTest.cpp + + LINK_LIBS + lldbPluginPlatformMacOSX + LINK_COMPONENTS + Support + ) \ No newline at end of file Index: lldb/unittests/Platform/POSIX/CMakeLists.txt =================================================================== --- /dev/null +++ lldb/unittests/Platform/POSIX/CMakeLists.txt @@ -0,0 +1,14 @@ +include_directories(${LLDB_SOURCE_DIR}/source/Plugins/Platform/POSIX) +include_directories(${LLDB_SOURCE_DIR}/source/lldb/Target) + +add_lldb_unittest(PlatformPOSIXTest + PlatformPOSIXTest.cpp + + LINK_LIBS + lldbPluginPlatformPOSIX + lldbCore + lldbTarget + lldbSymbol + LINK_COMPONENTS + Support + ) \ No newline at end of file Index: lldb/unittests/Platform/POSIX/PlatformPOSIXTest.cpp =================================================================== --- /dev/null +++ lldb/unittests/Platform/POSIX/PlatformPOSIXTest.cpp @@ -0,0 +1,103 @@ +//===-- PlatformPOSIXTest.cpp +//--------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" + +#include "Plugins/Platform/POSIX/PlatformPOSIX.h" +#include "lldb/Core/Module.h" +#include "lldb/Core/ModuleSpec.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Target/Platform.h" + +using namespace lldb_private; +using namespace lldb; +using namespace testing; + +class PlatformPOSIXTester : public PlatformPOSIX { +public: + PlatformPOSIXTester(bool is_host) : PlatformPOSIX(is_host) {} + + const char *GetDescription() override { return ""; } + + uint32_t GetPluginVersion() override { return 1; } + + ConstString GetPluginName() override { return ConstString(); } + + bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override { + return false; + } + + void SetRemotePlatform(lldb::PlatformSP platform) { + m_remote_platform_sp = platform; + } +}; + +class TargetPlatformTester : public Platform { +public: + TargetPlatformTester(ModuleSP executable) : Platform(true) { + m_executable = executable; + } + + const char *GetDescription() override { return ""; } + + uint32_t GetPluginVersion() override { return 1; } + + ConstString GetPluginName() override { return ConstString(); } + + bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override { + return false; + } + + UserIDResolver &GetUserIDResolver() override { + return UserIDResolver::GetNoopResolver(); + } + + lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, + Target *target, Status &error) override { + return nullptr; + } + + void CalculateTrapHandlerSymbolNames() override {} + + Status + ResolveExecutable(const ModuleSpec &module_spec, + lldb::ModuleSP &exe_module_sp, + const FileSpecList *module_search_paths_ptr) override { + exe_module_sp = m_executable; + return Status(); + } + +private: + ModuleSP m_executable; +}; + +namespace { +class PlatformPOSIXTest : public testing::Test { +public: + static void SetUpTestCase() { FileSystem::Initialize(); } + static void TearDownTestCase() { FileSystem::Terminate(); } +}; +} // namespace + +TEST_F(PlatformPOSIXTest, TestResolveExecutabelOnClientByPlatform) { + PlatformPOSIXTester platform(false); + + ModuleSpec executable_spec; + ModuleSP expected_executable(new Module(executable_spec)); + + lldb::PlatformSP platform_sp(new TargetPlatformTester(expected_executable)); + platform.SetRemotePlatform(platform_sp); + + ModuleSP resolved_sp; + lldb_private::Status status = + platform.ResolveExecutable(executable_spec, resolved_sp, nullptr); + + ASSERT_TRUE(status.Success()); + EXPECT_EQ(expected_executable.get(), resolved_sp.get()); +}