JDevlieghere created this revision. JDevlieghere added reviewers: friss, aprantl, jingham. JDevlieghere requested review of this revision.
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. https://reviews.llvm.org/D99314 Files: lldb/include/lldb/Target/DynamicLoader.h lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h =================================================================== --- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h +++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h @@ -68,6 +68,8 @@ uint32_t GetPluginVersion() override; + bool IsSafeToCallAPI() override; + protected: void PutToLog(lldb_private::Log *log) const; Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp =================================================================== --- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -1114,6 +1114,12 @@ return false; } +bool DynamicLoaderMacOSXDYLD::IsSafeToCallAPI() { + if (ReadAllImageInfosStructure()) + return m_dyld_all_image_infos.libSystemInitialized; + return false; +} + void DynamicLoaderMacOSXDYLD::Initialize() { PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance); Index: lldb/include/lldb/Target/DynamicLoader.h =================================================================== --- lldb/include/lldb/Target/DynamicLoader.h +++ lldb/include/lldb/Target/DynamicLoader.h @@ -251,6 +251,14 @@ return false; } + /// Return whether the dynamic loader is fully initialized and it's safe to + /// call its APIs. + /// + /// On some systems (e.g. Darwin based systems), lldb will get notified by + /// the dynamic loader before it itself finished initializing and it's not + /// safe to call certain APIs or SPIs. + virtual bool IsSafeToCallAPI() { return true; } + protected: // Utility methods for derived classes @@ -294,7 +302,7 @@ // Read a pointer from memory at the given addr. Return LLDB_INVALID_ADDRESS // if the read fails. lldb::addr_t ReadPointer(lldb::addr_t addr); - + // Calls into the Process protected method LoadOperatingSystemPlugin: void LoadOperatingSystemPlugin(bool flush);
Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h =================================================================== --- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h +++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h @@ -68,6 +68,8 @@ uint32_t GetPluginVersion() override; + bool IsSafeToCallAPI() override; + protected: void PutToLog(lldb_private::Log *log) const; Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp =================================================================== --- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -1114,6 +1114,12 @@ return false; } +bool DynamicLoaderMacOSXDYLD::IsSafeToCallAPI() { + if (ReadAllImageInfosStructure()) + return m_dyld_all_image_infos.libSystemInitialized; + return false; +} + void DynamicLoaderMacOSXDYLD::Initialize() { PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance); Index: lldb/include/lldb/Target/DynamicLoader.h =================================================================== --- lldb/include/lldb/Target/DynamicLoader.h +++ lldb/include/lldb/Target/DynamicLoader.h @@ -251,6 +251,14 @@ return false; } + /// Return whether the dynamic loader is fully initialized and it's safe to + /// call its APIs. + /// + /// On some systems (e.g. Darwin based systems), lldb will get notified by + /// the dynamic loader before it itself finished initializing and it's not + /// safe to call certain APIs or SPIs. + virtual bool IsSafeToCallAPI() { return true; } + protected: // Utility methods for derived classes @@ -294,7 +302,7 @@ // Read a pointer from memory at the given addr. Return LLDB_INVALID_ADDRESS // if the read fails. lldb::addr_t ReadPointer(lldb::addr_t addr); - + // Calls into the Process protected method LoadOperatingSystemPlugin: void LoadOperatingSystemPlugin(bool flush);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits