Add debug support for X86/ELF targets (Linux). This allows llvm-gcc4
authorReid Spencer <rspencer@reidspencer.com>
Mon, 30 Oct 2006 22:32:30 +0000 (22:32 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Mon, 30 Oct 2006 22:32:30 +0000 (22:32 +0000)
generated object modules to be debugged with gdb. Hopefully this helps
pre-release debugging.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31299 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetAsmInfo.h
lib/CodeGen/DwarfWriter.cpp
lib/Target/TargetAsmInfo.cpp
lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.h
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86InstrInfo.td
lib/Target/X86/X86TargetAsmInfo.cpp

index a1f4553e455c5e554aa2931baf6297583c252154..cf8f7a55be10298e98c2503507cebcad372bdb5a 100644 (file)
@@ -227,6 +227,10 @@ namespace llvm {
     ///
     bool HasDotFile; // Defaults to false.
     
+    /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
+    ///
+    bool DwarfRequiresFrameSection; // Defaults to false.
+
     /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
     ///
     const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
@@ -417,6 +421,9 @@ namespace llvm {
     bool hasDotFile() const {
       return HasDotFile;
     }
+    bool getDwarfRequiresFrameSection() const {
+      return DwarfRequiresFrameSection;
+    }
     const char *getDwarfAbbrevSection() const {
       return DwarfAbbrevSection;
     }
index fbcf6413be17205f048dd6a941f618df567f282a..40de586a3e5ffb95c8c35e63367be27237346207 100644 (file)
@@ -1921,8 +1921,8 @@ CompileUnit *Dwarf::NewCompileUnit(CompileUnitDesc *UnitDesc,
                                          unsigned ID) {
   // Construct debug information entry.
   DIE *Die = new DIE(DW_TAG_compile_unit);
-  Die->AddDelta (DW_AT_stmt_list, DW_FORM_data4,  DWLabel("line", 0),
-                                                  DWLabel("section_line", 0));
+  Die->AddDelta (DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0), 
+                                                 DWLabel("section_line", 0));
 //  Die->AddLabel (DW_AT_high_pc,   DW_FORM_addr,   DWLabel("text_end", 0));
 //  Die->AddLabel (DW_AT_low_pc,    DW_FORM_addr,   DWLabel("text_begin", 0));
   Die->AddString(DW_AT_producer,  DW_FORM_string, UnitDesc->getProducer());
@@ -2175,21 +2175,20 @@ void Dwarf::EmitInitial() {
   didInitial = true;
   
   // Dwarf sections base addresses.
-  Asm->SwitchToDataSection(TAI->getDwarfFrameSection(), 0);
-  EmitLabel("section_frame", 0);
+  if (TAI->getDwarfRequiresFrameSection()) {
+    Asm->SwitchToDataSection(TAI->getDwarfFrameSection(), 0);
+    EmitLabel("section_frame", 0);
+  }
   Asm->SwitchToDataSection(TAI->getDwarfInfoSection(), 0);
   EmitLabel("section_info", 0);
-  EmitLabel("info", 0);
   Asm->SwitchToDataSection(TAI->getDwarfAbbrevSection(), 0);
   EmitLabel("section_abbrev", 0);
-  EmitLabel("abbrev", 0);
   Asm->SwitchToDataSection(TAI->getDwarfARangesSection(), 0);
   EmitLabel("section_aranges", 0);
   Asm->SwitchToDataSection(TAI->getDwarfMacInfoSection(), 0);
   EmitLabel("section_macinfo", 0);
   Asm->SwitchToDataSection(TAI->getDwarfLineSection(), 0);
   EmitLabel("section_line", 0);
-  EmitLabel("line", 0);
   Asm->SwitchToDataSection(TAI->getDwarfLocSection(), 0);
   EmitLabel("section_loc", 0);
   Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection(), 0);
@@ -2198,7 +2197,6 @@ void Dwarf::EmitInitial() {
   EmitLabel("section_str", 0);
   Asm->SwitchToDataSection(TAI->getDwarfRangesSection(), 0);
   EmitLabel("section_ranges", 0);
-
   Asm->SwitchToTextSection(TAI->getTextSection(), 0);
   EmitLabel("text_begin", 0);
   Asm->SwitchToDataSection(TAI->getDataSection(), 0);
@@ -2629,6 +2627,9 @@ void Dwarf::EmitDebugLines() const {
 /// EmitInitialDebugFrame - Emit common frame info into a debug frame section.
 ///
 void Dwarf::EmitInitialDebugFrame() {
+  if (TAI->getDwarfRequiresFrameSection())
+    return;
+
   int stackGrowth =
       Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
         TargetFrameInfo::StackGrowsUp ?
@@ -2664,6 +2665,9 @@ void Dwarf::EmitInitialDebugFrame() {
 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
 /// section.
 void Dwarf::EmitFunctionDebugFrame() {
+  if (TAI->getDwarfRequiresFrameSection())
+    return;
+
   // Start the dwarf frame section.
   Asm->SwitchToDataSection(TAI->getDwarfFrameSection(), 0);
   
index b4014dd6b296625a9cb1ad69cb4063f88f1ac404..d68affd96b18124da5b370598a58fe0f68c1506c 100644 (file)
@@ -64,6 +64,7 @@ TargetAsmInfo::TargetAsmInfo() :
   HasLEB128(false),
   HasDotLoc(false),
   HasDotFile(false),
+  DwarfRequiresFrameSection(true),
   DwarfAbbrevSection(".debug_abbrev"),
   DwarfInfoSection(".debug_info"),
   DwarfLineSection(".debug_line"),
index dc2ecca7cb4544e6431f2f674ae684503493575b..42af5b69ac1483c4a6c4c3a72d8336c03a9de1f8 100755 (executable)
@@ -52,7 +52,7 @@ std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
 /// method to print assembly for each instruction.
 ///
 bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
-  if (Subtarget->isTargetDarwin()) {
+  if (Subtarget->isTargetDarwin() || Subtarget->isTargetELF()) {
     // Let PassManager know we need debug information and relay
     // the MachineDebugInfo address on to DwarfWriter.
     DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
@@ -111,7 +111,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        F->getLinkage() == Function::WeakLinkage))
     O << "_llvm$workaround$fake$stub_" << CurrentFnName << ":\n";
 
-  if (Subtarget->isTargetDarwin()) {
+  if (Subtarget->isTargetDarwin() || Subtarget->isTargetELF()) {
     // Emit pre-function debug information.
     DW.BeginFunction(&MF);
   }
@@ -141,7 +141,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   if (TAI->hasDotTypeDotSizeDirective())
     O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
 
-  if (Subtarget->isTargetDarwin()) {
+  if (Subtarget->isTargetDarwin() || Subtarget->isTargetELF()) {
     // Emit post-function debug information.
     DW.EndFunction();
   }
index 38dbe57aed0fa45f4f502600c1c7ef082d106dd2..60316517a829e5edd6302b73ea3f5dd2f28463f5 100644 (file)
@@ -114,6 +114,9 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
     if (!Subtarget->is64Bit())
       X86PICStyle = PICStyle::Stub;
 
+    // Emit initial debug information.
+    DW.BeginModule(&M);
+  } else if (Subtarget->isTargetELF()) {
     // Emit initial debug information.
     DW.BeginModule(&M);
   }
@@ -278,7 +281,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       O << "\t.long\t0\n";
     }
 
-    // Emit initial debug information.
+    // Emit final debug information.
     DW.EndModule();
 
     // Funny Darwin hack: This flag tells the linker that no global symbols
@@ -287,6 +290,9 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     // linker can safely perform dead code stripping.  Since LLVM never
     // generates code that does this, it is always safe to set.
     O << "\t.subsections_via_symbols\n";
+  } else if (Subtarget->isTargetELF()) {
+    // Emit final debug information.
+    DW.EndModule();
   }
 
   AsmPrinter::doFinalization(M);
index 1bbfa559e6e9ace06175284b2e079af09b04d991..b2fbe0529cbba424a6627d4dfe6ee5468d20cc41 100755 (executable)
@@ -67,7 +67,7 @@ struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
 
   void getAnalysisUsage(AnalysisUsage &AU) const {
     AU.setPreservesAll();
-    if (Subtarget->isTargetDarwin()) {
+    if (Subtarget->isTargetDarwin() || Subtarget->isTargetELF()) {
       AU.addRequired<MachineDebugInfo>();
     }
     MachineFunctionPass::getAnalysisUsage(AU);
index 0b8550686c3e0ae77423d093443d1c0f3ec0d69d..6de5032ff302b429a482b90d859296328e0e93d2 100644 (file)
@@ -219,7 +219,7 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM)
   setOperationAction(ISD::LOCATION, MVT::Other, Expand);
   setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
   // FIXME - use subtarget debug flags
-  if (!Subtarget->isTargetDarwin())
+  if (!Subtarget->isTargetDarwin() && !Subtarget->isTargetELF())
     setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
 
   // VASTART needs to be custom lowered to use the VarArgsFrameIndex
index 509fb053895e7f12b3ef7a0fe0c99866837e4f75..359513c9487f900b19f3e58f07601db9a473c5fe 100644 (file)
@@ -2451,9 +2451,9 @@ def DWARF_LOC   : I<0, Pseudo, (ops i32imm:$line, i32imm:$col, i32imm:$file),
                     [(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))]>;
+def DWARF_LABEL : I<0, Pseudo, (ops i32imm:$id), 
+                    "\n${:private}debug_loc${id:debug}:",
+                    [(dwarf_label (i32 imm:$id))]>;
 
 //===----------------------------------------------------------------------===//
 // Non-Instruction Patterns
index e67773711cbe07875d561550903170cad403be60..93596c04b46729d7cde960ca4d90ebf3af38a935 100644 (file)
@@ -60,6 +60,30 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
     DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
     break;
+
+  case X86Subtarget::isELF:
+    // Set up DWARF directives
+    HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
+    // bool HasLEB128; // Defaults to false.
+    // hasDotLoc - True if target asm supports .loc directives.
+    // bool HasDotLoc; // Defaults to false.
+    // HasDotFile - True if target asm supports .file directives.
+    // bool HasDotFile; // Defaults to false.
+    PrivateGlobalPrefix = ".";  // Prefix for private global symbols
+    DwarfRequiresFrameSection = false;
+    DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
+    DwarfInfoSection =    "\t.section\t.debug_info,\"\",@progbits";
+    DwarfLineSection =    "\t.section\t.debug_line,\"\",@progbits";
+    DwarfFrameSection =   "\t.section\t.debug_frame,\"\",@progbits";
+    DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
+    DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
+    DwarfStrSection =     "\t.section\t.debug_str,\"\",@progbits";
+    DwarfLocSection =     "\t.section\t.debug_loc,\"\",@progbits";
+    DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
+    DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",@progbits";
+    DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
+    break;
+
   case X86Subtarget::isCygwin:
     GlobalPrefix = "_";
     COMMDirectiveTakesAlignment = false;