[Lldb-commits] [lldb] r214092 - Fix supported architectures on PlatformWindows.

Zachary Turner zturner at google.com
Mon Jul 28 09:44:49 PDT 2014


Author: zturner
Date: Mon Jul 28 11:44:49 2014
New Revision: 214092

URL: http://llvm.org/viewvc/llvm-project?rev=214092&view=rev
Log:
Fix supported architectures on PlatformWindows.

i386, i486, i486sx, and i686 are all indistinguishable as far as
PE/COFF files are concerned.  This patch adds support for all of
these architectures to PlatformWindows.

Differential Revision: http://reviews.llvm.org/D4658

Modified:
    lldb/trunk/include/lldb/Core/ArchSpec.h
    lldb/trunk/source/Core/ArchSpec.cpp
    lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
    lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
    lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp

Modified: lldb/trunk/include/lldb/Core/ArchSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ArchSpec.h?rev=214092&r1=214091&r2=214092&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ArchSpec.h (original)
+++ lldb/trunk/include/lldb/Core/ArchSpec.h Mon Jul 28 11:44:49 2014
@@ -113,6 +113,7 @@ public:
         kCore_ppc_any,
         kCore_ppc64_any,
         kCore_x86_32_any,
+        kCore_x86_64_any,
         kCore_hexagon_any,
 
         kCore_arm_first     = eCore_arm_generic,
@@ -130,6 +131,9 @@ public:
         kCore_x86_32_first  = eCore_x86_32_i386,
         kCore_x86_32_last   = eCore_x86_32_i686,
 
+        kCore_x86_64_first  = eCore_x86_64_x86_64,
+        kCore_x86_64_last   = eCore_x86_64_x86_64h,
+
         kCore_hexagon_first  = eCore_hexagon_generic,
         kCore_hexagon_last   = eCore_hexagon_hexagonv5
     };

