Skip to content

Revert "rdar://90360204" #4152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions lldb/include/lldb/Core/ModuleSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "lldb/Target/PathMappingList.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Iterable.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/UUID.h"

Expand Down Expand Up @@ -294,7 +293,7 @@ class ModuleSpecList {
if (this != &rhs) {
std::lock(m_mutex, rhs.m_mutex);
std::lock_guard<std::recursive_mutex> lhs_guard(m_mutex, std::adopt_lock);
std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex,
std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex,
std::adopt_lock);
m_specs = rhs.m_specs;
}
Expand Down Expand Up @@ -394,16 +393,8 @@ class ModuleSpecList {
}
}

typedef std::vector<ModuleSpec> collection;
typedef LockingAdaptedIterable<collection, ModuleSpec, vector_adapter,
std::recursive_mutex>
ModuleSpecIterable;

ModuleSpecIterable ModuleSpecs() {
return ModuleSpecIterable(m_specs, m_mutex);
}

protected:
typedef std::vector<ModuleSpec> collection; ///< The module collection type.
collection m_specs; ///< The collection of modules.
mutable std::recursive_mutex m_mutex;
};
Expand Down
35 changes: 7 additions & 28 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,6 @@ class Platform : public PluginInterface {
const ArchSpec &process_host_arch = {},
ArchSpec *platform_arch_ptr = nullptr);

/// Get the platform for the given list of architectures.
///
/// The algorithm works a follows:
///
/// 1. Returns the selected platform if it matches any of the architectures.
/// 2. Returns the host platform if it matches any of the architectures.
/// 3. Returns the platform that matches all the architectures.
///
/// If none of the above apply, this function returns a default platform. The
/// candidates output argument differentiates between either no platforms
/// supporting the given architecture or multiple platforms supporting the
/// given architecture.
static lldb::PlatformSP
GetPlatformForArchitectures(std::vector<ArchSpec> archs,
const ArchSpec &process_host_arch,
lldb::PlatformSP selected_platform_sp,
std::vector<lldb::PlatformSP> &candidates);

static const char *GetHostPlatformName();

static void SetHostPlatform(const lldb::PlatformSP &platform_sp);
Expand Down Expand Up @@ -238,7 +220,7 @@ class Platform : public PluginInterface {
bool GetOSKernelDescription(std::string &s);

// Returns the name of the platform
llvm::StringRef GetName() { return GetPluginName(); }
ConstString GetName();

virtual const char *GetHostname();

Expand Down Expand Up @@ -532,17 +514,17 @@ class Platform : public PluginInterface {

virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
uint64_t dst_len, Status &error) {
error.SetErrorStringWithFormatv(
"Platform::ReadFile() is not supported in the {0} platform",
GetPluginName());
error.SetErrorStringWithFormat(
"Platform::ReadFile() is not supported in the %s platform",
GetName().GetCString());
return -1;
}

virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset,
const void *src, uint64_t src_len, Status &error) {
error.SetErrorStringWithFormatv(
"Platform::WriteFile() is not supported in the {0} platform",
GetPluginName());
error.SetErrorStringWithFormat(
"Platform::WriteFile() is not supported in the %s platform",
GetName().GetCString());
return -1;
}

Expand Down Expand Up @@ -870,9 +852,6 @@ class Platform : public PluginInterface {
}

protected:
/// For unit testing purposes only.
static void Clear();

/// Create a list of ArchSpecs with the given OS and a architectures. The
/// vendor field is left as an "unspecified unknown".
static std::vector<ArchSpec>
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/API/SBPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ const char *SBPlatform::GetName() {

PlatformSP platform_sp(GetSP());
if (platform_sp)
return ConstString(platform_sp->GetName()).AsCString();
return platform_sp->GetName().GetCString();
return nullptr;
}

