[Lldb-commits] [PATCH] D99314: [lldb] Add IsSafeToCallAPI to DynamicLoader

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 24 19:37:46 PDT 2021


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);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99314.333192.patch
Type: text/x-patch
Size: 2130 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210325/23671471/attachment.bin>


More information about the lldb-commits mailing list