diff options
-rw-r--r-- | include/llvm/MC/MCContext.h | 18 | ||||
-rw-r--r-- | lib/MC/MCContext.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 24 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 6 |
4 files changed, 50 insertions, 0 deletions
diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index 44bfb39c64..d45b0c8ca6 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -98,6 +98,17 @@ namespace llvm { MCDwarfLoc CurrentDwarfLoc; bool DwarfLocSeen; + /// Generate dwarf debugging info for assembly source files. + bool GenDwarfForAssembly; + + /// The current dwarf file number when generate dwarf debugging info for + /// assembly source files. + unsigned GenDwarfFileNumber; + + /// The default initial text section that we generate dwarf debugging line + /// info for when generating dwarf assembly source files. + const MCSection *GenDwarfSection; + /// Honor temporary labels, this is useful for debugging semantic /// differences between temporary and non-temporary labels (primarily on /// Darwin). @@ -252,6 +263,13 @@ namespace llvm { bool getDwarfLocSeen() { return DwarfLocSeen; } const MCDwarfLoc &getCurrentDwarfLoc() { return CurrentDwarfLoc; } + bool getGenDwarfForAssembly() { return GenDwarfForAssembly; } + void setGenDwarfForAssembly(bool Value) { GenDwarfForAssembly = Value; } + unsigned getGenDwarfFileNumber() { return GenDwarfFileNumber; } + unsigned nextGenDwarfFileNumber() { return ++GenDwarfFileNumber; } + const MCSection *getGenDwarfSection() { return GenDwarfSection; } + void setGenDwarfSection(const MCSection *Sec) { GenDwarfSection = Sec; } + /// @} char *getSecureLogFile() { return SecureLogFile; } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 9e28b8f41c..814726ebd8 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -43,6 +43,8 @@ MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri, SecureLogUsed = false; DwarfLocSeen = false; + GenDwarfForAssembly = false; + GenDwarfFileNumber = 0; } MCContext::~MCContext() { diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index d7ee1c4ca3..990fd17f59 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -464,6 +464,14 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { HadError = false; AsmCond StartingCondState = TheCondState; + // If we are generating dwarf for assembly source files save the initial text + // section and generate a .file directive. + if (getContext().getGenDwarfForAssembly()) { + getContext().setGenDwarfSection(getStreamer().getCurrentSection()); + getStreamer().EmitDwarfFileDirective(getContext().nextGenDwarfFileNumber(), + StringRef(), SrcMgr.getMemoryBuffer(CurBuffer)->getBufferIdentifier()); + } + // While we have input, parse each statement. while (Lexer.isNot(AsmToken::Eof)) { if (!ParseStatement()) continue; @@ -1211,6 +1219,18 @@ bool AsmParser::ParseStatement() { PrintMessage(IDLoc, SourceMgr::DK_Note, OS.str()); } + // If we are generating dwarf for assembly source files and the current + // section is the initial text section then generate a .loc directive for + // the instruction. + if (!HadError && getContext().getGenDwarfForAssembly() && + getContext().getGenDwarfSection() == getStreamer().getCurrentSection() ) { + getStreamer().EmitDwarfLocDirective(getContext().getGenDwarfFileNumber(), + SrcMgr.FindLineNumber(IDLoc, CurBuffer), + 0, DWARF2_LINE_DEFAULT_IS_STMT ? + DWARF2_FLAG_IS_STMT : 0, 0, 0, + StringRef()); + } + // If parsing succeeded, match the instruction. if (!HadError) HadError = getTargetParser().MatchAndEmitInstruction(IDLoc, ParsedOperands, @@ -2342,6 +2362,10 @@ bool GenericAsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) { if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.file' directive"); + if (getContext().getGenDwarfForAssembly() == true) + Error(DirectiveLoc, "input can't have .file dwarf directives when -g is " + "used to generate dwarf debug info for assembly code"); + if (FileNumber == -1) getStreamer().EmitFileDirective(Filename); else { diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index c188a76f54..8718b10ec2 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -152,6 +152,10 @@ NoInitialTextSection("n", cl::desc("Don't assume assembly file starts " static cl::opt<bool> SaveTempLabels("L", cl::desc("Don't discard temporary labels")); +static cl::opt<bool> +GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly " + "source files")); + enum ActionType { AC_AsLex, AC_Assemble, @@ -377,6 +381,8 @@ static int AssembleInput(const char *ProgName) { if (SaveTempLabels) Ctx.setAllowTemporaryLabels(false); + Ctx.setGenDwarfForAssembly(GenDwarfForAssembly); + // Package up features to be passed to target/subtarget std::string FeaturesStr; if (MAttrs.size()) { |