Skip to content

Commit 3d7161e

Browse files
committed
[lldb] Remove shared_ptr from some global Properties objects
they're unnecessary, make the code longer, and their removal actually ensures proper initialization in multithreaded scenarios.
1 parent b1309a1 commit 3d7161e

File tree

18 files changed

+89
-150
lines changed

18 files changed

+89
-150
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class PlatformProperties : public Properties {
5555
void SetDefaultModuleCacheDirectory(const FileSpec &dir_spec);
5656
};
5757

58-
typedef std::shared_ptr<PlatformProperties> PlatformPropertiesSP;
5958
typedef llvm::SmallVector<lldb::addr_t, 6> MmapArgList;
6059

6160
/// \class Platform Platform.h "lldb/Target/Platform.h"
@@ -84,7 +83,7 @@ class Platform : public PluginInterface {
8483

8584
static void Terminate();
8685

87-
static const PlatformPropertiesSP &GetGlobalPlatformProperties();
86+
static PlatformProperties &GetGlobalPlatformProperties();
8887

8988
/// Get the native host platform plug-in.
9089
///

lldb/include/lldb/Target/Process.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ class ProcessProperties : public Properties {
106106
std::unique_ptr<ProcessExperimentalProperties> m_experimental_properties_up;
107107
};
108108

109-
typedef std::shared_ptr<ProcessProperties> ProcessPropertiesSP;
110-
111109
// ProcessAttachInfo
112110
//
113111
// Describes any information that is required to attach to a process.
@@ -501,7 +499,7 @@ class Process : public std::enable_shared_from_this<Process>,
501499

502500
static void SettingsTerminate();
503501

504-
static const ProcessPropertiesSP &GetGlobalProperties();
502+
static ProcessProperties &GetGlobalProperties();
505503

506504
/// Find a Process plug-in that can debug \a module using the currently
507505
/// selected architecture.

lldb/include/lldb/Target/Target.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class Target : public std::enable_shared_from_this<Target>,
562562

563563
// Settings accessors
564564

565-
static const lldb::TargetPropertiesSP &GetGlobalProperties();
565+
static TargetProperties &GetGlobalProperties();
566566

567567
std::recursive_mutex &GetAPIMutex();
568568

lldb/include/lldb/Target/Thread.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class ThreadProperties : public Properties {
5757
uint64_t GetMaxBacktraceDepth() const;
5858
};
5959

60-
typedef std::shared_ptr<ThreadProperties> ThreadPropertiesSP;
61-
6260
class Thread : public std::enable_shared_from_this<Thread>,
6361
public ThreadProperties,
6462
public UserID,
@@ -149,7 +147,7 @@ class Thread : public std::enable_shared_from_this<Thread>,
149147

150148
static void SettingsTerminate();
151149

152-
static const ThreadPropertiesSP &GetGlobalProperties();
150+
static ThreadProperties &GetGlobalProperties();
153151

154152
lldb::ProcessSP GetProcess() const { return m_process_wp.lock(); }
155153

lldb/include/lldb/lldb-forward.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ typedef std::shared_ptr<lldb_private::SyntheticChildrenFrontEnd>
399399
SyntheticChildrenFrontEndSP;
400400
typedef std::shared_ptr<lldb_private::Target> TargetSP;
401401
typedef std::weak_ptr<lldb_private::Target> TargetWP;
402-
typedef std::shared_ptr<lldb_private::TargetProperties> TargetPropertiesSP;
403402
typedef std::shared_ptr<lldb_private::Thread> ThreadSP;
404403
typedef std::weak_ptr<lldb_private::Thread> ThreadWP;
405404
typedef std::shared_ptr<lldb_private::ThreadCollection> ThreadCollectionSP;

lldb/source/Core/Debugger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,10 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
723723
m_collection_sp->AppendProperty(
724724
ConstString("target"),
725725
ConstString("Settings specify to debugging targets."), true,
726-
Target::GetGlobalProperties()->GetValueProperties());
726+
Target::GetGlobalProperties().GetValueProperties());
727727
m_collection_sp->AppendProperty(
728728
ConstString("platform"), ConstString("Platform settings."), true,
729-
Platform::GetGlobalPlatformProperties()->GetValueProperties());
729+
Platform::GetGlobalPlatformProperties().GetValueProperties());
730730
m_collection_sp->AppendProperty(
731731
ConstString("symbols"), ConstString("Symbol lookup and cache settings."),
732732
true, ModuleList::GetGlobalModuleListProperties().GetValueProperties());

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,13 +2113,6 @@ static void GetCwdInitFile(llvm::SmallVectorImpl<char> &init_file) {
21132113
FileSystem::Instance().Resolve(init_file);
21142114
}
21152115

