[Lldb-commits] [lldb] r189316 - Plugins/ObjectFile/PECOFF: Use enums from LLVM, and don't use Mach-O definitions.

Charles Davis cdavis5x at gmail.com
Mon Aug 26 22:04:33 PDT 2013


Author: cdavis
Date: Tue Aug 27 00:04:33 2013
New Revision: 189316

URL: http://llvm.org/viewvc/llvm-project?rev=189316&view=rev
Log:
Plugins/ObjectFile/PECOFF: Use enums from LLVM, and don't use Mach-O definitions.

Since I renamed most of the LLVM Mach-O enums in r189314, I had to go fix
LLDB to use the new names. While I was here, I decided that a COFF
plugin really shouldn't be using Mach-O enums.

Modified:
    lldb/trunk/include/lldb/lldb-private-enumerations.h
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Modified: lldb/trunk/include/lldb/lldb-private-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-enumerations.h?rev=189316&r1=189315&r2=189316&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-private-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-private-enumerations.h Tue Aug 27 00:04:33 2013
@@ -51,6 +51,7 @@ typedef enum ArchitectureType
     eArchTypeInvalid,
     eArchTypeMachO,
     eArchTypeELF,
+    eArchTypeCOFF,
     kNumArchTypes
 } ArchitectureType;
 

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=189316&r1=189315&r2=189316&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Tue Aug 27 00:04:33 2013
@@ -14,6 +14,7 @@
 
 #include <string>
 
+#include "llvm/Support/COFF.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MachO.h"
@@ -238,11 +239,30 @@ static const ArchDefinition g_elf_arch_d
     "elf",
 };
 
