Skip to content

Commit e42e4fd

Browse files
committed
[RISCV-LLDB] RISCV feature attribute support and allows overriding additional(default) feature #147990
I have updated the core logic to to handle all the feature attributes.
1 parent 0448f0f commit e42e4fd

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,8 +1318,18 @@ void ObjectFileELF::ParseRISCVAttributes(DataExtractor &data, uint64_t length,
13181318
}
13191319
}
13201320
}
1321-
if (!attr.empty() && attr.contains("xqci")) {
1322-
arch_spec.SetAdditionalDisassemblyFeatureStr("+xqci,");
1321+
1322+
// List of RISC-V architecture extensions to detect from ELF.
1323+
// These extensions are extracted from the ".riscv.attributes" section.
1324+
// New extensions can be added to this list for detection without
1325+
// modifying the core logic.
1326+
std::vector<std::string> riscv_extensions = {"xqci"};
1327+
1328+
for (const auto &ext : riscv_extensions) {
1329+
if (!attr.empty() && attr.contains(ext) &&
1330+
!arch_spec.GetAdditionalDisassemblyFeatureStr().contains(ext)) {
1331+
arch_spec.SetAdditionalDisassemblyFeatureStr("+" + ext + ",");
1332+
}
13231333
}
13241334
}
13251335

@@ -1613,9 +1623,7 @@ size_t ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl &section_headers,
16131623
DataExtractor data;
16141624
if (sheader.sh_type == SHT_RISCV_ATTRIBUTES && section_size != 0 &&
16151625
(data.SetData(object_data, sheader.sh_offset, section_size) ==
1616-
section_size) &&
1617-
!arch_spec.GetAdditionalDisassemblyFeatureStr().contains(
1618-
"xqci")) {
1626+
section_size)) {
16191627
ParseRISCVAttributes(data, section_size, arch_spec);
16201628
}
16211629
}

lldb/test/Shell/Disassemble/TestDisassembleRISCVXqciInstrutions.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# RUN: %lldb -b -o "disassemble -b -n main" %p/Inputs/riscv_xqci.out | FileCheck %s
44

5-
# CHECK: 1f 05 58 00 00 00 qc.e.li a0, 0x58
6-
# CHECK: 16 15 qc.extu a0, a0, 0x6, 0x0
5+
# CHECK: 051f 0058 0000 qc.e.li a0, 0x58
6+
# CHECK: 1516 qc.extu a0, a0, 0x6, 0x0
77

88
# RUN: %lldb -b -o "disassemble -b -n main -Y -xqci,+c" %p/Inputs/riscv_xqci.out | FileCheck --check-prefix=CHECK-NOXQCI %s
99

10-
# CHECK-NOXQCI: <invalid>
10+
# CHECK-NOXQCI: <unknown>
1111

0 commit comments

Comments
 (0)