Skip to content

Commit e13e97f

Browse files
Introduce debug_ranges representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces DebugRangesRef and DebugRangesSectionRef to represent the debug_ranges section in DWARF4.
1 parent d68ee59 commit e13e97f

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

llvm/include/llvm/MCCAS/MCCASObjectV1.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CASV1_SIMPLE_DATA_REF(MergedFragmentRef, mc:merged_fragment)
2020
CASV1_SIMPLE_DATA_REF(DebugStrRef, mc:debug_string)
2121
CASV1_SIMPLE_DATA_REF(DebugStrOffsetsRef, mc:debug_string_offsets)
2222
CASV1_SIMPLE_DATA_REF(DebugLoclistsRef, mc:debug_loclists)
23+
CASV1_SIMPLE_DATA_REF(DebugRangesRef, mc:debug_ranges)
2324
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
2425
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
2526
CASV1_SIMPLE_DATA_REF(DebugInfoUnoptRef, mc:debug_info_unopt)
@@ -44,6 +45,7 @@ CASV1_SIMPLE_GROUP_REF(SymbolTableRef, mc:symbol_table)
4445
CASV1_SIMPLE_GROUP_REF(DebugStringSectionRef, mc:debug_string_section)
4546
CASV1_SIMPLE_GROUP_REF(DebugStringOffsetsSectionRef, mc:debug_string_offsets_section)
4647
CASV1_SIMPLE_GROUP_REF(DebugLoclistsSectionRef, mc:debug_loclists_section)
48+
CASV1_SIMPLE_GROUP_REF(DebugRangesSectionRef, mc:debug_ranges_section)
4749
CASV1_SIMPLE_GROUP_REF(DIEAbbrevSetRef, mc:debug_DIE_abbrev_set)
4850
CASV1_SIMPLE_GROUP_REF(DIETopLevelRef, mc:debug_DIE_top_level)
4951
CASV1_SIMPLE_GROUP_REF(DIEDedupeTopLevelRef, mc:debug_DIE_Dedupe_top_level)

llvm/include/llvm/MCCAS/MCCASObjectV1.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ struct DwarfSectionsCache {
481481
MCSection *Abbrev;
482482
MCSection *StrOffsets;
483483
MCSection *Loclists;
484+
MCSection *Ranges;
484485
};
485486

486487
/// Queries `Asm` for all dwarf sections and returns an object with (possibly
@@ -608,6 +609,10 @@ class MCCASBuilder {
608609
// object for the section.
609610
Error createDebugLoclistsSection();
610611

612+
// If a DWARF Ranges section exists, create a DebugRangesRef CAS
613+
// object for the section.
614+
Error createDebugRangesSection();
615+
611616
/// If there is any padding between one section and the next, create a
612617
/// PaddingRef CAS object to represent the bytes of Padding between the two
613618
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,20 @@ DebugLoclistsSectionRef::create(MCCASBuilder &MB,
793793
return get(B->build());
794794
}
795795

796+
Expected<DebugRangesSectionRef>
797+
DebugRangesSectionRef::create(MCCASBuilder &MB,
798+
ArrayRef<cas::ObjectRef> Fragments) {
799+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
800+
if (!B)
801+
return B.takeError();
802+
803+
if (auto E = createGenericDebugSection<DebugRangesSectionRef>(
804+
MB, Fragments, B->Data, B->Refs))
805+
return E;
806+
807+
return get(B->build());
808+
}
809+
796810
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
797811
raw_ostream *Stream) const {
798812
// Start a new section for relocations.
@@ -1262,6 +1276,14 @@ DebugLoclistsSectionRef::materialize(MCCASReader &Reader,
12621276
Reader, Remaining, *this);
12631277
}
12641278

