diff --git a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp --- a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp +++ b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp @@ -19,6 +19,7 @@ #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/PDB.h" #include "llvm/Support/BinaryByteStream.h" +#include "llvm/Support/Host.h" using namespace lldb; using namespace lldb_private; @@ -128,24 +129,38 @@ lldb_private::UUID &uuid = module_spec.GetUUID(); uuid = GetPDBUUID(*info_stream); + static llvm::Triple::EnvironmentType default_env = [] { + auto def_target = llvm::Triple( + llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())); + if (def_target.getOS() == llvm::Triple::Win32 && + def_target.getEnvironment() != llvm::Triple::UnknownEnvironment) + return def_target.getEnvironment(); + return llvm::Triple::MSVC; + }(); + ArchSpec &module_arch = module_spec.GetArchitecture(); switch (dbi_stream->getMachineType()) { case PDB_Machine::Amd64: module_arch.SetTriple("x86_64-pc-windows"); + module_arch.GetTriple().setEnvironment(default_env); specs.Append(module_spec); break; case PDB_Machine::x86: module_arch.SetTriple("i386-pc-windows"); + module_arch.GetTriple().setEnvironment(default_env); specs.Append(module_spec); module_arch.SetTriple("i686-pc-windows"); + module_arch.GetTriple().setEnvironment(default_env); specs.Append(module_spec); break; case PDB_Machine::ArmNT: module_arch.SetTriple("armv7-pc-windows"); + module_arch.GetTriple().setEnvironment(default_env); specs.Append(module_spec); break; case PDB_Machine::Arm64: module_arch.SetTriple("aarch64-pc-windows"); + module_arch.GetTriple().setEnvironment(default_env); specs.Append(module_spec); break; default: diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -32,6 +32,7 @@ #include "llvm/Object/COFFImportFile.h" #include "llvm/Support/Error.h" +#include "llvm/Support/Host.h" #include "llvm/Support/MemoryBuffer.h" #define IMAGE_DOS_SIGNATURE 0x5A4D // MZ @@ -155,23 +156,37 @@ if (!uuid.IsValid()) uuid = GetCoffUUID(*COFFObj); + static llvm::Triple::EnvironmentType default_env = [] { + auto def_target = llvm::Triple( + llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())); + if (def_target.getOS() == llvm::Triple::Win32 && + def_target.getEnvironment() != llvm::Triple::UnknownEnvironment) + return def_target.getEnvironment(); + return llvm::Triple::MSVC; + }(); + switch (COFFObj->getMachine()) { case MachineAmd64: spec.SetTriple("x86_64-pc-windows"); + spec.GetTriple().setEnvironment(default_env); specs.Append(module_spec); break; case MachineX86: spec.SetTriple("i386-pc-windows"); + spec.GetTriple().setEnvironment(default_env); specs.Append(module_spec); spec.SetTriple("i686-pc-windows"); + spec.GetTriple().setEnvironment(default_env); specs.Append(module_spec); break; case MachineArmNt: spec.SetTriple("armv7-pc-windows"); + spec.GetTriple().setEnvironment(default_env); specs.Append(module_spec); break; case MachineArm64: spec.SetTriple("aarch64-pc-windows"); + spec.GetTriple().setEnvironment(default_env); specs.Append(module_spec); break; default: diff --git a/lldb/test/Shell/ObjectFile/PDB/object.test b/lldb/test/Shell/ObjectFile/PDB/object.test --- a/lldb/test/Shell/ObjectFile/PDB/object.test +++ b/lldb/test/Shell/ObjectFile/PDB/object.test @@ -1,3 +1,5 @@ +# XFAIL: windows-gnu + # RUN: llvm-pdbutil yaml2pdb %s -pdb=%t.pdb # RUN: lldb-test object-file %t.pdb | FileCheck %s diff --git a/lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-gnu.yaml b/lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-gnu.yaml new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-gnu.yaml @@ -0,0 +1,41 @@ +# XFAIL: !windows-gnu + +# RUN: yaml2obj %s -o %t +# RUN: lldb-test object-file %t | FileCheck %s + +# CHECK: Architecture: x86_64-pc-windows-gnu + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 5152 + ImageBase: 5368709120 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 6 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 6 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI + DLLCharacteristics: [ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 64 + SectionData: DEADBEEFBAADF00D + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + VirtualAddress: 8192 + VirtualSize: 64 + SectionData: DEADBEEFBAADF00D +symbols: [] +... diff --git a/lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-msvc.yaml b/lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-msvc.yaml new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-msvc.yaml @@ -0,0 +1,41 @@ +# XFAIL: windows-gnu + +# RUN: yaml2obj %s -o %t +# RUN: lldb-test object-file %t | FileCheck %s + +# CHECK: Architecture: x86_64-pc-windows-msvc + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 5152 + ImageBase: 5368709120 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 6 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 6 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI + DLLCharacteristics: [ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 64 + SectionData: DEADBEEFBAADF00D + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + VirtualAddress: 8192 + VirtualSize: 64 + SectionData: DEADBEEFBAADF00D +symbols: [] +... diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py --- a/lldb/test/Shell/lit.cfg.py +++ b/lldb/test/Shell/lit.cfg.py @@ -62,6 +62,12 @@ if re.match(r'^arm(hf.*-linux)|(.*-linux-gnuabihf)', config.target_triple): config.available_features.add("armhf-linux") +if re.match(r'.*-(windows-msvc)$', config.target_triple): + config.available_features.add("windows-msvc") + +if re.match(r'.*-(windows-gnu|mingw32)$', config.target_triple): + config.available_features.add("windows-gnu") + def calculate_arch_features(arch_string): # This will add a feature such as x86, arm, mips, etc for each built # target