diff options
author | Tiezhu Yang <yangtiezhu@loongson.cn> | 2022-11-01 12:56:55 +0800 |
---|---|---|
committer | Weining Lu <luweining@loongson.cn> | 2022-11-01 17:06:04 +0800 |
commit | e9c34618c904e0b22b6c9fec1f4a410e7484b8d3 (patch) | |
tree | 551b886f25cbd7286e51646dc12df4ccce831e13 /lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp | |
parent | 6aa672f14197e84520671de4ce3fcc724bbfe8d9 (diff) | |
download | llvm-e9c34618c904e0b22b6c9fec1f4a410e7484b8d3.zip llvm-e9c34618c904e0b22b6c9fec1f4a410e7484b8d3.tar.gz llvm-e9c34618c904e0b22b6c9fec1f4a410e7484b8d3.tar.bz2 |
[LLDB][LoongArch] Add LoongArch ArchSpec and subtype detection
Define LoongArch architecture subtypes, add the LoongArch ArchSpec bits,
and inspect the ELF header to detect the right subtype based on ELF class.
Here is a simple test:
```
[loongson@linux ~]$ cat hello.c
int main()
{
printf("Hello, World!\n");
return 0;
}
[loongson@linux ~]$ clang hello.c -g -o hello
```
Without this patch:
```
[loongson@linux ~]$ llvm-project/llvm/build/bin/lldb hello
(lldb) target create "hello"
error: '/home/loongson/hello' doesn't contain any 'host' platform architectures: unknown
```
With this patch:
```
[loongson@linux ~]$ llvm-project/llvm/build/bin/lldb hello
(lldb) target create "hello"
Current executable set to '/home/loongson/hello' (loongarch64).
(lldb) run
Process 735167 launched: '/home/loongson/hello' (loongarch64)
Hello, World!
Process 735167 exited with status = 0 (0x00000000)
(lldb) quit
[loongson@linux ~]$ llvm-project/llvm/build/bin/llvm-lit llvm-project/lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml
llvm-lit: /home/loongson/llvm-project/llvm/utils/lit/lit/llvm/config.py:456: note: using clang: /home/loongson/llvm-project/llvm/build/bin/clang
-- Testing: 1 tests, 1 workers --
PASS: lldb-shell :: ObjectFile/ELF/loongarch-arch.yaml (1 of 1)
Testing Time: 0.09s
Passed: 1
```
Reviewed By: SixWeining, xen0n, DavidSpickett
Differential Revision: https://reviews.llvm.org/D137057
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp')
-rw-r--r-- | lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index af1b093..cf1b375 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -320,6 +320,18 @@ static uint32_t ppc64VariantFromElfFlags(const elf::ELFHeader &header) { 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 @@ static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) { 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; } |