[Lldb-commits] [lldb] r139401 - in /lldb/trunk: lldb.xcodeproj/project.pbxproj source/Plugins/ObjectFile/PECOFF/ source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h source/lldb.cpp

Greg Clayton gclayton at apple.com
Fri Sep 9 13:33:05 PDT 2011


Author: gclayton
Date: Fri Sep  9 15:33:05 2011
New Revision: 139401

URL: http://llvm.org/viewvc/llvm-project?rev=139401&view=rev
Log:
Added first pass at PE COFF file reading support. It parses the sections
correctly, symbols are coming soon. It also needs to be 32/64 bit hardened
with more testing.


Added:
    lldb/trunk/source/Plugins/ObjectFile/PECOFF/
    lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
    lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
Modified:
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/lldb.cpp

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=139401&r1=139400&r2=139401&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Sep  9 15:33:05 2011
@@ -384,6 +384,7 @@
 		26DE20611161902700A093E2 /* SBBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26DE20601161902600A093E2 /* SBBlock.cpp */; };
 		26DE20631161904200A093E2 /* SBLineEntry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26DE20621161904200A093E2 /* SBLineEntry.cpp */; };
 		26DE20651161904E00A093E2 /* SBSymbol.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26DE20641161904E00A093E2 /* SBSymbol.cpp */; };
+		26E152261419CAD4007967D0 /* ObjectFilePECOFF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26E152231419CACA007967D0 /* ObjectFilePECOFF.cpp */; };
 		26ECA04313665FED008D1F18 /* ARM_DWARF_Registers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26ECA04213665FED008D1F18 /* ARM_DWARF_Registers.cpp */; };
 		26ED3D6D13C563810017D45E /* OptionGroupVariable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26ED3D6C13C563810017D45E /* OptionGroupVariable.cpp */; };
 		26F4A21C13FBA31A0064B613 /* ThreadMemory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F4A21A13FBA31A0064B613 /* ThreadMemory.cpp */; };
@@ -1060,6 +1061,8 @@
 		26DFBC57113B48F300DD817F /* CommandObjectCrossref.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectCrossref.cpp; path = source/Commands/CommandObjectCrossref.cpp; sourceTree = "<group>"; };
 		26DFBC58113B48F300DD817F /* CommandObjectMultiword.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectMultiword.cpp; path = source/Commands/CommandObjectMultiword.cpp; sourceTree = "<group>"; };
 		26DFBC59113B48F300DD817F /* CommandObjectRegexCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectRegexCommand.cpp; path = source/Interpreter/CommandObjectRegexCommand.cpp; sourceTree = "<group>"; };
+		26E152231419CACA007967D0 /* ObjectFilePECOFF.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectFilePECOFF.cpp; sourceTree = "<group>"; };
+		26E152241419CACA007967D0 /* ObjectFilePECOFF.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ObjectFilePECOFF.h; sourceTree = "<group>"; };
 		26E3EEBD11A9870400FBADB6 /* Unwind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Unwind.h; path = include/lldb/Target/Unwind.h; sourceTree = "<group>"; };
 		26E3EEE311A9901300FBADB6 /* UnwindMacOSXFrameBackchain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnwindMacOSXFrameBackchain.cpp; path = Utility/UnwindMacOSXFrameBackchain.cpp; sourceTree = "<group>"; };
 		26E3EEE411A9901300FBADB6 /* UnwindMacOSXFrameBackchain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnwindMacOSXFrameBackchain.h; path = Utility/UnwindMacOSXFrameBackchain.h; sourceTree = "<group>"; };
@@ -1494,6 +1497,7 @@
 			children = (
 				260C898310F57C5600BB2B04 /* ELF */,
 				260C898710F57C5600BB2B04 /* Mach-O */,
+				26E152221419CACA007967D0 /* PECOFF */,
 			);
 			path = ObjectFile;
 			sourceTree = "<group>";
@@ -2553,6 +2557,15 @@
 			name = "lldb-platform";
 			sourceTree = "<group>";
 		};
