DwarfDebug.h revision 4243e67bd5eeae930060824d4290f8071a66e28f
1a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
2a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//
3a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//                     The LLVM Compiler Infrastructure
4a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//
5a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch// This file is distributed under the University of Illinois Open Source
6a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch// License. See LICENSE.TXT for details.
7a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//
8a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//===----------------------------------------------------------------------===//
9a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//
10a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch// This file contains support for writing dwarf debug info into asm files.
11a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//
12a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//===----------------------------------------------------------------------===//
13a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
14a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
15a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
16a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
17a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/CodeGen/AsmPrinter.h"
18a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/CodeGen/MachineLocation.h"
19a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/Analysis/DebugInfo.h"
20a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "DIE.h"
21a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/ADT/DenseMap.h"
22a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/ADT/FoldingSet.h"
23a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/ADT/SmallPtrSet.h"
24a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/ADT/StringMap.h"
25a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/ADT/UniqueVector.h"
26a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/Support/Allocator.h"
27a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "llvm/Support/DebugLoc.h"
28a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
29a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochnamespace llvm {
30a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
31a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass CompileUnit;
32a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DbgConcreteScope;
33a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DbgScope;
34a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DbgVariable;
35a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass MachineFrameInfo;
36a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass MachineModuleInfo;
37a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass MachineOperand;
38a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass MCAsmInfo;
39a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DIEAbbrev;
40a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DIE;
41a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DIEBlock;
42a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DIEEntry;
43a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
44a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//===----------------------------------------------------------------------===//
45a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch/// SrcLineInfo - This class is used to record source line correspondence.
46a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch///
47a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass SrcLineInfo {
48a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned Line;                     // Source line number.
49a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned Column;                   // Source column.
50a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned SourceID;                 // Source ID number.
51a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  MCSymbol *Label;                   // Label in code ID number.
52a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochpublic:
53a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
54a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    : Line(L), Column(C), SourceID(S), Label(label) {}
55a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
56a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  // Accessors
57a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned getLine() const { return Line; }
58a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned getColumn() const { return Column; }
59a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned getSourceID() const { return SourceID; }
60a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  MCSymbol *getLabel() const { return Label; }
61a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch};
62a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
63a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch/// DotDebugLocEntry - This struct describes location entries emitted in
64a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch/// .debug_loc section.
65a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochtypedef struct DotDebugLocEntry {
66a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  const MCSymbol *Begin;
67a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  const MCSymbol *End;
68a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  MachineLocation Loc;
69a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  const MDNode *Variable;
70a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  bool Merged;
71a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DotDebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {}
72a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
73a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch                   const MDNode *V)
74a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {}
75a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// Empty entries are also used as a trigger to emit temp label. Such
76a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// labels are referenced is used to find debug_loc offset for a given DIE.
77a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  bool isEmpty() { return Begin == 0 && End == 0; }
78a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  bool isMerged() { return Merged; }
79a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  void Merge(DotDebugLocEntry *Next) {
80a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    if (!(Begin && Loc == Next->Loc && End == Next->Begin))
81a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch      return;
82a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    Next->Begin = Begin;
83a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    Merged = true;
84a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  }
85a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} DotDebugLocEntry;
86a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
87a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch//===----------------------------------------------------------------------===//
88a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch/// DbgVariable - This class is used to track local variable information.
89a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch///
90a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DbgVariable {
91a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DIVariable Var;                    // Variable Descriptor.
92a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DIE *TheDIE;                       // Variable DIE.
93a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned DotDebugLocOffset;        // Offset in DotDebugLocEntries.
94a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochpublic:
95a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  // AbsVar may be NULL.
96a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DbgVariable(DIVariable V) : Var(V), TheDIE(0), DotDebugLocOffset(~0U) {}
97a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
98a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  // Accessors.
99a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DIVariable getVariable()           const { return Var; }
100a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  void setDIE(DIE *D)                      { TheDIE = D; }
101a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DIE *getDIE()                      const { return TheDIE; }
102a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  void setDotDebugLocOffset(unsigned O)    { DotDebugLocOffset = O; }
103a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned getDotDebugLocOffset()    const { return DotDebugLocOffset; }
104a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  StringRef getName()                const { return Var.getName(); }
105a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned getTag()                  const { return Var.getTag(); }
106a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  bool variableHasComplexAddress()   const {
107a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    assert(Var.Verify() && "Invalid complex DbgVariable!");
108a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return Var.hasComplexAddress();
109a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  }
110a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  bool isBlockByrefVariable()        const {
111a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    assert(Var.Verify() && "Invalid complex DbgVariable!");
112a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return Var.isBlockByrefVariable();
113a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  }
114a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned getNumAddrElements()      const {
115a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    assert(Var.Verify() && "Invalid complex DbgVariable!");
116a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return Var.getNumAddrElements();
117a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  }
118a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  uint64_t getAddrElement(unsigned i) const {
119a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return Var.getAddrElement(i);
120a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  }
121a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DIType getType() const;
122a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch};
123a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
124a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DwarfDebug {
125a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// Asm - Target of Dwarf emission.
126a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  AsmPrinter *Asm;
127a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
128a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// MMI - Collected machine module information.
129a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  MachineModuleInfo *MMI;
130a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
131a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  //===--------------------------------------------------------------------===//
132a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  // Attributes used to construct specific Dwarf sections.
133a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  //
134a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
135a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  CompileUnit *FirstCU;
136a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DenseMap <const MDNode *, CompileUnit *> CUMap;
137a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
138a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// AbbreviationsSet - Used to uniquely define abbreviations.
139a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  ///
140a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  FoldingSet<DIEAbbrev> AbbreviationsSet;
141a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
142a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// Abbreviations - A list of all the unique abbreviations in use.
143a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  ///
144a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  std::vector<DIEAbbrev *> Abbreviations;
145a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
146a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// SourceIdMap - Source id map, i.e. pair of directory id and source file
147a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// id mapped to a unique id.
148a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  StringMap<unsigned> SourceIdMap;
149a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
150a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// StringPool - A String->Symbol mapping of strings used by indirect
151a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// references.
152a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  StringMap<std::pair<MCSymbol*, unsigned> > StringPool;
153a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  unsigned NextStringPoolNumber;
154a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
155a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  MCSymbol *getStringPoolEntry(StringRef Str);
156a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
157a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// SectionMap - Provides a unique id per text section.
158a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  ///
159a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  UniqueVector<const MCSection*> SectionMap;
160a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
161a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// CurrentFnDbgScope - Top level scope for the current function.
162a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  ///
163a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DbgScope *CurrentFnDbgScope;
164a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
165a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// CurrentFnArguments - List of Arguments (DbgValues) for current function.
166a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  SmallVector<DbgVariable *, 8> CurrentFnArguments;
167a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
168a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// DbgScopeMap - Tracks the scopes in the current function.  Owns the
169a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  /// contained DbgScope*s.
170a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  ///
171a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch  DenseMap<const MDNode *, DbgScope *> DbgScopeMap;
172a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
173  /// ConcreteScopes - Tracks the concrete scopees in the current function.
174  /// These scopes are also included in DbgScopeMap.
175  DenseMap<const MDNode *, DbgScope *> ConcreteScopes;
176
177  /// AbstractScopes - Tracks the abstract scopes a module. These scopes are
178  /// not included DbgScopeMap.  AbstractScopes owns its DbgScope*s.
179  DenseMap<const MDNode *, DbgScope *> AbstractScopes;
180
181  /// AbstractSPDies - Collection of abstract subprogram DIEs.
182  DenseMap<const MDNode *, DIE *> AbstractSPDies;
183
184  /// AbstractScopesList - Tracks abstract scopes constructed while processing
185  /// a function. This list is cleared during endFunction().
186  SmallVector<DbgScope *, 4>AbstractScopesList;
187
188  /// AbstractVariables - Collection on abstract variables.  Owned by the
189  /// DbgScopes in AbstractScopes.
190  DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
191
192  /// DbgVariableToFrameIndexMap - Tracks frame index used to find
193  /// variable's value.
194  DenseMap<const DbgVariable *, int> DbgVariableToFrameIndexMap;
195
196  /// DbgVariableToDbgInstMap - Maps DbgVariable to corresponding DBG_VALUE
197  /// machine instruction.
198  DenseMap<const DbgVariable *, const MachineInstr *> DbgVariableToDbgInstMap;
199
200  /// DotDebugLocEntries - Collection of DotDebugLocEntry.
201  SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
202
203  /// UseDotDebugLocEntry - DW_AT_location attributes for the DIEs in this set
204  /// idetifies corresponding .debug_loc entry offset.
205  SmallPtrSet<const DIE *, 4> UseDotDebugLocEntry;
206
207  /// VarToAbstractVarMap - Maps DbgVariable with corresponding Abstract
208  /// DbgVariable, if any.
209  DenseMap<const DbgVariable *, const DbgVariable *> VarToAbstractVarMap;
210
211  /// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked
212  /// (at the end of the module) as DW_AT_inline.
213  SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
214
215  /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
216  /// need DW_AT_containing_type attribute. This attribute points to a DIE that
217  /// corresponds to the MDNode mapped with the subprogram DIE.
218  DenseMap<DIE *, const MDNode *> ContainingTypeMap;
219
220  /// InlineInfo - Keep track of inlined functions and their location.  This
221  /// information is used to populate debug_inlined section.
222  typedef std::pair<const MCSymbol *, DIE *> InlineInfoLabels;
223  DenseMap<const MDNode *, SmallVector<InlineInfoLabels, 4> > InlineInfo;
224  SmallVector<const MDNode *, 4> InlinedSPNodes;
225
226  // ProcessedSPNodes - This is a collection of subprogram MDNodes that
227  // are processed to create DIEs.
228  SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
229
230  /// LabelsBeforeInsn - Maps instruction with label emitted before
231  /// instruction.
232  DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
233
234  /// LabelsAfterInsn - Maps instruction with label emitted after
235  /// instruction.
236  DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
237
238  /// UserVariables - Every user variable mentioned by a DBG_VALUE instruction
239  /// in order of appearance.
240  SmallVector<const MDNode*, 8> UserVariables;
241
242  /// DbgValues - For each user variable, keep a list of DBG_VALUE
243  /// instructions in order. The list can also contain normal instructions that
244  /// clobber the previous DBG_VALUE.
245  typedef DenseMap<const MDNode*, SmallVector<const MachineInstr*, 4> >
246    DbgValueHistoryMap;
247  DbgValueHistoryMap DbgValues;
248
249  SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
250
251  /// Previous instruction's location information. This is used to determine
252  /// label location to indicate scope boundries in dwarf debug info.
253  DebugLoc PrevInstLoc;
254  MCSymbol *PrevLabel;
255
256  /// PrologEndLoc - This location indicates end of function prologue and
257  /// beginning of function body.
258  DebugLoc PrologEndLoc;
259
260  struct FunctionDebugFrameInfo {
261    unsigned Number;
262    std::vector<MachineMove> Moves;
263
264    FunctionDebugFrameInfo(unsigned Num, const std::vector<MachineMove> &M)
265      : Number(Num), Moves(M) {}
266  };
267
268  std::vector<FunctionDebugFrameInfo> DebugFrames;
269
270  // DIEValueAllocator - All DIEValues are allocated through this allocator.
271  BumpPtrAllocator DIEValueAllocator;
272
273  // Section Symbols: these are assembler temporary labels that are emitted at
274  // the beginning of each supported dwarf section.  These are used to form
275  // section offsets and are created by EmitSectionLabels.
276  MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
277  MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
278  MCSymbol *DwarfDebugLocSectionSym;
279  MCSymbol *FunctionBeginSym, *FunctionEndSym;
280
281private:
282
283  /// assignAbbrevNumber - Define a unique number for the abbreviation.
284  ///
285  void assignAbbrevNumber(DIEAbbrev &Abbrev);
286
287  /// getOrCreateDbgScope - Create DbgScope for the scope.
288  DbgScope *getOrCreateDbgScope(const MDNode *Scope, const MDNode *InlinedAt);
289
290  DbgScope *getOrCreateAbstractScope(const MDNode *N);
291
292  /// findAbstractVariable - Find abstract variable associated with Var.
293  DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
294
295  /// updateSubprogramScopeDIE - Find DIE for the given subprogram and
296  /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes.
297  /// If there are global variables in this scope then create and insert
298  /// DIEs for these variables.
299  DIE *updateSubprogramScopeDIE(const MDNode *SPNode);
300
301  /// constructLexicalScope - Construct new DW_TAG_lexical_block
302  /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
303  DIE *constructLexicalScopeDIE(DbgScope *Scope);
304
305  /// constructInlinedScopeDIE - This scope represents inlined body of
306  /// a function. Construct DIE to represent this concrete inlined copy
307  /// of the function.
308  DIE *constructInlinedScopeDIE(DbgScope *Scope);
309
310  /// constructVariableDIE - Construct a DIE for the given DbgVariable.
311  DIE *constructVariableDIE(DbgVariable *DV, DbgScope *S);
312
313  /// constructScopeDIE - Construct a DIE for this scope.
314  DIE *constructScopeDIE(DbgScope *Scope);
315
316  /// EmitSectionLabels - Emit initial Dwarf sections with a label at
317  /// the start of each one.
318  void EmitSectionLabels();
319
320  /// emitDIE - Recusively Emits a debug information entry.
321  ///
322  void emitDIE(DIE *Die);
323
324  /// computeSizeAndOffset - Compute the size and offset of a DIE.
325  ///
326  unsigned computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last);
327
328  /// computeSizeAndOffsets - Compute the size and offset of all the DIEs.
329  ///
330  void computeSizeAndOffsets();
331
332  /// EmitDebugInfo - Emit the debug info section.
333  ///
334  void emitDebugInfo();
335
336  /// emitAbbreviations - Emit the abbreviation section.
337  ///
338  void emitAbbreviations() const;
339
340  /// emitEndOfLineMatrix - Emit the last address of the section and the end of
341  /// the line matrix.
342  ///
343  void emitEndOfLineMatrix(unsigned SectionEnd);
344
345  /// emitDebugPubNames - Emit visible names into a debug pubnames section.
346  ///
347  void emitDebugPubNames();
348
349  /// emitDebugPubTypes - Emit visible types into a debug pubtypes section.
350  ///
351  void emitDebugPubTypes();
352
353  /// emitDebugStr - Emit visible names into a debug str section.
354  ///
355  void emitDebugStr();
356
357  /// emitDebugLoc - Emit visible names into a debug loc section.
358  ///
359  void emitDebugLoc();
360
361  /// EmitDebugARanges - Emit visible names into a debug aranges section.
362  ///
363  void EmitDebugARanges();
364
365  /// emitDebugRanges - Emit visible names into a debug ranges section.
366  ///
367  void emitDebugRanges();
368
369  /// emitDebugMacInfo - Emit visible names into a debug macinfo section.
370  ///
371  void emitDebugMacInfo();
372
373  /// emitDebugInlineInfo - Emit inline info using following format.
374  /// Section Header:
375  /// 1. length of section
376  /// 2. Dwarf version number
377  /// 3. address size.
378  ///
379  /// Entries (one "entry" for each function that was inlined):
380  ///
381  /// 1. offset into __debug_str section for MIPS linkage name, if exists;
382  ///   otherwise offset into __debug_str for regular function name.
383  /// 2. offset into __debug_str section for regular function name.
384  /// 3. an unsigned LEB128 number indicating the number of distinct inlining
385  /// instances for the function.
386  ///
387  /// The rest of the entry consists of a {die_offset, low_pc}  pair for each
388  /// inlined instance; the die_offset points to the inlined_subroutine die in
389  /// the __debug_info section, and the low_pc is the starting address  for the
390  ///  inlining instance.
391  void emitDebugInlineInfo();
392
393  /// constructCompileUnit - Create new CompileUnit for the given
394  /// metadata node with tag DW_TAG_compile_unit.
395  void constructCompileUnit(const MDNode *N);
396
397  /// getCompielUnit - Get CompileUnit DIE.
398  CompileUnit *getCompileUnit(const MDNode *N) const;
399
400  /// constructGlobalVariableDIE - Construct global variable DIE.
401  void constructGlobalVariableDIE(const MDNode *N);
402
403  /// construct SubprogramDIE - Construct subprogram DIE.
404  void constructSubprogramDIE(const MDNode *N);
405
406  /// recordSourceLine - Register a source line with debug info. Returns the
407  /// unique label that was emitted and which provides correspondence to
408  /// the source line list.
409  void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
410                        unsigned Flags);
411
412  /// recordVariableFrameIndex - Record a variable's index.
413  void recordVariableFrameIndex(const DbgVariable *V, int Index);
414
415  /// findVariableFrameIndex - Return true if frame index for the variable
416  /// is found. Update FI to hold value of the index.
417  bool findVariableFrameIndex(const DbgVariable *V, int *FI);
418
419  /// findDbgScope - Find DbgScope for the debug loc attached with an
420  /// instruction.
421  DbgScope *findDbgScope(const MachineInstr *MI);
422
423  /// identifyScopeMarkers() - Indentify instructions that are marking
424  /// beginning of or end of a scope.
425  void identifyScopeMarkers();
426
427  /// extractScopeInformation - Scan machine instructions in this function
428  /// and collect DbgScopes. Return true, if atleast one scope was found.
429  bool extractScopeInformation();
430
431  /// addCurrentFnArgument - If Var is an current function argument that add
432  /// it in CurrentFnArguments list.
433  bool addCurrentFnArgument(const MachineFunction *MF,
434                            DbgVariable *Var, DbgScope *Scope);
435
436  /// collectVariableInfo - Populate DbgScope entries with variables' info.
437  void collectVariableInfo(const MachineFunction *,
438                           SmallPtrSet<const MDNode *, 16> &ProcessedVars);
439
440  /// collectVariableInfoFromMMITable - Collect variable information from
441  /// side table maintained by MMI.
442  void collectVariableInfoFromMMITable(const MachineFunction * MF,
443                                       SmallPtrSet<const MDNode *, 16> &P);
444
445  /// requestLabelBeforeInsn - Ensure that a label will be emitted before MI.
446  void requestLabelBeforeInsn(const MachineInstr *MI) {
447    LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol*)0));
448  }
449
450  /// getLabelBeforeInsn - Return Label preceding the instruction.
451  const MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
452
453  /// requestLabelAfterInsn - Ensure that a label will be emitted after MI.
454  void requestLabelAfterInsn(const MachineInstr *MI) {
455    LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol*)0));
456  }
457
458  /// getLabelAfterInsn - Return Label immediately following the instruction.
459  const MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
460
461public:
462  //===--------------------------------------------------------------------===//
463  // Main entry points.
464  //
465  DwarfDebug(AsmPrinter *A, Module *M);
466  ~DwarfDebug();
467
468  /// beginModule - Emit all Dwarf sections that should come prior to the
469  /// content.
470  void beginModule(Module *M);
471
472  /// endModule - Emit all Dwarf sections that should come after the content.
473  ///
474  void endModule();
475
476  /// beginFunction - Gather pre-function debug information.  Assumes being
477  /// emitted immediately after the function entry point.
478  void beginFunction(const MachineFunction *MF);
479
480  /// endFunction - Gather and emit post-function debug information.
481  ///
482  void endFunction(const MachineFunction *MF);
483
484  /// beginInstruction - Process beginning of an instruction.
485  void beginInstruction(const MachineInstr *MI);
486
487  /// endInstruction - Prcess end of an instruction.
488  void endInstruction(const MachineInstr *MI);
489
490  /// GetOrCreateSourceID - Look up the source id with the given directory and
491  /// source file names. If none currently exists, create a new id and insert it
492  /// in the SourceIds map.
493  unsigned GetOrCreateSourceID(StringRef DirName, StringRef FullName);
494
495  /// createSubprogramDIE - Create new DIE using SP.
496  DIE *createSubprogramDIE(DISubprogram SP);
497};
498} // End of namespace llvm
499
500#endif
501