2116-
static LoadCWDlldbinitFile ShouldLoadCwdInitFile() {
2117-
lldb::TargetPropertiesSP properties = Target::GetGlobalProperties();
2118-
if (!properties)
2119-
return eLoadCWDlldbinitFalse;
2120-
return properties->GetLoadCWDlldbinitFile();
2121-
}
2122-
21232116
void CommandInterpreter::SourceInitFile(FileSpec file,
21242117
CommandReturnObject &result) {
21252118
assert(!m_skip_lldbinit_files);
@@ -2155,7 +2148,8 @@ void CommandInterpreter::SourceInitFileCwd(CommandReturnObject &result) {
21552148
return;
21562149
}
21572150

2158-
LoadCWDlldbinitFile should_load = ShouldLoadCwdInitFile();
2151+
LoadCWDlldbinitFile should_load =
2152+
Target::GetGlobalProperties().GetLoadCWDlldbinitFile();
21592153

21602154
switch (should_load) {
21612155
case eLoadCWDlldbinitFalse:

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,9 @@ class DynamicLoaderDarwinKernelProperties : public Properties {
124124
}
125125
};
126126

127-
typedef std::shared_ptr<DynamicLoaderDarwinKernelProperties>
128-
DynamicLoaderDarwinKernelPropertiesSP;
129-
130-
static const DynamicLoaderDarwinKernelPropertiesSP &GetGlobalProperties() {
131-
static DynamicLoaderDarwinKernelPropertiesSP g_settings_sp;
132-
if (!g_settings_sp)
133-
g_settings_sp = std::make_shared<DynamicLoaderDarwinKernelProperties>();
134-
return g_settings_sp;
127+
static DynamicLoaderDarwinKernelProperties &GetGlobalProperties() {
128+
static DynamicLoaderDarwinKernelProperties g_settings;
129+
return g_settings;
135130
}
136131

137132
// Create an instance of this class. This function is filled into the plugin
@@ -240,7 +235,7 @@ DynamicLoaderDarwinKernel::SearchForKernelAtSameLoadAddr(Process *process) {
240235
// address of the kernel if one was found, else LLDB_INVALID_ADDRESS.
241236
lldb::addr_t
242237
DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) {
243-
if (GetGlobalProperties()->GetScanType() == eKASLRScanNone)
238+
if (GetGlobalProperties().GetScanType() == eKASLRScanNone)
244239
return LLDB_INVALID_ADDRESS;
245240

246241
Status read_err;
@@ -292,8 +287,8 @@ DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) {
292287
// LLDB_INVALID_ADDRESS.
293288
lldb::addr_t
294289
DynamicLoaderDarwinKernel::SearchForKernelNearPC(Process *process) {
295-
if (GetGlobalProperties()->GetScanType() == eKASLRScanNone ||
296-
GetGlobalProperties()->GetScanType() == eKASLRScanLowgloAddresses) {
290+
if (GetGlobalProperties().GetScanType() == eKASLRScanNone ||
291+
GetGlobalProperties().GetScanType() == eKASLRScanLowgloAddresses) {
297292
return LLDB_INVALID_ADDRESS;
298293
}
299294

@@ -350,7 +345,7 @@ DynamicLoaderDarwinKernel::SearchForKernelNearPC(Process *process) {
350345
// kernel if one was found, else LLDB_INVALID_ADDRESS.
351346
lldb::addr_t DynamicLoaderDarwinKernel::SearchForKernelViaExhaustiveSearch(
352347
Process *process) {
353-
if (GetGlobalProperties()->GetScanType() != eKASLRScanExhaustiveScan) {
348+
if (GetGlobalProperties().GetScanType() != eKASLRScanExhaustiveScan) {
354349
return LLDB_INVALID_ADDRESS;
355350
}
356351

@@ -1177,7 +1172,7 @@ bool DynamicLoaderDarwinKernel::ParseKextSummaries(
11771172
// read the plugin.dynamic-loader.darwin-kernel.load-kexts setting -- if the
11781173
// user requested no kext loading, don't print any messages about kexts &
11791174
// don't try to read them.
1180-
const bool load_kexts = GetGlobalProperties()->GetLoadKexts();
1175+
const bool load_kexts = GetGlobalProperties().GetLoadKexts();
11811176

11821177
// By default, all kexts we've loaded in the past are marked as "remove" and
11831178
// all of the kexts we just found out about from ReadKextSummaries are marked
@@ -1548,7 +1543,7 @@ void DynamicLoaderDarwinKernel::DebuggerInitialize(
15481543
debugger, DynamicLoaderDarwinKernelProperties::GetSettingName())) {
15491544
const bool is_global_setting = true;
15501545
PluginManager::CreateSettingForDynamicLoaderPlugin(
1551-
debugger, GetGlobalProperties()->GetValueProperties(),
1546+
debugger, GetGlobalProperties().GetValueProperties(),
15521547
ConstString("Properties for the DynamicLoaderDarwinKernel plug-in."),
15531548
is_global_setting);
15541549
}

lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,9 @@ class PluginProperties : public Properties {
105105
}
106106
};
107107

108-
typedef std::shared_ptr<PluginProperties> JITLoaderGDBPropertiesSP;
109-
110-
static const JITLoaderGDBPropertiesSP &GetGlobalPluginProperties() {
111-
static const auto g_settings_sp(std::make_shared<PluginProperties>());
112-
return g_settings_sp;
108+
static PluginProperties &GetGlobalPluginProperties() {
109+
static PluginProperties g_settings;
110+
return g_settings;
113111
}
114112

115113
template <typename ptr_t>
@@ -160,7 +158,7 @@ void JITLoaderGDB::DebuggerInitialize(Debugger &debugger) {
160158
debugger, PluginProperties::GetSettingName())) {
161159
const bool is_global_setting = true;
162160
PluginManager::CreateSettingForJITLoaderPlugin(
163-
debugger, GetGlobalPluginProperties()->GetValueProperties(),
161+
debugger, GetGlobalPluginProperties().GetValueProperties(),
164162
ConstString("Properties for the JIT LoaderGDB plug-in."),
165163
is_global_setting);
166164
}
@@ -412,7 +410,7 @@ lldb_private::ConstString JITLoaderGDB::GetPluginNameStatic() {
412410
JITLoaderSP JITLoaderGDB::CreateInstance(Process *process, bool force) {
413411
JITLoaderSP jit_loader_sp;
414412
bool enable;
415-
switch (GetGlobalPluginProperties()->GetEnable()) {
413+
switch (GetGlobalPluginProperties().GetEnable()) {
416414
case EnableJITLoaderGDB::eEnableJITLoaderGDBOn:
417415
enable = true;
418416
break;

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,9 @@ class PlatformDarwinKernelProperties : public Properties {
209209
}
210210
};
211211

212-
typedef std::shared_ptr<PlatformDarwinKernelProperties>
213-
PlatformDarwinKernelPropertiesSP;
214-
215-
static const PlatformDarwinKernelPropertiesSP &GetGlobalProperties() {
216-
static PlatformDarwinKernelPropertiesSP g_settings_sp;
217-
if (!g_settings_sp)
218-
g_settings_sp = std::make_shared<PlatformDarwinKernelProperties>();
219-
return g_settings_sp;
212+
static PlatformDarwinKernelProperties &GetGlobalProperties() {
213+
static PlatformDarwinKernelProperties g_settings;
214+
return g_settings;
220215
}
221216

222217
void PlatformDarwinKernel::DebuggerInitialize(
@@ -225,7 +220,7 @@ void PlatformDarwinKernel::DebuggerInitialize(
225220
debugger, PlatformDarwinKernelProperties::GetSettingName())) {
226221
const bool is_global_setting = true;
227222
PluginManager::CreateSettingForPlatformPlugin(
228-
debugger, GetGlobalProperties()->GetValueProperties(),
223+
debugger, GetGlobalProperties().GetValueProperties(),
229224
ConstString("Properties for the PlatformDarwinKernel plug-in."),
230225
is_global_setting);
231226
}
@@ -377,7 +372,7 @@ void PlatformDarwinKernel::CollectKextAndKernelDirectories() {
377372
}
378373

379374
void PlatformDarwinKernel::GetUserSpecifiedDirectoriesToSearch() {
380-
FileSpecList user_dirs(GetGlobalProperties()->GetKextDirectories());
375+
FileSpecList user_dirs(GetGlobalProperties().GetKextDirectories());
381376
std::vector<FileSpec> possible_sdk_dirs;
382377

383378
const uint32_t user_dirs_count = user_dirs.GetSize();

lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,9 @@ class PluginProperties : public Properties {
8282
}
8383
};
8484

85-
typedef std::shared_ptr<PluginProperties> ProcessKDPPropertiesSP;
86-
87-
static const ProcessKDPPropertiesSP &GetGlobalPluginProperties() {
88-
static ProcessKDPPropertiesSP g_settings_sp;
89-
if (!g_settings_sp)
90-
g_settings_sp = std::make_shared<PluginProperties>();
91-
return g_settings_sp;
85+
static PluginProperties &GetGlobalPluginProperties() {
86+
static PluginProperties g_settings;
87+
return g_settings;
9288
}
9389

9490
} // anonymous namespace end
@@ -161,7 +157,7 @@ ProcessKDP::ProcessKDP(TargetSP target_sp, ListenerSP listener_sp)
161157
m_async_broadcaster.SetEventName(eBroadcastBitAsyncContinue,
162158
"async thread continue");
163159
const uint64_t timeout_seconds =
164-
GetGlobalPluginProperties()->GetPacketTimeout();
160+
GetGlobalPluginProperties().GetPacketTimeout();
165161
if (timeout_seconds > 0)
166162
m_comm.SetPacketTimeout(std::chrono::seconds(timeout_seconds));
167163
}
@@ -725,7 +721,7 @@ void ProcessKDP::DebuggerInitialize(lldb_private::Debugger &debugger) {
725721
debugger, PluginProperties::GetSettingName())) {
726722
const bool is_global_setting = true;
727723
PluginManager::CreateSettingForProcessPlugin(
728-
debugger, GetGlobalPluginProperties()->GetValueProperties(),
724+
debugger, GetGlobalPluginProperties().GetValueProperties(),
729725
ConstString("Properties for the kdp-remote process plug-in."),
730726
is_global_setting);
731727
}

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,9 @@ class PluginProperties : public Properties {
165165
}
166166
};
167167

168-
typedef std::shared_ptr<PluginProperties> ProcessKDPPropertiesSP;
169-
170-
static const ProcessKDPPropertiesSP &GetGlobalPluginProperties() {
171-
static ProcessKDPPropertiesSP g_settings_sp;
172-
if (!g_settings_sp)
173-
g_settings_sp = std::make_shared<PluginProperties>();
174-
return g_settings_sp;
168+
static PluginProperties &GetGlobalPluginProperties() {
169+
static PluginProperties g_settings;
170+
return g_settings;
175171
}
176172

177173
} // namespace
@@ -213,7 +209,7 @@ ProcessGDBRemote::CreateInstance(lldb::TargetSP target_sp,
213209
}
214210

215211
std::chrono::seconds ProcessGDBRemote::GetPacketTimeout() {
216-
return std::chrono::seconds(GetGlobalPluginProperties()->GetPacketTimeout());
212+
return std::chrono::seconds(GetGlobalPluginProperties().GetPacketTimeout());
217213
}
218214

219215
bool ProcessGDBRemote::CanDebug(lldb::TargetSP target_sp,
@@ -302,12 +298,12 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp,
302298
}
303299

304300
const uint64_t timeout_seconds =
305-
GetGlobalPluginProperties()->GetPacketTimeout();
301+
GetGlobalPluginProperties().GetPacketTimeout();
306302
if (timeout_seconds > 0)
307303
m_gdb_comm.SetPacketTimeout(std::chrono::seconds(timeout_seconds));
308304

309305
m_use_g_packet_for_reading =
310-
GetGlobalPluginProperties()->GetUseGPacketForReading();
306+
GetGlobalPluginProperties().GetUseGPacketForReading();
311307
}
312308

313309
// Destructor
@@ -401,7 +397,7 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
401397
// timeout is and can see it.
402398
const auto host_packet_timeout = m_gdb_comm.GetHostDefaultPacketTimeout();
403399
if (host_packet_timeout > std::chrono::seconds(0)) {
404-
GetGlobalPluginProperties()->SetPacketTimeout(host_packet_timeout.count());
400+
GetGlobalPluginProperties().SetPacketTimeout(host_packet_timeout.count());
405401
}
406402

407403
// Register info search order:
@@ -411,7 +407,7 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
411407
// 3 - Fall back on the qRegisterInfo packets.
412408

413409
FileSpec target_definition_fspec =
414-
GetGlobalPluginProperties()->GetTargetDefinitionFile();
410+
GetGlobalPluginProperties().GetTargetDefinitionFile();
415411
if (!FileSystem::Instance().Exists(target_definition_fspec)) {
416412
// If the filename doesn't exist, it may be a ~ not having been expanded -
417413
// try to resolve it.
@@ -3528,7 +3524,7 @@ void ProcessGDBRemote::DebuggerInitialize(Debugger &debugger) {
35283524
debugger, PluginProperties::GetSettingName())) {
35293525
const bool is_global_setting = true;
35303526
PluginManager::CreateSettingForProcessPlugin(
3531-
debugger, GetGlobalPluginProperties()->GetValueProperties(),
3527+
debugger, GetGlobalPluginProperties().GetValueProperties(),
35323528
ConstString("Properties for the gdb-remote process plug-in."),
35333529
is_global_setting);
35343530
}
@@ -4564,7 +4560,7 @@ llvm::Expected<LoadedModuleInfoList> ProcessGDBRemote::GetLoadedModuleList() {
45644560

45654561
LoadedModuleInfoList list;
45664562
GDBRemoteCommunicationClient &comm = m_gdb_comm;
4567-
bool can_use_svr4 = GetGlobalPluginProperties()->GetUseSVR4();
4563+
bool can_use_svr4 = GetGlobalPluginProperties().GetUseSVR4();
45684564

45694565
// check that we have extended feature read support
45704566
if (can_use_svr4 && comm.GetQXferLibrariesSVR4ReadSupported()) {

0 commit comments

Comments
 (0)