Enable Dwarf debugging info.
authorEvan Cheng <evan.cheng@apple.com>
Tue, 7 Mar 2006 02:02:57 +0000 (02:02 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Tue, 7 Mar 2006 02:02:57 +0000 (02:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26581 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86ATTAsmPrinter.h
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.h
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86InstrInfo.td
lib/Target/X86/X86IntelAsmPrinter.cpp
lib/Target/X86/X86IntelAsmPrinter.h

index e9da1855ddd5b86d1acdbc576bd72f589044b39b..e50100e7528ad7f79ff71150076e793386c517e2 100755 (executable)
@@ -27,9 +27,16 @@ using namespace x86;
 /// method to print assembly for each instruction.
 ///
 bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
+  // Let PassManager know we need debug information and relay
+  // the MachineDebugInfo address on to DwarfWriter.
+  DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
+
   SetupMachineFunction(MF);
   O << "\n\n";
 
+  // Emit pre-function debug information.
+  DW.BeginFunction(MF);
+
   // Print out constants referenced by the function
   EmitConstantPool(MF.getConstantPool());
 
@@ -81,6 +88,9 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   if (HasDotTypeDotSizeDirective)
     O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
 
+  // Emit post-function debug information.
+  DW.EndFunction(MF);
+
   // We didn't modify anything.
   return false;
 }
@@ -101,7 +111,9 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
 
   case MachineOperand::MO_SignExtendedImmed:
   case MachineOperand::MO_UnextendedImmed:
-    O << '$' << (int)MO.getImmedValue();
+    if (!Modifier || strcmp(Modifier, "debug") != 0)
+      O << '$';
+    O << (int)MO.getImmedValue();
     return;
   case MachineOperand::MO_MachineBasicBlock: {
     MachineBasicBlock *MBBOp = MO.getMachineBasicBlock();
index 2fc1aa57b435052fe459ce83046e74f2521d2352..325b43d32b2cd3a5e500feb8854f567117515a30 100755 (executable)
@@ -21,7 +21,7 @@ namespace llvm {
 namespace x86 {
 
 struct X86ATTAsmPrinter : public X86SharedAsmPrinter {
 X86ATTAsmPrinter(std::ostream &O, TargetMachine &TM)
+ X86ATTAsmPrinter(std::ostream &O, TargetMachine &TM)
     : X86SharedAsmPrinter(O, TM) { }
 
   virtual const char *getPassName() const {
index bd96cb93c7f4ced916053f8d12cdbda08ad270f8..edc2397e604ad3e57223f033cd79a9aa01095bd7 100644 (file)
@@ -75,6 +75,9 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
   default: break;
   }
   
+  // Emit initial debug information.
+  DW.BeginModule(M);
+
   return AsmPrinter::doInitialization(M);
 }
 
@@ -187,6 +190,9 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     }
   }
 
+  // Emit initial debug information.
+  DW.EndModule(M);
+
   AsmPrinter::doFinalization(M);
   return false; // success
 }
index b27cdf067d4eaedbc956616f84356a3b8d3a8daf..5b27c564577bc382067a628b75c0e0d79f43f74c 100755 (executable)
@@ -18,6 +18,8 @@
 
 #include "X86.h"
 #include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/DwarfWriter.h"
+#include "llvm/CodeGen/MachineDebugInfo.h"
 #include "llvm/ADT/Statistic.h"
 #include <set>
 
@@ -27,14 +29,46 @@ namespace x86 {
 
 extern Statistic<> EmittedInsts;
 
+/// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
+///
+struct X86DwarfWriter : public DwarfWriter {
+ // Ctor.
+X86DwarfWriter(std::ostream &o, AsmPrinter *ap)
+  : DwarfWriter(o, ap)
+    {
+      needsSet = true;
+      DwarfAbbrevSection = ".section __DWARFA,__debug_abbrev";
+      DwarfInfoSection = ".section __DWARFA,__debug_info";
+      DwarfLineSection = ".section __DWARFA,__debug_line";
+      DwarfFrameSection = ".section __DWARFA,__debug_frame";
+      DwarfPubNamesSection = ".section __DWARFA,__debug_pubnames";
+      DwarfPubTypesSection = ".section __DWARFA,__debug_pubtypes";
+      DwarfStrSection = ".section __DWARFA,__debug_str";
+      DwarfLocSection = ".section __DWARFA,__debug_loc";
+      DwarfARangesSection = ".section __DWARFA,__debug_aranges";
+      DwarfRangesSection = ".section __DWARFA,__debug_ranges";
+      DwarfMacInfoSection = ".section __DWARFA,__debug_macinfo";
+      TextSection = ".text";
+       DataSection = ".data";
+    }
+};
+
 struct X86SharedAsmPrinter : public AsmPrinter {
+  X86DwarfWriter DW;
+
   X86SharedAsmPrinter(std::ostream &O, TargetMachine &TM)
-    : AsmPrinter(O, TM), forDarwin(false) { }
+    : AsmPrinter(O, TM), DW(O, this), forDarwin(false) { }
 
   bool doInitialization(Module &M);
   bool doFinalization(Module &M);
 
-  bool forDarwin;  // FIXME: eliminate.
+  void getAnalysisUsage(AnalysisUsage &AU) const {
+    AU.setPreservesAll();
+    AU.addRequired<MachineDebugInfo>();
+    MachineFunctionPass::getAnalysisUsage(AU);
+  }
+
+    bool forDarwin;  // FIXME: eliminate.
 
   // Necessary for Darwin to print out the apprioriate types of linker stubs
   std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
index eaabfd6a96cd542c12e2ffbaef5115d9f839a8b5..b59dad3a673bd0dbe3f39879ccb59b6a4e83e1ec 100644 (file)
@@ -168,7 +168,9 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM)
   // We don't have line number support yet.
   setOperationAction(ISD::LOCATION, MVT::Other, Expand);
   setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
-  setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
+  // FIXME - use subtarget debug flags
+  if (!TM.getSubtarget<X86Subtarget>().isTargetDarwin())
+    setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
 
   // VASTART needs to be custom lowered to use the VarArgsFrameIndex
   setOperationAction(ISD::VASTART           , MVT::Other, Custom);
index 6831428c6ea775f6f33061c713233ac57b94f75e..fd1410ba0bf48a3b5979972a9edfc355cf3fd29d 100644 (file)
@@ -2352,6 +2352,19 @@ def MOV32r0  : I<0x31, MRMInitReg,  (ops R32:$dst),
                  "xor{l} $dst, $dst",
                  [(set R32:$dst, 0)]>;
 
+//===----------------------------------------------------------------------===//
+// DWARF Pseudo Instructions
+//
+
+def DWARF_LOC   : I<0, Pseudo, (ops i32imm:$line, i32imm:$col, i32imm:$file),
+                    "; .loc $file, $line, $col",
+                    [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
+                      (i32 imm:$file))]>;
+
+def DWARF_LABEL : I<0, Pseudo, (ops i32imm:$id),
+                   "\nLdebug_loc${id:debug}:",
+                   [(dwarf_label (i32 imm:$id))]>;
+
 //===----------------------------------------------------------------------===//
 // Non-Instruction Patterns
 //===----------------------------------------------------------------------===//
index ed673df9fe56c0028d38616f859eff66267ac4ca..5bc8b243723cd08e0a7be1220dc4c0f647ebd111 100755 (executable)
@@ -26,9 +26,16 @@ using namespace x86;
 /// method to print assembly for each instruction.
 ///
 bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
+  // Let PassManager know we need debug information and relay
+  // the MachineDebugInfo address on to DwarfWriter.
+  DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
+
   SetupMachineFunction(MF);
   O << "\n\n";
 
+  // Emit pre-function debug information.
+  DW.BeginFunction(MF);
+
   // Print out constants referenced by the function
   EmitConstantPool(MF.getConstantPool());
 
@@ -56,6 +63,9 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
     }
   }
 
+  // Emit post-function debug information.
+  DW.EndFunction(MF);
+
   // We didn't modify anything.
   return false;
 }
index 02c654fcb174c19d783428b88a1e9a17baa22ae5..cf8d3cf366dcb0fdd42aa48465112e68dbcb26fe 100755 (executable)
@@ -23,7 +23,7 @@ namespace llvm {
 namespace x86 {
 
 struct X86IntelAsmPrinter : public X86SharedAsmPrinter {
 X86IntelAsmPrinter(std::ostream &O, TargetMachine &TM)
+ X86IntelAsmPrinter(std::ostream &O, TargetMachine &TM)
     : X86SharedAsmPrinter(O, TM) { }
 
   virtual const char *getPassName() const {