alvinhochun created this revision. Herald added a subscriber: mstorsjo. Herald added a project: All. alvinhochun updated this revision to Diff 434316. alvinhochun added a comment. alvinhochun published this revision for review. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Added tests PE/COFF can use either MSVC or GNU ABI (MinGW) for C++ code, however LLDB had defaulted to MSVC implicitly with no way to override it. This causes issues when debugging modules built with the GNU ABI, sometimes even crashes. This changes the PE/COFF and PDB plugins to set the module triple according to the default target triple used to build LLDB. If the default target triple is Windows and a valid environment is specified, then this environment will be used for the module spec. This not only works for MSVC and GNU, but also other environments. - Fixes https://github.com/llvm/llvm-project/issues/50775 - Fixes https://github.com/mstorsjo/llvm-mingw/issues/226 - Fixes https://github.com/mstorsjo/llvm-mingw/issues/282 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D127048 Files: lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-gnu.yaml lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-msvc.yaml lldb/test/Shell/lit.cfg.py
Index: lldb/test/Shell/lit.cfg.py =================================================================== --- lldb/test/Shell/lit.cfg.py +++ 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 Index: lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-msvc.yaml =================================================================== --- /dev/null +++ lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-msvc.yaml @@ -0,0 +1,41 @@ +# REQUIRES: windows-msvc + +# 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: [] +... Index: lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-gnu.yaml =================================================================== --- /dev/null +++ lldb/test/Shell/ObjectFile/PECOFF/default-triple-windows-gnu.yaml @@ -0,0 +1,41 @@ +# REQUIRES: 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: [] +... Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ 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: Index: lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp +++ 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:
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits