blob: 8694264d84e9bf3bf70380ab656c320a22cc0aa2 [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 Patelbdf45cb2009-10-27 20:47:17 +000023#include "llvm/ADT/ValueMap.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;
33class DbgVariable;
34class DbgScope;
35class DbgConcreteScope;
36class 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///
44class VISIBILITY_HIDDEN SrcLineInfo {
45 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
60class VISIBILITY_HIDDEN DwarfDebug : public Dwarf {
61 //===--------------------------------------------------------------------===//
62 // Attributes used to construct specific Dwarf sections.
63 //
64
65 /// CompileUnitMap - A map of global variables representing compile units to
66 /// compile units.
67 DenseMap<Value *, CompileUnit *> CompileUnitMap;
68
69 /// CompileUnits - All the compile units in this module.
70 ///
71 SmallVector<CompileUnit *, 8> CompileUnits;
72
Devang Patel1dbc7712009-06-29 20:45:18 +000073 /// ModuleCU - All DIEs are inserted in ModuleCU.
74 CompileUnit *ModuleCU;
Bill Wendling0310d762009-05-15 09:23:25 +000075
76 /// AbbreviationsSet - Used to uniquely define abbreviations.
77 ///
78 FoldingSet<DIEAbbrev> AbbreviationsSet;
79
80 /// Abbreviations - A list of all the unique abbreviations in use.
81 ///
82 std::vector<DIEAbbrev *> Abbreviations;
83
84 /// DirectoryIdMap - Directory name to directory id map.
85 ///
86 StringMap<unsigned> DirectoryIdMap;
87
88 /// DirectoryNames - A list of directory names.
89 SmallVector<std::string, 8> DirectoryNames;
90
91 /// SourceFileIdMap - Source file name to source file id map.
92 ///
93 StringMap<unsigned> SourceFileIdMap;
94
95 /// SourceFileNames - A list of source file names.
96 SmallVector<std::string, 8> SourceFileNames;
97
98 /// SourceIdMap - Source id map, i.e. pair of directory id and source file
99 /// id mapped to a unique id.
100 DenseMap<std::pair<unsigned, unsigned>, unsigned> SourceIdMap;
101
102 /// SourceIds - Reverse map from source id to directory id + file id pair.
103 ///
104 SmallVector<std::pair<unsigned, unsigned>, 8> SourceIds;
105
106 /// Lines - List of of source line correspondence.
107 std::vector<SrcLineInfo> Lines;
108
109 /// ValuesSet - Used to uniquely define values.
110 ///
111 FoldingSet<DIEValue> ValuesSet;
112
113 /// Values - A list of all the unique values in use.
114 ///
115 std::vector<DIEValue *> Values;
116
117 /// StringPool - A UniqueVector of strings used by indirect references.
118 ///
119 UniqueVector<std::string> StringPool;
120
121 /// SectionMap - Provides a unique id per text section.
122 ///
Chris Lattnera87dea42009-07-31 18:48:30 +0000123 UniqueVector<const MCSection*> SectionMap;
Bill Wendling0310d762009-05-15 09:23:25 +0000124
125 /// SectionSourceLines - Tracks line numbers per text section.
126 ///
127 std::vector<std::vector<SrcLineInfo> > SectionSourceLines;
128
129 /// didInitial - Flag to indicate if initial emission has been done.
130 ///
131 bool didInitial;
132
133 /// shouldEmit - Flag to indicate if debug information should be emitted.
134 ///
135 bool shouldEmit;
136
Devang Patel53bb5c92009-11-10 23:06:00 +0000137 // CurrentFnDbgScope - Top level scope for the current function.
Bill Wendling0310d762009-05-15 09:23:25 +0000138 //
Devang Patel53bb5c92009-11-10 23:06:00 +0000139 DbgScope *CurrentFnDbgScope;
Bill Wendling0310d762009-05-15 09:23:25 +0000140
141 /// DbgScopeMap - Tracks the scopes in the current function.
Devang Patel53bb5c92009-11-10 23:06:00 +0000142 ///
Devang Patelbdf45cb2009-10-27 20:47:17 +0000143 ValueMap<MDNode *, DbgScope *> DbgScopeMap;
Bill Wendling0310d762009-05-15 09:23:25 +0000144
Devang Patel53bb5c92009-11-10 23:06:00 +0000145 /// ConcreteScopes - Tracks the concrete scopees in the current function.
146 /// These scopes are also included in DbgScopeMap.
147 ValueMap<MDNode *, DbgScope *> ConcreteScopes;
148
149 /// AbstractScopes - Tracks the abstract scopes a module. These scopes are
150 /// not included DbgScopeMap.
151 ValueMap<MDNode *, DbgScope *> AbstractScopes;
152 SmallVector<DbgScope *, 4>AbstractScopesList;
153
154 /// AbstractVariables - Collection on abstract variables.
155 ValueMap<MDNode *, DbgVariable *> AbstractVariables;
156
157 /// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked
158 /// (at the end of the module) as DW_AT_inline.
159 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
160
161 /// AbstractSubprogramDIEs - Collection of abstruct subprogram DIEs.
162 SmallPtrSet<DIE *, 4> AbstractSubprogramDIEs;
163
Devang Patelfd07cf52009-10-05 23:40:42 +0000164 /// ScopedGVs - Tracks global variables that are not at file scope.
165 /// For example void f() { static int b = 42; }
166 SmallVector<WeakVH, 4> ScopedGVs;
167
Devang Patel53bb5c92009-11-10 23:06:00 +0000168 typedef SmallVector<DbgScope *, 2> ScopeVector;
169 typedef DenseMap<const MachineInstr *, ScopeVector>
Devang Patelaf9e8472009-10-01 20:31:14 +0000170 InsnToDbgScopeMapTy;
171
Devang Patel53bb5c92009-11-10 23:06:00 +0000172 /// DbgScopeBeginMap - Maps instruction with a list of DbgScopes it starts.
Devang Patelaf9e8472009-10-01 20:31:14 +0000173 InsnToDbgScopeMapTy DbgScopeBeginMap;
174
175 /// DbgScopeEndMap - Maps instruction with a list DbgScopes it ends.
176 InsnToDbgScopeMapTy DbgScopeEndMap;
177
Bill Wendling0310d762009-05-15 09:23:25 +0000178 /// InlineInfo - Keep track of inlined functions and their location. This
179 /// information is used to populate debug_inlined section.
Devang Patel53bb5c92009-11-10 23:06:00 +0000180 typedef std::pair<unsigned, DIE *> InlineInfoLabels;
181 ValueMap<MDNode *, SmallVector<InlineInfoLabels, 4> > InlineInfo;
182 SmallVector<MDNode *, 4> InlinedSPNodes;
Bill Wendling0310d762009-05-15 09:23:25 +0000183
184 /// CompileUnitOffsets - A vector of the offsets of the compile units. This is
185 /// used when calculating the "origin" of a concrete instance of an inlined
186 /// function.
187 DenseMap<CompileUnit *, unsigned> CompileUnitOffsets;
188
189 /// DebugTimer - Timer for the Dwarf debug writer.
190 Timer *DebugTimer;
Devang Patel43da8fb2009-07-13 21:26:33 +0000191
Bill Wendling0310d762009-05-15 09:23:25 +0000192 struct FunctionDebugFrameInfo {
193 unsigned Number;
194 std::vector<MachineMove> Moves;
195
196 FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M)
197 : Number(Num), Moves(M) {}
198 };
199
200 std::vector<FunctionDebugFrameInfo> DebugFrames;
201
202 /// getSourceDirectoryAndFileIds - Return the directory and file ids that
203 /// maps to the source id. Source id starts at 1.
204 std::pair<unsigned, unsigned>
205 getSourceDirectoryAndFileIds(unsigned SId) const {
206 return SourceIds[SId-1];
207 }
208
209 /// getNumSourceDirectories - Return the number of source directories in the
210 /// debug info.
211 unsigned getNumSourceDirectories() const {
212 return DirectoryNames.size();
213 }
214
215 /// getSourceDirectoryName - Return the name of the directory corresponding
216 /// to the id.
217 const std::string &getSourceDirectoryName(unsigned Id) const {
218 return DirectoryNames[Id - 1];
219 }
220
221 /// getSourceFileName - Return the name of the source file corresponding
222 /// to the id.
223 const std::string &getSourceFileName(unsigned Id) const {
224 return SourceFileNames[Id - 1];
225 }
226
227 /// getNumSourceIds - Return the number of unique source ids.
228 unsigned getNumSourceIds() const {
229 return SourceIds.size();
230 }
231
232 /// AssignAbbrevNumber - Define a unique number for the abbreviation.
233 ///
234 void AssignAbbrevNumber(DIEAbbrev &Abbrev);
235
Bill Wendling995f80a2009-05-20 23:24:48 +0000236 /// CreateDIEEntry - Creates a new DIEEntry to be a proxy for a debug
237 /// information entry.
238 DIEEntry *CreateDIEEntry(DIE *Entry = NULL);
Bill Wendling0310d762009-05-15 09:23:25 +0000239
240 /// SetDIEEntry - Set a DIEEntry once the debug information entry is defined.
241 ///
242 void SetDIEEntry(DIEEntry *Value, DIE *Entry);
243
244 /// AddUInt - Add an unsigned integer attribute data and value.
245 ///
246 void AddUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
247
248 /// AddSInt - Add an signed integer attribute data and value.
249 ///
250 void AddSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
251
252 /// AddString - Add a string attribute data and value.
253 ///
254 void AddString(DIE *Die, unsigned Attribute, unsigned Form,
255 const std::string &String);
256
257 /// AddLabel - Add a Dwarf label attribute data and value.
258 ///
259 void AddLabel(DIE *Die, unsigned Attribute, unsigned Form,
260 const DWLabel &Label);
261
262 /// AddObjectLabel - Add an non-Dwarf label attribute data and value.
263 ///
264 void AddObjectLabel(DIE *Die, unsigned Attribute, unsigned Form,
265 const std::string &Label);
266
267 /// AddSectionOffset - Add a section offset label attribute data and value.
268 ///
269 void AddSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
270 const DWLabel &Label, const DWLabel &Section,
271 bool isEH = false, bool useSet = true);
272
273 /// AddDelta - Add a label delta attribute data and value.
274 ///
275 void AddDelta(DIE *Die, unsigned Attribute, unsigned Form,
276 const DWLabel &Hi, const DWLabel &Lo);
277
278 /// AddDIEEntry - Add a DIE attribute data and value.
279 ///
280 void AddDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry) {
Bill Wendling995f80a2009-05-20 23:24:48 +0000281 Die->AddValue(Attribute, Form, CreateDIEEntry(Entry));
Bill Wendling0310d762009-05-15 09:23:25 +0000282 }
283
284 /// AddBlock - Add block data.
285 ///
286 void AddBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
287
288 /// AddSourceLine - Add location information to specified debug information
289 /// entry.
290 void AddSourceLine(DIE *Die, const DIVariable *V);
Bill Wendling0310d762009-05-15 09:23:25 +0000291 void AddSourceLine(DIE *Die, const DIGlobal *G);
Devang Patel82dfc0c2009-08-31 22:47:13 +0000292 void AddSourceLine(DIE *Die, const DISubprogram *SP);
Bill Wendling0310d762009-05-15 09:23:25 +0000293 void AddSourceLine(DIE *Die, const DIType *Ty);
294
295 /// AddAddress - Add an address attribute to a die based on the location
296 /// provided.
297 void AddAddress(DIE *Die, unsigned Attribute,
298 const MachineLocation &Location);
299
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000300 /// AddComplexAddress - Start with the address based on the location provided,
301 /// and generate the DWARF information necessary to find the actual variable
302 /// (navigating the extra location information encoded in the type) based on
303 /// the starting location. Add the DWARF information to the die.
304 ///
305 void AddComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
306 const MachineLocation &Location);
307
308 // FIXME: Should be reformulated in terms of AddComplexAddress.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000309 /// AddBlockByrefAddress - Start with the address based on the location
310 /// provided, and generate the DWARF information necessary to find the
311 /// actual Block variable (navigating the Block struct) based on the
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000312 /// starting location. Add the DWARF information to the die. Obsolete,
313 /// please use AddComplexAddress instead.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000314 ///
315 void AddBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
316 const MachineLocation &Location);
317
Bill Wendling0310d762009-05-15 09:23:25 +0000318 /// AddType - Add a new type attribute to the specified entity.
319 void AddType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty);
320
321 /// ConstructTypeDIE - Construct basic type die from DIBasicType.
322 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
323 DIBasicType BTy);
324
325 /// ConstructTypeDIE - Construct derived type die from DIDerivedType.
326 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
327 DIDerivedType DTy);
328
329 /// ConstructTypeDIE - Construct type DIE from DICompositeType.
330 void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
331 DICompositeType CTy);
332
333 /// ConstructSubrangeDIE - Construct subrange DIE from DISubrange.
334 void ConstructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
335
336 /// ConstructArrayTypeDIE - Construct array type DIE from DICompositeType.
337 void ConstructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
338 DICompositeType *CTy);
339
340 /// ConstructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
341 DIE *ConstructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy);
342
343 /// CreateGlobalVariableDIE - Create new DIE using GV.
344 DIE *CreateGlobalVariableDIE(CompileUnit *DW_Unit,
345 const DIGlobalVariable &GV);
346
347 /// CreateMemberDIE - Create new member DIE.
348 DIE *CreateMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT);
349
350 /// CreateSubprogramDIE - Create new DIE using SP.
351 DIE *CreateSubprogramDIE(CompileUnit *DW_Unit,
352 const DISubprogram &SP,
Bill Wendling6679ee42009-05-18 22:02:36 +0000353 bool IsConstructor = false,
354 bool IsInlined = false);
Bill Wendling0310d762009-05-15 09:23:25 +0000355
356 /// FindCompileUnit - Get the compile unit for the given descriptor.
357 ///
358 CompileUnit &FindCompileUnit(DICompileUnit Unit) const;
359
Bill Wendling995f80a2009-05-20 23:24:48 +0000360 /// CreateDbgScopeVariable - Create a new scope variable.
Bill Wendling0310d762009-05-15 09:23:25 +0000361 ///
Bill Wendling995f80a2009-05-20 23:24:48 +0000362 DIE *CreateDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit);
Bill Wendling0310d762009-05-15 09:23:25 +0000363
Devang Patel53bb5c92009-11-10 23:06:00 +0000364 /// getUpdatedDbgScope - Find or create DbgScope assicated with
365 /// the instruction. Initialize scope and update scope hierarchy.
366 DbgScope *getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, MDNode *InlinedAt);
367
368 /// createDbgScope - Create DbgScope for the scope.
369 void createDbgScope(MDNode *Scope, MDNode *InlinedAt);
Devang Patele4b27562009-08-28 23:24:31 +0000370 DbgScope *getOrCreateScope(MDNode *N);
Devang Patel53bb5c92009-11-10 23:06:00 +0000371 DbgScope *getOrCreateAbstractScope(MDNode *N);
372
373 /// findAbstractVariable - Find abstract variable associated with Var.
374 DbgVariable *findAbstractVariable(DIVariable &Var, unsigned FrameIdx,
375 DILocation &Loc);
376
377 DIE *UpdateSubprogramScopeDIE(MDNode *SPNode);
378 DIE *ConstructLexicalScopeDIE(DbgScope *Scope);
379 DIE *ConstructScopeDIE(DbgScope *Scope);
380 DIE *ConstructInlinedScopeDIE(DbgScope *Scope);
381 DIE *ConstructVariableDIE(DbgVariable *DV, DbgScope *S, CompileUnit *Unit);
Bill Wendling0310d762009-05-15 09:23:25 +0000382
383 /// ConstructDbgScope - Construct the components of a scope.
384 ///
385 void ConstructDbgScope(DbgScope *ParentScope,
386 unsigned ParentStartID, unsigned ParentEndID,
387 DIE *ParentDie, CompileUnit *Unit);
388
Devang Patel53bb5c92009-11-10 23:06:00 +0000389 /// ConstructCurrentFnDbgScope - Construct the scope for the subprogram.
Bill Wendling0310d762009-05-15 09:23:25 +0000390 ///
Devang Patel53bb5c92009-11-10 23:06:00 +0000391 void ConstructCurrentFnDbgScope(DbgScope *RootScope,
392 bool AbstractScope = false);
Bill Wendling0310d762009-05-15 09:23:25 +0000393
394 /// ConstructDefaultDbgScope - Construct a default scope for the subprogram.
395 ///
396 void ConstructDefaultDbgScope(MachineFunction *MF);
397
398 /// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
399 /// tools to recognize the object file contains Dwarf information.
400 void EmitInitial();
401
402 /// EmitDIE - Recusively Emits a debug information entry.
403 ///
404 void EmitDIE(DIE *Die);
405
406 /// SizeAndOffsetDie - Compute the size and offset of a DIE.
407 ///
408 unsigned SizeAndOffsetDie(DIE *Die, unsigned Offset, bool Last);
409
410 /// SizeAndOffsets - Compute the size and offset of all the DIEs.
411 ///
412 void SizeAndOffsets();
413
414 /// EmitDebugInfo / EmitDebugInfoPerCU - Emit the debug info section.
415 ///
416 void EmitDebugInfoPerCU(CompileUnit *Unit);
417
418 void EmitDebugInfo();
419
420 /// EmitAbbreviations - Emit the abbreviation section.
421 ///
422 void EmitAbbreviations() const;
423
424 /// EmitEndOfLineMatrix - Emit the last address of the section and the end of
425 /// the line matrix.
426 ///
427 void EmitEndOfLineMatrix(unsigned SectionEnd);
428
429 /// EmitDebugLines - Emit source line information.
430 ///
431 void EmitDebugLines();
432
433 /// EmitCommonDebugFrame - Emit common frame info into a debug frame section.
434 ///
435 void EmitCommonDebugFrame();
436
437 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
438 /// section.
439 void EmitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo);
440
441 void EmitDebugPubNamesPerCU(CompileUnit *Unit);
442
443 /// EmitDebugPubNames - Emit visible names into a debug pubnames section.
444 ///
445 void EmitDebugPubNames();
446
447 /// EmitDebugStr - Emit visible names into a debug str section.
448 ///
449 void EmitDebugStr();
450
451 /// EmitDebugLoc - Emit visible names into a debug loc section.
452 ///
453 void EmitDebugLoc();
454
455 /// EmitDebugARanges - Emit visible names into a debug aranges section.
456 ///
457 void EmitDebugARanges();
458
459 /// EmitDebugRanges - Emit visible names into a debug ranges section.
460 ///
461 void EmitDebugRanges();
462
463 /// EmitDebugMacInfo - Emit visible names into a debug macinfo section.
464 ///
465 void EmitDebugMacInfo();
466
467 /// EmitDebugInlineInfo - Emit inline info using following format.
468 /// Section Header:
469 /// 1. length of section
470 /// 2. Dwarf version number
471 /// 3. address size.
472 ///
473 /// Entries (one "entry" for each function that was inlined):
474 ///
475 /// 1. offset into __debug_str section for MIPS linkage name, if exists;
476 /// otherwise offset into __debug_str for regular function name.
477 /// 2. offset into __debug_str section for regular function name.
478 /// 3. an unsigned LEB128 number indicating the number of distinct inlining
479 /// instances for the function.
480 ///
481 /// The rest of the entry consists of a {die_offset, low_pc} pair for each
482 /// inlined instance; the die_offset points to the inlined_subroutine die in
483 /// the __debug_info section, and the low_pc is the starting address for the
484 /// inlining instance.
485 void EmitDebugInlineInfo();
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000486
487 /// GetOrCreateSourceID - Look up the source id with the given directory and
488 /// source file names. If none currently exists, create a new id and insert it
489 /// in the SourceIds map. This can update DirectoryNames and SourceFileNames maps
490 /// as well.
Devang Patel5ccdd102009-09-29 18:40:58 +0000491 unsigned GetOrCreateSourceID(const char *DirName,
492 const char *FileName);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000493
Devang Patele4b27562009-08-28 23:24:31 +0000494 void ConstructCompileUnit(MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000495
Devang Patele4b27562009-08-28 23:24:31 +0000496 void ConstructGlobalVariableDIE(MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000497
Devang Patele4b27562009-08-28 23:24:31 +0000498 void ConstructSubprogram(MDNode *N);
Bill Wendlingf0fb9872009-05-20 23:19:06 +0000499
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000500 // FIXME: This should go away in favor of complex addresses.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000501 /// Find the type the programmer originally declared the variable to be
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000502 /// and return that type. Obsolete, use GetComplexAddrType instead.
Caroline Ticedc8f6042009-08-31 21:19:37 +0000503 ///
504 DIType GetBlockByrefType(DIType Ty, std::string Name);
505
Bill Wendling0310d762009-05-15 09:23:25 +0000506public:
507 //===--------------------------------------------------------------------===//
508 // Main entry points.
509 //
Chris Lattneraf76e592009-08-22 20:48:53 +0000510 DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T);
Bill Wendling0310d762009-05-15 09:23:25 +0000511 virtual ~DwarfDebug();
512
513 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
514 /// be emitted.
515 bool ShouldEmitDwarfDebug() const { return shouldEmit; }
516
Bill Wendling0310d762009-05-15 09:23:25 +0000517 /// BeginModule - Emit all Dwarf sections that should come prior to the
518 /// content.
Devang Patel208622d2009-06-25 22:36:02 +0000519 void BeginModule(Module *M, MachineModuleInfo *MMI);
Bill Wendling0310d762009-05-15 09:23:25 +0000520
521 /// EndModule - Emit all Dwarf sections that should come after the content.
522 ///
523 void EndModule();
524
525 /// BeginFunction - Gather pre-function debug information. Assumes being
526 /// emitted immediately after the function entry point.
527 void BeginFunction(MachineFunction *MF);
528
529 /// EndFunction - Gather and emit post-function debug information.
530 ///
531 void EndFunction(MachineFunction *MF);
532
533 /// RecordSourceLine - Records location information and associates it with a
534 /// label. Returns a unique label ID used to generate a label and provide
535 /// correspondence to the source line list.
Devang Patel3d910832009-09-30 22:51:28 +0000536 unsigned RecordSourceLine(unsigned Line, unsigned Col, MDNode *Scope);
Bill Wendling0310d762009-05-15 09:23:25 +0000537
538 /// getRecordSourceLineCount - Return the number of source lines in the debug
539 /// info.
540 unsigned getRecordSourceLineCount() const {
541 return Lines.size();
542 }
543
544 /// getOrCreateSourceID - Public version of GetOrCreateSourceID. This can be
545 /// timed. Look up the source id with the given directory and source file
546 /// names. If none currently exists, create a new id and insert it in the
547 /// SourceIds map. This can update DirectoryNames and SourceFileNames maps as
548 /// well.
549 unsigned getOrCreateSourceID(const std::string &DirName,
550 const std::string &FileName);
551
552 /// RecordRegionStart - Indicate the start of a region.
Devang Patele4b27562009-08-28 23:24:31 +0000553 unsigned RecordRegionStart(MDNode *N);
Bill Wendling0310d762009-05-15 09:23:25 +0000554
555 /// RecordRegionEnd - Indicate the end of a region.
Devang Patele4b27562009-08-28 23:24:31 +0000556 unsigned RecordRegionEnd(MDNode *N);
Bill Wendling0310d762009-05-15 09:23:25 +0000557
558 /// RecordVariable - Indicate the declaration of a local variable.
Devang Patele4b27562009-08-28 23:24:31 +0000559 void RecordVariable(MDNode *N, unsigned FrameIndex);
Bill Wendling0310d762009-05-15 09:23:25 +0000560
Devang Patelaf9e8472009-10-01 20:31:14 +0000561 /// ExtractScopeInformation - Scan machine instructions in this function
562 /// and collect DbgScopes. Return true, if atleast one scope was found.
563 bool ExtractScopeInformation(MachineFunction *MF);
564
Devang Patele717faa2009-10-06 01:26:37 +0000565 /// CollectVariableInfo - Populate DbgScope entries with variables' info.
Devang Patelac1ceb32009-10-09 22:42:28 +0000566 void CollectVariableInfo();
Devang Patele717faa2009-10-06 01:26:37 +0000567
Devang Patel0d20ac82009-10-06 01:50:42 +0000568 /// SetDbgScopeEndLabels - Update DbgScope end labels for the scopes that
569 /// end with this machine instruction.
570 void SetDbgScopeEndLabels(const MachineInstr *MI, unsigned Label);
Bill Wendling0310d762009-05-15 09:23:25 +0000571
Devang Patel53bb5c92009-11-10 23:06:00 +0000572 /// BeginScope - Process beginning of a scope starting at Label.
573 void BeginScope(const MachineInstr *MI, unsigned Label);
574
575 /// EndScope - Prcess end of a scope.
576 void EndScope(const MachineInstr *MI);
577};
Bill Wendling0310d762009-05-15 09:23:25 +0000578} // End of namespace llvm
579
580#endif