1279+
Expected<uint64_t>
1280+
DebugRangesSectionRef::materialize(MCCASReader &Reader,
1281+
raw_ostream *Stream) const {
1282+
StringRef Remaining = getData();
1283+
return materializeGenericDebugSection<DebugRangesSectionRef>(
1284+
Reader, Remaining, *this);
1285+
}
1286+
12651287
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
12661288
ArrayRef<cas::ObjectRef> Fragments) {
12671289
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1592,7 +1614,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
15921614
Asm.getContext().getObjectFileInfo()->getDwarfStrSection(),
15931615
Asm.getContext().getObjectFileInfo()->getDwarfAbbrevSection(),
15941616
Asm.getContext().getObjectFileInfo()->getDwarfStrOffSection(),
1595-
Asm.getContext().getObjectFileInfo()->getDwarfLoclistsSection()};
1617+
Asm.getContext().getObjectFileInfo()->getDwarfLoclistsSection(),
1618+
Asm.getContext().getObjectFileInfo()->getDwarfRangesSection()};
15961619
}
15971620

15981621
Error MCCASBuilder::prepare() {
@@ -2452,6 +2475,23 @@ Error MCCASBuilder::createDebugLoclistsSection() {
24522475
return finalizeSection<DebugLoclistsSectionRef>();
24532476
}
24542477

2478+
Error MCCASBuilder::createDebugRangesSection() {
2479+
2480+
auto MaybeDebugRangesRef =
2481+
createGenericDebugRef<DebugRangesRef>(DwarfSections.Ranges);
2482+
if (!MaybeDebugRangesRef)
2483+
return Error::success();
2484+
2485+
if (!*MaybeDebugRangesRef)
2486+
return MaybeDebugRangesRef->takeError();
2487+
2488+
startSection(DwarfSections.Ranges);
2489+
addNode(**MaybeDebugRangesRef);
2490+
if (auto E = createPaddingRef(DwarfSections.Ranges))
2491+
return E;
2492+
return finalizeSection<DebugRangesSectionRef>();
2493+
}
2494+
24552495
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
24562496
switch (Fragment.getKind()) {
24572497
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2597,6 +2637,13 @@ Error MCCASBuilder::buildFragments() {
25972637
continue;
25982638
}
25992639

2640+
// Handle Debug Ranges sections separately.
2641+
if (&Sec == DwarfSections.Ranges) {
2642+
if (auto E = createDebugRangesSection())
2643+
return E;
2644+
continue;
2645+
}
2646+
26002647
// Start Subsection for one section.
26012648
startSection(&Sec);
26022649

@@ -2757,7 +2804,7 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
27572804
// SectionRelocs. No Atoms are considered for this section.
27582805
if (R.F && Sec != DwarfSections.Line && Sec != DwarfSections.DebugInfo &&
27592806
Sec != DwarfSections.Abbrev && Sec != DwarfSections.StrOffsets &&
2760-
Sec != DwarfSections.Loclists)
2807+
Sec != DwarfSections.Loclists && Sec != DwarfSections.Ranges)
27612808
RelMap[R.F].push_back(R.MRE);
27622809
else
27632810
// If the fragment is nullptr, it should a section with only relocation
@@ -2964,6 +3011,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
29643011
return F->materialize(*this);
29653012
if (auto F = DebugLoclistsSectionRef::Cast(*Node))
29663013
return F->materialize(*this);
3014+
if (auto F = DebugRangesSectionRef::Cast(*Node))
3015+
return F->materialize(*this);
29673016
if (auto F = CStringRef::Cast(*Node)) {
29683017
auto Size = F->materialize(OS);
29693018
if (!Size)
@@ -3032,6 +3081,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
30323081
return F->materialize(*Stream);
30333082
if (auto F = DebugLoclistsRef::Cast(*Node))
30343083
return F->materialize(*Stream);
3084+
if (auto F = DebugRangesRef::Cast(*Node))
3085+
return F->materialize(*Stream);
30353086
if (auto F = AddendsRef::Cast(*Node))
30363087
// AddendsRef is already handled when materializing Atoms, skip.
30373088
return 0;

0 commit comments

Comments
 (0)