Skip to content

Commit bbb4191

Browse files
committed
[lldb] Add IsFullyInitialized to DynamicLoader
On Darwin based systems, lldb will get notified by dyld before it itself finished initializing, at which point it's not safe to call certain APIs or SPIs. Add a method to the DynamicLoader to query that. Differential revision: https://reviews.llvm.org/D99314
1 parent 36eaeaf commit bbb4191

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lldb/include/lldb/Target/DynamicLoader.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ class DynamicLoader : public PluginInterface {
251251
return false;
252252
}
253253

254+
/// Return whether the dynamic loader is fully initialized and it's safe to
255+
/// call its APIs.
256+
///
257+
/// On some systems (e.g. Darwin based systems), lldb will get notified by
258+
/// the dynamic loader before it itself finished initializing and it's not
259+
/// safe to call certain APIs or SPIs.
260+
virtual bool IsFullyInitialized() { return true; }
261+
254262
protected:
255263
// Utility methods for derived classes
256264

@@ -294,7 +302,7 @@ class DynamicLoader : public PluginInterface {
294302
// Read a pointer from memory at the given addr. Return LLDB_INVALID_ADDRESS
295303
// if the read fails.
296304
lldb::addr_t ReadPointer(lldb::addr_t addr);
297-
305+
298306
// Calls into the Process protected method LoadOperatingSystemPlugin:
299307
void LoadOperatingSystemPlugin(bool flush);
300308

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,12 @@ bool DynamicLoaderMacOSXDYLD::GetSharedCacheInformation(
11141114
return false;
11151115
}
11161116

1117+
bool DynamicLoaderMacOSXDYLD::IsFullyInitialized() {
1118+
if (ReadAllImageInfosStructure())
1119+
return m_dyld_all_image_infos.libSystemInitialized;
1120+
return false;
1121+
}
1122+
11171123
void DynamicLoaderMacOSXDYLD::Initialize() {
11181124
PluginManager::RegisterPlugin(GetPluginNameStatic(),
11191125
GetPluginDescriptionStatic(), CreateInstance);

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class DynamicLoaderMacOSXDYLD : public lldb_private::DynamicLoaderDarwin {
6868

6969
uint32_t GetPluginVersion() override;
7070

71+
bool IsFullyInitialized() override;
72+
7173
protected:
7274
void PutToLog(lldb_private::Log *log) const;
7375

0 commit comments

Comments
 (0)