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 @@ -165,28 +165,49 @@ return llvm::Triple::MSVC; }(); + llvm::Triple::EnvironmentType env = default_env; + if (default_env == llvm::Triple::MSVC) { + // If there is DWARF debug info or gnu_debuglink, then it is very likely + // not using the MSVC C++ ABI. + bool has_dwarf_debug = false; + for (const auto &sec : COFFObj->sections()) { + if (sec.isDebugSection()) { + has_dwarf_debug = true; + break; + } + if (auto name = sec.getName()) { + if (*name == ".gnu_debuglink") { + has_dwarf_debug = true; + break; + } + } + } + if (has_dwarf_debug) + env = llvm::Triple::GNU; + } + switch (COFFObj->getMachine()) { case MachineAmd64: spec.SetTriple("x86_64-pc-windows"); - spec.GetTriple().setEnvironment(default_env); + spec.GetTriple().setEnvironment(env); specs.Append(module_spec); break; case MachineX86: spec.SetTriple("i386-pc-windows"); - spec.GetTriple().setEnvironment(default_env); + spec.GetTriple().setEnvironment(env); specs.Append(module_spec); spec.SetTriple("i686-pc-windows"); - spec.GetTriple().setEnvironment(default_env); + spec.GetTriple().setEnvironment(env); specs.Append(module_spec); break; case MachineArmNt: spec.SetTriple("armv7-pc-windows"); - spec.GetTriple().setEnvironment(default_env); + spec.GetTriple().setEnvironment(env); specs.Append(module_spec); break; case MachineArm64: spec.SetTriple("aarch64-pc-windows"); - spec.GetTriple().setEnvironment(default_env); + spec.GetTriple().setEnvironment(env); specs.Append(module_spec); break; default: