Skip to content

Commit 9d0c069

Browse files
Introduce debug_names representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces DebugNamesRef and DebugNamesSectionRef to represent the debug_names section in DWARF5.
1 parent c69d1a2 commit 9d0c069

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

llvm/include/llvm/MCCAS/MCCASObjectV1.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CASV1_SIMPLE_DATA_REF(DebugLocRef, mc:debug_loc)
2323
CASV1_SIMPLE_DATA_REF(DebugLoclistsRef, mc:debug_loclists)
2424
CASV1_SIMPLE_DATA_REF(DebugRangesRef, mc:debug_ranges)
2525
CASV1_SIMPLE_DATA_REF(DebugRangelistsRef, mc:debug_rangelists)
26+
CASV1_SIMPLE_DATA_REF(DebugNamesRef, mc:debug_names)
2627
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
2728
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
2829
CASV1_SIMPLE_DATA_REF(DebugLineStrRef, mc:debug_line_str)
@@ -52,6 +53,7 @@ CASV1_SIMPLE_GROUP_REF(DebugLocSectionRef, mc:debug_loc_section)
5253
CASV1_SIMPLE_GROUP_REF(DebugLoclistsSectionRef, mc:debug_loclists_section)
5354
CASV1_SIMPLE_GROUP_REF(DebugRangesSectionRef, mc:debug_ranges_section)
5455
CASV1_SIMPLE_GROUP_REF(DebugRangelistsSectionRef, mc:debug_rangelists_section)
56+
CASV1_SIMPLE_GROUP_REF(DebugNamesSectionRef, mc:debug_names_section)
5557
CASV1_SIMPLE_GROUP_REF(DIEAbbrevSetRef, mc:debug_DIE_abbrev_set)
5658
CASV1_SIMPLE_GROUP_REF(DIETopLevelRef, mc:debug_DIE_top_level)
5759
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
@@ -485,6 +485,7 @@ struct DwarfSectionsCache {
485485
MCSection *Ranges;
486486
MCSection *Rangelists;
487487
MCSection *LineStr;
488+
MCSection *Names;
488489
};
489490

490491
/// Queries `Asm` for all dwarf sections and returns an object with (possibly
@@ -628,6 +629,10 @@ class MCCASBuilder {
628629
// object for the section.
629630
Error createDebugLineStrSection();
630631

632+
// If a DWARF Names section exists, create a DebugNamesRef CAS
633+
// object for the section.
634+
Error createDebugNamesSection();
635+
631636
/// If there is any padding between one section and the next, create a
632637
/// PaddingRef CAS object to represent the bytes of Padding between the two
633638
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,20 @@ DebugLineStrSectionRef::create(MCCASBuilder &MB,
849849
return get(B->build());
850850
}
851851

852+
Expected<DebugNamesSectionRef>
853+
DebugNamesSectionRef::create(MCCASBuilder &MB,
854+
ArrayRef<cas::ObjectRef> Fragments) {
855+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
856+
if (!B)
857+
return B.takeError();
858+
859+
if (auto E = createGenericDebugSection<DebugNamesSectionRef>(
860+
MB, Fragments, B->Data, B->Refs))
861+
return E;
862+
863+
return get(B->build());
864+
}
865+
852866
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
853867
raw_ostream *Stream) const {
854868
// Start a new section for relocations.
@@ -1349,6 +1363,14 @@ DebugLineStrSectionRef::materialize(MCCASReader &Reader,
13491363
Reader, Remaining, *this);
13501364
}
13511365

1366+
Expected<uint64_t>
1367+
DebugNamesSectionRef::materialize(MCCASReader &Reader,
1368+
raw_ostream *Stream) const {
1369+
StringRef Remaining = getData();
1370+
return materializeGenericDebugSection<DebugNamesSectionRef>(Reader, Remaining,
1371+
*this);
1372+
}
1373+
13521374
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
13531375
ArrayRef<cas::ObjectRef> Fragments) {
13541376
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1683,7 +1705,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
16831705
Asm.getContext().getObjectFileInfo()->getDwarfLoclistsSection(),
16841706
Asm.getContext().getObjectFileInfo()->getDwarfRangesSection(),
16851707
Asm.getContext().getObjectFileInfo()->getDwarfRnglistsSection(),
1686-
Asm.getContext().getObjectFileInfo()->getDwarfLineStrSection()};
1708+
Asm.getContext().getObjectFileInfo()->getDwarfLineStrSection(),
1709+
Asm.getContext().getObjectFileInfo()->getDwarfDebugNamesSection()};
16871710
}
16881711

16891712
Error MCCASBuilder::prepare() {
@@ -2610,6 +2633,23 @@ Error MCCASBuilder::createDebugLineStrSection() {
26102633
return finalizeSection<DebugLineStrSectionRef>();
26112634
}
26122635

2636+
Error MCCASBuilder::createDebugNamesSection() {
2637+
2638+
auto MaybeDebugNamesRef =
2639+
createGenericDebugRef<DebugNamesRef>(DwarfSections.Names);
2640+
if (!MaybeDebugNamesRef)
2641+
return Error::success();
2642+
2643+
if (!*MaybeDebugNamesRef)
2644+
return MaybeDebugNamesRef->takeError();
2645+
2646+
startSection(DwarfSections.Names);
2647+
addNode(**MaybeDebugNamesRef);
2648+
if (auto E = createPaddingRef(DwarfSections.Names))
2649+
return E;
2650+
return finalizeSection<DebugNamesSectionRef>();
2651+
}
2652+
26132653
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
26142654
switch (Fragment.getKind()) {
26152655
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2783,6 +2823,13 @@ Error MCCASBuilder::buildFragments() {
27832823
continue;
27842824
}
27852825

2826+
// Handle Debug Names sections separately.
2827+
if (&Sec == DwarfSections.Names) {
2828+
if (auto E = createDebugNamesSection())
2829+
return E;
2830+
continue;
2831+
}
2832+
27862833
// Start Subsection for one section.
27872834
startSection(&Sec);
27882835

@@ -2944,7 +2991,8 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
29442991
if (R.F && Sec != DwarfSections.Line && Sec != DwarfSections.DebugInfo &&
29452992
Sec != DwarfSections.Abbrev && Sec != DwarfSections.StrOffsets &&
29462993
Sec != DwarfSections.Loclists && Sec != DwarfSections.Ranges &&
2947-
Sec != DwarfSections.Rangelists && Sec != DwarfSections.LineStr)
2994+
Sec != DwarfSections.Rangelists && Sec != DwarfSections.LineStr &&
2995+
Sec != DwarfSections.Names)
29482996
RelMap[R.F].push_back(R.MRE);
29492997
else
29502998
// If the fragment is nullptr, it should a section with only relocation
@@ -3159,6 +3207,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
31593207
return F->materialize(*this);
31603208
if (auto F = DebugLineStrSectionRef::Cast(*Node))
31613209
return F->materialize(*this);
3210+
if (auto F = DebugNamesSectionRef::Cast(*Node))
3211+
return F->materialize(*this);
31623212
if (auto F = CStringRef::Cast(*Node)) {
31633213
auto Size = F->materialize(OS);
31643214
if (!Size)
@@ -3235,6 +3285,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
32353285
return F->materialize(*Stream);
32363286
if (auto F = DebugLineStrRef::Cast(*Node))
32373287
return F->materialize(*Stream);
3288+
if (auto F = DebugNamesRef::Cast(*Node))
3289+
return F->materialize(*Stream);
32383290
if (auto F = AddendsRef::Cast(*Node))
32393291
// AddendsRef is already handled when materializing Atoms, skip.
32403292
return 0;

0 commit comments

Comments
 (0)