[llvm-commits] [llvm] r143509 - in /llvm/trunk: include/llvm/MC/MCContext.h lib/MC/MCContext.cpp lib/MC/MCParser/AsmParser.cpp tools/llvm-mc/llvm-mc.cpp

Kevin Enderby enderby at apple.com
Tue Nov 1 15:27:23 PDT 2011


Author: enderby
Date: Tue Nov  1 17:27:22 2011
New Revision: 143509

URL: http://llvm.org/viewvc/llvm-project?rev=143509&view=rev
Log:
First part of support for generating dwarf for assembly source files with the
-g flag.  In this part we generate the .file for the source being assembled and
the .loc's for the assembled instructions.

The next part will be to generate the dwarf Compile Unit DIE and a dwarf
subprogram DIE for each non-temporary label.

Once the next part is done test cases will be added.  rdar://9275556

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/lib/MC/MCContext.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=143509&r1=143508&r2=143509&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Tue Nov  1 17:27:22 2011
@@ -98,6 +98,17 @@
     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 @@
     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; }

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=143509&r1=143508&r2=143509&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Tue Nov  1 17:27:22 2011
@@ -43,6 +43,8 @@
   SecureLogUsed = false;
 
   DwarfLocSeen = false;
+  GenDwarfForAssembly = false;
+  GenDwarfFileNumber = 0;
 }
 
 MCContext::~MCContext() {

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=143509&r1=143508&r2=143509&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Nov  1 17:27:22 2011
@@ -464,6 +464,14 @@
   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 @@
     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 @@
   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 {

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=143509&r1=143508&r2=143509&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Tue Nov  1 17:27:22 2011
@@ -152,6 +152,10 @@
 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 @@
   if (SaveTempLabels)
     Ctx.setAllowTemporaryLabels(false);
 
+  Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
+
   // Package up features to be passed to target/subtarget
   std::string FeaturesStr;
   if (MAttrs.size()) {





More information about the llvm-commits mailing list