JDevlieghere created this revision.
JDevlieghere added a reviewer: aprantl.
JDevlieghere requested review of this revision.

Move UpdateISAToDescriptorMap into ClassInfoExtractor so that all the formerly 
public functions can be private and remain an implementation detail of the 
extractor.


https://reviews.llvm.org/D99448

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h

Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -318,6 +318,10 @@
     DynamicClassInfoExtractor(AppleObjCRuntimeV2 &runtime)
         : ClassInfoExtractor(runtime) {}
 
+    DescriptorMapUpdateResult
+    UpdateISAToDescriptorMap(RemoteNXMapTable &hash_table);
+
+  private:
     enum Helper { gdb_objc_realized_classes, objc_copyRealizedClassList };
 
     /// Compute which helper to use. Prefer objc_copyRealizedClassList if it's
@@ -329,7 +333,6 @@
                                                  Helper helper);
     lldb::addr_t &GetClassInfoArgs(Helper helper);
 
-  private:
     std::unique_ptr<UtilityFunction>
     GetClassInfoUtilityFunctionImpl(ExecutionContext &exe_ctx, std::string code,
                                     std::string name);
@@ -356,17 +359,16 @@
     SharedCacheClassInfoExtractor(AppleObjCRuntimeV2 &runtime)
         : ClassInfoExtractor(runtime) {}
 
-    UtilityFunction *GetClassInfoUtilityFunction(ExecutionContext &exe_ctx);
-    lldb::addr_t &GetClassInfoArgs() { return m_args; }
-    std::mutex &GetMutex() { return m_mutex; }
+    DescriptorMapUpdateResult UpdateISAToDescriptorMap();
 
   private:
+    UtilityFunction *GetClassInfoUtilityFunction(ExecutionContext &exe_ctx);
+
     std::unique_ptr<UtilityFunction>
     GetClassInfoUtilityFunctionImpl(ExecutionContext &exe_ctx);
 
     std::unique_ptr<UtilityFunction> m_utility_function;
     lldb::addr_t m_args = LLDB_INVALID_ADDRESS;
-    std::mutex m_mutex;
   };
 
   AppleObjCRuntimeV2(Process *process, const lldb::ModuleSP &objc_module_sp);
@@ -381,14 +383,9 @@
   /// change when lazily named classes get realized.
   bool RealizedClassGenerationCountChanged();
 
-  DescriptorMapUpdateResult
-  UpdateISAToDescriptorMapDynamic(RemoteNXMapTable &hash_table);
-
   uint32_t ParseClassInfoArray(const lldb_private::DataExtractor &data,
                                uint32_t num_class_infos);
 
-  DescriptorMapUpdateResult UpdateISAToDescriptorMapSharedCache();
-
   enum class SharedCacheWarningReason {
     eExpressionExecutionFailure,
     eNotEnoughClassesRead
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -1551,10 +1551,9 @@
 }
 
 AppleObjCRuntimeV2::DescriptorMapUpdateResult
-AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
+AppleObjCRuntimeV2::DynamicClassInfoExtractor::UpdateISAToDescriptorMap(
     RemoteNXMapTable &hash_table) {
-  Process *process = GetProcess();
-
+  Process *process = m_runtime.GetProcess();
   if (process == nullptr)
     return DescriptorMapUpdateResult::Fail();
 
@@ -1583,22 +1582,20 @@
   Status err;
 
   // Compute which helper we're going to use for this update.
-  const DynamicClassInfoExtractor::Helper helper =
-      m_dynamic_class_info_extractor.ComputeHelper();
+  const DynamicClassInfoExtractor::Helper helper = ComputeHelper();
 
   // Read the total number of classes from the hash table
   const uint32_t num_classes =
       helper == DynamicClassInfoExtractor::gdb_objc_realized_classes
           ? hash_table.GetCount()
-          : m_realized_class_generation_count;
+          : m_runtime.m_realized_class_generation_count;
   if (num_classes == 0) {
     LLDB_LOGF(log, "No dynamic classes found.");
     return DescriptorMapUpdateResult::Success(0);
   }
 
   UtilityFunction *get_class_info_code =
-      m_dynamic_class_info_extractor.GetClassInfoUtilityFunction(exe_ctx,
-                                                                 helper);
+      GetClassInfoUtilityFunction(exe_ctx, helper);
   if (!get_class_info_code) {
     // The callee will have already logged a useful error message.
     return DescriptorMapUpdateResult::Fail();
@@ -1629,7 +1626,7 @@
     return DescriptorMapUpdateResult::Fail();
   }
 
-  std::lock_guard<std::mutex> guard(m_dynamic_class_info_extractor.GetMutex());
+  std::lock_guard<std::mutex> guard(m_mutex);
 
   // Fill in our function argument values
   arguments.GetValueAtIndex(0)->GetScalar() = hash_table.GetTableLoadAddress();
@@ -1649,8 +1646,7 @@
 
   // Write our function arguments into the process so we can run our function
   if (get_class_info_function->WriteFunctionArguments(
-          exe_ctx, m_dynamic_class_info_extractor.GetClassInfoArgs(helper),
-          arguments, diagnostics)) {
+          exe_ctx, GetClassInfoArgs(helper), arguments, diagnostics)) {
     EvaluateExpressionOptions options;
     options.SetUnwindOnError(true);
     options.SetTryAllThreads(false);
@@ -1671,8 +1667,7 @@
 
     // Run the function
     ExpressionResults results = get_class_info_function->ExecuteFunction(
-        exe_ctx, &m_dynamic_class_info_extractor.GetClassInfoArgs(helper),
-        options, diagnostics, return_value);
+        exe_ctx, &GetClassInfoArgs(helper), options, diagnostics, return_value);
 
     if (results == eExpressionCompleted) {
       // The result is the number of ClassInfo structures that were filled in
@@ -1687,7 +1682,7 @@
           DataExtractor class_infos_data(buffer.GetBytes(),
                                          buffer.GetByteSize(),
                                          process->GetByteOrder(), addr_size);
-          ParseClassInfoArray(class_infos_data, num_class_infos);
+          m_runtime.ParseClassInfoArray(class_infos_data, num_class_infos);
         }
       }
       success = true;
