lldb/ObjectFile,Disassembler: read some state from the executable

Add support to inspect the ELF headers for RISCV targets to determine if
RVC or RVE are enabled and the floating point support to enable.  As per
the RISCV specification, d implies f, q implies d implies f, which gives
us the cascading effect that is used to enable the features when setting
up the disassembler.  With this change, it is now possible to attach the
debugger to a remote process and be able to disassemble the instruction
stream.

~~~
$ bin/lldb tmp/reduced
(lldb) target create "reduced"
Current executable set to '/tmp/reduced' (riscv64).
(lldb) gdb-remote localhost:1234
(lldb) Process 5737 stopped
* thread #1, name = 'reduced', stop reason = signal SIGTRAP
    frame #0: 0x0000003ff7fe1b20
->  0x3ff7fe1b20: mv     a0, sp
    0x3ff7fe1b22: jal    1936
    0x3ff7fe1b26: mv     s0, a0
    0x3ff7fe1b28: auipc  a0, 27
~~~
This commit is contained in:
Saleem Abdulrasool
2022-03-10 20:55:46 +00:00
parent 1f45a1071d
commit c604207608
3 changed files with 51 additions and 0 deletions

View File

@@ -1364,6 +1364,28 @@ size_t ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl &section_headers,
arch_spec.SetFlags(ArchSpec::eARM_abi_hard_float);
}
if (arch_spec.GetMachine() == llvm::Triple::riscv32 ||
arch_spec.GetMachine() == llvm::Triple::riscv64) {
uint32_t flags = arch_spec.GetFlags();
if (header.e_flags & llvm::ELF::EF_RISCV_RVC)
flags |= ArchSpec::eRISCV_rvc;
if (header.e_flags & llvm::ELF::EF_RISCV_RVE)
flags |= ArchSpec::eRISCV_rve;
if ((header.e_flags & llvm::ELF::EF_RISCV_FLOAT_ABI_SINGLE) ==
llvm::ELF::EF_RISCV_FLOAT_ABI_SINGLE)
flags |= ArchSpec::eRISCV_float_abi_single;
else if ((header.e_flags & llvm::ELF::EF_RISCV_FLOAT_ABI_DOUBLE) ==
llvm::ELF::EF_RISCV_FLOAT_ABI_DOUBLE)
flags |= ArchSpec::eRISCV_float_abi_double;
else if ((header.e_flags & llvm::ELF::EF_RISCV_FLOAT_ABI_QUAD) ==
llvm::ELF::EF_RISCV_FLOAT_ABI_QUAD)
flags |= ArchSpec::eRISCV_float_abi_quad;
arch_spec.SetFlags(flags);
}
// If there are no section headers we are done.
if (header.e_shnum == 0)
return 0;