Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains support for writing dwarf debug info into asm files.
//
//===----------------------------------------------------------------------===//
#include "DwarfDebug.h"
#include "llvm/Module.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/Support/Timer.h"
#include "llvm/System/Path.h"
#include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetFrameInfo.h"
using namespace llvm;
static TimerGroup &getDwarfTimerGroup() {
static TimerGroup DwarfTimerGroup("Dwarf Debugging");
return DwarfTimerGroup;
}
//===----------------------------------------------------------------------===//
/// Configuration values for initial hash set sizes (log2).
///
static const unsigned InitDiesSetSize = 9; // log2(512)
static const unsigned InitAbbreviationsSetSize = 9; // log2(512)
static const unsigned InitValuesSetSize = 9; // log2(512)
namespace llvm {
//===----------------------------------------------------------------------===//
/// CompileUnit - This dwarf writer support class manages information associate
/// with a source file.
class VISIBILITY_HIDDEN CompileUnit {
/// ID - File identifier for source.
///
unsigned ID;
/// Die - Compile unit debug information entry.
///
DIE *Die;
/// GVToDieMap - Tracks the mapping of unit level debug informaton
/// variables to debug information entries.
std::map<GlobalVariable *, DIE *> GVToDieMap;
/// GVToDIEEntryMap - Tracks the mapping of unit level debug informaton
/// descriptors to debug information entries using a DIEEntry proxy.
std::map<GlobalVariable *, DIEEntry *> GVToDIEEntryMap;
/// Globals - A map of globally visible named entities for this unit.
///
StringMap<DIE*> Globals;
/// DiesSet - Used to uniquely define dies within the compile unit.
///
FoldingSet<DIE> DiesSet;
public:
CompileUnit(unsigned I, DIE *D)
: ID(I), Die(D), DiesSet(InitDiesSetSize) {}
~CompileUnit() { delete Die; }
// Accessors.
unsigned getID() const { return ID; }
DIE* getDie() const { return Die; }
StringMap<DIE*> &getGlobals() { return Globals; }
/// hasContent - Return true if this compile unit has something to write out.
///
bool hasContent() const { return !Die->getChildren().empty(); }
/// AddGlobal - Add a new global entity to the compile unit.
///
void AddGlobal(const std::string &Name, DIE *Die) { Globals[Name] = Die; }
/// getDieMapSlotFor - Returns the debug information entry map slot for the
/// specified debug variable.
DIE *&getDieMapSlotFor(GlobalVariable *GV) { return GVToDieMap[GV]; }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/// getDIEEntrySlotFor - Returns the debug information entry proxy slot for the
/// specified debug variable.
DIEEntry *&getDIEEntrySlotFor(GlobalVariable *GV) {
return GVToDIEEntryMap[GV];
}
/// AddDie - Adds or interns the DIE to the compile unit.
///
DIE *AddDie(DIE &Buffer) {
FoldingSetNodeID ID;
Buffer.Profile(ID);
void *Where;
DIE *Die = DiesSet.FindNodeOrInsertPos(ID, Where);
if (!Die) {
Die = new DIE(Buffer);
DiesSet.InsertNode(Die, Where);
this->Die->AddChild(Die);
Buffer.Detach();
}
return Die;
}
};
//===----------------------------------------------------------------------===//
/// DbgVariable - This class is used to track local variable information.
///
class VISIBILITY_HIDDEN DbgVariable {
DIVariable Var; // Variable Descriptor.
unsigned FrameIndex; // Variable frame index.
bool InlinedFnVar; // Variable for an inlined function.
DbgVariable(DIVariable V, unsigned I, bool IFV)
: Var(V), FrameIndex(I), InlinedFnVar(IFV) {}
// Accessors.
DIVariable getVariable() const { return Var; }
unsigned getFrameIndex() const { return FrameIndex; }
bool isInlinedFnVar() const { return InlinedFnVar; }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
};
//===----------------------------------------------------------------------===//
/// DbgScope - This class is used to track scope information.
///
class DbgConcreteScope;
class VISIBILITY_HIDDEN DbgScope {
DbgScope *Parent; // Parent to this scope.
DIDescriptor Desc; // Debug info descriptor for scope.
// Either subprogram or block.
unsigned StartLabelID; // Label ID of the beginning of scope.
unsigned EndLabelID; // Label ID of the end of scope.
SmallVector<DbgScope *, 4> Scopes; // Scopes defined in scope.
SmallVector<DbgVariable *, 8> Variables;// Variables declared in scope.
SmallVector<DbgConcreteScope *, 8> ConcreteInsts;// Concrete insts of funcs.
public:
DbgScope(DbgScope *P, DIDescriptor D)
: Parent(P), Desc(D), StartLabelID(0), EndLabelID(0) {}
virtual ~DbgScope();
// Accessors.
DbgScope *getParent() const { return Parent; }
DIDescriptor getDesc() const { return Desc; }
unsigned getStartLabelID() const { return StartLabelID; }
unsigned getEndLabelID() const { return EndLabelID; }
SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
SmallVector<DbgVariable *, 8> &getVariables() { return Variables; }
SmallVector<DbgConcreteScope*,8> &getConcreteInsts() { return ConcreteInsts; }
void setStartLabelID(unsigned S) { StartLabelID = S; }
void setEndLabelID(unsigned E) { EndLabelID = E; }
/// AddScope - Add a scope to the scope.
///
void AddScope(DbgScope *S) { Scopes.push_back(S); }
/// AddVariable - Add a variable to the scope.
///
void AddVariable(DbgVariable *V) { Variables.push_back(V); }
/// AddConcreteInst - Add a concrete instance to the scope.
///
void AddConcreteInst(DbgConcreteScope *C) { ConcreteInsts.push_back(C); }
#ifndef NDEBUG
void dump() const;
#endif
};
#ifndef NDEBUG
void DbgScope::dump() const {
static unsigned IndentLevel = 0;
std::string Indent(IndentLevel, ' ');
cerr << Indent; Desc.dump();
cerr << " [" << StartLabelID << ", " << EndLabelID << "]\n";
IndentLevel += 2;
for (unsigned i = 0, e = Scopes.size(); i != e; ++i)
if (Scopes[i] != this)
Scopes[i]->dump();
IndentLevel -= 2;
}
#endif
//===----------------------------------------------------------------------===//
/// DbgConcreteScope - This class is used to track a scope that holds concrete
/// instance information.
///
class VISIBILITY_HIDDEN DbgConcreteScope : public DbgScope {
CompileUnit *Unit;
Loading
Loading full blame...