blob: 23da39ca6b3638b9eca4b61fa3922b5b2e48874c [file] [log] [blame]
Bill Wendling0310d762009-05-15 09:23:25 +00001//===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains support for writing dwarf debug info into asm files.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
15#define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
16
Bill Wendling0310d762009-05-15 09:23:25 +000017#include "llvm/CodeGen/AsmPrinter.h"
Devang Patelc3f5f782010-05-25 23:40:22 +000018#include "llvm/CodeGen/MachineLocation.h"
Chris Lattnerd2c4f192010-04-05 06:12:01 +000019#include "DIE.h"
Devang Patel622b0262010-01-19 06:19:05 +000020#include "llvm/ADT/DenseMap.h"
Bill Wendling0310d762009-05-15 09:23:25 +000021#include "llvm/ADT/FoldingSet.h"
Chris Lattner74e41f92010-04-05 05:24:55 +000022#include "llvm/ADT/SmallPtrSet.h"
Bill Wendling0310d762009-05-15 09:23:25 +000023#include "llvm/ADT/StringMap.h"
24#include "llvm/ADT/UniqueVector.h"
Chris Lattner74e41f92010-04-05 05:24:55 +000025#include "llvm/Support/Allocator.h"
Benjamin Kramer12ea7652010-09-13 20:04:49 +000026#include "llvm/Support/DebugLoc.h"
Bill Wendling0310d762009-05-15 09:23:25 +000027
28namespace llvm {
29
30class CompileUnit;
Bill Wendling0310d762009-05-15 09:23:25 +000031class DbgConcreteScope;
Nick Lewycky381afae2009-11-17 09:17:08 +000032class DbgScope;
33class DbgVariable;
Bill Wendling0310d762009-05-15 09:23:25 +000034class MachineFrameInfo;
35class MachineModuleInfo;
Devang Patela43098d2010-04-28 01:03:09 +000036class MachineOperand;
Chris Lattneraf76e592009-08-22 20:48:53 +000037class MCAsmInfo;
Chris Lattner74e41f92010-04-05 05:24:55 +000038class DIEAbbrev;
39class DIE;
40class DIEBlock;
41class DIEEntry;
42
43class DIEnumerator;
44class DIDescriptor;
45class DIVariable;
46class DIGlobal;
47class DIGlobalVariable;
48class DISubprogram;
49class DIBasicType;
50class DIDerivedType;
51class DIType;
52class DINameSpace;
53class DISubrange;
54class DICompositeType;
Bill Wendling0310d762009-05-15 09:23:25 +000055
56//===----------------------------------------------------------------------===//
57/// SrcLineInfo - This class is used to record source line correspondence.
58///
Nick Lewycky381afae2009-11-17 09:17:08 +000059class SrcLineInfo {
Bill Wendling0310d762009-05-15 09:23:25 +000060 unsigned Line; // Source line number.
61 unsigned Column; // Source column.
62 unsigned SourceID; // Source ID number.
Chris Lattner25b68c62010-03-14 08:15:55 +000063 MCSymbol *Label; // Label in code ID number.
Bill Wendling0310d762009-05-15 09:23:25 +000064public:
Chris Lattner25b68c62010-03-14 08:15:55 +000065 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
66 : Line(L), Column(C), SourceID(S), Label(label) {}
Bill Wendling0310d762009-05-15 09:23:25 +000067
68 // Accessors
69 unsigned getLine() const { return Line; }
70 unsigned getColumn() const { return Column; }
71 unsigned getSourceID() const { return SourceID; }
Chris Lattner25b68c62010-03-14 08:15:55 +000072 MCSymbol *getLabel() const { return Label; }
Bill Wendling0310d762009-05-15 09:23:25 +000073};
74
Chris Lattnerd38fee82010-04-05 00:13:49 +000075class DwarfDebug {
76 /// Asm - Target of Dwarf emission.
77 AsmPrinter *Asm;
Chris Lattner105d6972010-04-05 05:31:04 +000078
Chris Lattnerd38fee82010-04-05 00:13:49 +000079 /// MMI - Collected machine module information.
80 MachineModuleInfo *MMI;
81
Bill Wendling0310d762009-05-15 09:23:25 +000082 //===--------------------------------------------------------------------===//
83 // Attributes used to construct specific Dwarf sections.
84 //
85
Devang Patel163a9f72010-05-10 22:49:55 +000086 CompileUnit *FirstCU;
87 DenseMap <const MDNode *, CompileUnit *> CUMap;
Bill Wendling0310d762009-05-15 09:23:25 +000088
89 /// AbbreviationsSet - Used to uniquely define abbreviations.
90 ///
91 FoldingSet<DIEAbbrev> AbbreviationsSet;
92
93 /// Abbreviations - A list of all the unique abbreviations in use.
94 ///
95 std::vector<DIEAbbrev *> Abbreviations;
96
97 /// DirectoryIdMap - Directory name to directory id map.
98 ///
99 StringMap<unsigned> DirectoryIdMap;
100
101 /// DirectoryNames - A list of directory names.
102 SmallVector<std::string, 8> DirectoryNames;
103
104 /// SourceFileIdMap - Source file name to source file id map.
105 ///
106 StringMap<unsigned> SourceFileIdMap;
107
108 /// SourceFileNames - A list of source file names.
109 SmallVector<std::string, 8> SourceFileNames;
110
111 /// SourceIdMap - Source id map, i.e. pair of directory id and source file
112 /// id mapped to a unique id.
113 DenseMap<std::pair<unsigned, unsigned>, unsigned> SourceIdMap;
114
115 /// SourceIds - Reverse map from source id to directory id + file id pair.
116 ///
117 SmallVector<std::pair<unsigned, unsigned>, 8> SourceIds;
118
Dan Gohmanf451cb82010-02-10 16:03:48 +0000119 /// Lines - List of source line correspondence.
Bill Wendling0310d762009-05-15 09:23:25 +0000120 std::vector<SrcLineInfo> Lines;
121
Benjamin Kramer345ef342010-03-31 19:34:01 +0000122 /// DIEBlocks - A list of all the DIEBlocks in use.
123 std::vector<DIEBlock *> DIEBlocks;
124
125 // DIEValueAllocator - All DIEValues are allocated through this allocator.
126 BumpPtrAllocator DIEValueAllocator;
Bill Wendling0310d762009-05-15 09:23:25 +0000127
Chris Lattnerbc733f52010-03-13 02:17:42 +0000128 /// StringPool - A String->Symbol mapping of strings used by indirect
129 /// references.
130 StringMap<std::pair<MCSymbol*, unsigned> > StringPool;
131 unsigned NextStringPoolNumber;
132
133 MCSymbol *getStringPoolEntry(StringRef Str);
Bill Wendling0310d762009-05-15 09:23:25 +0000134
135 /// SectionMap - Provides a unique id per text section.
136 ///
Chris Lattnera87dea42009-07-31 18:48:30 +0000137 UniqueVector<const MCSection*> SectionMap;
Bill Wendling0310d762009-05-15 09:23:25 +0000138
139 /// SectionSourceLines - Tracks line numbers per text section.
140 ///
141 std::vector<std::vector<SrcLineInfo> > SectionSourceLines;
142
Devang Patel53bb5c92009-11-10 23:06:00 +0000143 // CurrentFnDbgScope - Top level scope for the current function.
Bill Wendling0310d762009-05-15 09:23:25 +0000144 //
Devang Patel53bb5c92009-11-10 23:06:00 +0000145 DbgScope *CurrentFnDbgScope;
Bill Wendling0310d762009-05-15 09:23:25 +0000146
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000147 /// DbgScopeMap - Tracks the scopes in the current function. Owns the
148 /// contained DbgScope*s.
Devang Patel53bb5c92009-11-10 23:06:00 +0000149 ///
Devang Patele9f8f5e2010-05-07 20:54:48 +0000150 DenseMap<const MDNode *, DbgScope *> DbgScopeMap;
Bill Wendling0310d762009-05-15 09:23:25 +0000151
Devang Patel53bb5c92009-11-10 23:06:00 +0000152 /// ConcreteScopes - Tracks the concrete scopees in the current function.
153 /// These scopes are also included in DbgScopeMap.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000154 DenseMap<const MDNode *, DbgScope *> ConcreteScopes;
Devang Patel53bb5c92009-11-10 23:06:00 +0000155
156 /// AbstractScopes - Tracks the abstract scopes a module. These scopes are
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000157 /// not included DbgScopeMap. AbstractScopes owns its DbgScope*s.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000158 DenseMap<const MDNode *, DbgScope *> AbstractScopes;
Devang Patel2ddefec2010-03-25 15:09:44 +0000159
Devang Patel8aa61472010-07-07 22:20:57 +0000160 /// AbstractSPDies - Collection of abstract subprogram DIEs.
161 DenseMap<const MDNode *, DIE *> AbstractSPDies;
162
Devang Patel2ddefec2010-03-25 15:09:44 +0000163 /// AbstractScopesList - Tracks abstract scopes constructed while processing
164 /// a function. This list is cleared during endFunction().
Devang Patel53bb5c92009-11-10 23:06:00 +0000165 SmallVector<DbgScope *, 4>AbstractScopesList;
166
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000167 /// AbstractVariables - Collection on abstract variables. Owned by the
168 /// DbgScopes in AbstractScopes.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000169 DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
Devang Patel53bb5c92009-11-10 23:06:00 +0000170
Devang Patel26c1e562010-05-20 16:36:41 +0000171 /// DbgVariableToFrameIndexMap - Tracks frame index used to find
172 /// variable's value.
173 DenseMap<const DbgVariable *, int> DbgVariableToFrameIndexMap;
174
175 /// DbgVariableToDbgInstMap - Maps DbgVariable to corresponding DBG_VALUE
176 /// machine instruction.
177 DenseMap<const DbgVariable *, const MachineInstr *> DbgVariableToDbgInstMap;
178
179 /// DbgVariableLabelsMap - Maps DbgVariable to corresponding MCSymbol.
180 DenseMap<const DbgVariable *, const MCSymbol *> DbgVariableLabelsMap;
181
Devang Patelc3f5f782010-05-25 23:40:22 +0000182 /// DotDebugLocEntry - This struct describes location entries emitted in
183 /// .debug_loc section.
184 typedef struct DotDebugLocEntry {
185 const MCSymbol *Begin;
186 const MCSymbol *End;
187 MachineLocation Loc;
188 DotDebugLocEntry() : Begin(0), End(0) {}
189 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E,
190 MachineLocation &L) : Begin(B), End(E), Loc(L) {}
191 /// Empty entries are also used as a trigger to emit temp label. Such
192 /// labels are referenced is used to find debug_loc offset for a given DIE.
193 bool isEmpty() { return Begin == 0 && End == 0; }
194 } DotDebugLocEntry;
195
196 /// DotDebugLocEntries - Collection of DotDebugLocEntry.
197 SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
198
199 /// UseDotDebugLocEntry - DW_AT_location attributes for the DIEs in this set
200 /// idetifies corresponding .debug_loc entry offset.
201 SmallPtrSet<const DIE *, 4> UseDotDebugLocEntry;
202
Devang Patel26c1e562010-05-20 16:36:41 +0000203 /// VarToAbstractVarMap - Maps DbgVariable with corresponding Abstract
204 /// DbgVariable, if any.
205 DenseMap<const DbgVariable *, const DbgVariable *> VarToAbstractVarMap;
206
Devang Patel53bb5c92009-11-10 23:06:00 +0000207 /// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked
208 /// (at the end of the module) as DW_AT_inline.
209 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
210
Devang Patelf8a2e012010-04-15 00:02:49 +0000211 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
212 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
213 /// corresponds to the MDNode mapped with the subprogram DIE.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000214 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
Devang Patel5d11eb02009-12-03 19:11:07 +0000215
Devang Patel461a6462010-05-19 21:58:28 +0000216 typedef SmallVector<DbgScope *, 2> ScopeVector;
Devang Patelf347b822010-06-28 05:59:13 +0000217
Devang Patel1c246352010-04-08 16:50:29 +0000218 SmallPtrSet<const MachineInstr *, 8> InsnsEndScopeSet;
Devang Patelaf9e8472009-10-01 20:31:14 +0000219
Bill Wendling0310d762009-05-15 09:23:25 +0000220 /// InlineInfo - Keep track of inlined functions and their location. This
221 /// information is used to populate debug_inlined section.
Devang Patelc3f5f782010-05-25 23:40:22 +0000222 typedef std::pair<const MCSymbol *, DIE *> InlineInfoLabels;
Devang Patele9f8f5e2010-05-07 20:54:48 +0000223 DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> > InlineInfo;
224 SmallVector<const MDNode *, 4> InlinedSPNodes;
Bill Wendling0310d762009-05-15 09:23:25 +0000225
Devang Patel4a1cad62010-06-28 18:25:03 +0000226 // ProcessedSPNodes - This is a collection of subprogram MDNodes that
227 // are processed to create DIEs.
228 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
229
Devang Pateleac9c072010-04-27 19:46:33 +0000230 /// LabelsBeforeInsn - Maps instruction with label emitted before
Devang Patel1c246352010-04-08 16:50:29 +0000231 /// instruction.
Devang Pateleac9c072010-04-27 19:46:33 +0000232 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
Devang Patel1c246352010-04-08 16:50:29 +0000233
Devang Pateleac9c072010-04-27 19:46:33 +0000234 /// LabelsAfterInsn - Maps instruction with label emitted after
Devang Patel1c246352010-04-08 16:50:29 +0000235 /// instruction.
Devang Pateleac9c072010-04-27 19:46:33 +0000236 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
Devang Patel1c246352010-04-08 16:50:29 +0000237
Devang Patelb2b31a62010-05-26 19:37:24 +0000238 /// insnNeedsLabel - Collection of instructions that need a label to mark
239 /// a debuggging information entity.
240 SmallPtrSet<const MachineInstr *, 8> InsnNeedsLabel;
241
Devang Patelf2548ca2010-04-16 23:33:45 +0000242 SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
Devang Patelc04d5452010-04-22 20:56:35 +0000243
Devang Patel553881b2010-03-29 17:20:31 +0000244 /// Previous instruction's location information. This is used to determine
245 /// label location to indicate scope boundries in dwarf debug info.
Chris Lattnerde4845c2010-04-02 19:42:39 +0000246 DebugLoc PrevInstLoc;
Devang Patelf2548ca2010-04-16 23:33:45 +0000247 MCSymbol *PrevLabel;
Devang Patel553881b2010-03-29 17:20:31 +0000248
Bill Wendling0310d762009-05-15 09:23:25 +0000249 struct FunctionDebugFrameInfo {
250 unsigned Number;
251 std::vector<MachineMove> Moves;
252
253 FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M)
254 : Number(Num), Moves(M) {}
255 };
256
257 std::vector<FunctionDebugFrameInfo> DebugFrames;
258
Chris Lattner9c69e285532010-04-04 22:59:04 +0000259 // Section Symbols: these are assembler temporary labels that are emitted at
260 // the beginning of each supported dwarf section. These are used to form
261 // section offsets and are created by EmitSectionLabels.
262 MCSymbol *DwarfFrameSectionSym, *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
Devang Patelf2548ca2010-04-16 23:33:45 +0000263 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
Devang Patelc3f5f782010-05-25 23:40:22 +0000264 MCSymbol *DwarfDebugLocSectionSym;
265 MCSymbol *FunctionBeginSym, *FunctionEndSym;
Devang Patelca76f6f2010-07-08 20:10:35 +0000266
267 DIEInteger *DIEIntegerOne;
Chris Lattner9c69e285532010-04-04 22:59:04 +0000268private:
269
Bill Wendling0310d762009-05-15 09:23:25 +0000270 /// getSourceDirectoryAndFileIds - Return the directory and file ids that
271 /// maps to the source id. Source id starts at 1.
272 std::pair<unsigned, unsigned>
273 getSourceDirectoryAndFileIds(unsigned SId) const {
274 return SourceIds[SId-1];
275 }
276
277 /// getNumSourceDirectories - Return the number of source directories in the
278 /// debug info.
279 unsigned getNumSourceDirectories() const {
280 return DirectoryNames.size();
281 }
282
283 /// getSourceDirectoryName - Return the name of the directory corresponding
284 /// to the id.
285 const std::string &getSourceDirectoryName(unsigned Id) const {
286 return DirectoryNames[Id - 1];
287 }
288
289 /// getSourceFileName - Return the name of the source file corresponding
290 /// to the id.
291 const std::string &getSourceFileName(unsigned Id) const {
292 return SourceFileNames[Id - 1];
293 }
294
295 /// getNumSourceIds - Return the number of unique source ids.
296 unsigned getNumSourceIds() const {
297 return SourceIds.size();
298 }
299
Devang Patel2c4ceb12009-11-21 02:48:08 +0000300 /// assignAbbrevNumber - Define a unique number for the abbreviation.
Bill Wendling0310d762009-05-15 09:23:25 +0000301 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000302 void assignAbbrevNumber(DIEAbbrev &Abbrev);
Bill Wendling0310d762009-05-15 09:23:25 +0000303
Devang Patel2c4ceb12009-11-21 02:48:08 +0000304 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
Bill Wendling995f80a2009-05-20 23:24:48 +0000305 /// information entry.
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000306 DIEEntry *createDIEEntry(DIE *Entry);
Bill Wendling0310d762009-05-15 09:23:25 +0000307
Devang Patel2c4ceb12009-11-21 02:48:08 +0000308 /// addUInt - Add an unsigned integer attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000309 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000310 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
Bill Wendling0310d762009-05-15 09:23:25 +0000311
Devang Patel2c4ceb12009-11-21 02:48:08 +0000312 /// addSInt - Add an signed integer attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000313 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000314 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
Bill Wendling0310d762009-05-15 09:23:25 +0000315
Devang Patel2c4ceb12009-11-21 02:48:08 +0000316 /// addString - Add a string attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000317 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000318 void addString(DIE *Die, unsigned Attribute, unsigned Form,
Devang Patele9a05972009-11-24 19:42:17 +0000319 const StringRef Str);
Bill Wendling0310d762009-05-15 09:23:25 +0000320
Devang Patel2c4ceb12009-11-21 02:48:08 +0000321 /// addLabel - Add a Dwarf label attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000322 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000323 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000324 const MCSymbol *Label);
Bill Wendling0310d762009-05-15 09:23:25 +0000325
Devang Patel2c4ceb12009-11-21 02:48:08 +0000326 /// addDelta - Add a label delta attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000327 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000328 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000329 const MCSymbol *Hi, const MCSymbol *Lo);
Bill Wendling0310d762009-05-15 09:23:25 +0000330
Devang Patel2c4ceb12009-11-21 02:48:08 +0000331 /// addDIEEntry - Add a DIE attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000332 ///
Chris Lattner74e41f92010-04-05 05:24:55 +0000333 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
334
Devang Patel2c4ceb12009-11-21 02:48:08 +0000335 /// addBlock - Add block data.
Bill Wendling0310d762009-05-15 09:23:25 +0000336 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000337 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
Bill Wendling0310d762009-05-15 09:23:25 +0000338
Devang Patel2c4ceb12009-11-21 02:48:08 +0000339 /// addSourceLine - Add location information to specified debug information
Bill Wendling0310d762009-05-15 09:23:25 +0000340 /// entry.
Devang Patel85e95802010-08-10 04:09:06 +0000341 void addSourceLine(DIE *Die, DIVariable V);
342 void addSourceLine(DIE *Die, DIGlobalVariable G);
343 void addSourceLine(DIE *Die, DISubprogram SP);
344 void addSourceLine(DIE *Die, DIType Ty);
345 void addSourceLine(DIE *Die, DINameSpace NS);
Bill Wendling0310d762009-05-15 09:23:25 +0000346
Devang Patel2c4ceb12009-11-21 02:48:08 +0000347 /// addAddress - Add an address attribute to a die based on the location
Bill Wendling0310d762009-05-15 09:23:25 +0000348 /// provided.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000349 void addAddress(DIE *Die, unsigned Attribute,
Bill Wendling0310d762009-05-15 09:23:25 +0000350 const MachineLocation &Location);
351
Devang Patela43098d2010-04-28 01:03:09 +0000352 /// addRegisterAddress - Add register location entry in variable DIE.
Devang Patel26c1e562010-05-20 16:36:41 +0000353 bool addRegisterAddress(DIE *Die, const MCSymbol *VS, const MachineOperand &MO);
Devang Patela43098d2010-04-28 01:03:09 +0000354
355 /// addConstantValue - Add constant value entry in variable DIE.
Devang Patel26c1e562010-05-20 16:36:41 +0000356 bool addConstantValue(DIE *Die, const MCSymbol *VS, const MachineOperand &MO);
Devang Patela43098d2010-04-28 01:03:09 +0000357
358 /// addConstantFPValue - Add constant value entry in variable DIE.
Devang Patel26c1e562010-05-20 16:36:41 +0000359 bool addConstantFPValue(DIE *Die, const MCSymbol *VS, const MachineOperand &MO);
Devang Patela43098d2010-04-28 01:03:09 +0000360
Devang Patel2c4ceb12009-11-21 02:48:08 +0000361 /// addComplexAddress - Start with the address based on the location provided,
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000362 /// and generate the DWARF information necessary to find the actual variable
363 /// (navigating the extra location information encoded in the type) based on
364 /// the starting location. Add the DWARF information to the die.
365 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000366 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000367 const MachineLocation &Location);
368
Devang Patel2c4ceb12009-11-21 02:48:08 +0000369 // FIXME: Should be reformulated in terms of addComplexAddress.
370 /// addBlockByrefAddress - Start with the address based on the location
Caroline Ticedc8f6042009-08-31 21:19:37 +0000371 /// provided, and generate the DWARF information necessary to find the
372 /// actual Block variable (navigating the Block struct) based on the
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000373 /// starting location. Add the DWARF information to the die. Obsolete,
Devang Patel2c4ceb12009-11-21 02:48:08 +0000374 /// please use addComplexAddress instead.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000375 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000376 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
Caroline Ticedc8f6042009-08-31 21:19:37 +0000377 const MachineLocation &Location);
378
Devang Patel9e3bd2c2010-08-31 06:11:28 +0000379 /// addVariableAddress - Add DW_AT_location attribute for a DbgVariable based
380 /// on provided frame index.
381 void addVariableAddress(DbgVariable *&DV, DIE *Die, int64_t FI);
Devang Patel8bd11de2010-08-09 21:01:39 +0000382
Devang Patelc366f832009-12-10 19:14:49 +0000383 /// addToContextOwner - Add Die into the list of its context owner's children.
384 void addToContextOwner(DIE *Die, DIDescriptor Context);
385
Devang Patel2c4ceb12009-11-21 02:48:08 +0000386 /// addType - Add a new type attribute to the specified entity.
Devang Patel8a241142009-12-09 18:24:21 +0000387 void addType(DIE *Entity, DIType Ty);
Bill Wendling0310d762009-05-15 09:23:25 +0000388
Devang Patel6404e4e2009-12-15 19:16:48 +0000389
390 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
391 DIE *getOrCreateNameSpace(DINameSpace NS);
392
Devang Patel16ced732009-12-10 18:05:33 +0000393 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
394 /// given DIType.
395 DIE *getOrCreateTypeDIE(DIType Ty);
396
Devang Patel193f7202009-11-24 01:14:22 +0000397 void addPubTypes(DISubprogram SP);
398
Devang Patel2c4ceb12009-11-21 02:48:08 +0000399 /// constructTypeDIE - Construct basic type die from DIBasicType.
Devang Patel8a241142009-12-09 18:24:21 +0000400 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000401 DIBasicType BTy);
402
Devang Patel2c4ceb12009-11-21 02:48:08 +0000403 /// constructTypeDIE - Construct derived type die from DIDerivedType.
Devang Patel8a241142009-12-09 18:24:21 +0000404 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000405 DIDerivedType DTy);
406
Devang Patel2c4ceb12009-11-21 02:48:08 +0000407 /// constructTypeDIE - Construct type DIE from DICompositeType.
Devang Patel8a241142009-12-09 18:24:21 +0000408 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000409 DICompositeType CTy);
410
Devang Patel2c4ceb12009-11-21 02:48:08 +0000411 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
412 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
Bill Wendling0310d762009-05-15 09:23:25 +0000413
Devang Patel2c4ceb12009-11-21 02:48:08 +0000414 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
Devang Patel8a241142009-12-09 18:24:21 +0000415 void constructArrayTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000416 DICompositeType *CTy);
417
Devang Patel2c4ceb12009-11-21 02:48:08 +0000418 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
Devang Patel3c91b052010-03-08 20:52:55 +0000419 DIE *constructEnumTypeDIE(DIEnumerator ETy);
Devang Patel4063f6b2009-12-07 21:41:32 +0000420
Devang Patel2c4ceb12009-11-21 02:48:08 +0000421 /// createMemberDIE - Create new member DIE.
Devang Patelecbd8e82010-08-10 04:12:17 +0000422 DIE *createMemberDIE(DIDerivedType DT);
Bill Wendling0310d762009-05-15 09:23:25 +0000423
Devang Patel2c4ceb12009-11-21 02:48:08 +0000424 /// createSubprogramDIE - Create new DIE using SP.
Devang Patelee70fa72010-09-27 23:15:27 +0000425 DIE *createSubprogramDIE(DISubprogram SP);
Bill Wendling0310d762009-05-15 09:23:25 +0000426
Devang Pateleac9c072010-04-27 19:46:33 +0000427 /// getOrCreateDbgScope - Create DbgScope for the scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000428 DbgScope *getOrCreateDbgScope(const MDNode *Scope, const MDNode *InlinedAt);
Devang Patel70d75ca2009-11-12 19:02:56 +0000429
Devang Patele9f8f5e2010-05-07 20:54:48 +0000430 DbgScope *getOrCreateAbstractScope(const MDNode *N);
Devang Patel53bb5c92009-11-10 23:06:00 +0000431
432 /// findAbstractVariable - Find abstract variable associated with Var.
Devang Patel26c1e562010-05-20 16:36:41 +0000433 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
Devang Patel53bb5c92009-11-10 23:06:00 +0000434
Devang Patel2c4ceb12009-11-21 02:48:08 +0000435 /// updateSubprogramScopeDIE - Find DIE for the given subprogram and
436 /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes.
437 /// If there are global variables in this scope then create and insert
438 /// DIEs for these variables.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000439 DIE *updateSubprogramScopeDIE(const MDNode *SPNode);
Bill Wendling0310d762009-05-15 09:23:25 +0000440
Devang Patel2c4ceb12009-11-21 02:48:08 +0000441 /// constructLexicalScope - Construct new DW_TAG_lexical_block
442 /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
443 DIE *constructLexicalScopeDIE(DbgScope *Scope);
Bill Wendling0310d762009-05-15 09:23:25 +0000444
Devang Patel2c4ceb12009-11-21 02:48:08 +0000445 /// constructInlinedScopeDIE - This scope represents inlined body of
446 /// a function. Construct DIE to represent this concrete inlined copy
447 /// of the function.
448 DIE *constructInlinedScopeDIE(DbgScope *Scope);
449
450 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
Devang Patel8a241142009-12-09 18:24:21 +0000451 DIE *constructVariableDIE(DbgVariable *DV, DbgScope *S);
Devang Patel2c4ceb12009-11-21 02:48:08 +0000452
453 /// constructScopeDIE - Construct a DIE for this scope.
454 DIE *constructScopeDIE(DbgScope *Scope);
455
Chris Lattnerfa070b02010-04-04 22:33:59 +0000456 /// EmitSectionLabels - Emit initial Dwarf sections with a label at
457 /// the start of each one.
458 void EmitSectionLabels();
Bill Wendling0310d762009-05-15 09:23:25 +0000459
Devang Patel2c4ceb12009-11-21 02:48:08 +0000460 /// emitDIE - Recusively Emits a debug information entry.
Bill Wendling0310d762009-05-15 09:23:25 +0000461 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000462 void emitDIE(DIE *Die);
Bill Wendling0310d762009-05-15 09:23:25 +0000463
Devang Patel2c4ceb12009-11-21 02:48:08 +0000464 /// computeSizeAndOffset - Compute the size and offset of a DIE.
Bill Wendling0310d762009-05-15 09:23:25 +0000465 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000466 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last);
Bill Wendling0310d762009-05-15 09:23:25 +0000467
Devang Patel2c4ceb12009-11-21 02:48:08 +0000468 /// computeSizeAndOffsets - Compute the size and offset of all the DIEs.
Bill Wendling0310d762009-05-15 09:23:25 +0000469 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000470 void computeSizeAndOffsets();
Bill Wendling0310d762009-05-15 09:23:25 +0000471
Devang Patel8a241142009-12-09 18:24:21 +0000472 /// EmitDebugInfo - Emit the debug info section.
Bill Wendling0310d762009-05-15 09:23:25 +0000473 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000474 void emitDebugInfo();
Bill Wendling0310d762009-05-15 09:23:25 +0000475
Devang Patel2c4ceb12009-11-21 02:48:08 +0000476 /// emitAbbreviations - Emit the abbreviation section.
Bill Wendling0310d762009-05-15 09:23:25 +0000477 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000478 void emitAbbreviations() const;
Bill Wendling0310d762009-05-15 09:23:25 +0000479
Devang Patel2c4ceb12009-11-21 02:48:08 +0000480 /// emitEndOfLineMatrix - Emit the last address of the section and the end of
Bill Wendling0310d762009-05-15 09:23:25 +0000481 /// the line matrix.
482 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000483 void emitEndOfLineMatrix(unsigned SectionEnd);
Bill Wendling0310d762009-05-15 09:23:25 +0000484
Devang Patel2c4ceb12009-11-21 02:48:08 +0000485 /// emitDebugLines - Emit source line information.
Bill Wendling0310d762009-05-15 09:23:25 +0000486 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000487 void emitDebugLines();
Bill Wendling0310d762009-05-15 09:23:25 +0000488
Devang Patel2c4ceb12009-11-21 02:48:08 +0000489 /// emitCommonDebugFrame - Emit common frame info into a debug frame section.
Bill Wendling0310d762009-05-15 09:23:25 +0000490 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000491 void emitCommonDebugFrame();
Bill Wendling0310d762009-05-15 09:23:25 +0000492
Devang Patel2c4ceb12009-11-21 02:48:08 +0000493 /// emitFunctionDebugFrame - Emit per function frame info into a debug frame
Bill Wendling0310d762009-05-15 09:23:25 +0000494 /// section.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000495 void emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo);
Bill Wendling0310d762009-05-15 09:23:25 +0000496
Devang Patel2c4ceb12009-11-21 02:48:08 +0000497 /// emitDebugPubNames - Emit visible names into a debug pubnames section.
Bill Wendling0310d762009-05-15 09:23:25 +0000498 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000499 void emitDebugPubNames();
Bill Wendling0310d762009-05-15 09:23:25 +0000500
Devang Patel193f7202009-11-24 01:14:22 +0000501 /// emitDebugPubTypes - Emit visible types into a debug pubtypes section.
502 ///
503 void emitDebugPubTypes();
504
Devang Patel2c4ceb12009-11-21 02:48:08 +0000505 /// emitDebugStr - Emit visible names into a debug str section.
Bill Wendling0310d762009-05-15 09:23:25 +0000506 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000507 void emitDebugStr();
Bill Wendling0310d762009-05-15 09:23:25 +0000508
Devang Patel2c4ceb12009-11-21 02:48:08 +0000509 /// emitDebugLoc - Emit visible names into a debug loc section.
Bill Wendling0310d762009-05-15 09:23:25 +0000510 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000511 void emitDebugLoc();
Bill Wendling0310d762009-05-15 09:23:25 +0000512
513 /// EmitDebugARanges - Emit visible names into a debug aranges section.
514 ///
515 void EmitDebugARanges();
516
Devang Patel2c4ceb12009-11-21 02:48:08 +0000517 /// emitDebugRanges - Emit visible names into a debug ranges section.
Bill Wendling0310d762009-05-15 09:23:25 +0000518 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000519 void emitDebugRanges();
Bill Wendling0310d762009-05-15 09:23:25 +0000520
Devang Patel2c4ceb12009-11-21 02:48:08 +0000521 /// emitDebugMacInfo - Emit visible names into a debug macinfo section.
Bill Wendling0310d762009-05-15 09:23:25 +0000522 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000523 void emitDebugMacInfo();
Bill Wendling0310d762009-05-15 09:23:25 +0000524
Devang Patel2c4ceb12009-11-21 02:48:08 +0000525 /// emitDebugInlineInfo - Emit inline info using following format.
Bill Wendling0310d762009-05-15 09:23:25 +0000526 /// Section Header:
527 /// 1. length of section
528 /// 2. Dwarf version number
529 /// 3. address size.
530 ///
531 /// Entries (one "entry" for each function that was inlined):
532 ///
533 /// 1. offset into __debug_str section for MIPS linkage name, if exists;
534 /// otherwise offset into __debug_str for regular function name.
535 /// 2. offset into __debug_str section for regular function name.
536 /// 3. an unsigned LEB128 number indicating the number of distinct inlining
537 /// instances for the function.
538 ///
539 /// The rest of the entry consists of a {die_offset, low_pc} pair for each
540 /// inlined instance; the die_offset points to the inlined_subroutine die in
541 /// the __debug_info section, and the low_pc is the starting address for the
542 /// inlining instance.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000543 void emitDebugInlineInfo();
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000544
545 /// GetOrCreateSourceID - Look up the source id with the given directory and
546 /// source file names. If none currently exists, create a new id and insert it
Chris Lattner75f50722010-04-04 07:48:20 +0000547 /// in the SourceIds map. This can update DirectoryNames and SourceFileNames
548 /// maps as well.
Devang Patel65dbc902009-11-25 17:36:49 +0000549 unsigned GetOrCreateSourceID(StringRef DirName, StringRef FileName);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000550
Devang Patel163a9f72010-05-10 22:49:55 +0000551 /// constructCompileUnit - Create new CompileUnit for the given
552 /// metadata node with tag DW_TAG_compile_unit.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000553 void constructCompileUnit(const MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000554
Devang Patel163a9f72010-05-10 22:49:55 +0000555 /// getCompielUnit - Get CompileUnit DIE.
556 CompileUnit *getCompileUnit(const MDNode *N) const;
557
558 /// constructGlobalVariableDIE - Construct global variable DIE.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000559 void constructGlobalVariableDIE(const MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000560
Devang Patel163a9f72010-05-10 22:49:55 +0000561 /// construct SubprogramDIE - Construct subprogram DIE.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000562 void constructSubprogramDIE(const MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000563
Chris Lattner2b1b3312010-04-05 05:32:45 +0000564 /// recordSourceLine - Register a source line with debug info. Returns the
565 /// unique label that was emitted and which provides correspondence to
566 /// the source line list.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000567 MCSymbol *recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope);
Chris Lattner2b1b3312010-04-05 05:32:45 +0000568
569 /// getSourceLineCount - Return the number of source lines in the debug
570 /// info.
571 unsigned getSourceLineCount() const {
572 return Lines.size();
573 }
574
Devang Patel26c1e562010-05-20 16:36:41 +0000575 /// recordVariableFrameIndex - Record a variable's index.
576 void recordVariableFrameIndex(const DbgVariable *V, int Index);
577
578 /// findVariableFrameIndex - Return true if frame index for the variable
579 /// is found. Update FI to hold value of the index.
580 bool findVariableFrameIndex(const DbgVariable *V, int *FI);
581
582 /// findVariableLabel - Find MCSymbol for the variable.
583 const MCSymbol *findVariableLabel(const DbgVariable *V);
584
Devang Patelee432862010-05-20 19:57:06 +0000585 /// findDbgScope - Find DbgScope for the debug loc attached with an
586 /// instruction.
587 DbgScope *findDbgScope(const MachineInstr *MI);
588
Devang Patele37b0c62010-04-08 18:43:56 +0000589 /// identifyScopeMarkers() - Indentify instructions that are marking
590 /// beginning of or end of a scope.
591 void identifyScopeMarkers();
Devang Patel6122a4d2010-04-08 15:37:09 +0000592
Chris Lattner2b1b3312010-04-05 05:32:45 +0000593 /// extractScopeInformation - Scan machine instructions in this function
594 /// and collect DbgScopes. Return true, if atleast one scope was found.
595 bool extractScopeInformation();
596
597 /// collectVariableInfo - Populate DbgScope entries with variables' info.
Devang Patel78e127d2010-06-25 22:07:34 +0000598 void collectVariableInfo(const MachineFunction *,
599 SmallPtrSet<const MDNode *, 16> &ProcessedVars);
Chris Lattner2b1b3312010-04-05 05:32:45 +0000600
Devang Patelee432862010-05-20 19:57:06 +0000601 /// collectVariableInfoFromMMITable - Collect variable information from
602 /// side table maintained by MMI.
603 void collectVariableInfoFromMMITable(const MachineFunction * MF,
604 SmallPtrSet<const MDNode *, 16> &P);
Bill Wendling0310d762009-05-15 09:23:25 +0000605public:
606 //===--------------------------------------------------------------------===//
607 // Main entry points.
608 //
Chris Lattner49cd6642010-04-05 05:11:15 +0000609 DwarfDebug(AsmPrinter *A, Module *M);
Chris Lattner2b1b3312010-04-05 05:32:45 +0000610 ~DwarfDebug();
Bill Wendling0310d762009-05-15 09:23:25 +0000611
Devang Patel2c4ceb12009-11-21 02:48:08 +0000612 /// beginModule - Emit all Dwarf sections that should come prior to the
Bill Wendling0310d762009-05-15 09:23:25 +0000613 /// content.
Chris Lattner75f50722010-04-04 07:48:20 +0000614 void beginModule(Module *M);
Bill Wendling0310d762009-05-15 09:23:25 +0000615
Devang Patel2c4ceb12009-11-21 02:48:08 +0000616 /// endModule - Emit all Dwarf sections that should come after the content.
Bill Wendling0310d762009-05-15 09:23:25 +0000617 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000618 void endModule();
Bill Wendling0310d762009-05-15 09:23:25 +0000619
Devang Patel2c4ceb12009-11-21 02:48:08 +0000620 /// beginFunction - Gather pre-function debug information. Assumes being
Bill Wendling0310d762009-05-15 09:23:25 +0000621 /// emitted immediately after the function entry point.
Chris Lattnereec791a2010-01-26 23:18:02 +0000622 void beginFunction(const MachineFunction *MF);
Bill Wendling0310d762009-05-15 09:23:25 +0000623
Devang Patel2c4ceb12009-11-21 02:48:08 +0000624 /// endFunction - Gather and emit post-function debug information.
Bill Wendling0310d762009-05-15 09:23:25 +0000625 ///
Chris Lattnereec791a2010-01-26 23:18:02 +0000626 void endFunction(const MachineFunction *MF);
Bill Wendling0310d762009-05-15 09:23:25 +0000627
Devang Patelc3f5f782010-05-25 23:40:22 +0000628 /// getLabelBeforeInsn - Return Label preceding the instruction.
629 const MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
630
631 /// getLabelAfterInsn - Return Label immediately following the instruction.
632 const MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
633
Devang Patel553881b2010-03-29 17:20:31 +0000634 /// beginScope - Process beginning of a scope.
635 void beginScope(const MachineInstr *MI);
Bill Wendling0310d762009-05-15 09:23:25 +0000636
Devang Patel2c4ceb12009-11-21 02:48:08 +0000637 /// endScope - Prcess end of a scope.
638 void endScope(const MachineInstr *MI);
Devang Patel53bb5c92009-11-10 23:06:00 +0000639};
Bill Wendling0310d762009-05-15 09:23:25 +0000640} // End of namespace llvm
641
642#endif