Skip to content

Commit

Permalink
The second part of support for generating dwarf for assembly source f…
Browse files Browse the repository at this point in the history
…iles. This

generates the dwarf Compile Unit DIE and a dwarf subprogram DIE for each
non-temporary label.

The next part will be to get the clang driver to enable this when assembling
a .s file.  rdar://9275556


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146262 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
enderby committed Dec 9, 2011
1 parent bf67a99 commit 94c2e85
Show file tree
Hide file tree
Showing 9 changed files with 554 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/llvm/MC/MCContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ namespace llvm {
/// The default initial text section that we generate dwarf debugging line
/// info for when generating dwarf assembly source files.
const MCSection *GenDwarfSection;
/// Symbols created for the start and end of this section.
MCSymbol *GenDwarfSectionStartSym, *GenDwarfSectionEndSym;

/// The information gathered from labels that will have dwarf subprogram
/// entries when generating dwarf assembly source files.
std::vector<const MCGenDwarfSubprogramEntry *> MCGenDwarfSubprogramEntries;

/// The string to embed in the debug information for the compile unit, if
/// non-empty.
StringRef DwarfDebugFlags;

/// Honor temporary labels, this is useful for debugging semantic
/// differences between temporary and non-temporary labels (primarily on
Expand Down Expand Up @@ -269,6 +279,24 @@ namespace llvm {
unsigned nextGenDwarfFileNumber() { return ++GenDwarfFileNumber; }
const MCSection *getGenDwarfSection() { return GenDwarfSection; }
void setGenDwarfSection(const MCSection *Sec) { GenDwarfSection = Sec; }
MCSymbol *getGenDwarfSectionStartSym() { return GenDwarfSectionStartSym; }
void setGenDwarfSectionStartSym(MCSymbol *Sym) {
GenDwarfSectionStartSym = Sym;
}
MCSymbol *getGenDwarfSectionEndSym() { return GenDwarfSectionEndSym; }
void setGenDwarfSectionEndSym(MCSymbol *Sym) {
GenDwarfSectionEndSym = Sym;
}
const std::vector<const MCGenDwarfSubprogramEntry *>
&getMCGenDwarfSubprogramEntries() const {
return MCGenDwarfSubprogramEntries;
}
void addMCGenDwarfSubprogramEntry(const MCGenDwarfSubprogramEntry *E) {
MCGenDwarfSubprogramEntries.push_back(E);
}

void setDwarfDebugFlags(StringRef S) { DwarfDebugFlags = S; }
StringRef getDwarfDebugFlags() { return DwarfDebugFlags; }

/// @}

Expand Down
42 changes: 42 additions & 0 deletions include/llvm/MC/MCDwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace llvm {
class MCSymbol;
class MCObjectStreamer;
class raw_ostream;
class SourceMgr;
class SMLoc;

/// MCDwarfFile - Instances of this class represent the name of the dwarf
/// .file directive and its associated dwarf file number in the MC file,
Expand Down Expand Up @@ -227,6 +229,46 @@ namespace llvm {
int64_t LineDelta, uint64_t AddrDelta);
};

class MCGenDwarfInfo {
public:
//
// When generating dwarf for assembly source files this emits the Dwarf
// sections.
//
static void Emit(MCStreamer *MCOS);
};

// When generating dwarf for assembly source files this is the info that is
// needed to be gathered for each symbol that will have a dwarf2_subprogram.
class MCGenDwarfSubprogramEntry {
private:
// Name of the symbol without a leading underbar, if any.
StringRef Name;
// The dwarf file number this symbol is in.
unsigned FileNumber;
// The line number this symbol is at.
unsigned LineNumber;
// The low_pc for the dwarf2_subprogram is taken from this symbol. The
// high_pc is taken from the next symbol's value or the end of the section
// for the last symbol
MCSymbol *Label;

public:
MCGenDwarfSubprogramEntry(StringRef name, unsigned fileNumber,
unsigned lineNumber, MCSymbol *label) :
Name(name), FileNumber(fileNumber), LineNumber(lineNumber), Label(label){}

StringRef getName() const { return Name; }
unsigned getFileNumber() const { return FileNumber; }
unsigned getLineNumber() const { return LineNumber; }
MCSymbol *getLabel() const { return Label; }

// This is called when label is created when we are generating dwarf for
// assembly source files.
static void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr,
SMLoc &Loc);
};

class MCCFIInstruction {
public:
enum OpType { SameValue, Remember, Restore, Move, RelMove };
Expand Down
1 change: 1 addition & 0 deletions include/llvm/Support/Dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ enum dwarf_constants {
DW_LANG_D = 0x0013,
DW_LANG_Python = 0x0014,
DW_LANG_lo_user = 0x8000,
DW_LANG_Mips_Assembler = 0x8001,
DW_LANG_hi_user = 0xffff,

// Identifier case codes
Expand Down
4 changes: 4 additions & 0 deletions lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,10 @@ void MCAsmStreamer::Finish() {
if (getContext().hasDwarfFiles() && !UseLoc)
MCDwarfFileTable::Emit(this);

// If we are generating dwarf for assembly source files dump out the sections.
if (getContext().getGenDwarfForAssembly())
MCGenDwarfInfo::Emit(this);

if (!UseCFI)
EmitFrames(false);
}
Expand Down
Loading

0 comments on commit 94c2e85

Please sign in to comment.