+		26E152221419CACA007967D0 /* PECOFF */ = {
+			isa = PBXGroup;
+			children = (
+				26E152231419CACA007967D0 /* ObjectFilePECOFF.cpp */,
+				26E152241419CACA007967D0 /* ObjectFilePECOFF.h */,
+			);
+			path = PECOFF;
+			sourceTree = "<group>";
+		};
 		26F5C22410F3D950009D5894 /* Tools */ = {
 			isa = PBXGroup;
 			children = (
@@ -3344,6 +3357,7 @@
 				268ED0A5140FF54200DE830F /* DataEncoder.cpp in Sources */,
 				26A0DA4E140F7226006DA411 /* HashedNameToDIE.cpp in Sources */,
 				B27318421416AC12006039C8 /* WatchpointLocationList.cpp in Sources */,
+				26E152261419CAD4007967D0 /* ObjectFilePECOFF.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp?rev=139401&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (added)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp Fri Sep  9 15:33:05 2011
@@ -0,0 +1,805 @@
+//===-- ObjectFilePECOFF.cpp ------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ObjectFilePECOFF.h"
+
+#include "llvm/Support/MachO.h"
+
+#include "lldb/Core/ArchSpec.h"
+#include "lldb/Core/DataBuffer.h"
+#include "lldb/Host/FileSpec.h"
+#include "lldb/Core/FileSpecList.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Core/Timer.h"
+#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
+
+using namespace lldb;
+using namespace lldb_private;
+
+void
+ObjectFilePECOFF::Initialize()
+{
+    PluginManager::RegisterPlugin (GetPluginNameStatic(),
+                                   GetPluginDescriptionStatic(),
+                                   CreateInstance);
+}
+
+void
+ObjectFilePECOFF::Terminate()
+{
+    PluginManager::UnregisterPlugin (CreateInstance);
+}
+
+
+const char *
+ObjectFilePECOFF::GetPluginNameStatic()
+{
+    return "object-file.pe-coff";
+}
+
+const char *
+ObjectFilePECOFF::GetPluginDescriptionStatic()
+{
+    return "Portable Executable and Common Object File Format object file reader (32 and 64 bit)";
+}
+
+
+ObjectFile *
+ObjectFilePECOFF::CreateInstance (Module* module, DataBufferSP& dataSP, const FileSpec* file, addr_t offset, addr_t length)
+{
+    if (ObjectFilePECOFF::MagicBytesMatch(dataSP))
+    {
+        std::auto_ptr<ObjectFile> objfile_ap(new ObjectFilePECOFF (module, dataSP, file, offset, length));
+        if (objfile_ap.get() && objfile_ap->ParseHeader())
+            return objfile_ap.release();
+    }
+    return NULL;
+}
+
+bool
+ObjectFilePECOFF::MagicBytesMatch (DataBufferSP& dataSP)
+{
+    DataExtractor data(dataSP, eByteOrderLittle, 4);
+    uint32_t offset = 0;
+    uint16_t magic = data.GetU16 (&offset);
+    return magic == IMAGE_DOS_SIGNATURE;
+}
+
+
+ObjectFilePECOFF::ObjectFilePECOFF (Module* module, 
+                                    DataBufferSP& dataSP, 
+                                    const FileSpec* file, 
+                                    addr_t offset, 
+                                    addr_t length) :
+    ObjectFile (module, file, offset, length, dataSP),
+    m_mutex (Mutex::eMutexTypeRecursive),
+    m_dos_header (),
+    m_coff_header (),
+    m_coff_header_opt (),
+    m_sect_headers ()
+{
+    ::memset (&m_dos_header, 0, sizeof(m_dos_header));
+    ::memset (&m_coff_header, 0, sizeof(m_coff_header));
+    ::memset (&m_coff_header_opt, 0, sizeof(m_coff_header_opt));
+}
+
+
+ObjectFilePECOFF::~ObjectFilePECOFF()
+{
+}
+
+
+bool
+ObjectFilePECOFF::ParseHeader ()
+{
+    Mutex::Locker locker(m_mutex);
+    m_sect_headers.clear();
+    m_data.SetByteOrder (eByteOrderLittle);
+    uint32_t offset = 0;
+    
+    if (ParseDOSHeader())
+    {
+        offset = m_dos_header.e_lfanew;
+        uint32_t pe_signature = m_data.GetU32 (&offset);
+        if (pe_signature != IMAGE_NT_SIGNATURE)
+            return false;
+    }
+    if (ParseCOFFHeader(&offset))
+    {
+        if (m_coff_header.hdrsize > 0)
+            ParseCOFFOptionalHeader(&offset);
+        ParseSectionHeaders (offset);
+        return true;
+    }
+    return false;
+}
+
+
+ByteOrder
+ObjectFilePECOFF::GetByteOrder () const
+{
+    return eByteOrderLittle;
+}
+
+bool
+ObjectFilePECOFF::IsExecutable() const
+{
+    return (m_coff_header.flags & IMAGE_FILE_DLL) == 0;
+}
+
+size_t
+ObjectFilePECOFF::GetAddressByteSize () const
+{
+    if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32_PLUS)
+        return 8;
+    else if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32)
+        return 4;
+    return 4;
+}
+
+//----------------------------------------------------------------------
+// NeedsEndianSwap
+//
+// Return true if an endian swap needs to occur when extracting data 
+// from this file.
+//----------------------------------------------------------------------
+bool 
+ObjectFilePECOFF::NeedsEndianSwap() const
+{
+#if defined(__LITTLE_ENDIAN__)
+    return false;
+#else
+    return true;
+#endif
+}
+//----------------------------------------------------------------------
+// ParseDOSHeader
+//----------------------------------------------------------------------
+bool
+ObjectFilePECOFF::ParseDOSHeader ()
+{
+    bool success = false;
+    uint32_t offset = 0;
+    success = m_data.ValidOffsetForDataOfSize(0, sizeof(m_dos_header));
+    
+    if (success)
+    {
+        m_dos_header.e_magic = m_data.GetU16(&offset); // Magic number
+        success = m_dos_header.e_magic == IMAGE_DOS_SIGNATURE;
+        
+        if (success)
+        {
+            m_dos_header.e_cblp     = m_data.GetU16(&offset); // Bytes on last page of file
+            m_dos_header.e_cp       = m_data.GetU16(&offset); // Pages in file
+            m_dos_header.e_crlc     = m_data.GetU16(&offset); // Relocations
+            m_dos_header.e_cparhdr  = m_data.GetU16(&offset); // Size of header in paragraphs
+            m_dos_header.e_minalloc = m_data.GetU16(&offset); // Minimum extra paragraphs needed
+            m_dos_header.e_maxalloc = m_data.GetU16(&offset); // Maximum extra paragraphs needed
+            m_dos_header.e_ss       = m_data.GetU16(&offset); // Initial (relative) SS value
+            m_dos_header.e_sp       = m_data.GetU16(&offset); // Initial SP value
+            m_dos_header.e_csum     = m_data.GetU16(&offset); // Checksum
+            m_dos_header.e_ip       = m_data.GetU16(&offset); // Initial IP value
+            m_dos_header.e_cs       = m_data.GetU16(&offset); // Initial (relative) CS value
+            m_dos_header.e_lfarlc   = m_data.GetU16(&offset); // File address of relocation table
+            m_dos_header.e_ovno     = m_data.GetU16(&offset); // Overlay number
+            
+            m_dos_header.e_res[0]   = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res[1]   = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res[2]   = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res[3]   = m_data.GetU16(&offset); // Reserved words
+            
+            m_dos_header.e_oemid    = m_data.GetU16(&offset); // OEM identifier (for e_oeminfo)
+            m_dos_header.e_oeminfo  = m_data.GetU16(&offset); // OEM information; e_oemid specific
+            m_dos_header.e_res2[0]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[1]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[2]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[3]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[4]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[5]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[6]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[7]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[8]  = m_data.GetU16(&offset); // Reserved words
+            m_dos_header.e_res2[9]  = m_data.GetU16(&offset); // Reserved words
+            
+            m_dos_header.e_lfanew   = m_data.GetU32(&offset); // File address of new exe header
+        }
+    }
+    if (!success)
+        memset(&m_dos_header, 0, sizeof(m_dos_header));
+    return success;
+}
+
+
+//----------------------------------------------------------------------
+// ParserCOFFHeader
+//----------------------------------------------------------------------
+bool
+ObjectFilePECOFF::ParseCOFFHeader(uint32_t* offset_ptr)
+{
+    bool success = m_data.ValidOffsetForDataOfSize (*offset_ptr, sizeof(m_coff_header));
+    if (success)
+    {
+        m_coff_header.machine   = m_data.GetU16(offset_ptr);
+        m_coff_header.nsects    = m_data.GetU16(offset_ptr);
+        m_coff_header.modtime   = m_data.GetU32(offset_ptr);
+        m_coff_header.symoff    = m_data.GetU32(offset_ptr);
+        m_coff_header.nsyms     = m_data.GetU32(offset_ptr);
+        m_coff_header.hdrsize   = m_data.GetU16(offset_ptr);
+        m_coff_header.flags     = m_data.GetU16(offset_ptr);
+    }
+    if (!success)
+        memset(&m_coff_header, 0, sizeof(m_coff_header));
+    return success;
+}
+
+bool
+ObjectFilePECOFF::ParseCOFFOptionalHeader(uint32_t* offset_ptr)
+{
+    bool success = false;
+    const uint32_t end_offset = *offset_ptr + m_coff_header.hdrsize;
+    if (*offset_ptr < end_offset)
+    {
+        success = true;
+        m_coff_header_opt.magic                         = m_data.GetU16(offset_ptr); 
+        m_coff_header_opt.major_linker_version          = m_data.GetU8 (offset_ptr);
+        m_coff_header_opt.minor_linker_version          = m_data.GetU8 (offset_ptr);     
+        m_coff_header_opt.code_size                     = m_data.GetU32(offset_ptr); 
+        m_coff_header_opt.data_size                     = m_data.GetU32(offset_ptr); 
+        m_coff_header_opt.bss_size                      = m_data.GetU32(offset_ptr); 
+        m_coff_header_opt.entry                         = m_data.GetU32(offset_ptr); 
+        m_coff_header_opt.code_offset                   = m_data.GetU32(offset_ptr); 
+
+        const uint32_t addr_byte_size = GetAddressByteSize ();
+
+        if (*offset_ptr < end_offset)
+        {
+            if (m_coff_header_opt.magic == OPT_HEADER_MAGIC_PE32)
+            {
+                // PE32 only
+                m_coff_header_opt.data_offset               = m_data.GetU32(offset_ptr);                             
+            }
+            else
+                m_coff_header_opt.data_offset = 0;
+        
+            if (*offset_ptr < end_offset)
+            {
+                m_coff_header_opt.image_base                    = m_data.GetMaxU64 (offset_ptr, addr_byte_size); 
+                m_coff_header_opt.sect_alignment                = m_data.GetU32(offset_ptr); 
+                m_coff_header_opt.file_alignment                = m_data.GetU32(offset_ptr); 
+                m_coff_header_opt.major_os_system_version       = m_data.GetU16(offset_ptr); 
+                m_coff_header_opt.minor_os_system_version       = m_data.GetU16(offset_ptr); 
+                m_coff_header_opt.major_image_version           = m_data.GetU16(offset_ptr); 
+                m_coff_header_opt.minor_image_version           = m_data.GetU16(offset_ptr); 
+                m_coff_header_opt.major_subsystem_version       = m_data.GetU16(offset_ptr); 
+                m_coff_header_opt.minor_subsystem_version       = m_data.GetU16(offset_ptr); 
+                m_coff_header_opt.reserved1                     = m_data.GetU32(offset_ptr); 
+                m_coff_header_opt.image_size                    = m_data.GetU32(offset_ptr); 
+                m_coff_header_opt.header_size                   = m_data.GetU32(offset_ptr); 
+                m_coff_header_opt.checksym                      = m_data.GetU32(offset_ptr); 
+                m_coff_header_opt.subsystem                     = m_data.GetU16(offset_ptr); 
+                m_coff_header_opt.dll_flags                     = m_data.GetU16(offset_ptr); 
+                m_coff_header_opt.stack_reserve_size            = m_data.GetMaxU64 (offset_ptr, addr_byte_size);
+                m_coff_header_opt.stack_commit_size             = m_data.GetMaxU64 (offset_ptr, addr_byte_size);
+                m_coff_header_opt.heap_reserve_size             = m_data.GetMaxU64 (offset_ptr, addr_byte_size);
+                m_coff_header_opt.heap_commit_size              = m_data.GetMaxU64 (offset_ptr, addr_byte_size);
+                m_coff_header_opt.loader_flags                  = m_data.GetU32(offset_ptr); 
+                uint32_t num_data_dir_entries = m_data.GetU32(offset_ptr);
+                m_coff_header_opt.data_dirs.clear();
+                m_coff_header_opt.data_dirs.resize(num_data_dir_entries);
+                uint32_t i;
+                for (i=0; i<num_data_dir_entries; i++)
+                {
+                    m_coff_header_opt.data_dirs[i].vmaddr = m_data.GetU32(offset_ptr);
+                    m_coff_header_opt.data_dirs[i].vmsize = m_data.GetU32(offset_ptr);
+                }
+            }
+        }
+    }
+    // Make sure we are on track for section data which follows
+    *offset_ptr = end_offset;
+    return success;
+}
+
+
+//----------------------------------------------------------------------
+// ParseSectionHeaders
+//----------------------------------------------------------------------
+bool
+ObjectFilePECOFF::ParseSectionHeaders (uint32_t section_header_data_offset)
+{
+    const uint32_t nsects = m_coff_header.nsects;
+    m_sect_headers.clear();
+    
+    if (nsects > 0)
+    {
+        const uint32_t addr_byte_size = GetAddressByteSize ();
+        const size_t section_header_byte_size = nsects * sizeof(section_header_t);
+        DataBufferSP section_header_data_sp(m_file.ReadFileContents (section_header_data_offset, section_header_byte_size));
+        DataExtractor section_header_data (section_header_data_sp, GetByteOrder(), addr_byte_size);
+
+        uint32_t offset = 0;
+        if (section_header_data.ValidOffsetForDataOfSize (offset, section_header_byte_size))
+        {
+            m_sect_headers.resize(nsects);
+            
+            for (uint32_t idx = 0; idx<nsects; ++idx)
+            {
+                const void *name_data = section_header_data.GetData(&offset, 8);
+                if (name_data)
+                {
+                    memcpy(m_sect_headers[idx].name, name_data, 8);
+                    m_sect_headers[idx].vmsize  = section_header_data.GetU32(&offset);
+                    m_sect_headers[idx].vmaddr  = section_header_data.GetU32(&offset);
+                    m_sect_headers[idx].size    = section_header_data.GetU32(&offset);
+                    m_sect_headers[idx].offset  = section_header_data.GetU32(&offset);
+                    m_sect_headers[idx].reloff  = section_header_data.GetU32(&offset);
+                    m_sect_headers[idx].lineoff = section_header_data.GetU32(&offset);
+                    m_sect_headers[idx].nreloc  = section_header_data.GetU16(&offset);
+                    m_sect_headers[idx].nline   = section_header_data.GetU16(&offset);
+                    m_sect_headers[idx].flags   = section_header_data.GetU32(&offset);
+                }
+            }
+        }
+    }
+    
+    return m_sect_headers.empty() == false;
+}
+
+bool
+ObjectFilePECOFF::GetSectionName(std::string& sect_name, const section_header_t& sect)
+{
+    if (sect.name[0] == '/')
+    {
+        uint32_t stroff = strtoul(&sect.name[1], NULL, 10);
+        uint32_t string_file_offset = m_coff_header.symoff + (m_coff_header.nsyms * 18) + stroff;
+        const char *name = m_data.GetCStr (&string_file_offset);
+        if (name)
+        {
+            sect_name = name;
+            return true;
+        }
+        
+        return false;
+    }
+    sect_name = sect.name;
+    return true;
+}       
+
+//----------------------------------------------------------------------
+// GetNListSymtab
+//----------------------------------------------------------------------
+Symtab *
+ObjectFilePECOFF::GetSymtab()
+{
+    Mutex::Locker symfile_locker(m_mutex);
+    if (m_symtab_ap.get() == NULL)
+    {
+        SectionList *sect_list = GetSectionList();
+        m_symtab_ap.reset(new Symtab(this));
+        Mutex::Locker symtab_locker (m_symtab_ap->GetMutex());
+        DataExtractor stab_data;
+        DataExtractor stabstr_data;
+        static ConstString g_stab_sect_name(".stab");
+        static ConstString g_stabstr_sect_name(".stabstr");
+        const Section *stab_section = sect_list->FindSectionByName (g_stab_sect_name).get();
+        if (stab_section == NULL)
+            return m_symtab_ap.get();
+        const Section *stabstr_section = sect_list->FindSectionByName (g_stabstr_sect_name).get();
+        if (stabstr_section == NULL)
+            return m_symtab_ap.get();
+        uint32_t offset = 0;
+        if (stab_section->ReadSectionDataFromObjectFile (this, stab_data) &&
+            stabstr_section->ReadSectionDataFromObjectFile (this, stabstr_data))
+        {
+            const uint32_t num_syms = stab_data.GetByteSize() / sizeof (coff_symbol_t);
+            Symbol *symbols = m_symtab_ap->Resize (num_syms);
+            for (uint32_t i=0; i<num_syms; ++i)
+            {
+                coff_symbol_t symbol;
+                const void *name_data = stab_data.GetData(&offset, sizeof(symbol.name));
+                
+                if (name_data == NULL)
+                    break;
+                memcpy (symbol.name, name_data, sizeof(symbol.name));
+                symbol.value = stab_data.GetU32 (&offset);
+                symbol.sect = stab_data.GetU16 (&offset);
+                symbol.type = stab_data.GetU16 (&offset);
+                symbol.storage = stab_data.GetU8 (&offset);
+                symbol.naux = stab_data.GetU8 (&offset);		
+
+                symbol.name[sizeof(symbol.name)-1] = '\0';
+                Address symbol_addr(sect_list->GetSectionAtIndex(symbol.sect-1).get(), symbol.value);
+                symbols[i].GetMangled ().SetValue(symbol.name, symbol.name[0]=='_' && symbol.name[1] == 'Z');
+                symbols[i].SetValue(symbol_addr);
+
+                if (symbol.naux > 0)
+                    i += symbol.naux;
+            }
+            
+        }
+    }
+    return m_symtab_ap.get();
+
+}
+
+SectionList *
+ObjectFilePECOFF::GetSectionList()
+{
+    Mutex::Locker symfile_locker(m_mutex);
+    if (m_sections_ap.get() == NULL)
+    {
+        m_sections_ap.reset(new SectionList());
+        const uint32_t nsects = m_sect_headers.size();
+        Module *module = GetModule();
+        for (uint32_t idx = 0; idx<nsects; ++idx)
+        {
+            std::string sect_name;
+            GetSectionName (sect_name, m_sect_headers[idx]);
+            ConstString const_sect_name (sect_name.c_str());
+            
+            // Use a segment ID of the segment index shifted left by 8 so they
+            // never conflict with any of the sections.
+            SectionSP section_sp (new Section (NULL,
+                                               module,                       // Module to which this section belongs
+                                               idx + 1,                      // Section ID is the 1 based segment index shifted right by 8 bits as not to collide with any of the 256 section IDs that are possible
+                                               const_sect_name,              // Name of this section
+                                               eSectionTypeCode,             // This section is a container of other sections.
+                                               m_sect_headers[idx].vmaddr,   // File VM address == addresses as they are found in the object file
+                                               m_sect_headers[idx].vmsize,   // VM size in bytes of this section
+                                               m_sect_headers[idx].offset,   // Offset to the data for this section in the file
+                                               m_sect_headers[idx].size,     // Size in bytes of this section as found in the the file
+                                               m_sect_headers[idx].flags));  // Flags for this section
+
+            //section_sp->SetIsEncrypted (segment_is_encrypted);
+
+            m_sections_ap->AddSection(section_sp);
+        }
+    }
+    return m_sections_ap.get();
+}
+
+bool
+ObjectFilePECOFF::GetUUID (UUID* uuid)
+{
+    return false;
+}
+
+uint32_t
+ObjectFilePECOFF::GetDependentModules (FileSpecList& files)
+{
+    return 0;
+}
+
+
+//----------------------------------------------------------------------
+// Dump
+//
+// Dump the specifics of the runtime file container (such as any headers
+// segments, sections, etc).
+//----------------------------------------------------------------------
+void 
+ObjectFilePECOFF::Dump(Stream *s)
+{
+    Mutex::Locker locker(m_mutex);
+    s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
+    s->Indent();
+    s->PutCString("ObjectFilePECOFF");
+    
+    ArchSpec header_arch;
+    GetArchitecture (header_arch);
+    
+    *s << ", file = '" << m_file << "', arch = " << header_arch.GetArchitectureName() << "\n";
+    
+    if (m_sections_ap.get())
+        m_sections_ap->Dump(s, NULL, true, UINT32_MAX);
+    
+    if (m_symtab_ap.get())
+        m_symtab_ap->Dump(s, NULL, eSortOrderNone);
+
+    if (m_dos_header.e_magic)
+        DumpDOSHeader (s, m_dos_header);
+    if (m_coff_header.machine)
+    {
+        DumpCOFFHeader (s, m_coff_header);
+        if (m_coff_header.hdrsize)
+            DumpOptCOFFHeader (s, m_coff_header_opt);
+    }
+    s->EOL();
+    DumpSectionHeaders(s);
+    s->EOL();    
+}
+
+//----------------------------------------------------------------------
+// DumpDOSHeader
+//
+// Dump the MS-DOS header to the specified output stream
+//----------------------------------------------------------------------
+void
+ObjectFilePECOFF::DumpDOSHeader(Stream *s, const dos_header_t& header)
+{
+    s->PutCString ("MSDOS Header\n");
+    s->Printf ("  e_magic    = 0x%4.4x\n", header.e_magic);
+    s->Printf ("  e_cblp     = 0x%4.4x\n", header.e_cblp);
+    s->Printf ("  e_cp       = 0x%4.4x\n", header.e_cp);
+    s->Printf ("  e_crlc     = 0x%4.4x\n", header.e_crlc);
+    s->Printf ("  e_cparhdr  = 0x%4.4x\n", header.e_cparhdr);
+    s->Printf ("  e_minalloc = 0x%4.4x\n", header.e_minalloc);
+    s->Printf ("  e_maxalloc = 0x%4.4x\n", header.e_maxalloc);
+    s->Printf ("  e_ss       = 0x%4.4x\n", header.e_ss);
+    s->Printf ("  e_sp       = 0x%4.4x\n", header.e_sp);
+    s->Printf ("  e_csum     = 0x%4.4x\n", header.e_csum);
+    s->Printf ("  e_ip       = 0x%4.4x\n", header.e_ip);
+    s->Printf ("  e_cs       = 0x%4.4x\n", header.e_cs);
+    s->Printf ("  e_lfarlc   = 0x%4.4x\n", header.e_lfarlc);
+    s->Printf ("  e_ovno     = 0x%4.4x\n", header.e_ovno);
+    s->Printf ("  e_res[4]   = { 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x }\n",
+               header.e_res[0],
+               header.e_res[1],
+               header.e_res[2],
+               header.e_res[3]);
+    s->Printf ("  e_oemid    = 0x%4.4x\n", header.e_oemid);
+    s->Printf ("  e_oeminfo  = 0x%4.4x\n", header.e_oeminfo);
+    s->Printf ("  e_res2[10] = { 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x, 0x%4.4x }\n",
+               header.e_res2[0],
+               header.e_res2[1],
+               header.e_res2[2],
+               header.e_res2[3],
+               header.e_res2[4],
+               header.e_res2[5],
+               header.e_res2[6],
+               header.e_res2[7],
+               header.e_res2[8],
+               header.e_res2[9]);
+    s->Printf ("  e_lfanew   = 0x%8.8x\n", header.e_lfanew);
+}
+
+//----------------------------------------------------------------------
+// DumpCOFFHeader
+//
+// Dump the COFF header to the specified output stream
+//----------------------------------------------------------------------
+void
+ObjectFilePECOFF::DumpCOFFHeader(Stream *s, const coff_header_t& header)
+{
+    s->PutCString ("COFF Header\n");
+    s->Printf ("  machine = 0x%4.4x\n", header.machine);
+    s->Printf ("  nsects  = 0x%4.4x\n", header.nsects);
+    s->Printf ("  modtime = 0x%8.8x\n", header.modtime);
+    s->Printf ("  symoff  = 0x%8.8x\n", header.symoff);
+    s->Printf ("  nsyms   = 0x%8.8x\n", header.nsyms);
+    s->Printf ("  hdrsize = 0x%4.4x\n", header.hdrsize);
+}
+
+//----------------------------------------------------------------------
+// DumpOptCOFFHeader
+//
+// Dump the optional COFF header to the specified output stream
+//----------------------------------------------------------------------
+void
+ObjectFilePECOFF::DumpOptCOFFHeader(Stream *s, const coff_opt_header_t& header)
+{
+    s->PutCString ("Optional COFF Header\n");
+    s->Printf ("  magic                   = 0x%4.4x\n", header.magic);
+    s->Printf ("  major_linker_version    = 0x%2.2x\n", header.major_linker_version);
+    s->Printf ("  minor_linker_version    = 0x%2.2x\n", header.minor_linker_version);
+    s->Printf ("  code_size               = 0x%8.8x\n", header.code_size);
+    s->Printf ("  data_size               = 0x%8.8x\n", header.data_size);
+    s->Printf ("  bss_size                = 0x%8.8x\n", header.bss_size);
+    s->Printf ("  entry                   = 0x%8.8x\n", header.entry);
+    s->Printf ("  code_offset             = 0x%8.8x\n", header.code_offset);
+    s->Printf ("  data_offset             = 0x%8.8x\n", header.data_offset);
+    s->Printf ("  image_base              = 0x%16.16llx\n", header.image_base);
+    s->Printf ("  sect_alignment          = 0x%8.8x\n", header.sect_alignment);
+    s->Printf ("  file_alignment          = 0x%8.8x\n", header.file_alignment);
+    s->Printf ("  major_os_system_version = 0x%4.4x\n", header.major_os_system_version);
+    s->Printf ("  minor_os_system_version = 0x%4.4x\n", header.minor_os_system_version);
+    s->Printf ("  major_image_version     = 0x%4.4x\n", header.major_image_version);
+    s->Printf ("  minor_image_version     = 0x%4.4x\n", header.minor_image_version);
+    s->Printf ("  major_subsystem_version = 0x%4.4x\n", header.major_subsystem_version);
+    s->Printf ("  minor_subsystem_version = 0x%4.4x\n", header.minor_subsystem_version);
+    s->Printf ("  reserved1               = 0x%8.8x\n", header.reserved1);
+    s->Printf ("  image_size              = 0x%8.8x\n", header.image_size);
+    s->Printf ("  header_size             = 0x%8.8x\n", header.header_size);
+    s->Printf ("  checksym                = 0x%8.8x\n", header.checksym);
+    s->Printf ("  subsystem               = 0x%4.4x\n", header.subsystem);
+    s->Printf ("  dll_flags               = 0x%4.4x\n", header.dll_flags);
+    s->Printf ("  stack_reserve_size      = 0x%16.16llx\n", header.stack_reserve_size);
+    s->Printf ("  stack_commit_size       = 0x%16.16llx\n", header.stack_commit_size);
+    s->Printf ("  heap_reserve_size       = 0x%16.16llx\n", header.heap_reserve_size);
+    s->Printf ("  heap_commit_size        = 0x%16.16llx\n", header.heap_commit_size);
+    s->Printf ("  loader_flags            = 0x%8.8x\n", header.loader_flags);
+    s->Printf ("  num_data_dir_entries    = 0x%8.8zx\n", header.data_dirs.size());
+    uint32_t i;
+    for (i=0; i<header.data_dirs.size(); i++)
+    {
+        s->Printf ("  data_dirs[%u] vmaddr = 0x%8.8x, vmsize = 0x%8.8x\n", 
+                   i,
+                   header.data_dirs[i].vmaddr,
+                   header.data_dirs[i].vmsize);
+    }
+}
+//----------------------------------------------------------------------
+// DumpSectionHeader
+//
+// Dump a single ELF section header to the specified output stream
+//----------------------------------------------------------------------
+void
+ObjectFilePECOFF::DumpSectionHeader(Stream *s, const section_header_t& sh)
+{
+    std::string name;
+    GetSectionName(name, sh);
+    s->Printf ("%-16s 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%4.4x 0x%4.4x 0x%8.8x\n",
+               name.c_str(),
+               sh.vmsize,
+               sh.vmaddr,
+               sh.size,
+               sh.offset,
+               sh.reloff,
+               sh.lineoff,
+               sh.nreloc,
+               sh.nline,
+               sh.flags);
+}
+
+
+//----------------------------------------------------------------------
+// DumpSectionHeaders
+//
+// Dump all of the ELF section header to the specified output stream
+//----------------------------------------------------------------------
+void
+ObjectFilePECOFF::DumpSectionHeaders(Stream *s)
+{
+    
+    s->PutCString ("Section Headers\n");
+    s->PutCString ("IDX  name             vm size  vm addr  size     offset   reloff   lineoff  nrel nlin flags\n");
+    s->PutCString ("==== ---------------- -------- -------- -------- -------- -------- -------- ---- ---- --------\n");
+    
+    uint32_t idx = 0;
+    SectionHeaderCollIter pos, end = m_sect_headers.end();
+    
+    for (pos = m_sect_headers.begin(); pos != end; ++pos, ++idx)
+    {
+        s->Printf ("[%2u]", idx);
+        ObjectFilePECOFF::DumpSectionHeader(s, *pos);
+    }
+}
+
+static bool 
+COFFMachineToMachCPU (uint16_t machine, ArchSpec &arch)
+{
+    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);
+            return true;
+    }
+    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)
+            return eTypeExecutable;
+        else
+            return eTypeSharedLibrary;
+    }
+    return eTypeExecutable;
+}
+
+ObjectFile::Strata
+ObjectFilePECOFF::CalculateStrata()
+{
+    return eStrataUser;
+}
+//------------------------------------------------------------------
+// PluginInterface protocol
+//------------------------------------------------------------------
+const char *
+ObjectFilePECOFF::GetPluginName()
+{
+    return "ObjectFilePECOFF";
+}
+
+const char *
+ObjectFilePECOFF::GetShortPluginName()
+{
+    return GetPluginNameStatic();
+}
+
+uint32_t
+ObjectFilePECOFF::GetPluginVersion()
+{
+    return 1;
+}
+

Added: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h?rev=139401&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h (added)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h Fri Sep  9 15:33:05 2011
@@ -0,0 +1,235 @@
+//===-- ObjectFilePECOFF.h --------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ObjectFilePECOFF_h_
+#define liblldb_ObjectFilePECOFF_h_
+
+#include <vector>
+
+#include "lldb/Host/Mutex.h"
+#include "lldb/Symbol/ObjectFile.h"
+
+class ObjectFilePECOFF : 
+    public lldb_private::ObjectFile
+{
+public:
+    
+    //------------------------------------------------------------------
+    // Static Functions
+    //------------------------------------------------------------------
+    static void
+    Initialize();
+    
+    static void
+    Terminate();
+    
+    static const char *
+    GetPluginNameStatic();
+    
+    static const char *
+    GetPluginDescriptionStatic();
+    
+    static ObjectFile *
+    CreateInstance (lldb_private::Module* module,
+                    lldb::DataBufferSP& dataSP,
+                    const lldb_private::FileSpec* file,
+                    lldb::addr_t offset,
+                    lldb::addr_t length);
+    
+    static bool
+    MagicBytesMatch (lldb::DataBufferSP& dataSP);
+    
+    
+    ObjectFilePECOFF (lldb_private::Module* module,
+                      lldb::DataBufferSP& dataSP,
+                      const lldb_private::FileSpec* file,
+                      lldb::addr_t offset,
+                      lldb::addr_t length);
+    
+	virtual 
+    ~ObjectFilePECOFF();
+    
+    virtual bool
+    ParseHeader ();
+    
+    virtual lldb::ByteOrder
+    GetByteOrder () const;
+    
+    virtual bool
+    IsExecutable () const;
+    
+    virtual size_t
+    GetAddressByteSize ()  const;
+    
+//    virtual lldb_private::AddressClass
+//    GetAddressClass (lldb::addr_t file_addr);
+//    
+    virtual lldb_private::Symtab *
+    GetSymtab();
+    
+    virtual lldb_private::SectionList *
+    GetSectionList();
+    
+    virtual void
+    Dump (lldb_private::Stream *s);
+    
+    virtual bool
+    GetArchitecture (lldb_private::ArchSpec &arch);
+    
+    virtual bool
+    GetUUID (lldb_private::UUID* uuid);
+    
+    virtual uint32_t
+    GetDependentModules (lldb_private::FileSpecList& files);
+    
+    //------------------------------------------------------------------
+    // PluginInterface protocol
+    //------------------------------------------------------------------
+    virtual const char *
+    GetPluginName();
+    
+    virtual const char *
+    GetShortPluginName();
+    
+    virtual uint32_t
+    GetPluginVersion();
+//    
+//    virtual lldb_private::Address
+//    GetEntryPointAddress ();
+    
+    virtual ObjectFile::Type
+    CalculateType();
+    
+    virtual ObjectFile::Strata
+    CalculateStrata();
+    
+protected:
+	bool NeedsEndianSwap() const;    
+    
+	typedef struct dos_header  {  // DOS .EXE header
+		uint16_t e_magic;         // Magic number
+		uint16_t e_cblp;          // Bytes on last page of file
+		uint16_t e_cp;            // Pages in file
+		uint16_t e_crlc;          // Relocations
+		uint16_t e_cparhdr;       // Size of header in paragraphs
+		uint16_t e_minalloc;      // Minimum extra paragraphs needed
+		uint16_t e_maxalloc;      // Maximum extra paragraphs needed
+		uint16_t e_ss;            // Initial (relative) SS value
+		uint16_t e_sp;            // Initial SP value
+		uint16_t e_csum;          // Checksum
+		uint16_t e_ip;            // Initial IP value
+		uint16_t e_cs;            // Initial (relative) CS value
+		uint16_t e_lfarlc;        // File address of relocation table
+		uint16_t e_ovno;          // Overlay number
+		uint16_t e_res[4];        // Reserved words
+		uint16_t e_oemid;         // OEM identifier (for e_oeminfo)
+		uint16_t e_oeminfo;       // OEM information; e_oemid specific
+		uint16_t e_res2[10];      // Reserved words
+		uint32_t e_lfanew;        // File address of new exe header
+    } dos_header_t;
+    
+	typedef struct coff_header {
+		uint16_t machine;
+		uint16_t nsects;
+		uint32_t modtime;
+		uint32_t symoff;
+		uint32_t nsyms;
+		uint16_t hdrsize;
+		uint16_t flags;
+	} coff_header_t;
+    
+	typedef struct data_directory {
+		uint32_t vmaddr;
+		uint32_t vmsize;
+	} data_directory_t;
+    
+	typedef struct coff_opt_header 
+	{
+		uint16_t	magic;
+		uint8_t		major_linker_version;
+		uint8_t		minor_linker_version;
+		uint32_t	code_size;
+		uint32_t	data_size;
+		uint32_t	bss_size;
+		uint32_t	entry;
+		uint32_t	code_offset;
+		uint32_t	data_offset;
+        
+		uint64_t	image_base;
+		uint32_t	sect_alignment;
+		uint32_t	file_alignment;
+		uint16_t	major_os_system_version;
+		uint16_t	minor_os_system_version;
+		uint16_t	major_image_version;
+		uint16_t	minor_image_version;
+		uint16_t	major_subsystem_version;
+		uint16_t	minor_subsystem_version;
+		uint32_t	reserved1;
+		uint32_t	image_size;
+		uint32_t	header_size;
+		uint32_t	checksym;
+		uint16_t	subsystem;
+		uint16_t	dll_flags;
+		uint64_t	stack_reserve_size;
+		uint64_t	stack_commit_size;
+		uint64_t	heap_reserve_size;
+		uint64_t	heap_commit_size;
+		uint32_t	loader_flags;
+        //    uint32_t	num_data_dir_entries;
+		std::vector<data_directory> data_dirs;	// will contain num_data_dir_entries entries
+	} coff_opt_header_t;
+    
+	typedef struct section_header {
+		char		name[8];
+		uint32_t	vmsize;	// Virtual Size
+		uint32_t	vmaddr;	// Virtual Addr
+		uint32_t	size;	// File size
+		uint32_t	offset;	// File offset
+		uint32_t	reloff;	// Offset to relocations
+		uint32_t	lineoff;// Offset to line table entries
+		uint16_t	nreloc;	// Number of relocation entries
+		uint16_t	nline;	// Number of line table entries
+		uint32_t	flags;
+	} section_header_t;
+    
+	typedef struct coff_symbol {
+		char		name[8];
+		uint32_t	value;
+		uint16_t	sect;
+		uint16_t	type;
+		uint8_t		storage;
+		uint8_t		naux;		
+	} coff_symbol_t;
+    
+	bool ParseDOSHeader ();
+	bool ParseCOFFHeader (uint32_t* offset_ptr);
+	bool ParseCOFFOptionalHeader (uint32_t* offset_ptr);
+	bool ParseSectionHeaders (uint32_t offset);
+	
+	static	void DumpDOSHeader(lldb_private::Stream *s, const dos_header_t& header);
+	static	void DumpCOFFHeader(lldb_private::Stream *s, const coff_header_t& header);
+	static	void DumpOptCOFFHeader(lldb_private::Stream *s, const coff_opt_header_t& header);
+    void DumpSectionHeaders(lldb_private::Stream *s);
+    void DumpSectionHeader(lldb_private::Stream *s, const section_header_t& sh);
+    bool GetSectionName(std::string& sect_name, const section_header_t& sect);
+    
+	typedef std::vector<section_header_t>		SectionHeaderColl;
+	typedef SectionHeaderColl::iterator			SectionHeaderCollIter;
+	typedef SectionHeaderColl::const_iterator	SectionHeaderCollConstIter;
+private:
+    mutable lldb_private::Mutex m_mutex;
+    mutable std::auto_ptr<lldb_private::SectionList> m_sections_ap;
+    mutable std::auto_ptr<lldb_private::Symtab> m_symtab_ap;
+	dos_header_t		m_dos_header;
+	coff_header_t		m_coff_header;
+	coff_opt_header_t	m_coff_header_opt;
+	SectionHeaderColl	m_sect_headers;
+};
+
+#endif  // #ifndef liblldb_ObjectFilePECOFF_h_

Modified: lldb/trunk/source/lldb.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=139401&r1=139400&r2=139401&view=diff
==============================================================================
--- lldb/trunk/source/lldb.cpp (original)
+++ lldb/trunk/source/lldb.cpp Fri Sep  9 15:33:05 2011
@@ -35,7 +35,7 @@
 #include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
 #include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h"
 #include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h"
-
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
 #if defined (__APPLE__)
 #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
 #include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
@@ -94,7 +94,7 @@
         UnwindAssemblyInstEmulation::Initialize();
         UnwindAssembly_x86::Initialize();
         EmulateInstructionARM::Initialize ();
-
+        ObjectFilePECOFF::Initialize ();
 #if defined (__APPLE__)
         //----------------------------------------------------------------------
         // Apple/Darwin hosted plugins
@@ -166,6 +166,7 @@
     UnwindAssembly_x86::Terminate();
     UnwindAssemblyInstEmulation::Terminate();
     EmulateInstructionARM::Terminate ();
+    ObjectFilePECOFF::Terminate ();
 
 #if defined (__APPLE__)
     DynamicLoaderMacOSXDYLD::Terminate();





More information about the lldb-commits mailing list