Index: lldb/include/lldb/Utility/ArchSpec.h =================================================================== --- lldb/include/lldb/Utility/ArchSpec.h +++ lldb/include/lldb/Utility/ArchSpec.h @@ -108,6 +108,12 @@ eRISCVSubType_riscv64, }; + enum LOONGARCHSubType { + eLOONGARCHSubType_unknown, + eLOONGARCHSubType_loongarch32, + eLOONGARCHSubType_loongarch64, + }; + enum Core { eCore_arm_generic, eCore_arm_armv4, @@ -204,6 +210,9 @@ eCore_riscv32, eCore_riscv64, + eCore_loongarch32, + eCore_loongarch64, + eCore_uknownMach32, eCore_uknownMach64, Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -320,6 +320,18 @@ return ArchSpec::eCore_ppc64_generic; } +static uint32_t loongarchVariantFromElfFlags(const elf::ELFHeader &header) { + uint32_t fileclass = header.e_ident[EI_CLASS]; + switch (fileclass) { + case llvm::ELF::ELFCLASS32: + return ArchSpec::eLOONGARCHSubType_loongarch32; + case llvm::ELF::ELFCLASS64: + return ArchSpec::eLOONGARCHSubType_loongarch64; + default: + return ArchSpec::eLOONGARCHSubType_unknown; + } +} + static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) { if (header.e_machine == llvm::ELF::EM_MIPS) return mipsVariantFromElfFlags(header); @@ -327,6 +339,8 @@ return ppc64VariantFromElfFlags(header); else if (header.e_machine == llvm::ELF::EM_RISCV) return riscvVariantFromElfFlags(header); + else if (header.e_machine == llvm::ELF::EM_LOONGARCH) + return loongarchVariantFromElfFlags(header); return LLDB_INVALID_CPUTYPE; } Index: lldb/source/Utility/ArchSpec.cpp =================================================================== --- lldb/source/Utility/ArchSpec.cpp +++ lldb/source/Utility/ArchSpec.cpp @@ -220,6 +220,11 @@ {eByteOrderLittle, 8, 2, 4, llvm::Triple::riscv64, ArchSpec::eCore_riscv64, "riscv64"}, + {eByteOrderLittle, 4, 1, 4, llvm::Triple::loongarch32, + ArchSpec::eCore_loongarch32, "loongarch32"}, + {eByteOrderLittle, 8, 1, 4, llvm::Triple::loongarch64, + ArchSpec::eCore_loongarch64, "loongarch64"}, + {eByteOrderLittle, 4, 4, 4, llvm::Triple::UnknownArch, ArchSpec::eCore_uknownMach32, "unknown-mach-32"}, {eByteOrderLittle, 8, 4, 4, llvm::Triple::UnknownArch, @@ -406,6 +411,12 @@ ArchSpec::eRISCVSubType_riscv32, 0xFFFFFFFFu, 0xFFFFFFFFu}, // riscv32 {ArchSpec::eCore_riscv64, llvm::ELF::EM_RISCV, ArchSpec::eRISCVSubType_riscv64, 0xFFFFFFFFu, 0xFFFFFFFFu}, // riscv64 + {ArchSpec::eCore_loongarch32, llvm::ELF::EM_LOONGARCH, + ArchSpec::eLOONGARCHSubType_loongarch32, 0xFFFFFFFFu, + 0xFFFFFFFFu}, // loongarch32 + {ArchSpec::eCore_loongarch64, llvm::ELF::EM_LOONGARCH, + ArchSpec::eLOONGARCHSubType_loongarch64, 0xFFFFFFFFu, + 0xFFFFFFFFu}, // loongarch64 }; static const ArchDefinition g_elf_arch_def = { Index: lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml =================================================================== --- /dev/null +++ lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml @@ -0,0 +1,24 @@ +# RUN: yaml2obj --docnum=1 %s > %t32 +# RUN: yaml2obj --docnum=2 %s > %t64 +# RUN: lldb-test object-file %t32 | FileCheck --check-prefix=CHECK-LA32 %s +# RUN: lldb-test object-file %t64 | FileCheck --check-prefix=CHECK-LA64 %s + +# CHECK-LA32: Architecture: loongarch32-- + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_LOONGARCH +... + +# CHECK-LA64: Architecture: loongarch64-- + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_LOONGARCH +...