When starting a kernel debug session, if the user specified an executable
authorJason Molenda <jmolenda@apple.com>
Wed, 27 Feb 2013 03:07:49 +0000 (03:07 +0000)
committerJason Molenda <jmolenda@apple.com>
Wed, 27 Feb 2013 03:07:49 +0000 (03:07 +0000)
binary to lldb already check that the UUID of that binary and the UUID of
the kernel binary in memory match.  Warn if they don't.
<rdar://problem/13184784>

llvm-svn: 176160

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

index d2fa3cc3360937051b0700e92165ca5f2c0cd7d7..9f7b1347412a4a7090c0b923e4faa65cc069b71f 100644 (file)
@@ -668,9 +668,9 @@ DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule (Process *process)
         }
     }
 
-    // If the kernel specified what UUID we should find at this load address,
-    // require that the memory module have a matching UUID or something has gone
-    // wrong and we should discard it.
+    // If this is a kext, and the kernel specified what UUID we should find at this 
+    // load address, require that the memory module have a matching UUID or something 
+    // has gone wrong and we should discard it.
     if (m_uuid.IsValid())
     {
         if (m_uuid != memory_module_sp->GetUUID())
@@ -689,10 +689,30 @@ DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule (Process *process)
     m_kernel_image = is_kernel;
     if (is_kernel)
     {
-       if (memory_module_sp->GetArchitecture().IsValid())
+        if (memory_module_sp->GetArchitecture().IsValid())
         {
             process->GetTarget().SetArchitecture(memory_module_sp->GetArchitecture());
         }
+        if (m_uuid.IsValid())
+        {
+            Module* exe_module = process->GetTarget().GetExecutableModulePointer();
+            if (exe_module && exe_module->GetUUID().IsValid())
+            {
+                if (m_uuid != exe_module->GetUUID())
+                {
+                    Stream *s = &process->GetTarget().GetDebugger().GetOutputStream();
+                    if (s)
+                    {
+                        char memory_module_uuidbuf[64];
+                        char exe_module_uuidbuf[64];
+                        s->Printf ("warning: Host-side kernel file has Mach-O UUID of %s but remote kernel has a UUID of %s -- a mismatched kernel file will result in a poor debugger experience.\n", 
+                                   exe_module->GetUUID().GetAsCString(exe_module_uuidbuf, sizeof (exe_module_uuidbuf)),
+                                   m_uuid.GetAsCString(memory_module_uuidbuf, sizeof (memory_module_uuidbuf)));
+                        s->Flush ();
+                    }
+                }
+            }
+        }
     }
 
     return true;