Skip to content

Commit 850bc40

Browse files
labathJDevlieghere
authored andcommitted
[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 (cherry picked from commit d2edca6)
1 parent 387a378 commit 850bc40

File tree

13 files changed

+28
-38
lines changed

13 files changed

+28
-38
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class Platform : public PluginInterface {
220220
bool GetOSKernelDescription(std::string &s);
221221

222222
// Returns the name of the platform
223-
ConstString GetName();
223+
llvm::StringRef GetName() { return GetPluginName(); }
224224

225225
virtual const char *GetHostname();
226226

@@ -514,17 +514,17 @@ class Platform : public PluginInterface {
514514

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

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

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
@@ -1289,16 +1289,15 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
12891289
result.AppendErrorWithFormatv(
12901290
"no processes were found that {0} \"{1}\" on the \"{2}\" "
12911291
"platform\n",
1292-
match_desc, match_name, platform_sp->GetPluginName());
1292+
match_desc, match_name, platform_sp->GetName());
12931293
else
12941294
result.AppendErrorWithFormatv(
12951295
"no processes were found on the \"{0}\" platform\n",
1296-
platform_sp->GetPluginName());
1296+
platform_sp->GetName());
12971297
} else {
1298-
result.AppendMessageWithFormat(
1299-
"%u matching process%s found on \"%s\"", matches,
1300-
matches > 1 ? "es were" : " was",
1301-
platform_sp->GetName().GetCString());
1298+
result.AppendMessageWithFormatv(
1299+
"{0} matching process{1} found on \"{2}\"", matches,
1300+
matches > 1 ? "es were" : " was", platform_sp->GetName());
13021301
if (match_desc)
13031302
result.AppendMessageWithFormat(" whose name %s \"%s\"",
13041303
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
@@ -1611,7 +1611,7 @@ class ChoicesFieldDelegate : public FieldDelegate {
16111611
// Returns the index of the choice.
16121612
int GetChoice() { return m_choice; }
16131613

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

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

lldb/source/Interpreter/OptionGroupPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
@@ -2434,9 +2434,8 @@ Status ProcessGDBRemote::DoDestroy() {
24342434
m_public_state.GetValue() != eStateRunning) {
24352435
PlatformSP platform_sp = GetTarget().GetPlatform();
24362436

2437-
if (platform_sp && platform_sp->GetName() &&
2438-
platform_sp->GetName().GetStringRef() ==
2439-
PlatformRemoteiOS::GetPluginNameStatic()) {
2437+
if (platform_sp && platform_sp->GetPluginName() ==
2438+
PlatformRemoteiOS::GetPluginNameStatic()) {
24402439
if (m_destroy_tried_resuming) {
24412440
if (log)
24422441
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";
@@ -1759,7 +1757,7 @@ Status Platform::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
17591757

17601758
FileSpec Platform::GetModuleCacheRoot() {
17611759
auto dir_spec = GetGlobalPlatformProperties().GetModuleCacheDirectory();
1762-
dir_spec.AppendPathComponent(GetName().AsCString());
1760+
dir_spec.AppendPathComponent(GetPluginName());
17631761
return dir_spec;
17641762
}
17651763

lldb/source/Target/Process.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,11 +3058,10 @@ void Process::CompleteAttach() {
30583058
if (platform_sp) {
30593059
GetTarget().SetPlatform(platform_sp);
30603060
GetTarget().SetArchitecture(platform_arch);
3061-
LLDB_LOGF(log,
3062-
"Process::%s switching platform to %s and architecture "
3063-
"to %s based on info from attach",
3064-
__FUNCTION__, platform_sp->GetName().AsCString(""),
3065-
platform_arch.GetTriple().getTriple().c_str());
3061+
LLDB_LOG(log,
3062+
"switching platform to {0} and architecture to {1} based on "
3063+
"info from attach",
3064+
platform_sp->GetName(), platform_arch.GetTriple().getTriple());
30663065
}
30673066
} else if (!process_arch.IsValid()) {
30683067
ProcessInstanceInfo process_info;

0 commit comments

Comments
 (0)