Bill Wendling | a5c8a4e | 2009-05-10 23:14:38 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===// |
Jim Laskey | e503289 | 2005-12-21 19:48:16 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | e503289 | 2005-12-21 19:48:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 10 | // This file contains support for writing dwarf info into asm files. |
Jim Laskey | e503289 | 2005-12-21 19:48:16 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Jim Laskey | 3ea0e0e | 2006-01-27 18:32:41 +0000 | [diff] [blame] | 13 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/DwarfWriter.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame^] | 15 | #include "DwarfDebug.h" |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 16 | #include "DwarfException.h" |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame^] | 18 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 19 | using namespace llvm; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 20 | |
Devang Patel | eb3fc28 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 21 | static RegisterPass<DwarfWriter> |
| 22 | X("dwarfwriter", "DWARF Information Writer"); |
| 23 | char DwarfWriter::ID = 0; |
| 24 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 25 | //===----------------------------------------------------------------------===// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 26 | /// DwarfWriter Implementation |
Jim Laskey | ef42a01 | 2006-11-02 20:12:39 +0000 | [diff] [blame] | 27 | /// |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 28 | |
Bill Wendling | 91b8b80 | 2009-03-10 20:41:52 +0000 | [diff] [blame] | 29 | DwarfWriter::DwarfWriter() |
Bill Wendling | 163ba3f | 2009-03-10 21:23:25 +0000 | [diff] [blame] | 30 | : ImmutablePass(&ID), DD(0), DE(0) {} |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 31 | |
| 32 | DwarfWriter::~DwarfWriter() { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 33 | delete DE; |
| 34 | delete DD; |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 37 | /// BeginModule - Emit all Dwarf sections that should come prior to the |
| 38 | /// content. |
Devang Patel | eb3fc28 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 39 | void DwarfWriter::BeginModule(Module *M, |
| 40 | MachineModuleInfo *MMI, |
| 41 | raw_ostream &OS, AsmPrinter *A, |
| 42 | const TargetAsmInfo *T) { |
| 43 | DE = new DwarfException(OS, A, T); |
| 44 | DD = new DwarfDebug(OS, A, T); |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 45 | DE->BeginModule(M); |
| 46 | DD->BeginModule(M); |
Devang Patel | 7bb89ed | 2009-01-13 00:20:51 +0000 | [diff] [blame] | 47 | DD->SetDebugInfo(MMI); |
Devang Patel | eb3fc28 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 48 | DE->SetModuleInfo(MMI); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /// EndModule - Emit all Dwarf sections that should come after the content. |
| 52 | /// |
| 53 | void DwarfWriter::EndModule() { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 54 | DE->EndModule(); |
| 55 | DD->EndModule(); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 58 | /// BeginFunction - Gather pre-function debug information. Assumes being |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 59 | /// emitted immediately after the function entry point. |
| 60 | void DwarfWriter::BeginFunction(MachineFunction *MF) { |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 61 | DE->BeginFunction(MF); |
| 62 | DD->BeginFunction(MF); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /// EndFunction - Gather and emit post-function debug information. |
| 66 | /// |
Bill Wendling | d751c64 | 2008-09-26 00:28:12 +0000 | [diff] [blame] | 67 | void DwarfWriter::EndFunction(MachineFunction *MF) { |
| 68 | DD->EndFunction(MF); |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 69 | DE->EndFunction(); |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 70 | |
Bill Wendling | c91d0b9 | 2008-07-22 00:53:37 +0000 | [diff] [blame] | 71 | if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI()) |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 72 | // Clear function debug information. |
| 73 | MMI->EndFunction(); |
Jim Laskey | 6519546 | 2006-10-30 13:35:07 +0000 | [diff] [blame] | 74 | } |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 75 | |
| 76 | /// RecordSourceLine - Records location information and associates it with a |
| 77 | /// label. Returns a unique label ID used to generate a label and provide |
| 78 | /// correspondence to the source line list. |
| 79 | unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, |
Argyrios Kyrtzidis | a26eae6 | 2009-04-30 23:22:31 +0000 | [diff] [blame] | 80 | DICompileUnit CU) { |
| 81 | return DD->RecordSourceLine(Line, Col, CU); |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /// RecordRegionStart - Indicate the start of a region. |
| 85 | unsigned DwarfWriter::RecordRegionStart(GlobalVariable *V) { |
Bill Wendling | 163ba3f | 2009-03-10 21:23:25 +0000 | [diff] [blame] | 86 | return DD->RecordRegionStart(V); |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /// RecordRegionEnd - Indicate the end of a region. |
Dan Gohman | 9a38e3e | 2009-05-07 19:46:24 +0000 | [diff] [blame] | 90 | unsigned DwarfWriter::RecordRegionEnd(GlobalVariable *V) { |
| 91 | return DD->RecordRegionEnd(V); |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /// getRecordSourceLineCount - Count source lines. |
| 95 | unsigned DwarfWriter::getRecordSourceLineCount() { |
Bill Wendling | 163ba3f | 2009-03-10 21:23:25 +0000 | [diff] [blame] | 96 | return DD->getRecordSourceLineCount(); |
Devang Patel | ccca7fe | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 97 | } |
Devang Patel | bb8c595 | 2009-01-13 21:25:00 +0000 | [diff] [blame] | 98 | |
Devang Patel | c48c550 | 2009-01-13 21:44:10 +0000 | [diff] [blame] | 99 | /// RecordVariable - Indicate the declaration of a local variable. |
| 100 | /// |
Devang Patel | 1be3ecc | 2009-04-15 00:10:26 +0000 | [diff] [blame] | 101 | void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex, |
| 102 | const MachineInstr *MI) { |
| 103 | DD->RecordVariable(GV, FrameIndex, MI); |
Devang Patel | c48c550 | 2009-01-13 21:44:10 +0000 | [diff] [blame] | 104 | } |
Devang Patel | bbdc820 | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 105 | |
Bill Wendling | 4ed0c5f | 2009-02-20 00:44:43 +0000 | [diff] [blame] | 106 | /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should |
| 107 | /// be emitted. |
| 108 | bool DwarfWriter::ShouldEmitDwarfDebug() const { |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 109 | return DD && DD->ShouldEmitDwarfDebug(); |
Bill Wendling | 4ed0c5f | 2009-02-20 00:44:43 +0000 | [diff] [blame] | 110 | } |
Devang Patel | 0f7fef3 | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 111 | |
Devang Patel | 1be3ecc | 2009-04-15 00:10:26 +0000 | [diff] [blame] | 112 | //// RecordInlinedFnStart - Global variable GV is inlined at the location marked |
Devang Patel | 0f7fef3 | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 113 | //// by LabelID label. |
Argyrios Kyrtzidis | 116b274 | 2009-05-07 00:16:31 +0000 | [diff] [blame] | 114 | unsigned DwarfWriter::RecordInlinedFnStart(DISubprogram SP, DICompileUnit CU, |
| 115 | unsigned Line, unsigned Col) { |
| 116 | return DD->RecordInlinedFnStart(SP, CU, Line, Col); |
Devang Patel | 0f7fef3 | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Devang Patel | 1be3ecc | 2009-04-15 00:10:26 +0000 | [diff] [blame] | 119 | /// RecordInlinedFnEnd - Indicate the end of inlined subroutine. |
Argyrios Kyrtzidis | 116b274 | 2009-05-07 00:16:31 +0000 | [diff] [blame] | 120 | unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP) { |
Devang Patel | 1be3ecc | 2009-04-15 00:10:26 +0000 | [diff] [blame] | 121 | return DD->RecordInlinedFnEnd(SP); |
| 122 | } |
| 123 | |
| 124 | /// RecordVariableScope - Record scope for the variable declared by |
| 125 | /// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE. |
| 126 | void DwarfWriter::RecordVariableScope(DIVariable &DV, |
| 127 | const MachineInstr *DeclareMI) { |
| 128 | DD->RecordVariableScope(DV, DeclareMI); |
| 129 | } |