From 49bce8ecdbf84c44b84b405bc54cd76df22702f8 Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Fri, 10 Feb 2012 20:22:35 +0000 Subject: [PATCH] Improved detection of object file types, moving detection of kernels into the object file and adding a new category for raw binary images. Fixed all clients who previously searched for sections manually, making them use the object file's facilities instead. llvm-svn: 150272 --- lldb/include/lldb/Symbol/ObjectFile.h | 3 ++- .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp | 10 +--------- .../MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp | 10 +--------- .../DynamicLoader/Static/DynamicLoaderStatic.cpp | 13 +++++++++++++ .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 16 ++++++++++++++-- .../OperatingSystemDarwinKernel.cpp | 9 ++------- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h index e17e9c7721d0..094285a65ea7 100644 --- a/lldb/include/lldb/Symbol/ObjectFile.h +++ b/lldb/include/lldb/Symbol/ObjectFile.h @@ -75,7 +75,8 @@ public: eStrataInvalid = 0, eStrataUnknown, eStrataUser, - eStrataKernel + eStrataKernel, + eStrataRawImage } Strata; //------------------------------------------------------------------ diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp index 8225d3decf09..b82d6869edfe 100644 --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -58,15 +58,7 @@ DynamicLoaderDarwinKernel::CreateInstance (Process* process, bool force) ObjectFile *object_file = exe_module->GetObjectFile(); if (object_file) { - SectionList *section_list = object_file->GetSectionList(); - if (section_list) - { - static ConstString g_kld_section_name ("__KLD"); - if (section_list->FindSectionByName (g_kld_section_name)) - { - create = true; - } - } + create = (object_file->GetStrata() == ObjectFile::eStrataKernel); } } diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index d6094b439aba..f929ce13466e 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -98,15 +98,7 @@ DynamicLoaderMacOSXDYLD::CreateInstance (Process* process, bool force) ObjectFile *object_file = exe_module->GetObjectFile(); if (object_file) { - SectionList *section_list = object_file->GetSectionList(); - if (section_list) - { - static ConstString g_kld_section_name ("__KLD"); - if (section_list->FindSectionByName (g_kld_section_name)) - { - create = false; - } - } + create = (object_file->GetStrata() == ObjectFile::eStrataUser); } } diff --git a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp index 4d5ae558a5b1..a1d64422e600 100644 --- a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp +++ b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp @@ -33,6 +33,19 @@ DynamicLoaderStatic::CreateInstance (Process* process, bool force) create = true; } + if (!create) + { + Module *exe_module = process->GetTarget().GetExecutableModulePointer(); + if (exe_module) + { + ObjectFile *object_file = exe_module->GetObjectFile(); + if (object_file) + { + create = (object_file->GetStrata() == ObjectFile::eStrataRawImage); + } + } + } + if (create) return new DynamicLoaderStatic (process); return NULL; diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 67fe1e4e66f5..565682360c36 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -2180,12 +2180,24 @@ ObjectFileMachO::CalculateStrata() case HeaderFileTypeExecutable: // 0x2u MH_EXECUTE // Check for the MH_DYLDLINK bit in the flags if (m_header.flags & HeaderFlagBitIsDynamicLinkObject) + { return eStrataUser; - return eStrataKernel; + } + else + { + SectionList *section_list = GetSectionList(); + if (section_list) + { + static ConstString g_kld_section_name ("__KLD"); + if (section_list->FindSectionByName(g_kld_section_name)) + return eStrataKernel; + } + } + return eStrataRawImage; case HeaderFileTypeFixedVMShlib: return eStrataUser; // 0x3u MH_FVMLIB case HeaderFileTypeCore: return eStrataUnknown; // 0x4u MH_CORE - case HeaderFileTypePreloadedExecutable: return eStrataUser; // 0x5u MH_PRELOAD + case HeaderFileTypePreloadedExecutable: return eStrataRawImage; // 0x5u MH_PRELOAD case HeaderFileTypeDynamicShlib: return eStrataUser; // 0x6u MH_DYLIB case HeaderFileTypeDynamicLinkEditor: return eStrataUser; // 0x7u MH_DYLINKER case HeaderFileTypeBundle: return eStrataUser; // 0x8u MH_BUNDLE diff --git a/lldb/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemDarwinKernel.cpp b/lldb/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemDarwinKernel.cpp index 7aa33c39aa2a..8294861365f7 100644 --- a/lldb/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemDarwinKernel.cpp +++ b/lldb/source/Plugins/OperatingSystem/Darwin-Kernel/OperatingSystemDarwinKernel.cpp @@ -68,14 +68,9 @@ OperatingSystemDarwinKernel::CreateInstance (Process *process, bool force) ObjectFile *object_file = exe_module->GetObjectFile(); if (object_file) { - SectionList *section_list = object_file->GetSectionList(); - if (section_list) + if (object_file->GetStrata() != ObjectFile::eStrataKernel) { - static ConstString g_kld_section_name ("__KLD"); - if (section_list->FindSectionByName (g_kld_section_name)) - { - create = true; - } + return NULL; } } }