Expand Down
11 changes: 6 additions & 5 deletions lldb/source/Commands/CommandObjectPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,15 +1289,16 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
result.AppendErrorWithFormatv(
"no processes were found that {0} \"{1}\" on the \"{2}\" "
"platform\n",
match_desc, match_name, platform_sp->GetName());
match_desc, match_name, platform_sp->GetPluginName());
else
result.AppendErrorWithFormatv(
"no processes were found on the \"{0}\" platform\n",
platform_sp->GetName());
platform_sp->GetPluginName());
} else {
result.AppendMessageWithFormatv(
"{0} matching process{1} found on \"{2}\"", matches,
matches > 1 ? "es were" : " was", platform_sp->GetName());
result.AppendMessageWithFormat(
"%u matching process%s found on \"%s\"", matches,
matches > 1 ? "es were" : " was",
platform_sp->GetName().GetCString());
if (match_desc)
result.AppendMessageWithFormat(" whose name %s \"%s\"",
match_desc, match_name);
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ static void DumpTargetInfo(uint32_t target_idx, Target *target,
}
PlatformSP platform_sp(target->GetPlatform());
if (platform_sp)
strm.Format("{0}platform={1}", properties++ > 0 ? ", " : " ( ",
platform_sp->GetName());
strm.Printf("%splatform=%s", properties++ > 0 ? ", " : " ( ",
platform_sp->GetName().GetCString());

ProcessSP process_sp(target->GetProcessSP());
bool show_process_status = false;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Core/IOHandlerCursesGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ class ChoicesFieldDelegate : public FieldDelegate {
// Returns the index of the choice.
int GetChoice() { return m_choice; }

void SetChoice(llvm::StringRef choice) {
void SetChoice(const std::string &choice) {
for (int i = 0; i < GetNumberOfChoices(); i++) {
if (choice == m_choices[i]) {
m_choice = i;
Expand All @@ -1636,7 +1636,7 @@ class PlatformPluginFieldDelegate : public ChoicesFieldDelegate {
: ChoicesFieldDelegate("Platform Plugin", 3, GetPossiblePluginNames()) {
PlatformSP platform_sp = debugger.GetPlatformList().GetSelectedPlatform();
if (platform_sp)
SetChoice(platform_sp->GetPluginName());
SetChoice(platform_sp->GetName().AsCString());
}

std::vector<std::string> GetPossiblePluginNames() {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/OptionGroupPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool OptionGroupPlatform::PlatformMatches(
const lldb::PlatformSP &platform_sp) const {
if (platform_sp) {
if (!m_platform_name.empty()) {
if (platform_sp->GetName() != m_platform_name)
if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ static Status FindUnusedPort(uint16_t &port) {
return error;
}

PlatformAndroidRemoteGDBServer::PlatformAndroidRemoteGDBServer() = default;

PlatformAndroidRemoteGDBServer::~PlatformAndroidRemoteGDBServer() {
for (const auto &it : m_port_forwards)
DeleteForwardPortWithAdb(it.second, m_device_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace platform_android {
class PlatformAndroidRemoteGDBServer
: public platform_gdb_server::PlatformRemoteGDBServer {
public:
using PlatformRemoteGDBServer::PlatformRemoteGDBServer;
PlatformAndroidRemoteGDBServer();

~PlatformAndroidRemoteGDBServer() override;

Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
using namespace lldb;
using namespace lldb_private;

/// Default Constructor
PlatformDarwin::PlatformDarwin(bool is_host) : PlatformPOSIX(is_host) {}

/// Destructor.
///
/// The destructor is virtual since this class is designed to be
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class PlatformDarwin : public PlatformPOSIX {
public:
using PlatformPOSIX::PlatformPOSIX;
PlatformDarwin(bool is_host);

~PlatformDarwin() override;

Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2434,8 +2434,9 @@ Status ProcessGDBRemote::DoDestroy() {
m_public_state.GetValue() != eStateRunning) {
PlatformSP platform_sp = GetTarget().GetPlatform();

if (platform_sp && platform_sp->GetPluginName() ==
PlatformRemoteiOS::GetPluginNameStatic()) {
if (platform_sp && platform_sp->GetName() &&
platform_sp->GetName().GetStringRef() ==
PlatformRemoteiOS::GetPluginNameStatic()) {
if (m_destroy_tried_resuming) {
if (log)
log->PutCString("ProcessGDBRemote::DoDestroy() - Tried resuming to "
Expand Down
64 changes: 4 additions & 60 deletions lldb/source/Target/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StructuredData.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"

Expand Down Expand Up @@ -157,8 +156,6 @@ void Platform::Terminate() {
}
}

void Platform::Clear() { GetPlatformList().clear(); }

PlatformProperties &Platform::GetGlobalPlatformProperties() {
static PlatformProperties g_settings;
return g_settings;
Expand Down Expand Up @@ -283,7 +280,7 @@ PlatformSP Platform::Find(ConstString name) {

std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
for (const auto &platform_sp : GetPlatformList()) {
if (platform_sp->GetName() == name.GetStringRef())
if (platform_sp->GetName() == name)
return platform_sp;
}
}
Expand Down Expand Up @@ -789,6 +786,8 @@ Status Platform::SetFilePermissions(const FileSpec &file_spec,
}
}

ConstString Platform::GetName() { return ConstString(GetPluginName()); }

const char *Platform::GetHostname() {
if (IsHost())
return "127.0.0.1";
Expand Down Expand Up @@ -1232,61 +1231,6 @@ Platform::GetPlatformForArchitecture(const ArchSpec &arch,
return platform_sp;
}

lldb::PlatformSP Platform::GetPlatformForArchitectures(
std::vector<ArchSpec> archs, const ArchSpec &process_host_arch,
lldb::PlatformSP selected_platform_sp,
std::vector<lldb::PlatformSP> &candidates) {
candidates.clear();
candidates.reserve(archs.size());

if (archs.empty())
return nullptr;

PlatformSP host_platform_sp = Platform::GetHostPlatform();

// Prefer the selected platform if it matches at least one architecture.
if (selected_platform_sp) {
for (const ArchSpec &arch : archs) {
if (selected_platform_sp->IsCompatibleArchitecture(
arch, process_host_arch, false, nullptr))
return selected_platform_sp;
}
}

// Prefer the host platform if it matches at least one architecture.
if (host_platform_sp) {
for (const ArchSpec &arch : archs) {
if (host_platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
false, nullptr))
return host_platform_sp;
}
}

// Collect a list of candidate platforms for the architectures.
for (const ArchSpec &arch : archs) {
if (PlatformSP platform =
Platform::GetPlatformForArchitecture(arch, process_host_arch))
candidates.push_back(platform);
}

// The selected or host platform didn't match any of the architectures. If
// the same platform supports all architectures then that's the obvious next
// best thing.
if (candidates.size() == archs.size()) {
if (std::all_of(candidates.begin(), candidates.end(),
[&](const PlatformSP &p) -> bool {
return p->GetName() == candidates.front()->GetName();
})) {
return candidates.front();
}
}

// At this point we either have no platforms that match the given
// architectures or multiple platforms with no good way to disambiguate
// between them.
return nullptr;
}

std::vector<ArchSpec>
Platform::CreateArchList(llvm::ArrayRef<llvm::Triple::ArchType> archs,
llvm::Triple::OSType os) {
Expand Down Expand Up @@ -1815,7 +1759,7 @@ Status Platform::DownloadSymbolFile(const lldb::ModuleSP &module_sp,

FileSpec Platform::GetModuleCacheRoot() {
auto dir_spec = GetGlobalPlatformProperties().GetModuleCacheDirectory();
dir_spec.AppendPathComponent(GetPluginName());
dir_spec.AppendPathComponent(GetName().AsCString());
return dir_spec;
}

Expand Down
9 changes: 5 additions & 4 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3058,10 +3058,11 @@ void Process::CompleteAttach() {
if (platform_sp) {
GetTarget().SetPlatform(platform_sp);
GetTarget().SetArchitecture(platform_arch);
LLDB_LOG(log,
"switching platform to {0} and architecture to {1} based on "
"info from attach",
platform_sp->GetName(), platform_arch.GetTriple().getTriple());
LLDB_LOGF(log,
"Process::%s switching platform to %s and architecture "
"to %s based on info from attach",
__FUNCTION__, platform_sp->GetName().AsCString(""),
platform_arch.GetTriple().getTriple().c_str());
}
} else if (!process_arch.IsValid()) {
ProcessInstanceInfo process_info;
Expand Down
Loading