@@ -1788,9 +1783,8 @@
 }
 
 AppleObjCRuntimeV2::DescriptorMapUpdateResult
-AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
-  Process *process = GetProcess();
-
+AppleObjCRuntimeV2::SharedCacheClassInfoExtractor::UpdateISAToDescriptorMap() {
+  Process *process = m_runtime.GetProcess();
   if (process == nullptr)
     return DescriptorMapUpdateResult::Fail();
 
@@ -1818,15 +1812,14 @@
 
   uint32_t num_class_infos = 0;
 
-  const lldb::addr_t objc_opt_ptr = GetSharedCacheReadOnlyAddress();
+  const lldb::addr_t objc_opt_ptr = m_runtime.GetSharedCacheReadOnlyAddress();
 
   if (objc_opt_ptr == LLDB_INVALID_ADDRESS)
     return DescriptorMapUpdateResult::Fail();
 
   const uint32_t num_classes = 128 * 1024;
 
-  UtilityFunction *get_class_info_code =
-      m_shared_cache_class_info_extractor.GetClassInfoUtilityFunction(exe_ctx);
+  UtilityFunction *get_class_info_code = GetClassInfoUtilityFunction(exe_ctx);
   FunctionCaller *get_shared_cache_class_info_function =
       get_class_info_code->GetFunctionCaller();
 
@@ -1853,8 +1846,7 @@
     return DescriptorMapUpdateResult::Fail();
   }
 
-  std::lock_guard<std::mutex> guard(
-      m_shared_cache_class_info_extractor.GetMutex());
+  std::lock_guard<std::mutex> guard(m_mutex);
 
   // Fill in our function argument values
   arguments.GetValueAtIndex(0)->GetScalar() = objc_opt_ptr;
@@ -1873,8 +1865,7 @@
 
   // Write our function arguments into the process so we can run our function
   if (get_shared_cache_class_info_function->WriteFunctionArguments(
-          exe_ctx, m_shared_cache_class_info_extractor.GetClassInfoArgs(),
-          arguments, diagnostics)) {
+          exe_ctx, m_args, arguments, diagnostics)) {
     EvaluateExpressionOptions options;
     options.SetUnwindOnError(true);
     options.SetTryAllThreads(false);
@@ -1896,8 +1887,7 @@
     // Run the function
     ExpressionResults results =
         get_shared_cache_class_info_function->ExecuteFunction(
-            exe_ctx, &m_shared_cache_class_info_extractor.GetClassInfoArgs(),
-            options, diagnostics, return_value);
+            exe_ctx, &m_args, options, diagnostics, return_value);
 
     if (results == eExpressionCompleted) {
       // The result is the number of ClassInfo structures that were filled in
@@ -1923,7 +1913,7 @@
                                          buffer.GetByteSize(),
                                          process->GetByteOrder(), addr_size);
 
-          ParseClassInfoArray(class_infos_data, num_class_infos);
+          m_runtime.ParseClassInfoArray(class_infos_data, num_class_infos);
         }
       } else {
         success = true;
@@ -2007,7 +1997,7 @@
 
     // Grab the dynamically loaded Objective-C classes from memory.
     DescriptorMapUpdateResult dynamic_update_result =
-        UpdateISAToDescriptorMapDynamic(hash_table);
+        m_dynamic_class_info_extractor.UpdateISAToDescriptorMap(hash_table);
 
     // Now get the objc classes that are baked into the Objective-C runtime in
     // the shared cache, but only once per process as this data never changes
@@ -2023,7 +2013,7 @@
       const uint32_t num_classes_to_warn_at = 500;
 
       DescriptorMapUpdateResult shared_cache_update_result =
-          UpdateISAToDescriptorMapSharedCache();
+          m_shared_cache_class_info_extractor.UpdateISAToDescriptorMap();
 
       LLDB_LOGF(log,
                 "attempted to read objc class data - results: "
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] ... Jonas Devlieghere via Phabricator via lldb-commits

Reply via email to