blob: 23704ebc258ea5d48f014b27261770b9c6b4e945 [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
17#include "DIE.h"
18#include "DwarfPrinter.h"
19#include "llvm/CodeGen/AsmPrinter.h"
20#include "llvm/CodeGen/MachineLocation.h"
21#include "llvm/Analysis/DebugInfo.h"
22#include "llvm/Support/raw_ostream.h"
Devang Patel622b0262010-01-19 06:19:05 +000023#include "llvm/ADT/DenseMap.h"
Bill Wendling0310d762009-05-15 09:23:25 +000024#include "llvm/ADT/FoldingSet.h"
Bill Wendling6679ee42009-05-18 22:02:36 +000025#include "llvm/ADT/SmallSet.h"
Bill Wendling0310d762009-05-15 09:23:25 +000026#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/UniqueVector.h"
28#include <string>
29
30namespace llvm {
31
32class CompileUnit;
Bill Wendling0310d762009-05-15 09:23:25 +000033class DbgConcreteScope;
Nick Lewycky381afae2009-11-17 09:17:08 +000034class DbgScope;
35class DbgVariable;
Bill Wendling0310d762009-05-15 09:23:25 +000036class MachineFrameInfo;
37class MachineModuleInfo;
Chris Lattneraf76e592009-08-22 20:48:53 +000038class MCAsmInfo;
Bill Wendling0310d762009-05-15 09:23:25 +000039class Timer;
40
41//===----------------------------------------------------------------------===//
42/// SrcLineInfo - This class is used to record source line correspondence.
43///
Nick Lewycky381afae2009-11-17 09:17:08 +000044class SrcLineInfo {
Bill Wendling0310d762009-05-15 09:23:25 +000045 unsigned Line; // Source line number.
46 unsigned Column; // Source column.
47 unsigned SourceID; // Source ID number.
48 unsigned LabelID; // Label in code ID number.
49public:
50 SrcLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
51 : Line(L), Column(C), SourceID(S), LabelID(I) {}
52
53 // Accessors
54 unsigned getLine() const { return Line; }
55 unsigned getColumn() const { return Column; }
56 unsigned getSourceID() const { return SourceID; }
57 unsigned getLabelID() const { return LabelID; }
58};
59
Chris Lattner066c9ac2010-01-22 22:23:57 +000060class DwarfDebug : public DwarfPrinter {
Bill Wendling0310d762009-05-15 09:23:25 +000061 //===--------------------------------------------------------------------===//
62 // Attributes used to construct specific Dwarf sections.
63 //
64
Devang Patel1dbc7712009-06-29 20:45:18 +000065 /// ModuleCU - All DIEs are inserted in ModuleCU.
66 CompileUnit *ModuleCU;
Bill Wendling0310d762009-05-15 09:23:25 +000067
68 /// AbbreviationsSet - Used to uniquely define abbreviations.
69 ///
70 FoldingSet<DIEAbbrev> AbbreviationsSet;
71
72 /// Abbreviations - A list of all the unique abbreviations in use.
73 ///
74 std::vector<DIEAbbrev *> Abbreviations;
75
76 /// DirectoryIdMap - Directory name to directory id map.
77 ///
78 StringMap<unsigned> DirectoryIdMap;
79
80 /// DirectoryNames - A list of directory names.
81 SmallVector<std::string, 8> DirectoryNames;
82
83 /// SourceFileIdMap - Source file name to source file id map.
84 ///
85 StringMap<unsigned> SourceFileIdMap;
86
87 /// SourceFileNames - A list of source file names.
88 SmallVector<std::string, 8> SourceFileNames;
89
90 /// SourceIdMap - Source id map, i.e. pair of directory id and source file
91 /// id mapped to a unique id.
92 DenseMap<std::pair<unsigned, unsigned>, unsigned> SourceIdMap;
93
94 /// SourceIds - Reverse map from source id to directory id + file id pair.
95 ///
96 SmallVector<std::pair<unsigned, unsigned>, 8> SourceIds;
97
Dan Gohmanf451cb82010-02-10 16:03:48 +000098 /// Lines - List of source line correspondence.
Bill Wendling0310d762009-05-15 09:23:25 +000099 std::vector<SrcLineInfo> Lines;
100
Devang Patel2c4ceb12009-11-21 02:48:08 +0000101 /// DIEValues - A list of all the unique values in use.
Bill Wendling0310d762009-05-15 09:23:25 +0000102 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000103 std::vector<DIEValue *> DIEValues;
Bill Wendling0310d762009-05-15 09:23:25 +0000104
105 /// StringPool - A UniqueVector of strings used by indirect references.
106 ///
107 UniqueVector<std::string> StringPool;
108
109 /// SectionMap - Provides a unique id per text section.
110 ///
Chris Lattnera87dea42009-07-31 18:48:30 +0000111 UniqueVector<const MCSection*> SectionMap;
Bill Wendling0310d762009-05-15 09:23:25 +0000112
113 /// SectionSourceLines - Tracks line numbers per text section.
114 ///
115 std::vector<std::vector<SrcLineInfo> > SectionSourceLines;
116
117 /// didInitial - Flag to indicate if initial emission has been done.
118 ///
119 bool didInitial;
120
121 /// shouldEmit - Flag to indicate if debug information should be emitted.
122 ///
123 bool shouldEmit;
124
Devang Patel53bb5c92009-11-10 23:06:00 +0000125 // CurrentFnDbgScope - Top level scope for the current function.
Bill Wendling0310d762009-05-15 09:23:25 +0000126 //
Devang Patel53bb5c92009-11-10 23:06:00 +0000127 DbgScope *CurrentFnDbgScope;
Bill Wendling0310d762009-05-15 09:23:25 +0000128
Douglas Gregor1ddcf352010-03-08 02:58:37 +0000129 /// DbgScopeMap - Tracks the scopes in the current function.
Devang Patel53bb5c92009-11-10 23:06:00 +0000130 ///
Devang Patel622b0262010-01-19 06:19:05 +0000131 DenseMap<MDNode *, DbgScope *> DbgScopeMap;
Bill Wendling0310d762009-05-15 09:23:25 +0000132
Devang Patel53bb5c92009-11-10 23:06:00 +0000133 /// ConcreteScopes - Tracks the concrete scopees in the current function.
134 /// These scopes are also included in DbgScopeMap.
Devang Patel622b0262010-01-19 06:19:05 +0000135 DenseMap<MDNode *, DbgScope *> ConcreteScopes;
Devang Patel53bb5c92009-11-10 23:06:00 +0000136
137 /// AbstractScopes - Tracks the abstract scopes a module. These scopes are
Douglas Gregor1ddcf352010-03-08 02:58:37 +0000138 /// not included DbgScopeMap.
Devang Patel622b0262010-01-19 06:19:05 +0000139 DenseMap<MDNode *, DbgScope *> AbstractScopes;
Devang Patel53bb5c92009-11-10 23:06:00 +0000140 SmallVector<DbgScope *, 4>AbstractScopesList;
141
142 /// AbstractVariables - Collection on abstract variables.
Devang Patel622b0262010-01-19 06:19:05 +0000143 DenseMap<MDNode *, DbgVariable *> AbstractVariables;
Devang Patel53bb5c92009-11-10 23:06:00 +0000144
145 /// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked
146 /// (at the end of the module) as DW_AT_inline.
147 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
148
Devang Patel622b0262010-01-19 06:19:05 +0000149 DenseMap<DIE *, MDNode *> ContainingTypeMap;
Devang Patel5d11eb02009-12-03 19:11:07 +0000150
Devang Patel53bb5c92009-11-10 23:06:00 +0000151 /// AbstractSubprogramDIEs - Collection of abstruct subprogram DIEs.
152 SmallPtrSet<DIE *, 4> AbstractSubprogramDIEs;
153
Devang Patel1d5cc1d2009-12-03 01:25:38 +0000154 /// TopLevelDIEs - Collection of top level DIEs.
155 SmallPtrSet<DIE *, 4> TopLevelDIEs;
156 SmallVector<DIE *, 4> TopLevelDIEsVector;
157
Devang Patel53bb5c92009-11-10 23:06:00 +0000158 typedef SmallVector<DbgScope *, 2> ScopeVector;
159 typedef DenseMap<const MachineInstr *, ScopeVector>
Devang Patelaf9e8472009-10-01 20:31:14 +0000160 InsnToDbgScopeMapTy;
161
Devang Patel53bb5c92009-11-10 23:06:00 +0000162 /// DbgScopeBeginMap - Maps instruction with a list of DbgScopes it starts.
Devang Patelaf9e8472009-10-01 20:31:14 +0000163 InsnToDbgScopeMapTy DbgScopeBeginMap;
164
165 /// DbgScopeEndMap - Maps instruction with a list DbgScopes it ends.
166 InsnToDbgScopeMapTy DbgScopeEndMap;
167
Bill Wendling0310d762009-05-15 09:23:25 +0000168 /// InlineInfo - Keep track of inlined functions and their location. This
169 /// information is used to populate debug_inlined section.
Devang Patel53bb5c92009-11-10 23:06:00 +0000170 typedef std::pair<unsigned, DIE *> InlineInfoLabels;
Devang Patel622b0262010-01-19 06:19:05 +0000171 DenseMap<MDNode *, SmallVector<InlineInfoLabels, 4> > InlineInfo;
Devang Patel53bb5c92009-11-10 23:06:00 +0000172 SmallVector<MDNode *, 4> InlinedSPNodes;
Bill Wendling0310d762009-05-15 09:23:25 +0000173
174 /// CompileUnitOffsets - A vector of the offsets of the compile units. This is
175 /// used when calculating the "origin" of a concrete instance of an inlined
176 /// function.
177 DenseMap<CompileUnit *, unsigned> CompileUnitOffsets;
178
179 /// DebugTimer - Timer for the Dwarf debug writer.
180 Timer *DebugTimer;
Devang Patel43da8fb2009-07-13 21:26:33 +0000181
Bill Wendling0310d762009-05-15 09:23:25 +0000182 struct FunctionDebugFrameInfo {
183 unsigned Number;
184 std::vector<MachineMove> Moves;
185
186 FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M)
187 : Number(Num), Moves(M) {}
188 };
189
190 std::vector<FunctionDebugFrameInfo> DebugFrames;
191
192 /// getSourceDirectoryAndFileIds - Return the directory and file ids that
193 /// maps to the source id. Source id starts at 1.
194 std::pair<unsigned, unsigned>
195 getSourceDirectoryAndFileIds(unsigned SId) const {
196 return SourceIds[SId-1];
197 }
198
199 /// getNumSourceDirectories - Return the number of source directories in the
200 /// debug info.
201 unsigned getNumSourceDirectories() const {
202 return DirectoryNames.size();
203 }
204
205 /// getSourceDirectoryName - Return the name of the directory corresponding
206 /// to the id.
207 const std::string &getSourceDirectoryName(unsigned Id) const {
208 return DirectoryNames[Id - 1];
209 }
210
211 /// getSourceFileName - Return the name of the source file corresponding
212 /// to the id.
213 const std::string &getSourceFileName(unsigned Id) const {
214 return SourceFileNames[Id - 1];
215 }
216
217 /// getNumSourceIds - Return the number of unique source ids.
218 unsigned getNumSourceIds() const {
219 return SourceIds.size();
220 }
221
Devang Patel2c4ceb12009-11-21 02:48:08 +0000222 /// assignAbbrevNumber - Define a unique number for the abbreviation.
Bill Wendling0310d762009-05-15 09:23:25 +0000223 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000224 void assignAbbrevNumber(DIEAbbrev &Abbrev);
Bill Wendling0310d762009-05-15 09:23:25 +0000225
Devang Patel2c4ceb12009-11-21 02:48:08 +0000226 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
Bill Wendling995f80a2009-05-20 23:24:48 +0000227 /// information entry.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000228 DIEEntry *createDIEEntry(DIE *Entry = NULL);
Bill Wendling0310d762009-05-15 09:23:25 +0000229
Devang Patel2c4ceb12009-11-21 02:48:08 +0000230 /// addUInt - Add an unsigned integer attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000231 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000232 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
Bill Wendling0310d762009-05-15 09:23:25 +0000233
Devang Patel2c4ceb12009-11-21 02:48:08 +0000234 /// addSInt - Add an signed integer attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000235 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000236 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
Bill Wendling0310d762009-05-15 09:23:25 +0000237
Devang Patel2c4ceb12009-11-21 02:48:08 +0000238 /// addString - Add a string attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000239 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000240 void addString(DIE *Die, unsigned Attribute, unsigned Form,
Devang Patele9a05972009-11-24 19:42:17 +0000241 const StringRef Str);
Bill Wendling0310d762009-05-15 09:23:25 +0000242
Devang Patel2c4ceb12009-11-21 02:48:08 +0000243 /// addLabel - Add a Dwarf label attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000244 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000245 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000246 const MCSymbol *Label);
Bill Wendling0310d762009-05-15 09:23:25 +0000247
Devang Patel2c4ceb12009-11-21 02:48:08 +0000248 /// addObjectLabel - Add an non-Dwarf label attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000249 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000250 void addObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattner858431d2010-01-16 18:50:28 +0000251 const MCSymbol *Sym);
Bill Wendling0310d762009-05-15 09:23:25 +0000252
Devang Patel2c4ceb12009-11-21 02:48:08 +0000253 /// addSectionOffset - Add a section offset label attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000254 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000255 void addSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000256 const MCSymbol *Label, const MCSymbol *Section,
Bill Wendling0310d762009-05-15 09:23:25 +0000257 bool isEH = false, bool useSet = true);
258
Devang Patel2c4ceb12009-11-21 02:48:08 +0000259 /// addDelta - Add a label delta attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000260 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000261 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000262 const MCSymbol *Hi, const MCSymbol *Lo);
Bill Wendling0310d762009-05-15 09:23:25 +0000263
Devang Patel2c4ceb12009-11-21 02:48:08 +0000264 /// addDIEEntry - Add a DIE attribute data and value.
Bill Wendling0310d762009-05-15 09:23:25 +0000265 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000266 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) {
267 Die->addValue(Attribute, Form, createDIEEntry(Entry));
Bill Wendling0310d762009-05-15 09:23:25 +0000268 }
269
Devang Patel2c4ceb12009-11-21 02:48:08 +0000270 /// addBlock - Add block data.
Bill Wendling0310d762009-05-15 09:23:25 +0000271 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000272 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
Bill Wendling0310d762009-05-15 09:23:25 +0000273
Devang Patel2c4ceb12009-11-21 02:48:08 +0000274 /// addSourceLine - Add location information to specified debug information
Bill Wendling0310d762009-05-15 09:23:25 +0000275 /// entry.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000276 void addSourceLine(DIE *Die, const DIVariable *V);
277 void addSourceLine(DIE *Die, const DIGlobal *G);
278 void addSourceLine(DIE *Die, const DISubprogram *SP);
279 void addSourceLine(DIE *Die, const DIType *Ty);
Devang Patel6404e4e2009-12-15 19:16:48 +0000280 void addSourceLine(DIE *Die, const DINameSpace *NS);
Bill Wendling0310d762009-05-15 09:23:25 +0000281
Devang Patel2c4ceb12009-11-21 02:48:08 +0000282 /// addAddress - Add an address attribute to a die based on the location
Bill Wendling0310d762009-05-15 09:23:25 +0000283 /// provided.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000284 void addAddress(DIE *Die, unsigned Attribute,
Bill Wendling0310d762009-05-15 09:23:25 +0000285 const MachineLocation &Location);
286
Devang Patel2c4ceb12009-11-21 02:48:08 +0000287 /// addComplexAddress - Start with the address based on the location provided,
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000288 /// and generate the DWARF information necessary to find the actual variable
289 /// (navigating the extra location information encoded in the type) based on
290 /// the starting location. Add the DWARF information to the die.
291 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000292 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000293 const MachineLocation &Location);
294
Devang Patel2c4ceb12009-11-21 02:48:08 +0000295 // FIXME: Should be reformulated in terms of addComplexAddress.
296 /// addBlockByrefAddress - Start with the address based on the location
Caroline Ticedc8f6042009-08-31 21:19:37 +0000297 /// provided, and generate the DWARF information necessary to find the
298 /// actual Block variable (navigating the Block struct) based on the
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000299 /// starting location. Add the DWARF information to the die. Obsolete,
Devang Patel2c4ceb12009-11-21 02:48:08 +0000300 /// please use addComplexAddress instead.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000301 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000302 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
Caroline Ticedc8f6042009-08-31 21:19:37 +0000303 const MachineLocation &Location);
304
Devang Patelc366f832009-12-10 19:14:49 +0000305 /// addToContextOwner - Add Die into the list of its context owner's children.
306 void addToContextOwner(DIE *Die, DIDescriptor Context);
307
Devang Patel2c4ceb12009-11-21 02:48:08 +0000308 /// addType - Add a new type attribute to the specified entity.
Devang Patel8a241142009-12-09 18:24:21 +0000309 void addType(DIE *Entity, DIType Ty);
Bill Wendling0310d762009-05-15 09:23:25 +0000310
Devang Patel6404e4e2009-12-15 19:16:48 +0000311
312 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
313 DIE *getOrCreateNameSpace(DINameSpace NS);
314
Devang Patel16ced732009-12-10 18:05:33 +0000315 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
316 /// given DIType.
317 DIE *getOrCreateTypeDIE(DIType Ty);
318
Devang Patel193f7202009-11-24 01:14:22 +0000319 void addPubTypes(DISubprogram SP);
320
Devang Patel2c4ceb12009-11-21 02:48:08 +0000321 /// constructTypeDIE - Construct basic type die from DIBasicType.
Devang Patel8a241142009-12-09 18:24:21 +0000322 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000323 DIBasicType BTy);
324
Devang Patel2c4ceb12009-11-21 02:48:08 +0000325 /// constructTypeDIE - Construct derived type die from DIDerivedType.
Devang Patel8a241142009-12-09 18:24:21 +0000326 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000327 DIDerivedType DTy);
328
Devang Patel2c4ceb12009-11-21 02:48:08 +0000329 /// constructTypeDIE - Construct type DIE from DICompositeType.
Devang Patel8a241142009-12-09 18:24:21 +0000330 void constructTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000331 DICompositeType CTy);
332
Devang Patel2c4ceb12009-11-21 02:48:08 +0000333 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
334 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
Bill Wendling0310d762009-05-15 09:23:25 +0000335
Devang Patel2c4ceb12009-11-21 02:48:08 +0000336 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
Devang Patel8a241142009-12-09 18:24:21 +0000337 void constructArrayTypeDIE(DIE &Buffer,
Bill Wendling0310d762009-05-15 09:23:25 +0000338 DICompositeType *CTy);
339
Devang Patel2c4ceb12009-11-21 02:48:08 +0000340 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
Devang Patel3c91b052010-03-08 20:52:55 +0000341 DIE *constructEnumTypeDIE(DIEnumerator ETy);
Devang Patel4063f6b2009-12-07 21:41:32 +0000342
Devang Patel2c4ceb12009-11-21 02:48:08 +0000343 /// createGlobalVariableDIE - Create new DIE using GV.
Devang Patel8a241142009-12-09 18:24:21 +0000344 DIE *createGlobalVariableDIE(const DIGlobalVariable &GV);
Bill Wendling0310d762009-05-15 09:23:25 +0000345
Devang Patel2c4ceb12009-11-21 02:48:08 +0000346 /// createMemberDIE - Create new member DIE.
Devang Patel8a241142009-12-09 18:24:21 +0000347 DIE *createMemberDIE(const DIDerivedType &DT);
Bill Wendling0310d762009-05-15 09:23:25 +0000348
Devang Patel2c4ceb12009-11-21 02:48:08 +0000349 /// createSubprogramDIE - Create new DIE using SP.
Devang Patelffe966c2009-12-14 16:18:45 +0000350 DIE *createSubprogramDIE(const DISubprogram &SP, bool MakeDecl = false);
Bill Wendling0310d762009-05-15 09:23:25 +0000351
Devang Patel53bb5c92009-11-10 23:06:00 +0000352 /// getUpdatedDbgScope - Find or create DbgScope assicated with
353 /// the instruction. Initialize scope and update scope hierarchy.
354 DbgScope *getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, MDNode *InlinedAt);
355
356 /// createDbgScope - Create DbgScope for the scope.
357 void createDbgScope(MDNode *Scope, MDNode *InlinedAt);
Devang Patel70d75ca2009-11-12 19:02:56 +0000358
Devang Patel53bb5c92009-11-10 23:06:00 +0000359 DbgScope *getOrCreateAbstractScope(MDNode *N);
360
361 /// findAbstractVariable - Find abstract variable associated with Var.
362 DbgVariable *findAbstractVariable(DIVariable &Var, unsigned FrameIdx,
363 DILocation &Loc);
364
Devang Patel2c4ceb12009-11-21 02:48:08 +0000365 /// updateSubprogramScopeDIE - Find DIE for the given subprogram and
366 /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes.
367 /// If there are global variables in this scope then create and insert
368 /// DIEs for these variables.
369 DIE *updateSubprogramScopeDIE(MDNode *SPNode);
Bill Wendling0310d762009-05-15 09:23:25 +0000370
Devang Patel2c4ceb12009-11-21 02:48:08 +0000371 /// constructLexicalScope - Construct new DW_TAG_lexical_block
372 /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
373 DIE *constructLexicalScopeDIE(DbgScope *Scope);
Bill Wendling0310d762009-05-15 09:23:25 +0000374
Devang Patel2c4ceb12009-11-21 02:48:08 +0000375 /// constructInlinedScopeDIE - This scope represents inlined body of
376 /// a function. Construct DIE to represent this concrete inlined copy
377 /// of the function.
378 DIE *constructInlinedScopeDIE(DbgScope *Scope);
379
380 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
Devang Patel8a241142009-12-09 18:24:21 +0000381 DIE *constructVariableDIE(DbgVariable *DV, DbgScope *S);
Devang Patel2c4ceb12009-11-21 02:48:08 +0000382
383 /// constructScopeDIE - Construct a DIE for this scope.
384 DIE *constructScopeDIE(DbgScope *Scope);
385
386 /// emitInitial - Emit initial Dwarf declarations. This is necessary for cc
Bill Wendling0310d762009-05-15 09:23:25 +0000387 /// tools to recognize the object file contains Dwarf information.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000388 void emitInitial();
Bill Wendling0310d762009-05-15 09:23:25 +0000389
Devang Patel2c4ceb12009-11-21 02:48:08 +0000390 /// emitDIE - Recusively Emits a debug information entry.
Bill Wendling0310d762009-05-15 09:23:25 +0000391 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000392 void emitDIE(DIE *Die);
Bill Wendling0310d762009-05-15 09:23:25 +0000393
Devang Patel2c4ceb12009-11-21 02:48:08 +0000394 /// computeSizeAndOffset - Compute the size and offset of a DIE.
Bill Wendling0310d762009-05-15 09:23:25 +0000395 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000396 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last);
Bill Wendling0310d762009-05-15 09:23:25 +0000397
Devang Patel2c4ceb12009-11-21 02:48:08 +0000398 /// computeSizeAndOffsets - Compute the size and offset of all the DIEs.
Bill Wendling0310d762009-05-15 09:23:25 +0000399 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000400 void computeSizeAndOffsets();
Bill Wendling0310d762009-05-15 09:23:25 +0000401
Devang Patel8a241142009-12-09 18:24:21 +0000402 /// EmitDebugInfo - Emit the debug info section.
Bill Wendling0310d762009-05-15 09:23:25 +0000403 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000404 void emitDebugInfo();
Bill Wendling0310d762009-05-15 09:23:25 +0000405
Devang Patel2c4ceb12009-11-21 02:48:08 +0000406 /// emitAbbreviations - Emit the abbreviation section.
Bill Wendling0310d762009-05-15 09:23:25 +0000407 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000408 void emitAbbreviations() const;
Bill Wendling0310d762009-05-15 09:23:25 +0000409
Devang Patel2c4ceb12009-11-21 02:48:08 +0000410 /// emitEndOfLineMatrix - Emit the last address of the section and the end of
Bill Wendling0310d762009-05-15 09:23:25 +0000411 /// the line matrix.
412 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000413 void emitEndOfLineMatrix(unsigned SectionEnd);
Bill Wendling0310d762009-05-15 09:23:25 +0000414
Devang Patel2c4ceb12009-11-21 02:48:08 +0000415 /// emitDebugLines - Emit source line information.
Bill Wendling0310d762009-05-15 09:23:25 +0000416 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000417 void emitDebugLines();
Bill Wendling0310d762009-05-15 09:23:25 +0000418
Devang Patel2c4ceb12009-11-21 02:48:08 +0000419 /// emitCommonDebugFrame - Emit common frame info into a debug frame section.
Bill Wendling0310d762009-05-15 09:23:25 +0000420 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000421 void emitCommonDebugFrame();
Bill Wendling0310d762009-05-15 09:23:25 +0000422
Devang Patel2c4ceb12009-11-21 02:48:08 +0000423 /// emitFunctionDebugFrame - Emit per function frame info into a debug frame
Bill Wendling0310d762009-05-15 09:23:25 +0000424 /// section.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000425 void emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo);
Bill Wendling0310d762009-05-15 09:23:25 +0000426
Devang Patel2c4ceb12009-11-21 02:48:08 +0000427 /// emitDebugPubNames - Emit visible names into a debug pubnames section.
Bill Wendling0310d762009-05-15 09:23:25 +0000428 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000429 void emitDebugPubNames();
Bill Wendling0310d762009-05-15 09:23:25 +0000430
Devang Patel193f7202009-11-24 01:14:22 +0000431 /// emitDebugPubTypes - Emit visible types into a debug pubtypes section.
432 ///
433 void emitDebugPubTypes();
434
Devang Patel2c4ceb12009-11-21 02:48:08 +0000435 /// emitDebugStr - Emit visible names into a debug str section.
Bill Wendling0310d762009-05-15 09:23:25 +0000436 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000437 void emitDebugStr();
Bill Wendling0310d762009-05-15 09:23:25 +0000438
Devang Patel2c4ceb12009-11-21 02:48:08 +0000439 /// emitDebugLoc - Emit visible names into a debug loc section.
Bill Wendling0310d762009-05-15 09:23:25 +0000440 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000441 void emitDebugLoc();
Bill Wendling0310d762009-05-15 09:23:25 +0000442
443 /// EmitDebugARanges - Emit visible names into a debug aranges section.
444 ///
445 void EmitDebugARanges();
446
Devang Patel2c4ceb12009-11-21 02:48:08 +0000447 /// emitDebugRanges - Emit visible names into a debug ranges section.
Bill Wendling0310d762009-05-15 09:23:25 +0000448 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000449 void emitDebugRanges();
Bill Wendling0310d762009-05-15 09:23:25 +0000450
Devang Patel2c4ceb12009-11-21 02:48:08 +0000451 /// emitDebugMacInfo - Emit visible names into a debug macinfo section.
Bill Wendling0310d762009-05-15 09:23:25 +0000452 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000453 void emitDebugMacInfo();
Bill Wendling0310d762009-05-15 09:23:25 +0000454
Devang Patel2c4ceb12009-11-21 02:48:08 +0000455 /// emitDebugInlineInfo - Emit inline info using following format.
Bill Wendling0310d762009-05-15 09:23:25 +0000456 /// Section Header:
457 /// 1. length of section
458 /// 2. Dwarf version number
459 /// 3. address size.
460 ///
461 /// Entries (one "entry" for each function that was inlined):
462 ///
463 /// 1. offset into __debug_str section for MIPS linkage name, if exists;
464 /// otherwise offset into __debug_str for regular function name.
465 /// 2. offset into __debug_str section for regular function name.
466 /// 3. an unsigned LEB128 number indicating the number of distinct inlining
467 /// instances for the function.
468 ///
469 /// The rest of the entry consists of a {die_offset, low_pc} pair for each
470 /// inlined instance; the die_offset points to the inlined_subroutine die in
471 /// the __debug_info section, and the low_pc is the starting address for the
472 /// inlining instance.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000473 void emitDebugInlineInfo();
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000474
475 /// GetOrCreateSourceID - Look up the source id with the given directory and
476 /// source file names. If none currently exists, create a new id and insert it
477 /// in the SourceIds map. This can update DirectoryNames and SourceFileNames maps
478 /// as well.
Devang Patel65dbc902009-11-25 17:36:49 +0000479 unsigned GetOrCreateSourceID(StringRef DirName, StringRef FileName);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000480
Devang Pateld037d7a2009-12-11 21:37:07 +0000481 CompileUnit *constructCompileUnit(MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000482
Devang Patel2c4ceb12009-11-21 02:48:08 +0000483 void constructGlobalVariableDIE(MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000484
Devang Patel2c4ceb12009-11-21 02:48:08 +0000485 void constructSubprogramDIE(MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000486
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000487 // FIXME: This should go away in favor of complex addresses.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000488 /// Find the type the programmer originally declared the variable to be
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000489 /// and return that type. Obsolete, use GetComplexAddrType instead.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000490 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000491 DIType getBlockByrefType(DIType Ty, std::string Name);
Caroline Ticedc8f6042009-08-31 21:19:37 +0000492
Bill Wendling0310d762009-05-15 09:23:25 +0000493public:
494 //===--------------------------------------------------------------------===//
495 // Main entry points.
496 //
Chris Lattneraf76e592009-08-22 20:48:53 +0000497 DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T);
Bill Wendling0310d762009-05-15 09:23:25 +0000498 virtual ~DwarfDebug();
499
500 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
501 /// be emitted.
502 bool ShouldEmitDwarfDebug() const { return shouldEmit; }
503
Devang Patel2c4ceb12009-11-21 02:48:08 +0000504 /// beginModule - Emit all Dwarf sections that should come prior to the
Bill Wendling0310d762009-05-15 09:23:25 +0000505 /// content.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000506 void beginModule(Module *M, MachineModuleInfo *MMI);
Bill Wendling0310d762009-05-15 09:23:25 +0000507
Devang Patel2c4ceb12009-11-21 02:48:08 +0000508 /// endModule - Emit all Dwarf sections that should come after the content.
Bill Wendling0310d762009-05-15 09:23:25 +0000509 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000510 void endModule();
Bill Wendling0310d762009-05-15 09:23:25 +0000511
Devang Patel2c4ceb12009-11-21 02:48:08 +0000512 /// beginFunction - Gather pre-function debug information. Assumes being
Bill Wendling0310d762009-05-15 09:23:25 +0000513 /// emitted immediately after the function entry point.
Chris Lattnereec791a2010-01-26 23:18:02 +0000514 void beginFunction(const MachineFunction *MF);
Bill Wendling0310d762009-05-15 09:23:25 +0000515
Devang Patel2c4ceb12009-11-21 02:48:08 +0000516 /// endFunction - Gather and emit post-function debug information.
Bill Wendling0310d762009-05-15 09:23:25 +0000517 ///
Chris Lattnereec791a2010-01-26 23:18:02 +0000518 void endFunction(const MachineFunction *MF);
Bill Wendling0310d762009-05-15 09:23:25 +0000519
Devang Patel2c4ceb12009-11-21 02:48:08 +0000520 /// recordSourceLine - Records location information and associates it with a
Bill Wendling0310d762009-05-15 09:23:25 +0000521 /// label. Returns a unique label ID used to generate a label and provide
522 /// correspondence to the source line list.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000523 unsigned recordSourceLine(unsigned Line, unsigned Col, MDNode *Scope);
Bill Wendling0310d762009-05-15 09:23:25 +0000524
Devang Patel2c4ceb12009-11-21 02:48:08 +0000525 /// getSourceLineCount - Return the number of source lines in the debug
Bill Wendling0310d762009-05-15 09:23:25 +0000526 /// info.
Devang Patel2c4ceb12009-11-21 02:48:08 +0000527 unsigned getSourceLineCount() const {
Bill Wendling0310d762009-05-15 09:23:25 +0000528 return Lines.size();
529 }
530
531 /// getOrCreateSourceID - Public version of GetOrCreateSourceID. This can be
532 /// timed. Look up the source id with the given directory and source file
533 /// names. If none currently exists, create a new id and insert it in the
534 /// SourceIds map. This can update DirectoryNames and SourceFileNames maps as
535 /// well.
536 unsigned getOrCreateSourceID(const std::string &DirName,
537 const std::string &FileName);
538
Devang Patel2c4ceb12009-11-21 02:48:08 +0000539 /// extractScopeInformation - Scan machine instructions in this function
Devang Patelaf9e8472009-10-01 20:31:14 +0000540 /// and collect DbgScopes. Return true, if atleast one scope was found.
Chris Lattnereec791a2010-01-26 23:18:02 +0000541 bool extractScopeInformation();
Devang Patelaf9e8472009-10-01 20:31:14 +0000542
Devang Patel2c4ceb12009-11-21 02:48:08 +0000543 /// collectVariableInfo - Populate DbgScope entries with variables' info.
544 void collectVariableInfo();
Devang Patele717faa2009-10-06 01:26:37 +0000545
Devang Patel2c4ceb12009-11-21 02:48:08 +0000546 /// beginScope - Process beginning of a scope starting at Label.
547 void beginScope(const MachineInstr *MI, unsigned Label);
Bill Wendling0310d762009-05-15 09:23:25 +0000548
Devang Patel2c4ceb12009-11-21 02:48:08 +0000549 /// endScope - Prcess end of a scope.
550 void endScope(const MachineInstr *MI);
Devang Patel53bb5c92009-11-10 23:06:00 +0000551};
Bill Wendling0310d762009-05-15 09:23:25 +0000552} // End of namespace llvm
553
554#endif