llvm.org GIT mirror llvm / 5c213dc
Free DbgScopes in DwarfDebug::endFunction(). Also increased the const-ness of several fields to make it easier to figure out where bugs might be creeping in. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98358 91177308-0d34-0410-b5e6-96231b3b80d8 Jeffrey Yasskin 10 years ago
4 changed file(s) with 59 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
278278 qsort(&*Start, End-Start, sizeof(*Start), Compare);
279279 }
280280
281 //===----------------------------------------------------------------------===//
282 // Extra additions to
283 //===----------------------------------------------------------------------===//
284
285 /// For a container of pointers, deletes the pointers and then clears the
286 /// container.
287 template
288 void DeleteContainerPointers(Container &C) {
289 for (typename Container::iterator I = C.begin(), E = C.end(); I != E; ++I)
290 delete *I;
291 C.clear();
292 }
293
294 /// In a container of pairs (usually a map) whose second element is a pointer,
295 /// deletes the second elements and then clears the container.
296 template
297 void DeleteContainerSeconds(Container &C) {
298 for (typename Container::iterator I = C.begin(), E = C.end(); I != E; ++I)
299 delete I->second;
300 C.clear();
301 }
302
281303 } // End llvm namespace
282304
283305 #endif
111111 //===--------------------------------------------------------------------===//
112112 /// DIE - A structured debug information entry. Has an abbreviation which
113113 /// describes it's organization.
114 class CompileUnit;
115114 class DIEValue;
116115
117116 class DIE {
158157 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
159158 void setOffset(unsigned O) { Offset = O; }
160159 void setSize(unsigned S) { Size = S; }
161 void setParent(DIE *P) { Parent = P; }
162160
163161 /// addValue - Add a value and attributes to a DIE.
164162 ///
184182 }
185183 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
186184 Children.push_back(Child);
187 Child->setParent(this);
185 Child->Parent = this;
188186 }
189187
190188 #ifndef NDEBUG
392390 /// this class can also be used as a proxy for a debug information entry not
393391 /// yet defined (ie. types.)
394392 class DIEEntry : public DIEValue {
395 DIE *Entry;
393 DIE *const Entry;
396394 public:
397395 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
398396
399397 DIE *getEntry() const { return Entry; }
400 void setEntry(DIE *E) { Entry = E; }
401398
402399 /// EmitValue - Emit debug information entry offset.
403400 ///
2424 #include "llvm/Target/TargetFrameInfo.h"
2525 #include "llvm/Target/TargetLoweringObjectFile.h"
2626 #include "llvm/Target/TargetRegisterInfo.h"
27 #include "llvm/ADT/STLExtras.h"
2728 #include "llvm/ADT/StringExtras.h"
2829 #include "llvm/Support/Debug.h"
2930 #include "llvm/Support/ErrorHandling.h"
5152
5253 /// Die - Compile unit debug information entry.
5354 ///
54 OwningPtr CUDie;
55 const OwningPtr CUDie;
5556
5657 /// IndexTyDie - An anonymous type for index type. Owned by CUDie.
5758 DIE *IndexTyDie;
146147 class DbgVariable {
147148 DIVariable Var; // Variable Descriptor.
148149 unsigned FrameIndex; // Variable frame index.
149 DbgVariable *AbstractVar; // Abstract variable for this variable.
150 DbgVariable *const AbstractVar; // Abstract variable for this variable.
150151 DIE *TheDIE;
151152 public:
152 DbgVariable(DIVariable V, unsigned I)
153 : Var(V), FrameIndex(I), AbstractVar(0), TheDIE(0) {}
153 // AbsVar may be NULL.
154 DbgVariable(DIVariable V, unsigned I, DbgVariable *AbsVar)
155 : Var(V), FrameIndex(I), AbstractVar(AbsVar), TheDIE(0) {}
154156
155157 // Accessors.
156158 DIVariable getVariable() const { return Var; }
157159 unsigned getFrameIndex() const { return FrameIndex; }
158 void setAbstractVariable(DbgVariable *V) { AbstractVar = V; }
159160 DbgVariable *getAbstractVariable() const { return AbstractVar; }
160161 void setDIE(DIE *D) { TheDIE = D; }
161162 DIE *getDIE() const { return TheDIE; }
174175 MCSymbol *EndLabel; // Label ID of the end of scope.
175176 const MachineInstr *LastInsn; // Last instruction of this scope.
176177 const MachineInstr *FirstInsn; // First instruction of this scope.
177 SmallVector Scopes; // Scopes defined in scope.
178 SmallVector Variables;// Variables declared in scope.
178 // Scopes defined in scope. Contents not owned.
179 SmallVector Scopes;
180 // Variables declared in scope. Contents owned.
181 SmallVector Variables;
179182
180183 // Private state for dump()
181184 mutable unsigned IndentLevel;
196199 MDNode *getScopeNode() const { return Desc.getNode(); }
197200 MCSymbol *getStartLabel() const { return StartLabel; }
198201 MCSymbol *getEndLabel() const { return EndLabel; }
199 SmallVector &getScopes() { return Scopes; }
200 SmallVector &getVariables() { return Variables; }
202 const SmallVector &getScopes() { return Scopes; }
203 const SmallVector &getVariables() { return Variables; }
201204 void setStartLabel(MCSymbol *S) { StartLabel = S; }
202205 void setEndLabel(MCSymbol *E) { EndLabel = E; }
203206 void setLastInsn(const MachineInstr *MI) { LastInsn = MI; }
220223 assert (getFirstInsn() && "First instruction is missing!");
221224
222225 // Use the end of last child scope as end of this scope.
223 SmallVector &Scopes = getScopes();
226 const SmallVector &Scopes = getScopes();
224227 const MachineInstr *LastInsn = getFirstInsn();
225228 unsigned LIndex = 0;
226229 if (Scopes.empty()) {
227230 assert (getLastInsn() && "Inner most scope does not have last insn!");
228231 return;
229232 }
230 for (SmallVector::iterator SI = Scopes.begin(),
233 for (SmallVector::const_iterator SI = Scopes.begin(),
231234 SE = Scopes.end(); SI != SE; ++SI) {
232235 DbgScope *DS = *SI;
233236 DS->fixInstructionMarkers(MIIndexMap);
279282 #endif
280283
281284 DbgScope::~DbgScope() {
282 for (unsigned i = 0, N = Scopes.size(); i < N; ++i)
283 delete Scopes[i];
284285 for (unsigned j = 0, M = Variables.size(); j < M; ++j)
285286 delete Variables[j];
286287 }
818819 return;
819820 }
820821
821 // Set up proxy.
822 Entry = createDIEEntry();
823 ModuleCU->insertDIEEntry(Ty.getNode(), Entry);
824
825822 // Construct type.
826823 DIE *Buffer = getOrCreateTypeDIE(Ty);
827824
828 Entry->setEntry(Buffer);
825 // Set up proxy.
826 Entry = createDIEEntry(Buffer);
827 ModuleCU->insertDIEEntry(Ty.getNode(), Entry);
828
829829 Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
830830 }
831831
15481548 }
15491549
15501550 // Add variables to scope.
1551 SmallVector &Variables = Scope->getVariables();
1551 const SmallVector &Variables = Scope->getVariables();
15521552 for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
15531553 DIE *VariableDIE = constructVariableDIE(Variables[i], Scope);
15541554 if (VariableDIE)
15561556 }
15571557
15581558 // Add nested scopes.
1559 SmallVector &Scopes = Scope->getScopes();
1559 const SmallVector &Scopes = Scope->getScopes();
15601560 for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
15611561 // Define the Scope debug information entry.
15621562 DIE *NestedDIE = constructScopeDIE(Scopes[j]);
19161916 if (!Scope)
19171917 return NULL;
19181918
1919 AbsDbgVariable = new DbgVariable(Var, FrameIdx);
1919 AbsDbgVariable = new DbgVariable(Var, FrameIdx,
1920 NULL /* No more-abstract variable*/);
19201921 Scope->addVariable(AbsDbgVariable);
19211922 AbstractVariables[Var.getNode()] = AbsDbgVariable;
19221923 return AbsDbgVariable;
19431944 if (!Scope)
19441945 continue;
19451946
1946 DbgVariable *RegVar = new DbgVariable(DV, VP.first);
1947 DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.first, ScopeLoc);
1948 DbgVariable *RegVar = new DbgVariable(DV, VP.first, AbsDbgVariable);
19471949 Scope->addVariable(RegVar);
1948 if (DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.first,
1949 ScopeLoc))
1950 RegVar->setAbstractVariable(AbsDbgVariable);
19511950 }
19521951 }
19531952
20662065 while (!WorkList.empty()) {
20672066 DbgScope *S = WorkList.back(); WorkList.pop_back();
20682067
2069 SmallVector &Children = S->getScopes();
2068 const SmallVector &Children = S->getScopes();
20702069 if (!Children.empty())
2071 for (SmallVector::iterator SI = Children.begin(),
2070 for (SmallVector::const_iterator SI = Children.begin(),
20722071 SE = Children.end(); SI != SE; ++SI)
20732072 WorkList.push_back(*SI);
20742073
21732172
21742173 // Clear debug info
21752174 CurrentFnDbgScope = NULL;
2176 DbgScopeMap.clear();
2175 DeleteContainerSeconds(DbgScopeMap);
21772176 DbgScopeBeginMap.clear();
21782177 DbgScopeEndMap.clear();
21792178 ConcreteScopes.clear();
2179 DeleteContainerSeconds(AbstractScopes);
21802180 AbstractScopesList.clear();
2181 AbstractVariables.clear();
21812182 Lines.clear();
21822183
21832184 if (TimePassesIsEnabled)
125125 //
126126 DbgScope *CurrentFnDbgScope;
127127
128 /// DbgScopeMap - Tracks the scopes in the current function.
128 /// DbgScopeMap - Tracks the scopes in the current function. Owns the
129 /// contained DbgScope*s.
129130 ///
130131 DenseMap DbgScopeMap;
131132
134135 DenseMap ConcreteScopes;
135136
136137 /// AbstractScopes - Tracks the abstract scopes a module. These scopes are
137 /// not included DbgScopeMap.
138 /// not included DbgScopeMap. AbstractScopes owns its DbgScope*s.
138139 DenseMap AbstractScopes;
139140 SmallVectorAbstractScopesList;
140141
141 /// AbstractVariables - Collection on abstract variables.
142 /// AbstractVariables - Collection on abstract variables. Owned by the
143 /// DbgScopes in AbstractScopes.
142144 DenseMap AbstractVariables;
143145
144146 /// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked
224226
225227 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
226228 /// information entry.
227 DIEEntry *createDIEEntry(DIE *Entry = NULL);
229 DIEEntry *createDIEEntry(DIE *Entry);
228230
229231 /// addUInt - Add an unsigned integer attribute data and value.
230232 ///