Skip to content

Commit ad587ae

Browse files
author
Zachary Turner
committedJul 28, 2014
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 llvm-svn: 214092
1 parent 3b2065f commit ad587ae

File tree

5 files changed

+80
-23
lines changed

5 files changed

+80
-23
lines changed
 

‎lldb/include/lldb/Core/ArchSpec.h

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class ArchSpec
113113
kCore_ppc_any,
114114
kCore_ppc64_any,
115115
kCore_x86_32_any,
116+
kCore_x86_64_any,
116117
kCore_hexagon_any,
117118

118119
kCore_arm_first = eCore_arm_generic,
@@ -130,6 +131,9 @@ class ArchSpec
130131
kCore_x86_32_first = eCore_x86_32_i386,
131132
kCore_x86_32_last = eCore_x86_32_i686,
132133

134+
kCore_x86_64_first = eCore_x86_64_x86_64,
135+
kCore_x86_64_last = eCore_x86_64_x86_64h,
136+
133137
kCore_hexagon_first = eCore_hexagon_generic,
134138
kCore_hexagon_last = eCore_hexagon_hexagonv5
135139
};

‎lldb/source/Core/ArchSpec.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ static const ArchDefinition g_elf_arch_def = {
270270

271271
static const ArchDefinitionEntry g_coff_arch_entries[] =
272272
{
273-
{ ArchSpec::eCore_x86_32_i386 , llvm::COFF::IMAGE_FILE_MACHINE_I386 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel 80386
273+
{ ArchSpec::eCore_x86_32_i386 , llvm::COFF::IMAGE_FILE_MACHINE_I386 , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // Intel 80x86
274274
{ ArchSpec::eCore_ppc_generic , llvm::COFF::IMAGE_FILE_MACHINE_POWERPC , LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC
275275
{ ArchSpec::eCore_ppc_generic , llvm::COFF::IMAGE_FILE_MACHINE_POWERPCFP, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu }, // PowerPC (with FPU)
276276
{ 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, const ArchSpec::Core core2, bool try_in
927927
if ((core2 >= ArchSpec::kCore_x86_32_first && core2 <= ArchSpec::kCore_x86_32_last) || (core2 == ArchSpec::kCore_x86_32_any))
928928
return true;
929929
break;
930-
930+
931+
case ArchSpec::kCore_x86_64_any:
932+
if ((core2 >= ArchSpec::kCore_x86_64_first && core2 <= ArchSpec::kCore_x86_64_last) || (core2 == ArchSpec::kCore_x86_64_any))
933+
return true;
934+
931935
case ArchSpec::kCore_ppc_any:
932936
if ((core2 >= ArchSpec::kCore_ppc_first && core2 <= ArchSpec::kCore_ppc_last) || (core2 == ArchSpec::kCore_ppc_any))
933937
return true;

‎lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ ObjectFilePECOFF::GetModuleSpecifications (const lldb_private::FileSpec& file,
129129
if (ParseCOFFHeader(data, &offset, coff_header))
130130
{
131131
ArchSpec spec;
132-
spec.SetArchitecture(eArchTypeCOFF, coff_header.machine, LLDB_INVALID_CPUTYPE);
132+
llvm::Triple::ArchType archType = llvm::Triple::UnknownArch;
133+
if (coff_header.machine == MachineAmd64)
134+
spec.SetTriple("x86_64-pc-windows");
135+
else if (coff_header.machine == MachineX86)
136+
spec.SetTriple("i386-pc-windows");
133137
specs.Append(ModuleSpec(file, spec));
134138
}
135139
}

‎lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h

+25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ class ObjectFilePECOFF :
1818
public lldb_private::ObjectFile
1919
{
2020
public:
21+
typedef enum MachineType
22+
{
23+
MachineUnknown = 0x0,
24+
MachineAm33 = 0x1d3,
25+
MachineAmd64 = 0x8664,
26+
MachineArm = 0x1c0,
27+
MachineArmNt = 0x1c4,
28+
MachineArm64 = 0xaa64,
29+
MachineEbc = 0xebc,
30+
MachineX86 = 0x14c,
31+
MachineIA64 = 0x200,
32+
MachineM32R = 0x9041,
33+
MachineMips16 = 0x266,
34+
MachineMipsFpu = 0x366,
35+
MachineMipsFpu16 = 0x466,
36+
MachinePowerPc = 0x1f0,
37+
MachinePowerPcfp = 0x1f1,
38+
MachineR4000 = 0x166,
39+
MachineSh3 = 0x1a2,
40+
MachineSh3dsp = 0x1a3,
41+
MachineSh4 = 0x1a6,
42+
MachineSh5 = 0x1a8,
43+
MachineThumb = 0x1c2,
44+
MachineWcemIpsv2 = 0x169
45+
};
2146

2247
//------------------------------------------------------------------
2348
// Static Functions

‎lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp

+40-20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,40 @@ using namespace lldb_private;
3232

3333
static uint32_t g_initialize_count = 0;
3434

35+
namespace
36+
{
37+
class SupportedArchList
38+
{
39+
public:
40+
SupportedArchList()
41+
{
42+
AddArch(ArchSpec("i686-pc-windows"));
43+
AddArch(Host::GetArchitecture(Host::eSystemDefaultArchitecture));
44+
AddArch(Host::GetArchitecture(Host::eSystemDefaultArchitecture32));
45+
AddArch(Host::GetArchitecture(Host::eSystemDefaultArchitecture64));
46+
AddArch(ArchSpec("i386-pc-windows"));
47+
}
48+
49+
size_t Count() const { return m_archs.size(); }
50+
51+
const ArchSpec& operator[](int idx) { return m_archs[idx]; }
52+
53+
private:
54+
void AddArch(const ArchSpec& spec)
55+
{
56+
auto iter = std::find_if(
57+
m_archs.begin(), m_archs.end(),
58+
[spec](const ArchSpec& rhs) { return spec.IsExactMatch(rhs); });
59+
if (iter != m_archs.end())
60+
return;
61+
if (spec.IsValid())
62+
m_archs.push_back(spec);
63+
}
64+
65+
std::vector<ArchSpec> m_archs;
66+
};
67+
}
68+
3569
Platform *
3670
PlatformWindows::CreateInstance (bool force, const lldb_private::ArchSpec *arch)
3771
{
@@ -605,26 +639,12 @@ PlatformWindows::GetSharedModule (const ModuleSpec &module_spec,
605639
bool
606640
PlatformWindows::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
607641
{
608-
// From macosx;s plugin code. For FreeBSD we may want to support more archs.
609-
if (idx == 0)
610-
{
611-
arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture);
612-
return arch.IsValid();
613-
}
614-
else if (idx == 1)
615-
{
616-
ArchSpec platform_arch (Host::GetArchitecture (Host::eSystemDefaultArchitecture));
617-
ArchSpec platform_arch64 (Host::GetArchitecture (Host::eSystemDefaultArchitecture64));
618-
if (platform_arch.IsExactMatch(platform_arch64))
619-
{
620-
// This freebsd platform supports both 32 and 64 bit. Since we already
621-
// returned the 64 bit arch for idx == 0, return the 32 bit arch
622-
// for idx == 1
623-
arch = Host::GetArchitecture (Host::eSystemDefaultArchitecture32);
624-
return arch.IsValid();
625-
}
626-
}
627-
return false;
642+
static SupportedArchList architectures;
643+
644+
if (idx >= architectures.Count())
645+
return false;
646+
arch = architectures[idx];
647+
return true;
628648
}
629649

630650
void

0 commit comments

Comments
 (0)
Please sign in to comment.