Skip to content

Commit c69d1a2

Browse files
Introduce debug_line_str representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces DebugLineStrRef and DebugLineStrSectionRef to represent the debug_line_str section in DWARF5.
1 parent 8a8213c commit c69d1a2

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
@@ -25,6 +25,7 @@ CASV1_SIMPLE_DATA_REF(DebugRangesRef, mc:debug_ranges)
2525
CASV1_SIMPLE_DATA_REF(DebugRangelistsRef, mc:debug_rangelists)
2626
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
2727
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
28+
CASV1_SIMPLE_DATA_REF(DebugLineStrRef, mc:debug_line_str)
2829
CASV1_SIMPLE_DATA_REF(DebugInfoUnoptRef, mc:debug_info_unopt)
2930
CASV1_SIMPLE_DATA_REF(DebugAbbrevUnoptRef, mc:debug_abbrev_unopt)
3031
CASV1_SIMPLE_DATA_REF(DistinctDebugLineRef, mc:debug_line_distinct_data)
@@ -42,6 +43,7 @@ CASV1_SIMPLE_GROUP_REF(GroupRef, mc:group)
4243
CASV1_SIMPLE_GROUP_REF(SectionRef, mc:section)
4344
CASV1_SIMPLE_GROUP_REF(DebugAbbrevSectionRef, mc:debug_abbrev_section)
4445
CASV1_SIMPLE_GROUP_REF(DebugLineSectionRef, mc:debug_line_section)
46+
CASV1_SIMPLE_GROUP_REF(DebugLineStrSectionRef, mc:debug_line_str_section)
4547
CASV1_SIMPLE_GROUP_REF(AtomRef, mc:atom)
4648
CASV1_SIMPLE_GROUP_REF(SymbolTableRef, mc:symbol_table)
4749
CASV1_SIMPLE_GROUP_REF(DebugStringSectionRef, mc:debug_string_section)

llvm/include/llvm/MCCAS/MCCASObjectV1.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ struct DwarfSectionsCache {
484484
MCSection *Loclists;
485485
MCSection *Ranges;
486486
MCSection *Rangelists;
487+
MCSection *LineStr;
487488
};
488489

489490
/// Queries `Asm` for all dwarf sections and returns an object with (possibly
@@ -623,6 +624,10 @@ class MCCASBuilder {
623624
// object for the section.
624625
Error createDebugRangelistsSection();
625626

627+
// If a DWARF LineStr section exists, create a DebugLineStrRef CAS
628+
// object for the section.
629+
Error createDebugLineStrSection();
630+
626631
/// If there is any padding between one section and the next, create a
627632
/// PaddingRef CAS object to represent the bytes of Padding between the two
628633
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,20 @@ DebugRangelistsSectionRef::create(MCCASBuilder &MB,
835835
return get(B->build());
836836
}
837837

838+
Expected<DebugLineStrSectionRef>
839+
DebugLineStrSectionRef::create(MCCASBuilder &MB,
840+
ArrayRef<cas::ObjectRef> Fragments) {
841+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
842+
if (!B)
843+
return B.takeError();
844+
845+
if (auto E = createGenericDebugSection<DebugLineStrSectionRef>(
846+
MB, Fragments, B->Data, B->Refs))
847+
return E;
848+
849+
return get(B->build());
850+
}
851+
838852
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
839853
raw_ostream *Stream) const {
840854
// Start a new section for relocations.
@@ -1327,6 +1341,14 @@ DebugRangelistsSectionRef::materialize(MCCASReader &Reader,
13271341
Reader, Remaining, *this);
13281342
}
13291343