+static const ArchDefinitionEntry g_coff_arch_entries[] =
+{
+    { ArchSpec::eCore_x86_32_i386  , llvm::COFF::IMAGE_FILE_MACHINE_I386     , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel 80386
+    { ArchSpec::eCore_ppc_generic  , llvm::COFF::IMAGE_FILE_MACHINE_POWERPC  , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC
+    { ArchSpec::eCore_ppc_generic  , llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC (with FPU)
+    { ArchSpec::eCore_arm_generic  , llvm::COFF::IMAGE_FILE_MACHINE_ARM      , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARM
+    { ArchSpec::eCore_arm_armv7    , llvm::COFF::IMAGE_FILE_MACHINE_ARMV7    , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARMv7
+    { ArchSpec::eCore_thumb        , llvm::COFF::IMAGE_FILE_MACHINE_THUMB    , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // ARMv7
+    { ArchSpec::eCore_x86_64_x86_64, llvm::COFF::IMAGE_FILE_MACHINE_AMD64    , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }  // AMD64
+};
+
+static const ArchDefinition g_coff_arch_def = {
+    eArchTypeCOFF,
+    sizeof(g_coff_arch_entries)/sizeof(g_coff_arch_entries[0]),
+    g_coff_arch_entries,
+    "pe-coff",
+};
+
 //===----------------------------------------------------------------------===//
 // Table of all ArchDefinitions
 static const ArchDefinition *g_arch_definitions[] = {
     &g_macho_arch_def,
-    &g_elf_arch_def
+    &g_elf_arch_def,
+    &g_coff_arch_def
 };
 
 static const size_t k_num_arch_definitions =

Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp?rev=189316&r1=189315&r2=189316&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp Tue Aug 27 00:04:33 2013
@@ -9,7 +9,7 @@
 
 #include "ObjectFilePECOFF.h"
 
-#include "llvm/Support/MachO.h"
+#include "llvm/Support/COFF.h"
 
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBuffer.h"
@@ -25,94 +25,11 @@
 #include "lldb/Core/UUID.h"
 #include "lldb/Symbol/ObjectFile.h"
 
-static uint32_t COFFMachineToMachCPU(uint16_t machine);
-
-#define IMAGE_FILE_MACHINE_UNKNOWN      0x0000
-#define IMAGE_FILE_MACHINE_AM33         0x01d3  // Matsushita AM33
-#define IMAGE_FILE_MACHINE_AMD64        0x8664  // x64
-#define IMAGE_FILE_MACHINE_ARM          0x01c0  // ARM little endian
-#define IMAGE_FILE_MACHINE_EBC          0x0ebc  // EFI byte code
-#define IMAGE_FILE_MACHINE_I386         0x014c  // Intel 386 or later processors and compatible processors
-#define IMAGE_FILE_MACHINE_IA64         0x0200  // Intel Itanium processor family
-#define IMAGE_FILE_MACHINE_M32R         0x9041  // Mitsubishi M32R little endian
-#define IMAGE_FILE_MACHINE_MIPS16       0x0266  // MIPS16
-#define IMAGE_FILE_MACHINE_MIPSFPU      0x0366  // MIPS with FPU
-#define IMAGE_FILE_MACHINE_MIPSFPU16    0x0466  // MIPS16 with FPU
-#define IMAGE_FILE_MACHINE_POWERPC      0x01f0  // Power PC little endian
-#define IMAGE_FILE_MACHINE_POWERPCFP    0x01f1  // Power PC with floating point support
-#define IMAGE_FILE_MACHINE_R4000        0x0166  // MIPS little endian
-#define IMAGE_FILE_MACHINE_SH3          0x01a2  // Hitachi SH3
-#define IMAGE_FILE_MACHINE_SH3DSP       0x01a3  // Hitachi SH3 DSP
-#define IMAGE_FILE_MACHINE_SH4          0x01a6  // Hitachi SH4
-#define IMAGE_FILE_MACHINE_SH5          0x01a8  // Hitachi SH5
-#define IMAGE_FILE_MACHINE_THUMB        0x01c2  // Thumb
-#define IMAGE_FILE_MACHINE_WCEMIPSV2    0x0169  // MIPS little-endian WCE v2
-
-
 #define IMAGE_DOS_SIGNATURE             0x5A4D      // MZ
-#define IMAGE_OS2_SIGNATURE             0x454E      // NE
-#define IMAGE_OS2_SIGNATURE_LE          0x454C      // LE
 #define IMAGE_NT_SIGNATURE              0x00004550  // PE00
 #define OPT_HEADER_MAGIC_PE32           0x010b
 #define OPT_HEADER_MAGIC_PE32_PLUS      0x020b
 
-#define IMAGE_FILE_RELOCS_STRIPPED          0x0001
-#define IMAGE_FILE_EXECUTABLE_IMAGE         0x0002
-#define IMAGE_FILE_LINE_NUMS_STRIPPED       0x0004
-#define IMAGE_FILE_LOCAL_SYMS_STRIPPED      0x0008    
-#define IMAGE_FILE_AGGRESSIVE_WS_TRIM       0x0010
-#define IMAGE_FILE_LARGE_ADDRESS_AWARE      0x0020
-//#define                                   0x0040  // Reserved
-#define IMAGE_FILE_BYTES_REVERSED_LO        0x0080
-#define IMAGE_FILE_32BIT_MACHINE            0x0100
-#define IMAGE_FILE_DEBUG_STRIPPED           0x0200
-#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP  0x0400
-#define IMAGE_FILE_NET_RUN_FROM_SWAP        0x0800
-#define IMAGE_FILE_SYSTEM                   0x1000
-#define IMAGE_FILE_DLL                      0x2000
-#define IMAGE_FILE_UP_SYSTEM_ONLY           0x4000
-#define IMAGE_FILE_BYTES_REVERSED_HI        0x8000
-
-
-// Section Flags
-// The section flags in the Characteristics field of the section header indicate
-// characteristics of the section.
-#define IMAGE_SCN_TYPE_NO_PAD               0x00000008 // The section should not be padded to the next boundary. This flag is obsolete and is replaced by IMAGE_SCN_ALIGN_1BYTES. This is valid only for object files.
-#define IMAGE_SCN_CNT_CODE                  0x00000020 // The section contains executable code.
-#define IMAGE_SCN_CNT_INITIALIZED_DATA      0x00000040 // The section contains initialized data.
-#define IMAGE_SCN_CNT_UNINITIALIZED_DATA    0x00000080 // The section contains uninitialized data.
-#define IMAGE_SCN_LNK_OTHER                 0x00000100 // Reserved for future use.
-#define IMAGE_SCN_LNK_INFO                  0x00000200 // The section contains comments or other information. The .drectve section has this type. This is valid for object files only.
-#define IMAGE_SCN_LNK_REMOVE                0x00000800 // The section will not become part of the image. This is valid only for object files.
-#define IMAGE_SCN_LNK_COMDAT                0x00001000 // The section contains COMDAT data. For more information, see section 5.5.6, “COMDAT Sections (Object Only).” This is valid only for object files.
-#define IMAGE_SCN_GPREL                     0x00008000 // The section contains data referenced through the global pointer (GP).
-#define IMAGE_SCN_MEM_PURGEABLE             0x00020000
-#define IMAGE_SCN_MEM_16BIT                 0x00020000 // For ARM machine types, the section contains Thumb code.  Reserved for future use with other machine types.
-#define IMAGE_SCN_MEM_LOCKED                0x00040000
-#define IMAGE_SCN_MEM_PRELOAD               0x00080000
-#define IMAGE_SCN_ALIGN_1BYTES              0x00100000 // Align data on a 1-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_2BYTES              0x00200000 // Align data on a 2-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_4BYTES              0x00300000 // Align data on a 4-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_8BYTES              0x00400000 // Align data on an 8-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_16BYTES             0x00500000 // Align data on a 16-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_32BYTES             0x00600000 // Align data on a 32-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_64BYTES             0x00700000 // Align data on a 64-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_128BYTES            0x00800000 // Align data on a 128-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_256BYTES            0x00900000 // Align data on a 256-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_512BYTES            0x00A00000 // Align data on a 512-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_1024BYTES           0x00B00000 // Align data on a 1024-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_2048BYTES           0x00C00000 // Align data on a 2048-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_4096BYTES           0x00D00000 // Align data on a 4096-byte boundary. Valid only for object files.
-#define IMAGE_SCN_ALIGN_8192BYTES           0x00E00000 // Align data on an 8192-byte boundary. Valid only for object files.
-#define IMAGE_SCN_LNK_NRELOC_OVFL           0x01000000 // The section contains extended relocations.
-#define IMAGE_SCN_MEM_DISCARDABLE           0x02000000 // The section can be discarded as needed.
-#define IMAGE_SCN_MEM_NOT_CACHED            0x04000000 // The section cannot be cached.
-#define IMAGE_SCN_MEM_NOT_PAGED             0x08000000 // The section is not pageable.
-#define IMAGE_SCN_MEM_SHARED                0x10000000 // The section can be shared in memory.
-#define IMAGE_SCN_MEM_EXECUTE               0x20000000 // The section can be executed as code.
-#define IMAGE_SCN_MEM_READ                  0x40000000 // The section can be read.
-#define IMAGE_SCN_MEM_WRITE                 0x80000000 // The section can be written to.
-
 using namespace lldb;
 using namespace lldb_private;
 
@@ -266,7 +183,7 @@ ObjectFilePECOFF::GetByteOrder () const
 bool
 ObjectFilePECOFF::IsExecutable() const
 {
-    return (m_coff_header.flags & IMAGE_FILE_DLL) == 0;
+    return (m_coff_header.flags & llvm::COFF::IMAGE_FILE_DLL) == 0;
 }
 
 uint32_t
@@ -700,17 +617,17 @@ ObjectFilePECOFF::CreateSections (Sectio
                 static ConstString g_sect_name_dwarf_debug_str (".debug_str");
                 static ConstString g_sect_name_eh_frame (".eh_frame");
                 SectionType section_type = eSectionTypeOther;
-                if (m_sect_headers[idx].flags & IMAGE_SCN_CNT_CODE && 
+                if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_CODE &&
                     ((const_sect_name == g_code_sect_name) || (const_sect_name == g_CODE_sect_name)))
                 {
                     section_type = eSectionTypeCode;
                 }
-                else if (m_sect_headers[idx].flags & IMAGE_SCN_CNT_INITIALIZED_DATA && 
+                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA &&
                          ((const_sect_name == g_data_sect_name) || (const_sect_name == g_DATA_sect_name)))
                 {
                     section_type = eSectionTypeData;
                 }
-                else if (m_sect_headers[idx].flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA && 
+                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA &&
                          ((const_sect_name == g_bss_sect_name) || (const_sect_name == g_BSS_sect_name)))
                 {
                     if (m_sect_headers[idx].size == 0)
@@ -742,15 +659,15 @@ ObjectFilePECOFF::CreateSections (Sectio
                 else if (const_sect_name == g_sect_name_dwarf_debug_ranges)    section_type = eSectionTypeDWARFDebugRanges;
                 else if (const_sect_name == g_sect_name_dwarf_debug_str)       section_type = eSectionTypeDWARFDebugStr;
                 else if (const_sect_name == g_sect_name_eh_frame)              section_type = eSectionTypeEHFrame;
-                else if (m_sect_headers[idx].flags & IMAGE_SCN_CNT_CODE)
+                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_CODE)
                 {
                     section_type = eSectionTypeCode;
                 }
-                else if (m_sect_headers[idx].flags & IMAGE_SCN_CNT_INITIALIZED_DATA)
+                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
                 {
                     section_type = eSectionTypeData;
                 }
-                else if (m_sect_headers[idx].flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
+                else if (m_sect_headers[idx].flags & llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
                 {
                     if (m_sect_headers[idx].size == 0)
                         section_type = eSectionTypeZeroFill;
@@ -992,52 +909,33 @@ ObjectFilePECOFF::DumpSectionHeaders(Str
     }
 }
 
-static bool 
-COFFMachineToMachCPU (uint16_t machine, ArchSpec &arch)
+bool
+ObjectFilePECOFF::GetArchitecture (ArchSpec &arch)
 {
+    uint16_t machine = m_coff_header.machine;
     switch (machine)
     {
-        case IMAGE_FILE_MACHINE_AMD64:
-        case IMAGE_FILE_MACHINE_IA64:
-            arch.SetArchitecture (eArchTypeMachO, 
-                                  llvm::MachO::CPUTypeX86_64,
-                                  llvm::MachO::CPUSubType_X86_64_ALL);
-            return true;
-
-        case IMAGE_FILE_MACHINE_I386:
-            arch.SetArchitecture (eArchTypeMachO, 
-                                  llvm::MachO::CPUTypeI386,
-                                  llvm::MachO::CPUSubType_I386_ALL);
-            return true;
-            
-        case IMAGE_FILE_MACHINE_POWERPC:    
-        case IMAGE_FILE_MACHINE_POWERPCFP:  
-            arch.SetArchitecture (eArchTypeMachO, 
-                                  llvm::MachO::CPUTypePowerPC,
-                                  llvm::MachO::CPUSubType_POWERPC_ALL);
-            return true;
-        case IMAGE_FILE_MACHINE_ARM:
-        case IMAGE_FILE_MACHINE_THUMB:
-            arch.SetArchitecture (eArchTypeMachO, 
-                                  llvm::MachO::CPUTypeARM,
-                                  llvm::MachO::CPUSubType_ARM_V7);
+        case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+        case llvm::COFF::IMAGE_FILE_MACHINE_I386:
+        case llvm::COFF::IMAGE_FILE_MACHINE_POWERPC:
+        case llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP:
+        case llvm::COFF::IMAGE_FILE_MACHINE_ARM:
+        case llvm::COFF::IMAGE_FILE_MACHINE_ARMV7:
+        case llvm::COFF::IMAGE_FILE_MACHINE_THUMB:
+            arch.SetArchitecture (eArchTypeCOFF, machine, 0);
             return true;
+        default:
+            break;
     }
     return false;
 }
-bool
-ObjectFilePECOFF::GetArchitecture (ArchSpec &arch)
-{
-    // For index zero return our cpu type
-    return COFFMachineToMachCPU (m_coff_header.machine, arch);
-}
 
 ObjectFile::Type
 ObjectFilePECOFF::CalculateType()
 {
     if (m_coff_header.machine != 0)
     {
-        if ((m_coff_header.flags & IMAGE_FILE_DLL) == 0)
+        if ((m_coff_header.flags & llvm::COFF::IMAGE_FILE_DLL) == 0)
             return eTypeExecutable;
         else
             return eTypeSharedLibrary;





More information about the lldb-commits mailing list