Skip to content

Commit d2edca6

Browse files
committed
[lldb/Platform] Prepare decouple instance and plugin names
This patch changes the return value of Platform::GetName() to a StringRef, and uses the opportunity (compile errors) to change some callsites to use GetPluginName() instead. The two methods still remain hardwired to return the same thing, but this will change once the ideas in <https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594> are implemented. Differential Revision: https://reviews.llvm.org/D119146
1 parent ea99870 commit d2edca6

File tree

14 files changed

+32
-42
lines changed

14 files changed

+32
-42
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class Platform : public PluginInterface {
217217
llvm::Optional<std::string> GetOSKernelDescription();
218218

219219
// Returns the name of the platform
220-
ConstString GetName();
220+
llvm::StringRef GetName() { return GetPluginName(); }
221221

222222
virtual const char *GetHostname();
223223

@@ -508,17 +508,17 @@ class Platform : public PluginInterface {
508508

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

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

lldb/source/API/SBPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ const char *SBPlatform::GetName() {
342342

343343
PlatformSP platform_sp(GetSP());
344344
if (platform_sp)
345-
return platform_sp->GetName().GetCString();
345+
return ConstString(platform_sp->GetName()).AsCString();
346346
return nullptr;
347347
}
348348

lldb/source/Commands/CommandObjectPlatform.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,16 +1281,15 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
12811281
result.AppendErrorWithFormatv(
12821282
"no processes were found that {0} \"{1}\" on the \"{2}\" "
12831283
"platform\n",
1284-
match_desc, match_name, platform_sp->GetPluginName());
1284+
match_desc, match_name, platform_sp->GetName());
12851285
else
12861286
result.AppendErrorWithFormatv(
12871287
"no processes were found on the \"{0}\" platform\n",
1288-
platform_sp->GetPluginName());
1288+
platform_sp->GetName());
12891289
} else {
1290-
result.AppendMessageWithFormat(
1291-
"%u matching process%s found on \"%s\"", matches,
1292-
matches > 1 ? "es were" : " was",
1293-
platform_sp->GetName().GetCString());
1290+
result.AppendMessageWithFormatv(
1291+
"{0} matching process{1} found on \"{2}\"", matches,
1292+
matches > 1 ? "es were" : " was", platform_sp->GetName());
12941293
if (match_desc)
12951294
result.AppendMessageWithFormat(" whose name %s \"%s\"",
12961295
match_desc, match_name);

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static void DumpTargetInfo(uint32_t target_idx, Target *target,
8484
}
8585
PlatformSP platform_sp(target->GetPlatform());
8686
if (platform_sp)
87-
strm.Printf("%splatform=%s", properties++ > 0 ? ", " : " ( ",
88-
platform_sp->GetName().GetCString());
87+
strm.Format("{0}platform={1}", properties++ > 0 ? ", " : " ( ",
88+
platform_sp->GetName());
8989

9090
ProcessSP process_sp(target->GetProcessSP());
9191
bool show_process_status = false;

lldb/source/Core/IOHandlerCursesGUI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ class ChoicesFieldDelegate : public FieldDelegate {
16091609
// Returns the index of the choice.
16101610
int GetChoice() { return m_choice; }
16111611

1612-
void SetChoice(const std::string &choice) {
1612+
void SetChoice(llvm::StringRef choice) {
16131613
for (int i = 0; i < GetNumberOfChoices(); i++) {
16141614
if (choice == m_choices[i]) {
16151615
m_choice = i;
@@ -1634,7 +1634,7 @@ class PlatformPluginFieldDelegate : public ChoicesFieldDelegate {
16341634
: ChoicesFieldDelegate("Platform Plugin", 3, GetPossiblePluginNames()) {
16351635
PlatformSP platform_sp = debugger.GetPlatformList().GetSelectedPlatform();
16361636
if (platform_sp)
1637-
SetChoice(platform_sp->GetName().AsCString());
1637+
SetChoice(platform_sp->GetPluginName());
16381638
}
16391639

16401640
std::vector<std::string> GetPossiblePluginNames() {

lldb/source/Interpreter/OptionGroupPlatform.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
2525
if (platform_sp) {
2626
if (platform_arch.IsValid() &&
2727
!platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) {
28-
error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'",
29-
platform_sp->GetName().GetCString(),
30-
arch.GetTriple().getTriple().c_str());
28+
error.SetErrorStringWithFormatv("platform '{0}' doesn't support '{1}'",
29+
platform_sp->GetPluginName(),
30+
arch.GetTriple().getTriple());
3131
platform_sp.reset();
3232
return platform_sp;
3333
}
@@ -122,7 +122,7 @@ bool OptionGroupPlatform::PlatformMatches(
122122
const lldb::PlatformSP &platform_sp) const {
123123
if (platform_sp) {
124124
if (!m_platform_name.empty()) {
125-
if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
125+
if (platform_sp->GetName() != m_platform_name)
126126
return false;
127127
}
128128

lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ static Status FindUnusedPort(uint16_t &port) {
7474
return error;
7575
}
7676

77-
PlatformAndroidRemoteGDBServer::PlatformAndroidRemoteGDBServer() = default;
78-
7977
PlatformAndroidRemoteGDBServer::~PlatformAndroidRemoteGDBServer() {
8078
for (const auto &it : m_port_forwards)
8179
DeleteForwardPortWithAdb(it.second, m_device_id);

lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace platform_android {
2424
class PlatformAndroidRemoteGDBServer
2525
: public platform_gdb_server::PlatformRemoteGDBServer {
2626
public:
27-
PlatformAndroidRemoteGDBServer();
27+
using PlatformRemoteGDBServer::PlatformRemoteGDBServer;
2828

2929
~PlatformAndroidRemoteGDBServer() override;
3030

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
using namespace lldb;
4949
using namespace lldb_private;
5050

51-
/// Default Constructor
52-
PlatformDarwin::PlatformDarwin(bool is_host) : PlatformPOSIX(is_host) {}
53-
5451
/// Destructor.
5552
///
5653
/// The destructor is virtual since this class is designed to be

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
class PlatformDarwin : public PlatformPOSIX {
2626
public:
27-
PlatformDarwin(bool is_host);
27+
using PlatformPOSIX::PlatformPOSIX;
2828

2929
~PlatformDarwin() override;
3030

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,9 +2404,8 @@ Status ProcessGDBRemote::DoDestroy() {
24042404
m_public_state.GetValue() != eStateRunning) {
24052405
PlatformSP platform_sp = GetTarget().GetPlatform();
24062406

2407-
if (platform_sp && platform_sp->GetName() &&
2408-
platform_sp->GetName().GetStringRef() ==
2409-
PlatformRemoteiOS::GetPluginNameStatic()) {
2407+
if (platform_sp && platform_sp->GetPluginName() ==
2408+
PlatformRemoteiOS::GetPluginNameStatic()) {
24102409
if (m_destroy_tried_resuming) {
24112410
if (log)
24122411
log->PutCString("ProcessGDBRemote::DoDestroy() - Tried resuming to "

lldb/source/Target/Platform.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ PlatformSP Platform::Find(ConstString name) {
280280

281281
std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
282282
for (const auto &platform_sp : GetPlatformList()) {
283-
if (platform_sp->GetName() == name)
283+
if (platform_sp->GetName() == name.GetStringRef())
284284
return platform_sp;
285285
}
286286
}
@@ -786,8 +786,6 @@ Status Platform::SetFilePermissions(const FileSpec &file_spec,
786786
}
787787
}
788788

789-
ConstString Platform::GetName() { return ConstString(GetPluginName()); }
790-
791789
const char *Platform::GetHostname() {
792790
if (IsHost())
793791
return "127.0.0.1";
@@ -1728,7 +1726,7 @@ Status Platform::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
17281726

17291727
FileSpec Platform::GetModuleCacheRoot() {
17301728
auto dir_spec = GetGlobalPlatformProperties().GetModuleCacheDirectory();
1731-
dir_spec.AppendPathComponent(GetName().AsCString());
1729+
dir_spec.AppendPathComponent(GetPluginName());
17321730
return dir_spec;
17331731
}
17341732

lldb/source/Target/Process.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,11 +2895,10 @@ void Process::CompleteAttach() {
28952895
if (platform_sp) {
28962896
GetTarget().SetPlatform(platform_sp);
28972897
GetTarget().SetArchitecture(platform_arch);
2898-
LLDB_LOGF(log,
2899-
"Process::%s switching platform to %s and architecture "
2900-
"to %s based on info from attach",
2901-
__FUNCTION__, platform_sp->GetName().AsCString(""),
2902-
platform_arch.GetTriple().getTriple().c_str());
2898+
LLDB_LOG(log,
2899+
"switching platform to {0} and architecture to {1} based on "
2900+
"info from attach",
2901+
platform_sp->GetName(), platform_arch.GetTriple().getTriple());
29032902
}
29042903
} else if (!process_arch.IsValid()) {
29052904
ProcessInstanceInfo process_info;

lldb/source/Target/TargetList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Status TargetList::CreateTargetInternal(
242242
platform_set.end()) {
243243
if (!platform_set.empty())
244244
error_strm.PutCString(", ");
245-
error_strm.PutCString(the_platform_sp->GetName().GetCString());
245+
error_strm.PutCString(the_platform_sp->GetName());
246246
platform_set.insert(the_platform_sp.get());
247247
}
248248
}

0 commit comments

Comments
 (0)