This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][LoongArch] Add LoongArch ArchSpec and subtype detection
ClosedPublic

Authored by seehearfeel on Oct 31 2022, 12:43 AM.

Details

Summary

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 
#include <stdio.h>

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

Diff Detail

Event Timeline

seehearfeel created this revision.Oct 31 2022, 12:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 12:43 AM
seehearfeel requested review of this revision.Oct 31 2022, 12:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 12:43 AM
DavidSpickett accepted this revision.Oct 31 2022, 3:33 AM

Looks good to me.

This revision is now accepted and ready to land.Oct 31 2022, 3:33 AM
xen0n added inline comments.Oct 31 2022, 3:50 AM
lldb/include/lldb/Utility/ArchSpec.h
111

Should be LoongArch. It's that way everywhere else in LLVM land.

lldb/source/Utility/ArchSpec.cpp
223

min_opcode_byte_size should be 4 too, all LoongArch insns are 32 bits long. Same for loongarch64.

SixWeining added inline comments.Oct 31 2022, 3:54 AM
lldb/source/Utility/ArchSpec.cpp
223

Right. So, the test doesn't cover this change?

seehearfeel added inline comments.Oct 31 2022, 4:22 AM
lldb/source/Utility/ArchSpec.cpp
223

OK, thank you.

It is a bit confusing at the first glance.
Maybe "min_opcode_byte_size" should rename to "min_insn_byte_size",
and "max_opcode_byte_size" should rename to "max_insn_byte_size".

Looks good to me.

Thanks for your review.

Let me update the diff to do some small modifications.

(1) Rename LOONGARCHSubType to LoongArchSubType
(2) Define min_opcode_byte_size as 4 for LoongArch

xen0n accepted this revision.Oct 31 2022, 5:30 AM
SixWeining accepted this revision.Oct 31 2022, 5:31 AM