Don't re-add kexts and the kernel each time we get a notification
authorJason Molenda <jmolenda@apple.com>
Sat, 1 Dec 2012 06:13:29 +0000 (06:13 +0000)
committerJason Molenda <jmolenda@apple.com>
Sat, 1 Dec 2012 06:13:29 +0000 (06:13 +0000)
that kexts were newly added.

The Darwin userland dynamic loader provides lldb with a list of
newly-added or newly-removed binaries but in the kernel case we
only know that something has changed.  DynamicLoaderDarwinKernel
really needs to maintain its own persistent list of kexts that
it has been notified about (most importantly, it will not detect
kext unlods) but for now we'll at least avoid re-adding an already
present kext.

<rdar://problem/12658487>, <rdar://problem/12658487>

llvm-svn: 169082

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

index f88f2c9..52b52a5 100644 (file)
@@ -321,6 +321,16 @@ DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageUsingMemoryModule (
                 {
                     module_sp = target.GetSharedModule (module_spec);
                 }
+
+                // If we managed to find a module, append it to the target's list of images
+                if (module_sp && module_sp->GetUUID() == memory_module_sp->GetUUID())
+                {
+                    target.GetImages().Append(module_sp);
+                    if (memory_module_is_kernel && target.GetExecutableModulePointer() != module_sp.get())
+                    {
+                        target.SetExecutableModule (module_sp, false);
+                    }
+                }
             }
         }
     }
@@ -330,12 +340,6 @@ DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageUsingMemoryModule (
     {
         if (module_sp->GetUUID() == memory_module_sp->GetUUID())
         {
-            target.GetImages().Append(module_sp);
-            if (memory_module_is_kernel && target.GetExecutableModulePointer() != module_sp.get())
-            {
-                target.SetExecutableModule (module_sp, false);
-            }
-
             ObjectFile *ondisk_object_file = module_sp->GetObjectFile();
             ObjectFile *memory_object_file = memory_module_sp->GetObjectFile();
             if (memory_object_file && ondisk_object_file)
@@ -723,14 +727,6 @@ DynamicLoaderDarwinKernel::ReadKextSummaries (const Address &kext_summary_addr,
             {
                 image_infos[i].reference_list = 0;
             }
-//            printf ("[%3u] %*.*s: address=0x%16.16" PRIx64 ", size=0x%16.16" PRIx64 ", version=0x%16.16" PRIx64 ", load_tag=0x%8.8x, flags=0x%8.8x\n",
-//                    i,
-//                    KERNEL_MODULE_MAX_NAME, KERNEL_MODULE_MAX_NAME,  (char *)name_data, 
-//                    image_infos[i].address, 
-//                    image_infos[i].size,
-//                    image_infos[i].version,
-//                    image_infos[i].load_tag,
-//                    image_infos[i].flags);
         }
         if (i < image_infos.size())
             image_infos.resize(i);