blob: 5d33f7668a0c7541c18d6135cc1e74da0a88fcd7 [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
Devang Patelc3f5f782010-05-25 23:40:22 +0000179 /// DotDebugLocEntry - This struct describes location entries emitted in
180 /// .debug_loc section.
181 typedef struct DotDebugLocEntry {
182 const MCSymbol *Begin;
183 const MCSymbol *End;
184 MachineLocation Loc;
185 DotDebugLocEntry() : Begin(0), End(0) {}
186 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E,
187 MachineLocation &L) : Begin(B), End(E), Loc(L) {}
188 /// Empty entries are also used as a trigger to emit temp label. Such
189 /// labels are referenced is used to find debug_loc offset for a given DIE.
190 bool isEmpty() { return Begin == 0 && End == 0; }
191 } DotDebugLocEntry;
192
193 /// DotDebugLocEntries - Collection of DotDebugLocEntry.
194 SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
195
196 /// UseDotDebugLocEntry - DW_AT_location attributes for the DIEs in this set
197 /// idetifies corresponding .debug_loc entry offset.
198 SmallPtrSet<const DIE *, 4> UseDotDebugLocEntry;
199
Devang Patel26c1e562010-05-20 16:36:41 +0000200 /// VarToAbstractVarMap - Maps DbgVariable with corresponding Abstract
201 /// DbgVariable, if any.
202 DenseMap<const DbgVariable *, const DbgVariable *> VarToAbstractVarMap;
203
Devang Patel53bb5c92009-11-10 23:06:00 +0000204 /// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked
205 /// (at the end of the module) as DW_AT_inline.
206 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
207
Devang Patelf8a2e012010-04-15 00:02:49 +0000208 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
209 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
210 /// corresponds to the MDNode mapped with the subprogram DIE.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000211 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
Devang Patel5d11eb02009-12-03 19:11:07 +0000212
Devang Patel461a6462010-05-19 21:58:28 +0000213 typedef SmallVector<DbgScope *, 2> ScopeVector;
Devang Patelf347b822010-06-28 05:59:13 +0000214
Devang Patel1c246352010-04-08 16:50:29 +0000215 SmallPtrSet<const MachineInstr *, 8> InsnsEndScopeSet;
Devang Patelaf9e8472009-10-01 20:31:14 +0000216
Bill Wendling0310d762009-05-15 09:23:25 +0000217 /// InlineInfo - Keep track of inlined functions and their location. This
218 /// information is used to populate debug_inlined section.
Devang Patelc3f5f782010-05-25 23:40:22 +0000219 typedef std::pair<const MCSymbol *, DIE *> InlineInfoLabels;
Devang Patele9f8f5e2010-05-07 20:54:48 +0000220 DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> > InlineInfo;
221 SmallVector<const MDNode *, 4> InlinedSPNodes;
Bill Wendling0310d762009-05-15 09:23:25 +0000222
Devang Patel4a1cad62010-06-28 18:25:03 +0000223 // ProcessedSPNodes - This is a collection of subprogram MDNodes that
224 // are processed to create DIEs.
225 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
226
Devang Pateleac9c072010-04-27 19:46:33 +0000227 /// LabelsBeforeInsn - Maps instruction with label emitted before
Devang Patel1c246352010-04-08 16:50:29 +0000228 /// instruction.
Devang Pateleac9c072010-04-27 19:46:33 +0000229 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
Devang Patel1c246352010-04-08 16:50:29 +0000230
Devang Pateleac9c072010-04-27 19:46:33 +0000231 /// LabelsAfterInsn - Maps instruction with label emitted after
Devang Patel1c246352010-04-08 16:50:29 +0000232 /// instruction.
Devang Pateleac9c072010-04-27 19:46:33 +0000233 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
Devang Patel1c246352010-04-08 16:50:29 +0000234
Devang Patelb2b31a62010-05-26 19:37:24 +0000235 /// insnNeedsLabel - Collection of instructions that need a label to mark
236 /// a debuggging information entity.
237 SmallPtrSet<const MachineInstr *, 8> InsnNeedsLabel;
238
Devang Patelf2548ca2010-04-16 23:33:45 +0000239 SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
Devang Patelc04d5452010-04-22 20:56:35 +0000240
Devang Patel553881b2010-03-29 17:20:31 +0000241 /// Previous instruction's location information. This is used to determine
242 /// label location to indicate scope boundries in dwarf debug info.
Chris Lattnerde4845c2010-04-02 19:42:39 +0000243 DebugLoc PrevInstLoc;
Devang Patelf2548ca2010-04-16 23:33:45 +0000244 MCSymbol *PrevLabel;
Devang Patel553881b2010-03-29 17:20:31 +0000245
Bill Wendling0310d762009-05-15 09:23:25 +0000246 struct FunctionDebugFrameInfo {
247 unsigned Number;
248 std::vector<MachineMove> Moves;
249
250 FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M)
251 : Number(Num), Moves(M) {}
252 };
253
254 std::vector<FunctionDebugFrameInfo> DebugFrames;
255
Chris Lattner9c69e285532010-04-04 22:59:04 +0000256 // Section Symbols: these are assembler temporary labels that are emitted at
257 // the beginning of each supported dwarf section. These are used to form
258 // section offsets and are created by EmitSectionLabels.
259 MCSymbol *DwarfFrameSectionSym, *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
Devang Patelf2548ca2010-04-16 23:33:45 +0000260 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
Devang Patelc3f5f782010-05-25 23:40:22 +0000261 MCSymbol *DwarfDebugLocSectionSym;
262 MCSymbol *FunctionBeginSym, *FunctionEndSym;
Devang Patelca76f6f2010-07-08 20:10:35 +0000263
264 DIEInteger *DIEIntegerOne;
Chris Lattner9c69e285532010-04-04 22:59:04 +0000265private:
266
Bill Wendling0310d762009-05-15 09:23:25 +0000267 /// getSourceDirectoryAndFileIds - Return the directory and file ids that
268 /// maps to the source id. Source id starts at 1.
269 std::pair<unsigned, unsigned>
270 getSourceDirectoryAndFileIds(unsigned SId) const {
271 return SourceIds[SId-1];
272 }
273
274 /// getNumSourceDirectories - Return the number of source directories in the
275 /// debug info.
276 unsigned getNumSourceDirectories() const {
277 return DirectoryNames.size();
278 }
279
280 /// getSourceDirectoryName - Return the name of the directory corresponding
281 /// to the id.
282 const std::string &getSourceDirectoryName(unsigned Id) const {
283 return DirectoryNames[Id - 1];
284 }
285
286 /// getSourceFileName - Return the name of the source file corresponding
287 /// to the id.
288 const std::string &getSourceFileName(unsigned Id) const {
289 return SourceFileNames[Id - 1];
290 }
291
292 /// getNumSourceIds - Return the number of unique source ids.
293 unsigned getNumSourceIds() const {
294 return SourceIds.size();
295 }
296
Devang Patel2c4ceb12009-11-21 02:48:08 +0000297 /// assignAbbrevNumber - Define a unique number for the abbreviation.
Bill Wendling0310d762009-05-15 09:23:25 +0000298 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000299 void assignAbbrevNumber(DIEAbbrev &Abbrev);
Bill Wendling0310d762009-05-15 09:23:25 +0000300
Devang Patel2c4ceb12009-11-21 02:48:08 +0000301 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
Bill Wendling995f80a2009-05-20 23:24:48 +0000302 /// information entry.
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000303 DIEEntry *createDIEEntry(DIE *Entry);
Bill Wendling0310d762009-05-15 09:23:25 +0000304
Devang Patel2c4ceb12009-11-21 02:48:08 +0000305 /// addUInt - Add an unsigned integer attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000306 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000307 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
Bill Wendling0310d762009-05-15 09:23:25 +0000308
Devang Patel2c4ceb12009-11-21 02:48:08 +0000309 /// addSInt - Add an signed integer attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000310 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000311 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
Bill Wendling0310d762009-05-15 09:23:25 +0000312
Devang Patel2c4ceb12009-11-21 02:48:08 +0000313 /// addString - Add a string attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000314 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000315 void addString(DIE *Die, unsigned Attribute, unsigned Form,
Devang Patele9a05972009-11-24 19:42:17 +0000316 const StringRef Str);
Bill Wendling0310d762009-05-15 09:23:25 +0000317
Devang Patel2c4ceb12009-11-21 02:48:08 +0000318 /// addLabel - Add a Dwarf label attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000319 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000320 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000321 const MCSymbol *Label);
Bill Wendling0310d762009-05-15 09:23:25 +0000322
Devang Patel2c4ceb12009-11-21 02:48:08 +0000323 /// addDelta - Add a label delta attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000324 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000325 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000326 const MCSymbol *Hi, const MCSymbol *Lo);
Bill Wendling0310d762009-05-15 09:23:25 +0000327
Devang Patel2c4ceb12009-11-21 02:48:08 +0000328 /// addDIEEntry - Add a DIE attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000329 ///
Chris Lattner74e41f92010-04-05 05:24:55 +0000330 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
331
Devang Patel2c4ceb12009-11-21 02:48:08 +0000332 /// addBlock - Add block data.
Bill Wendling0310d762009-05-15 09:23:25 +0000333 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000334 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
Bill Wendling0310d762009-05-15 09:23:25 +0000335
Devang Patel2c4ceb12009-11-21 02:48:08 +0000336 /// addSourceLine - Add location information to specified debug information
Bill Wendling0310d762009-05-15 09:23:25 +0000337 /// entry.
Devang Patel85e95802010-08-10 04:09:06 +0000338 void addSourceLine(DIE *Die, DIVariable V);
339 void addSourceLine(DIE *Die, DIGlobalVariable G);
340 void addSourceLine(DIE *Die, DISubprogram SP);
341 void addSourceLine(DIE *Die, DIType Ty);
342 void addSourceLine(DIE *Die, DINameSpace NS);
Bill Wendling0310d762009-05-15 09:23:25 +0000343
Devang Patel2c4ceb12009-11-21 02:48:08 +0000344 /// addAddress - Add an address attribute to a die based on the location
Bill Wendling0310d762009-05-15 09:23:25 +0000345 /// provided.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000346 void addAddress(DIE *Die, unsigned Attribute,
Bill Wendling0310d762009-05-15 09:23:25 +0000347 const MachineLocation &Location);
348
Devang Patela43098d2010-04-28 01:03:09 +0000349 /// addRegisterAddress - Add register location entry in variable DIE.
Devang Patel522ad742010-11-12 23:20:42 +0000350 bool addRegisterAddress(DIE *Die, const MachineOperand &MO);
Devang Patela43098d2010-04-28 01:03:09 +0000351
352 /// addConstantValue - Add constant value entry in variable DIE.
Devang Patel522ad742010-11-12 23:20:42 +0000353 bool addConstantValue(DIE *Die, const MachineOperand &MO);
Devang Patela43098d2010-04-28 01:03:09 +0000354
355 /// addConstantFPValue - Add constant value entry in variable DIE.
Devang Patel522ad742010-11-12 23:20:42 +0000356 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
Devang Patela43098d2010-04-28 01:03:09 +0000357
Devang Patel2c4ceb12009-11-21 02:48:08 +0000358 /// addComplexAddress - Start with the address based on the location provided,
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000359 /// and generate the DWARF information necessary to find the actual variable
360 /// (navigating the extra location information encoded in the type) based on
361 /// the starting location. Add the DWARF information to the die.
362 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000363 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000364 const MachineLocation &Location);
365
Devang Patel2c4ceb12009-11-21 02:48:08 +0000366 // FIXME: Should be reformulated in terms of addComplexAddress.
367 /// addBlockByrefAddress - Start with the address based on the location
Caroline Ticedc8f6042009-08-31 21:19:37 +0000368 /// provided, and generate the DWARF information necessary to find the
369 /// actual Block variable (navigating the Block struct) based on the
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000370 /// starting location. Add the DWARF information to the die. Obsolete,
Devang Patel2c4ceb12009-11-21 02:48:08 +0000371 /// please use addComplexAddress instead.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000372 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000373 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
Caroline Ticedc8f6042009-08-31 21:19:37 +0000374 const MachineLocation &Location);
375
Devang Patel9e3bd2c2010-08-31 06:11:28 +0000376 /// addVariableAddress - Add DW_AT_location attribute for a DbgVariable based
377 /// on provided frame index.
378 void addVariableAddress(DbgVariable *&DV, DIE *Die, int64_t FI);
Devang Patel8bd11de2010-08-09 21:01:39 +0000379
Devang Patelc366f832009-12-10 19:14:49 +0000380 /// addToContextOwner - Add Die into the list of its context owner's children.
381 void addToContextOwner(DIE *Die, DIDescriptor Context);
382
Devang Patel2c4ceb12009-11-21 02:48:08 +0000383 /// addType - Add a new type attribute to the specified entity.
Devang Patel8a241142009-12-09 18:24:21 +0000384 void addType(DIE *Entity, DIType Ty);
Bill Wendling0310d762009-05-15 09:23:25 +0000385
Devang Patel6404e4e2009-12-15 19:16:48 +0000386
387 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
388 DIE *getOrCreateNameSpace(DINameSpace NS);
389
Devang Patel16ced732009-12-10 18:05:33 +0000390 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
391 /// given DIType.
392 DIE *getOrCreateTypeDIE(DIType Ty);
393
Devang Patel193f7202009-11-24 01:14:22 +0000394 void addPubTypes(DISubprogram SP);
395
Devang Patel2c4ceb12009-11-21 02:48:08 +0000396 /// constructTypeDIE - Construct basic type die from DIBasicType.
Devang Patel8a241142009-12-09 18:24:21 +0000397 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000398 DIBasicType BTy);
399
Devang Patel2c4ceb12009-11-21 02:48:08 +0000400 /// constructTypeDIE - Construct derived type die from DIDerivedType.
Devang Patel8a241142009-12-09 18:24:21 +0000401 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000402 DIDerivedType DTy);
403
Devang Patel2c4ceb12009-11-21 02:48:08 +0000404 /// constructTypeDIE - Construct type DIE from DICompositeType.
Devang Patel8a241142009-12-09 18:24:21 +0000405 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000406 DICompositeType CTy);
407
Devang Patel2c4ceb12009-11-21 02:48:08 +0000408 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
409 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
Bill Wendling0310d762009-05-15 09:23:25 +0000410
Devang Patel2c4ceb12009-11-21 02:48:08 +0000411 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
Devang Patel8a241142009-12-09 18:24:21 +0000412 void constructArrayTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000413 DICompositeType *CTy);
414
Devang Patel2c4ceb12009-11-21 02:48:08 +0000415 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
Devang Patel3c91b052010-03-08 20:52:55 +0000416 DIE *constructEnumTypeDIE(DIEnumerator ETy);
Devang Patel4063f6b2009-12-07 21:41:32 +0000417
Devang Patel2c4ceb12009-11-21 02:48:08 +0000418 /// createMemberDIE - Create new member DIE.
Devang Patelecbd8e82010-08-10 04:12:17 +0000419 DIE *createMemberDIE(DIDerivedType DT);
Bill Wendling0310d762009-05-15 09:23:25 +0000420
Devang Patel2c4ceb12009-11-21 02:48:08 +0000421 /// createSubprogramDIE - Create new DIE using SP.
Devang Patelee70fa72010-09-27 23:15:27 +0000422 DIE *createSubprogramDIE(DISubprogram SP);
Bill Wendling0310d762009-05-15 09:23:25 +0000423
Devang Pateleac9c072010-04-27 19:46:33 +0000424 /// getOrCreateDbgScope - Create DbgScope for the scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000425 DbgScope *getOrCreateDbgScope(const MDNode *Scope, const MDNode *InlinedAt);
Devang Patel70d75ca2009-11-12 19:02:56 +0000426
Devang Patele9f8f5e2010-05-07 20:54:48 +0000427 DbgScope *getOrCreateAbstractScope(const MDNode *N);
Devang Patel53bb5c92009-11-10 23:06:00 +0000428
429 /// findAbstractVariable - Find abstract variable associated with Var.
Devang Patel26c1e562010-05-20 16:36:41 +0000430 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
Devang Patel53bb5c92009-11-10 23:06:00 +0000431
Devang Patel2c4ceb12009-11-21 02:48:08 +0000432 /// updateSubprogramScopeDIE - Find DIE for the given subprogram and
433 /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes.
434 /// If there are global variables in this scope then create and insert
435 /// DIEs for these variables.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000436 DIE *updateSubprogramScopeDIE(const MDNode *SPNode);
Bill Wendling0310d762009-05-15 09:23:25 +0000437
Devang Patel2c4ceb12009-11-21 02:48:08 +0000438 /// constructLexicalScope - Construct new DW_TAG_lexical_block
439 /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
440 DIE *constructLexicalScopeDIE(DbgScope *Scope);
Bill Wendling0310d762009-05-15 09:23:25 +0000441
Devang Patel2c4ceb12009-11-21 02:48:08 +0000442 /// constructInlinedScopeDIE - This scope represents inlined body of
443 /// a function. Construct DIE to represent this concrete inlined copy
444 /// of the function.
445 DIE *constructInlinedScopeDIE(DbgScope *Scope);
446
447 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
Devang Patel8a241142009-12-09 18:24:21 +0000448 DIE *constructVariableDIE(DbgVariable *DV, DbgScope *S);
Devang Patel2c4ceb12009-11-21 02:48:08 +0000449
450 /// constructScopeDIE - Construct a DIE for this scope.
451 DIE *constructScopeDIE(DbgScope *Scope);
452
Chris Lattnerfa070b02010-04-04 22:33:59 +0000453 /// EmitSectionLabels - Emit initial Dwarf sections with a label at
454 /// the start of each one.
455 void EmitSectionLabels();
Bill Wendling0310d762009-05-15 09:23:25 +0000456
Devang Patel2c4ceb12009-11-21 02:48:08 +0000457 /// emitDIE - Recusively Emits a debug information entry.
Bill Wendling0310d762009-05-15 09:23:25 +0000458 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000459 void emitDIE(DIE *Die);
Bill Wendling0310d762009-05-15 09:23:25 +0000460
Devang Patel2c4ceb12009-11-21 02:48:08 +0000461 /// computeSizeAndOffset - Compute the size and offset of a DIE.
Bill Wendling0310d762009-05-15 09:23:25 +0000462 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000463 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last);
Bill Wendling0310d762009-05-15 09:23:25 +0000464
Devang Patel2c4ceb12009-11-21 02:48:08 +0000465 /// computeSizeAndOffsets - Compute the size and offset of all the DIEs.
Bill Wendling0310d762009-05-15 09:23:25 +0000466 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000467 void computeSizeAndOffsets();
Bill Wendling0310d762009-05-15 09:23:25 +0000468
Devang Patel8a241142009-12-09 18:24:21 +0000469 /// EmitDebugInfo - Emit the debug info section.
Bill Wendling0310d762009-05-15 09:23:25 +0000470 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000471 void emitDebugInfo();
Bill Wendling0310d762009-05-15 09:23:25 +0000472
Devang Patel2c4ceb12009-11-21 02:48:08 +0000473 /// emitAbbreviations - Emit the abbreviation section.
Bill Wendling0310d762009-05-15 09:23:25 +0000474 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000475 void emitAbbreviations() const;
Bill Wendling0310d762009-05-15 09:23:25 +0000476
Devang Patel2c4ceb12009-11-21 02:48:08 +0000477 /// emitEndOfLineMatrix - Emit the last address of the section and the end of
Bill Wendling0310d762009-05-15 09:23:25 +0000478 /// the line matrix.
479 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000480 void emitEndOfLineMatrix(unsigned SectionEnd);
Bill Wendling0310d762009-05-15 09:23:25 +0000481
Devang Patel2c4ceb12009-11-21 02:48:08 +0000482 /// emitDebugLines - Emit source line information.
Bill Wendling0310d762009-05-15 09:23:25 +0000483 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000484 void emitDebugLines();
Bill Wendling0310d762009-05-15 09:23:25 +0000485
Devang Patel2c4ceb12009-11-21 02:48:08 +0000486 /// emitCommonDebugFrame - Emit common frame info into a debug frame section.
Bill Wendling0310d762009-05-15 09:23:25 +0000487 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000488 void emitCommonDebugFrame();
Bill Wendling0310d762009-05-15 09:23:25 +0000489
Devang Patel2c4ceb12009-11-21 02:48:08 +0000490 /// emitFunctionDebugFrame - Emit per function frame info into a debug frame
Bill Wendling0310d762009-05-15 09:23:25 +0000491 /// section.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000492 void emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo);
Bill Wendling0310d762009-05-15 09:23:25 +0000493
Devang Patel2c4ceb12009-11-21 02:48:08 +0000494 /// emitDebugPubNames - Emit visible names into a debug pubnames section.
Bill Wendling0310d762009-05-15 09:23:25 +0000495 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000496 void emitDebugPubNames();
Bill Wendling0310d762009-05-15 09:23:25 +0000497
Devang Patel193f7202009-11-24 01:14:22 +0000498 /// emitDebugPubTypes - Emit visible types into a debug pubtypes section.
499 ///
500 void emitDebugPubTypes();
501
Devang Patel2c4ceb12009-11-21 02:48:08 +0000502 /// emitDebugStr - Emit visible names into a debug str section.
Bill Wendling0310d762009-05-15 09:23:25 +0000503 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000504 void emitDebugStr();
Bill Wendling0310d762009-05-15 09:23:25 +0000505
Devang Patel2c4ceb12009-11-21 02:48:08 +0000506 /// emitDebugLoc - Emit visible names into a debug loc section.
Bill Wendling0310d762009-05-15 09:23:25 +0000507 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000508 void emitDebugLoc();
Bill Wendling0310d762009-05-15 09:23:25 +0000509
510 /// EmitDebugARanges - Emit visible names into a debug aranges section.
511 ///
512 void EmitDebugARanges();
513
Devang Patel2c4ceb12009-11-21 02:48:08 +0000514 /// emitDebugRanges - Emit visible names into a debug ranges section.
Bill Wendling0310d762009-05-15 09:23:25 +0000515 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000516 void emitDebugRanges();
Bill Wendling0310d762009-05-15 09:23:25 +0000517
Devang Patel2c4ceb12009-11-21 02:48:08 +0000518 /// emitDebugMacInfo - Emit visible names into a debug macinfo section.
Bill Wendling0310d762009-05-15 09:23:25 +0000519 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000520 void emitDebugMacInfo();
Bill Wendling0310d762009-05-15 09:23:25 +0000521
Devang Patel2c4ceb12009-11-21 02:48:08 +0000522 /// emitDebugInlineInfo - Emit inline info using following format.
Bill Wendling0310d762009-05-15 09:23:25 +0000523 /// Section Header:
524 /// 1. length of section
525 /// 2. Dwarf version number
526 /// 3. address size.
527 ///
528 /// Entries (one "entry" for each function that was inlined):
529 ///
530 /// 1. offset into __debug_str section for MIPS linkage name, if exists;
531 /// otherwise offset into __debug_str for regular function name.
532 /// 2. offset into __debug_str section for regular function name.
533 /// 3. an unsigned LEB128 number indicating the number of distinct inlining
534 /// instances for the function.
535 ///
536 /// The rest of the entry consists of a {die_offset, low_pc} pair for each
537 /// inlined instance; the die_offset points to the inlined_subroutine die in
538 /// the __debug_info section, and the low_pc is the starting address for the
539 /// inlining instance.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000540 void emitDebugInlineInfo();
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000541
542 /// GetOrCreateSourceID - Look up the source id with the given directory and
543 /// source file names. If none currently exists, create a new id and insert it
Chris Lattner75f50722010-04-04 07:48:20 +0000544 /// in the SourceIds map. This can update DirectoryNames and SourceFileNames
545 /// maps as well.
Devang Patel65dbc902009-11-25 17:36:49 +0000546 unsigned GetOrCreateSourceID(StringRef DirName, StringRef FileName);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000547
Devang Patel163a9f72010-05-10 22:49:55 +0000548 /// constructCompileUnit - Create new CompileUnit for the given
549 /// metadata node with tag DW_TAG_compile_unit.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000550 void constructCompileUnit(const MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000551
Devang Patel163a9f72010-05-10 22:49:55 +0000552 /// getCompielUnit - Get CompileUnit DIE.
553 CompileUnit *getCompileUnit(const MDNode *N) const;
554
555 /// constructGlobalVariableDIE - Construct global variable DIE.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000556 void constructGlobalVariableDIE(const MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000557
Devang Patel163a9f72010-05-10 22:49:55 +0000558 /// construct SubprogramDIE - Construct subprogram DIE.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000559 void constructSubprogramDIE(const MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000560
Chris Lattner2b1b3312010-04-05 05:32:45 +0000561 /// recordSourceLine - Register a source line with debug info. Returns the
562 /// unique label that was emitted and which provides correspondence to
563 /// the source line list.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000564 MCSymbol *recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope);
Chris Lattner2b1b3312010-04-05 05:32:45 +0000565
566 /// getSourceLineCount - Return the number of source lines in the debug
567 /// info.
568 unsigned getSourceLineCount() const {
569 return Lines.size();
570 }
571
Devang Patel26c1e562010-05-20 16:36:41 +0000572 /// recordVariableFrameIndex - Record a variable's index.
573 void recordVariableFrameIndex(const DbgVariable *V, int Index);
574
575 /// findVariableFrameIndex - Return true if frame index for the variable
576 /// is found. Update FI to hold value of the index.
577 bool findVariableFrameIndex(const DbgVariable *V, int *FI);
578
Devang Patelee432862010-05-20 19:57:06 +0000579 /// findDbgScope - Find DbgScope for the debug loc attached with an
580 /// instruction.
581 DbgScope *findDbgScope(const MachineInstr *MI);
582
Devang Patele37b0c62010-04-08 18:43:56 +0000583 /// identifyScopeMarkers() - Indentify instructions that are marking
584 /// beginning of or end of a scope.
585 void identifyScopeMarkers();
Devang Patel6122a4d2010-04-08 15:37:09 +0000586
Chris Lattner2b1b3312010-04-05 05:32:45 +0000587 /// extractScopeInformation - Scan machine instructions in this function
588 /// and collect DbgScopes. Return true, if atleast one scope was found.
589 bool extractScopeInformation();
590
591 /// collectVariableInfo - Populate DbgScope entries with variables' info.
Devang Patel78e127d2010-06-25 22:07:34 +0000592 void collectVariableInfo(const MachineFunction *,
593 SmallPtrSet<const MDNode *, 16> &ProcessedVars);
Chris Lattner2b1b3312010-04-05 05:32:45 +0000594
Devang Patelee432862010-05-20 19:57:06 +0000595 /// collectVariableInfoFromMMITable - Collect variable information from
596 /// side table maintained by MMI.
597 void collectVariableInfoFromMMITable(const MachineFunction * MF,
598 SmallPtrSet<const MDNode *, 16> &P);
Bill Wendling0310d762009-05-15 09:23:25 +0000599public:
600 //===--------------------------------------------------------------------===//
601 // Main entry points.
602 //
Chris Lattner49cd6642010-04-05 05:11:15 +0000603 DwarfDebug(AsmPrinter *A, Module *M);
Chris Lattner2b1b3312010-04-05 05:32:45 +0000604 ~DwarfDebug();
Bill Wendling0310d762009-05-15 09:23:25 +0000605
Devang Patel2c4ceb12009-11-21 02:48:08 +0000606 /// beginModule - Emit all Dwarf sections that should come prior to the
Bill Wendling0310d762009-05-15 09:23:25 +0000607 /// content.
Chris Lattner75f50722010-04-04 07:48:20 +0000608 void beginModule(Module *M);
Bill Wendling0310d762009-05-15 09:23:25 +0000609
Devang Patel2c4ceb12009-11-21 02:48:08 +0000610 /// endModule - Emit all Dwarf sections that should come after the content.
Bill Wendling0310d762009-05-15 09:23:25 +0000611 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000612 void endModule();
Bill Wendling0310d762009-05-15 09:23:25 +0000613
Devang Patel2c4ceb12009-11-21 02:48:08 +0000614 /// beginFunction - Gather pre-function debug information. Assumes being
Bill Wendling0310d762009-05-15 09:23:25 +0000615 /// emitted immediately after the function entry point.
Chris Lattnereec791a2010-01-26 23:18:02 +0000616 void beginFunction(const MachineFunction *MF);
Bill Wendling0310d762009-05-15 09:23:25 +0000617
Devang Patel2c4ceb12009-11-21 02:48:08 +0000618 /// endFunction - Gather and emit post-function debug information.
Bill Wendling0310d762009-05-15 09:23:25 +0000619 ///
Chris Lattnereec791a2010-01-26 23:18:02 +0000620 void endFunction(const MachineFunction *MF);
Bill Wendling0310d762009-05-15 09:23:25 +0000621
Devang Patelc3f5f782010-05-25 23:40:22 +0000622 /// getLabelBeforeInsn - Return Label preceding the instruction.
623 const MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
624
625 /// getLabelAfterInsn - Return Label immediately following the instruction.
626 const MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
627
Devang Patelcbbe2872010-10-26 17:49:02 +0000628 /// beginInstruction - Process beginning of an instruction.
629 void beginInstruction(const MachineInstr *MI);
Bill Wendling0310d762009-05-15 09:23:25 +0000630
Devang Patelcbbe2872010-10-26 17:49:02 +0000631 /// endInstruction - Prcess end of an instruction.
632 void endInstruction(const MachineInstr *MI);
Devang Patel53bb5c92009-11-10 23:06:00 +0000633};
Bill Wendling0310d762009-05-15 09:23:25 +0000634} // End of namespace llvm
635
636#endif