1344+
Expected<uint64_t>
1345+
DebugLineStrSectionRef::materialize(MCCASReader &Reader,
1346+
raw_ostream *Stream) const {
1347+
StringRef Remaining = getData();
1348+
return materializeGenericDebugSection<DebugLineStrSectionRef>(
1349+
Reader, Remaining, *this);
1350+
}
1351+
13301352
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
13311353
ArrayRef<cas::ObjectRef> Fragments) {
13321354
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1660,7 +1682,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
16601682
Asm.getContext().getObjectFileInfo()->getDwarfLocSection(),
16611683
Asm.getContext().getObjectFileInfo()->getDwarfLoclistsSection(),
16621684
Asm.getContext().getObjectFileInfo()->getDwarfRangesSection(),
1663-
Asm.getContext().getObjectFileInfo()->getDwarfRnglistsSection()};
1685+
Asm.getContext().getObjectFileInfo()->getDwarfRnglistsSection(),
1686+
Asm.getContext().getObjectFileInfo()->getDwarfLineStrSection()};
16641687
}
16651688

16661689
Error MCCASBuilder::prepare() {
@@ -2570,6 +2593,23 @@ Error MCCASBuilder::createDebugRangelistsSection() {
25702593
return finalizeSection<DebugRangelistsSectionRef>();
25712594
}
25722595

2596+
Error MCCASBuilder::createDebugLineStrSection() {
2597+
2598+
auto MaybeDebugLineStrRef =
2599+
createGenericDebugRef<DebugLineStrRef>(DwarfSections.LineStr);
2600+
if (!MaybeDebugLineStrRef)
2601+
return Error::success();
2602+
2603+
if (!*MaybeDebugLineStrRef)
2604+
return MaybeDebugLineStrRef->takeError();
2605+
2606+
startSection(DwarfSections.LineStr);
2607+
addNode(**MaybeDebugLineStrRef);
2608+
if (auto E = createPaddingRef(DwarfSections.LineStr))
2609+
return E;
2610+
return finalizeSection<DebugLineStrSectionRef>();
2611+
}
2612+
25732613
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
25742614
switch (Fragment.getKind()) {
25752615
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2736,6 +2776,13 @@ Error MCCASBuilder::buildFragments() {
27362776
continue;
27372777
}
27382778

2779+
// Handle Debug LineStr sections separately.
2780+
if (&Sec == DwarfSections.LineStr) {
2781+
if (auto E = createDebugLineStrSection())
2782+
return E;
2783+
continue;
2784+
}
2785+
27392786
// Start Subsection for one section.
27402787
startSection(&Sec);
27412788

@@ -2897,7 +2944,7 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
28972944
if (R.F && Sec != DwarfSections.Line && Sec != DwarfSections.DebugInfo &&
28982945
Sec != DwarfSections.Abbrev && Sec != DwarfSections.StrOffsets &&
28992946
Sec != DwarfSections.Loclists && Sec != DwarfSections.Ranges &&
2900-
Sec != DwarfSections.Rangelists)
2947+
Sec != DwarfSections.Rangelists && Sec != DwarfSections.LineStr)
29012948
RelMap[R.F].push_back(R.MRE);
29022949
else
29032950
// If the fragment is nullptr, it should a section with only relocation
@@ -3110,6 +3157,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
31103157
return F->materialize(*this);
31113158
if (auto F = DebugRangelistsSectionRef::Cast(*Node))
31123159
return F->materialize(*this);
3160+
if (auto F = DebugLineStrSectionRef::Cast(*Node))
3161+
return F->materialize(*this);
31133162
if (auto F = CStringRef::Cast(*Node)) {
31143163
auto Size = F->materialize(OS);
31153164
if (!Size)
@@ -3184,6 +3233,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
31843233
return F->materialize(*Stream);
31853234
if (auto F = DebugRangelistsRef::Cast(*Node))
31863235
return F->materialize(*Stream);
3236+
if (auto F = DebugLineStrRef::Cast(*Node))
3237+
return F->materialize(*Stream);
31873238
if (auto F = AddendsRef::Cast(*Node))
31883239
// AddendsRef is already handled when materializing Atoms, skip.
31893240
return 0;

0 commit comments

Comments
 (0)