Skip to content

Commit 2ace1e5

Browse files
committed
[lldb] Remove ConstString from GetPluginNameStatic of some plugins
This patch deals with ObjectFile, ObjectContainer and OperatingSystem plugins. I'll convert the other types in separate patches. In order to enable piecemeal conversion, I am leaving some ConstStrings in the lowest PluginManager layers. I'll convert those as the last step. Differential Revision: https://reviews.llvm.org/D112061
1 parent 898e809 commit 2ace1e5

27 files changed

+69
-157
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class PluginManager {
121121
GetEmulateInstructionCreateCallbackForPluginName(ConstString name);
122122

123123
// OperatingSystem
124-
static bool RegisterPlugin(ConstString name, const char *description,
124+
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
125125
OperatingSystemCreateInstance create_callback,
126126
DebuggerInitializeCallback debugger_init_callback);
127127

@@ -131,7 +131,7 @@ class PluginManager {
131131
GetOperatingSystemCreateCallbackAtIndex(uint32_t idx);
132132

133133
static OperatingSystemCreateInstance
134-
GetOperatingSystemCreateCallbackForPluginName(ConstString name);
134+
GetOperatingSystemCreateCallbackForPluginName(llvm::StringRef name);
135135

136136
// Language
137137
static bool RegisterPlugin(ConstString name, const char *description,
@@ -170,7 +170,7 @@ class PluginManager {
170170

171171
// ObjectFile
172172
static bool
173-
RegisterPlugin(ConstString name, const char *description,
173+
RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
174174
ObjectFileCreateInstance create_callback,
175175
ObjectFileCreateMemoryInstance create_memory_callback,
176176
ObjectFileGetModuleSpecifications get_module_specifications,
@@ -188,16 +188,16 @@ class PluginManager {
188188
GetObjectFileGetModuleSpecificationsCallbackAtIndex(uint32_t idx);
189189

190190
static ObjectFileCreateMemoryInstance
191-
GetObjectFileCreateMemoryCallbackForPluginName(ConstString name);
191+
GetObjectFileCreateMemoryCallbackForPluginName(llvm::StringRef name);
192192

193193
static Status SaveCore(const lldb::ProcessSP &process_sp,
194194
const FileSpec &outfile,
195195
lldb::SaveCoreStyle &core_style,
196-
const ConstString plugin_name);
196+
llvm::StringRef plugin_name);
197197

198198
// ObjectContainer
199199
static bool
200-
RegisterPlugin(ConstString name, const char *description,
200+
RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
201201
ObjectContainerCreateInstance create_callback,
202202
ObjectFileGetModuleSpecifications get_module_specifications);
203203

lldb/source/API/SBProcess.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,7 @@ lldb::SBError SBProcess::SaveCore(const char *file_name) {
12281228

12291229
FileSpec core_file(file_name);
12301230
SaveCoreStyle core_style = SaveCoreStyle::eSaveCoreFull;
1231-
error.ref() =
1232-
PluginManager::SaveCore(process_sp, core_file, core_style, ConstString());
1231+
error.ref() = PluginManager::SaveCore(process_sp, core_file, core_style, "");
12331232
return LLDB_RECORD_RESULT(error);
12341233
}
12351234

lldb/source/Commands/CommandObjectProcess.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed {
12161216

12171217
switch (short_option) {
12181218
case 'p':
1219-
m_requested_plugin_name.SetString(option_arg);
1219+
m_requested_plugin_name = option_arg.str();
12201220
break;
12211221
case 's':
12221222
m_requested_save_core_style =
@@ -1233,12 +1233,12 @@ class CommandObjectProcessSaveCore : public CommandObjectParsed {
12331233

12341234
void OptionParsingStarting(ExecutionContext *execution_context) override {
12351235
m_requested_save_core_style = eSaveCoreUnspecified;
1236-
m_requested_plugin_name.Clear();
1236+
m_requested_plugin_name.clear();
12371237
}
12381238

12391239
// Instance variables to hold the values for command options.
12401240
SaveCoreStyle m_requested_save_core_style;
1241-
ConstString m_requested_plugin_name;
1241+
std::string m_requested_plugin_name;
12421242
};
12431243

12441244
protected:

lldb/source/Core/PluginManager.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,12 @@ static OperatingSystemInstances &GetOperatingSystemInstances() {
473473
}
474474

475475
bool PluginManager::RegisterPlugin(
476-
ConstString name, const char *description,
476+
llvm::StringRef name, llvm::StringRef description,
477477
OperatingSystemCreateInstance create_callback,
478478
DebuggerInitializeCallback debugger_init_callback) {
479479
return GetOperatingSystemInstances().RegisterPlugin(
480-
name, description, create_callback, debugger_init_callback);
480+
ConstString(name), description.str().c_str(), create_callback,
481+
debugger_init_callback);
481482
}
482483

483484
bool PluginManager::UnregisterPlugin(
@@ -491,8 +492,9 @@ PluginManager::GetOperatingSystemCreateCallbackAtIndex(uint32_t idx) {
491492
}
492493

493494
OperatingSystemCreateInstance
494-
PluginManager::GetOperatingSystemCreateCallbackForPluginName(ConstString name) {
495-
return GetOperatingSystemInstances().GetCallbackForName(name);
495+
PluginManager::GetOperatingSystemCreateCallbackForPluginName(
496+
llvm::StringRef name) {
497+
return GetOperatingSystemInstances().GetCallbackForName(ConstString(name));
496498
}
497499

498500
#pragma mark Language
@@ -635,14 +637,14 @@ static ObjectFileInstances &GetObjectFileInstances() {
635637
}
636638

637639
bool PluginManager::RegisterPlugin(
638-
ConstString name, const char *description,
640+
llvm::StringRef name, llvm::StringRef description,
639641
ObjectFileCreateInstance create_callback,
640642
ObjectFileCreateMemoryInstance create_memory_callback,
641643
ObjectFileGetModuleSpecifications get_module_specifications,
642644
ObjectFileSaveCore save_core) {
643645
return GetObjectFileInstances().RegisterPlugin(
644-
name, description, create_callback, create_memory_callback,
645-
get_module_specifications, save_core);
646+
ConstString(name), description.str().c_str(), create_callback,
647+
create_memory_callback, get_module_specifications, save_core);
646648
}
647649

648650
bool PluginManager::UnregisterPlugin(ObjectFileCreateInstance create_callback) {
@@ -673,12 +675,10 @@ PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
673675

674676
ObjectFileCreateMemoryInstance
675677
PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
676-
ConstString name) {
677-
if (!name)
678-
return nullptr;
678+
llvm::StringRef name) {
679679
const auto &instances = GetObjectFileInstances().GetInstances();
680680
for (auto &instance : instances) {
681-
if (instance.name == name)
681+
if (instance.name.GetStringRef() == name)
682682
return instance.create_memory_callback;
683683
}
684684
return nullptr;
@@ -687,8 +687,8 @@ PluginManager::GetObjectFileCreateMemoryCallbackForPluginName(
687687
Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
688688
const FileSpec &outfile,
689689
lldb::SaveCoreStyle &core_style,
690-
const ConstString plugin_name) {
691-
if (!plugin_name) {
690+
llvm::StringRef plugin_name) {
691+
if (plugin_name.empty()) {
692692
// Try saving core directly from the process plugin first.
693693
llvm::Expected<bool> ret = process_sp->SaveCore(outfile.GetPath());
694694
if (!ret)
@@ -701,7 +701,7 @@ Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
701701
Status error;
702702
auto &instances = GetObjectFileInstances().GetInstances();
703703
for (auto &instance : instances) {
704-
if (plugin_name && instance.name != plugin_name)
704+
if (instance.name.GetStringRef() != plugin_name)
705705
continue;
706706
if (instance.save_core &&
707707
instance.save_core(process_sp, outfile, core_style, error))
@@ -733,11 +733,12 @@ static ObjectContainerInstances &GetObjectContainerInstances() {
733733
}
734734

735735
bool PluginManager::RegisterPlugin(
736-
ConstString name, const char *description,
736+
llvm::StringRef name, llvm::StringRef description,
737737
ObjectContainerCreateInstance create_callback,
738738
ObjectFileGetModuleSpecifications get_module_specifications) {
739739
return GetObjectContainerInstances().RegisterPlugin(
740-
name, description, create_callback, get_module_specifications);
740+
ConstString(name), description.str().c_str(), create_callback,
741+
get_module_specifications);
741742
}
742743

743744
bool PluginManager::UnregisterPlugin(

lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,6 @@ void ObjectContainerBSDArchive::Terminate() {
274274
PluginManager::UnregisterPlugin(CreateInstance);
275275
}
276276

277-
lldb_private::ConstString ObjectContainerBSDArchive::GetPluginNameStatic() {
278-
static ConstString g_name("bsd-archive");
279-
return g_name;
280-
}
281-
282-
const char *ObjectContainerBSDArchive::GetPluginDescriptionStatic() {
283-
return "BSD Archive object container reader.";
284-
}
285-
286277
ObjectContainer *ObjectContainerBSDArchive::CreateInstance(
287278
const lldb::ModuleSP &module_sp, DataBufferSP &data_sp,
288279
lldb::offset_t data_offset, const FileSpec *file,

lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {
3636

3737
static void Terminate();
3838

39-
static lldb_private::ConstString GetPluginNameStatic();
39+
static llvm::StringRef GetPluginNameStatic() { return "bsd-archive"; }
4040

41-
static const char *GetPluginDescriptionStatic();
41+
static llvm::StringRef GetPluginDescriptionStatic() {
42+
return "BSD Archive object container reader.";
43+
}
4244

4345
static lldb_private::ObjectContainer *
4446
CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
@@ -68,9 +70,7 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {
6870
lldb::ObjectFileSP GetObjectFile(const lldb_private::FileSpec *file) override;
6971

7072
// PluginInterface protocol
71-
llvm::StringRef GetPluginName() override {
72-
return GetPluginNameStatic().GetStringRef();
73-
}
73+
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
7474

7575
protected:
7676
struct Object {

lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ void ObjectContainerUniversalMachO::Terminate() {
3333
PluginManager::UnregisterPlugin(CreateInstance);
3434
}
3535

36-
lldb_private::ConstString ObjectContainerUniversalMachO::GetPluginNameStatic() {
37-
static ConstString g_name("mach-o");
38-
return g_name;
39-
}
40-
41-
const char *ObjectContainerUniversalMachO::GetPluginDescriptionStatic() {
42-
return "Universal mach-o object container reader.";
43-
}
44-
4536
ObjectContainer *ObjectContainerUniversalMachO::CreateInstance(
4637
const lldb::ModuleSP &module_sp, DataBufferSP &data_sp,
4738
lldb::offset_t data_offset, const FileSpec *file,

lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ class ObjectContainerUniversalMachO : public lldb_private::ObjectContainer {
2828

2929
static void Terminate();
3030

31-
static lldb_private::ConstString GetPluginNameStatic();
31+
static llvm::StringRef GetPluginNameStatic() { return "mach-o"; }
3232

33-
static const char *GetPluginDescriptionStatic();
33+
static llvm::StringRef GetPluginDescriptionStatic() {
34+
return "Universal mach-o object container reader.";
35+
}
3436

3537
static lldb_private::ObjectContainer *
3638
CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
@@ -59,9 +61,7 @@ class ObjectContainerUniversalMachO : public lldb_private::ObjectContainer {
5961
lldb::ObjectFileSP GetObjectFile(const lldb_private::FileSpec *file) override;
6062

6163
// PluginInterface protocol
62-
llvm::StringRef GetPluginName() override {
63-
return GetPluginNameStatic().GetStringRef();
64-
}
64+
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
6565

6666
protected:
6767
llvm::MachO::fat_header m_header;

lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ void ObjectFileBreakpad::Terminate() {
5656
PluginManager::UnregisterPlugin(CreateInstance);
5757
}
5858

59-
ConstString ObjectFileBreakpad::GetPluginNameStatic() {
60-
static ConstString g_name("breakpad");
61-
return g_name;
62-
}
63-
6459
ObjectFile *ObjectFileBreakpad::CreateInstance(
6560
const ModuleSP &module_sp, DataBufferSP &data_sp, offset_t data_offset,
6661
const FileSpec *file, offset_t file_offset, offset_t length) {

lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ObjectFileBreakpad : public ObjectFile {
2121
static void Initialize();
2222
static void Terminate();
2323

24-
static ConstString GetPluginNameStatic();
24+
static llvm::StringRef GetPluginNameStatic() { return "breakpad"; }
2525
static const char *GetPluginDescriptionStatic() {
2626
return "Breakpad object file reader.";
2727
}
@@ -44,9 +44,7 @@ class ObjectFileBreakpad : public ObjectFile {
4444
ModuleSpecList &specs);
4545

4646
// PluginInterface protocol
47-
llvm::StringRef GetPluginName() override {
48-
return GetPluginNameStatic().GetStringRef();
49-
}
47+
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
5048

5149
// LLVM RTTI support
5250
static char ID;

0 commit comments

Comments
 (0)