Modified: lldb/trunk/source/Core/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=214092&r1=214091&r2=214092&view=diff
==============================================================================
--- lldb/trunk/source/Core/ArchSpec.cpp (original)
+++ lldb/trunk/source/Core/ArchSpec.cpp Mon Jul 28 11:44:49 2014
@@ -270,7 +270,7 @@ static const ArchDefinition g_elf_arch_d
 
 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_x86_32_i386  , llvm::COFF::IMAGE_FILE_MACHINE_I386     , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel 80x86
     { 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
@@ -927,7 +927,11 @@ cores_match (const ArchSpec::Core core1,
         if ((core2 >= ArchSpec::kCore_x86_32_first && core2 <= ArchSpec::kCore_x86_32_last) || (core2 == ArchSpec::kCore_x86_32_any))
             return true;
         break;
-        
+
+    case ArchSpec::kCore_x86_64_any:
+        if ((core2 >= ArchSpec::kCore_x86_64_first && core2 <= ArchSpec::kCore_x86_64_last) || (core2 == ArchSpec::kCore_x86_64_any))
+            return true;
+
     case ArchSpec::kCore_ppc_any:
         if ((core2 >= ArchSpec::kCore_ppc_first && core2 <= ArchSpec::kCore_ppc_last) || (core2 == ArchSpec::kCore_ppc_any))
             return true;

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=214092&r1=214091&r2=214092&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp Mon Jul 28 11:44:49 2014
@@ -129,7 +129,11 @@ ObjectFilePECOFF::GetModuleSpecification
             if (ParseCOFFHeader(data, &offset, coff_header))
             {
                 ArchSpec spec;
-                spec.SetArchitecture(eArchTypeCOFF, coff_header.machine, LLDB_INVALID_CPUTYPE);
+                llvm::Triple::ArchType archType = llvm::Triple::UnknownArch;
+                if (coff_header.machine == MachineAmd64)
+                    spec.SetTriple("x86_64-pc-windows");
+                else if (coff_header.machine == MachineX86)
+                    spec.SetTriple("i386-pc-windows");
                 specs.Append(ModuleSpec(file, spec));
             }
         }

Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h?rev=214092&r1=214091&r2=214092&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h Mon Jul 28 11:44:49 2014
@@ -18,6 +18,31 @@ class ObjectFilePECOFF :
     public lldb_private::ObjectFile
 {
 public:
+    typedef enum MachineType
+    {
+        MachineUnknown = 0x0,
+        MachineAm33 = 0x1d3,
+        MachineAmd64 = 0x8664,
+        MachineArm = 0x1c0,
+        MachineArmNt = 0x1c4,
+        MachineArm64 = 0xaa64,
+        MachineEbc = 0xebc,
+        MachineX86 = 0x14c,
+        MachineIA64 = 0x200,
+        MachineM32R = 0x9041,
+        MachineMips16 = 0x266,
+        MachineMipsFpu = 0x366,
+        MachineMipsFpu16 = 0x466,
+        MachinePowerPc = 0x1f0,
+        MachinePowerPcfp = 0x1f1,
+        MachineR4000 = 0x166,
+        MachineSh3 = 0x1a2,
+        MachineSh3dsp = 0x1a3,
+        MachineSh4 = 0x1a6,
+        MachineSh5 = 0x1a8,
+        MachineThumb = 0x1c2,
+        MachineWcemIpsv2 = 0x169
+    };
     
     //------------------------------------------------------------------
     // Static Functions

Modified: lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp?rev=214092&r1=214091&r2=214092&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp Mon Jul 28 11:44:49 2014
@@ -32,6 +32,40 @@ using namespace lldb_private;
 
 static uint32_t g_initialize_count = 0;
 
+namespace
+{
+    class SupportedArchList
+    {
+    public:
+        SupportedArchList()
+        {
+            AddArch(ArchSpec("i686-pc-windows"));
+            AddArch(Host::GetArchitecture(Host::eSystemDefaultArchitecture));
+            AddArch(Host::GetArchitecture(Host::eSystemDefaultArchitecture32));
+            AddArch(Host::GetArchitecture(Host::eSystemDefaultArchitecture64));
+            AddArch(ArchSpec("i386-pc-windows"));
+        }
+
+        size_t Count() const { return m_archs.size(); }
+
+        const ArchSpec& operator[](int idx) { return m_archs[idx]; }
+
+    private:
+        void AddArch(const ArchSpec& spec)
+        {
+            auto iter = std::find_if(
+                m_archs.begin(), m_archs.end(), 
+                [spec](const ArchSpec& rhs) { return spec.IsExactMatch(rhs); });
+            if (iter != m_archs.end())
+                return;
+            if (spec.IsValid())
+                m_archs.push_back(spec);
+        }
+
+        std::vector<ArchSpec> m_archs;
+    };
+}
+
 Platform *
 PlatformWindows::CreateInstance (bool force, const lldb_private::ArchSpec *arch)
 {
@@ -605,26 +639,12 @@ PlatformWindows::GetSharedModule (const
 bool
 PlatformWindows::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
 {
-    // From macosx;s plugin code. For FreeBSD we may want to support more archs.
-    if (idx == 0)
-    {
-        arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
-        return arch.IsValid();
-    }
-    else if (idx == 1)
-    {
-        ArchSpec platform_arch (Host::GetArchitecture (Host::eSystemDefaultArchitecture));
-        ArchSpec platform_arch64 (Host::GetArchitecture (Host::eSystemDefaultArchitecture64));
-        if (platform_arch.IsExactMatch(platform_arch64))
-        {
-            // This freebsd platform supports both 32 and 64 bit. Since we already
-            // returned the 64 bit arch for idx == 0, return the 32 bit arch
-            // for idx == 1
-            arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
-            return arch.IsValid();
-        }
-    }
-    return false;
+    static SupportedArchList architectures;
+
+    if (idx >= architectures.Count())
+        return false;
+    arch = architectures[idx];
+    return true;
 }
 
 void





More information about the lldb-commits mailing list