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
This commit is contained in:
Jeffrey Yasskin 2010-03-12 17:45:06 +00:00
parent 0ac5d2d7ff
commit 5c213dc78c
4 changed files with 59 additions and 37 deletions

View File

@ -279,6 +279,28 @@ static inline void array_pod_sort(IteratorTy Start, IteratorTy End,
qsort(&*Start, End-Start, sizeof(*Start), Compare); qsort(&*Start, End-Start, sizeof(*Start), Compare);
} }
//===----------------------------------------------------------------------===//
// Extra additions to <algorithm>
//===----------------------------------------------------------------------===//
/// For a container of pointers, deletes the pointers and then clears the
/// container.
template<typename Container>
void DeleteContainerPointers(Container &C) {
for (typename Container::iterator I = C.begin(), E = C.end(); I != E; ++I)
delete *I;
C.clear();
}
/// In a container of pairs (usually a map) whose second element is a pointer,
/// deletes the second elements and then clears the container.
template<typename Container>
void DeleteContainerSeconds(Container &C) {
for (typename Container::iterator I = C.begin(), E = C.end(); I != E; ++I)
delete I->second;
C.clear();
}
} // End llvm namespace } // End llvm namespace
#endif #endif

View File

@ -112,7 +112,6 @@ namespace llvm {
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
/// DIE - A structured debug information entry. Has an abbreviation which /// DIE - A structured debug information entry. Has an abbreviation which
/// describes it's organization. /// describes it's organization.
class CompileUnit;
class DIEValue; class DIEValue;
class DIE { class DIE {
@ -159,7 +158,6 @@ namespace llvm {
void setTag(unsigned Tag) { Abbrev.setTag(Tag); } void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
void setOffset(unsigned O) { Offset = O; } void setOffset(unsigned O) { Offset = O; }
void setSize(unsigned S) { Size = S; } void setSize(unsigned S) { Size = S; }
void setParent(DIE *P) { Parent = P; }
/// addValue - Add a value and attributes to a DIE. /// addValue - Add a value and attributes to a DIE.
/// ///
@ -185,7 +183,7 @@ namespace llvm {
} }
Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes); Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
Children.push_back(Child); Children.push_back(Child);
Child->setParent(this); Child->Parent = this;
} }
#ifndef NDEBUG #ifndef NDEBUG
@ -393,12 +391,11 @@ namespace llvm {
/// this class can also be used as a proxy for a debug information entry not /// this class can also be used as a proxy for a debug information entry not
/// yet defined (ie. types.) /// yet defined (ie. types.)
class DIEEntry : public DIEValue { class DIEEntry : public DIEValue {
DIE *Entry; DIE *const Entry;
public: public:
explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {} explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
DIE *getEntry() const { return Entry; } DIE *getEntry() const { return Entry; }
void setEntry(DIE *E) { Entry = E; }
/// EmitValue - Emit debug information entry offset. /// EmitValue - Emit debug information entry offset.
/// ///

View File

@ -25,6 +25,7 @@
#include "llvm/Target/TargetFrameInfo.h" #include "llvm/Target/TargetFrameInfo.h"
#include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
@ -52,7 +53,7 @@ class CompileUnit {
/// Die - Compile unit debug information entry. /// Die - Compile unit debug information entry.
/// ///
OwningPtr<DIE> CUDie; const OwningPtr<DIE> CUDie;
/// IndexTyDie - An anonymous type for index type. Owned by CUDie. /// IndexTyDie - An anonymous type for index type. Owned by CUDie.
DIE *IndexTyDie; DIE *IndexTyDie;
@ -147,16 +148,16 @@ public:
class DbgVariable { class DbgVariable {
DIVariable Var; // Variable Descriptor. DIVariable Var; // Variable Descriptor.
unsigned FrameIndex; // Variable frame index. unsigned FrameIndex; // Variable frame index.
DbgVariable *AbstractVar; // Abstract variable for this variable. DbgVariable *const AbstractVar; // Abstract variable for this variable.
DIE *TheDIE; DIE *TheDIE;
public: public:
DbgVariable(DIVariable V, unsigned I) // AbsVar may be NULL.
: Var(V), FrameIndex(I), AbstractVar(0), TheDIE(0) {} DbgVariable(DIVariable V, unsigned I, DbgVariable *AbsVar)
: Var(V), FrameIndex(I), AbstractVar(AbsVar), TheDIE(0) {}
// Accessors. // Accessors.
DIVariable getVariable() const { return Var; } DIVariable getVariable() const { return Var; }
unsigned getFrameIndex() const { return FrameIndex; } unsigned getFrameIndex() const { return FrameIndex; }
void setAbstractVariable(DbgVariable *V) { AbstractVar = V; }
DbgVariable *getAbstractVariable() const { return AbstractVar; } DbgVariable *getAbstractVariable() const { return AbstractVar; }
void setDIE(DIE *D) { TheDIE = D; } void setDIE(DIE *D) { TheDIE = D; }
DIE *getDIE() const { return TheDIE; } DIE *getDIE() const { return TheDIE; }
@ -175,8 +176,10 @@ class DbgScope {
MCSymbol *EndLabel; // Label ID of the end of scope. MCSymbol *EndLabel; // Label ID of the end of scope.
const MachineInstr *LastInsn; // Last instruction of this scope. const MachineInstr *LastInsn; // Last instruction of this scope.
const MachineInstr *FirstInsn; // First instruction of this scope. const MachineInstr *FirstInsn; // First instruction of this scope.
SmallVector<DbgScope *, 4> Scopes; // Scopes defined in scope. // Scopes defined in scope. Contents not owned.
SmallVector<DbgVariable *, 8> Variables;// Variables declared in scope. SmallVector<DbgScope *, 4> Scopes;
// Variables declared in scope. Contents owned.
SmallVector<DbgVariable *, 8> Variables;
// Private state for dump() // Private state for dump()
mutable unsigned IndentLevel; mutable unsigned IndentLevel;
@ -197,8 +200,8 @@ public:
MDNode *getScopeNode() const { return Desc.getNode(); } MDNode *getScopeNode() const { return Desc.getNode(); }
MCSymbol *getStartLabel() const { return StartLabel; } MCSymbol *getStartLabel() const { return StartLabel; }
MCSymbol *getEndLabel() const { return EndLabel; } MCSymbol *getEndLabel() const { return EndLabel; }
SmallVector<DbgScope *, 4> &getScopes() { return Scopes; } const SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
SmallVector<DbgVariable *, 8> &getVariables() { return Variables; } const SmallVector<DbgVariable *, 8> &getVariables() { return Variables; }
void setStartLabel(MCSymbol *S) { StartLabel = S; } void setStartLabel(MCSymbol *S) { StartLabel = S; }
void setEndLabel(MCSymbol *E) { EndLabel = E; } void setEndLabel(MCSymbol *E) { EndLabel = E; }
void setLastInsn(const MachineInstr *MI) { LastInsn = MI; } void setLastInsn(const MachineInstr *MI) { LastInsn = MI; }
@ -221,14 +224,14 @@ public:
assert (getFirstInsn() && "First instruction is missing!"); assert (getFirstInsn() && "First instruction is missing!");
// Use the end of last child scope as end of this scope. // Use the end of last child scope as end of this scope.
SmallVector<DbgScope *, 4> &Scopes = getScopes(); const SmallVector<DbgScope *, 4> &Scopes = getScopes();
const MachineInstr *LastInsn = getFirstInsn(); const MachineInstr *LastInsn = getFirstInsn();
unsigned LIndex = 0; unsigned LIndex = 0;
if (Scopes.empty()) { if (Scopes.empty()) {
assert (getLastInsn() && "Inner most scope does not have last insn!"); assert (getLastInsn() && "Inner most scope does not have last insn!");
return; return;
} }
for (SmallVector<DbgScope *, 4>::iterator SI = Scopes.begin(), for (SmallVector<DbgScope *, 4>::const_iterator SI = Scopes.begin(),
SE = Scopes.end(); SI != SE; ++SI) { SE = Scopes.end(); SI != SE; ++SI) {
DbgScope *DS = *SI; DbgScope *DS = *SI;
DS->fixInstructionMarkers(MIIndexMap); DS->fixInstructionMarkers(MIIndexMap);
@ -280,8 +283,6 @@ void DbgScope::dump() const {
#endif #endif
DbgScope::~DbgScope() { DbgScope::~DbgScope() {
for (unsigned i = 0, N = Scopes.size(); i < N; ++i)
delete Scopes[i];
for (unsigned j = 0, M = Variables.size(); j < M; ++j) for (unsigned j = 0, M = Variables.size(); j < M; ++j)
delete Variables[j]; delete Variables[j];
} }
@ -819,14 +820,13 @@ void DwarfDebug::addType(DIE *Entity, DIType Ty) {
return; return;
} }
// Set up proxy.
Entry = createDIEEntry();
ModuleCU->insertDIEEntry(Ty.getNode(), Entry);
// Construct type. // Construct type.
DIE *Buffer = getOrCreateTypeDIE(Ty); DIE *Buffer = getOrCreateTypeDIE(Ty);
Entry->setEntry(Buffer); // Set up proxy.
Entry = createDIEEntry(Buffer);
ModuleCU->insertDIEEntry(Ty.getNode(), Entry);
Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry); Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
} }
@ -1549,7 +1549,7 @@ DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) {
} }
// Add variables to scope. // Add variables to scope.
SmallVector<DbgVariable *, 8> &Variables = Scope->getVariables(); const SmallVector<DbgVariable *, 8> &Variables = Scope->getVariables();
for (unsigned i = 0, N = Variables.size(); i < N; ++i) { for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
DIE *VariableDIE = constructVariableDIE(Variables[i], Scope); DIE *VariableDIE = constructVariableDIE(Variables[i], Scope);
if (VariableDIE) if (VariableDIE)
@ -1557,7 +1557,7 @@ DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) {
} }
// Add nested scopes. // Add nested scopes.
SmallVector<DbgScope *, 4> &Scopes = Scope->getScopes(); const SmallVector<DbgScope *, 4> &Scopes = Scope->getScopes();
for (unsigned j = 0, M = Scopes.size(); j < M; ++j) { for (unsigned j = 0, M = Scopes.size(); j < M; ++j) {
// Define the Scope debug information entry. // Define the Scope debug information entry.
DIE *NestedDIE = constructScopeDIE(Scopes[j]); DIE *NestedDIE = constructScopeDIE(Scopes[j]);
@ -1917,7 +1917,8 @@ DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var,
if (!Scope) if (!Scope)
return NULL; return NULL;
AbsDbgVariable = new DbgVariable(Var, FrameIdx); AbsDbgVariable = new DbgVariable(Var, FrameIdx,
NULL /* No more-abstract variable*/);
Scope->addVariable(AbsDbgVariable); Scope->addVariable(AbsDbgVariable);
AbstractVariables[Var.getNode()] = AbsDbgVariable; AbstractVariables[Var.getNode()] = AbsDbgVariable;
return AbsDbgVariable; return AbsDbgVariable;
@ -1944,11 +1945,9 @@ void DwarfDebug::collectVariableInfo() {
if (!Scope) if (!Scope)
continue; continue;
DbgVariable *RegVar = new DbgVariable(DV, VP.first); DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.first, ScopeLoc);
DbgVariable *RegVar = new DbgVariable(DV, VP.first, AbsDbgVariable);
Scope->addVariable(RegVar); Scope->addVariable(RegVar);
if (DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.first,
ScopeLoc))
RegVar->setAbstractVariable(AbsDbgVariable);
} }
} }
@ -2067,9 +2066,9 @@ bool DwarfDebug::extractScopeInformation() {
while (!WorkList.empty()) { while (!WorkList.empty()) {
DbgScope *S = WorkList.back(); WorkList.pop_back(); DbgScope *S = WorkList.back(); WorkList.pop_back();
SmallVector<DbgScope *, 4> &Children = S->getScopes(); const SmallVector<DbgScope *, 4> &Children = S->getScopes();
if (!Children.empty()) if (!Children.empty())
for (SmallVector<DbgScope *, 4>::iterator SI = Children.begin(), for (SmallVector<DbgScope *, 4>::const_iterator SI = Children.begin(),
SE = Children.end(); SI != SE; ++SI) SE = Children.end(); SI != SE; ++SI)
WorkList.push_back(*SI); WorkList.push_back(*SI);
@ -2174,11 +2173,13 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
// Clear debug info // Clear debug info
CurrentFnDbgScope = NULL; CurrentFnDbgScope = NULL;
DbgScopeMap.clear(); DeleteContainerSeconds(DbgScopeMap);
DbgScopeBeginMap.clear(); DbgScopeBeginMap.clear();
DbgScopeEndMap.clear(); DbgScopeEndMap.clear();
ConcreteScopes.clear(); ConcreteScopes.clear();
DeleteContainerSeconds(AbstractScopes);
AbstractScopesList.clear(); AbstractScopesList.clear();
AbstractVariables.clear();
Lines.clear(); Lines.clear();
if (TimePassesIsEnabled) if (TimePassesIsEnabled)

View File

@ -126,7 +126,8 @@ class DwarfDebug : public DwarfPrinter {
// //
DbgScope *CurrentFnDbgScope; DbgScope *CurrentFnDbgScope;
/// DbgScopeMap - Tracks the scopes in the current function. /// DbgScopeMap - Tracks the scopes in the current function. Owns the
/// contained DbgScope*s.
/// ///
DenseMap<MDNode *, DbgScope *> DbgScopeMap; DenseMap<MDNode *, DbgScope *> DbgScopeMap;
@ -135,11 +136,12 @@ class DwarfDebug : public DwarfPrinter {
DenseMap<MDNode *, DbgScope *> ConcreteScopes; DenseMap<MDNode *, DbgScope *> ConcreteScopes;
/// AbstractScopes - Tracks the abstract scopes a module. These scopes are /// AbstractScopes - Tracks the abstract scopes a module. These scopes are
/// not included DbgScopeMap. /// not included DbgScopeMap. AbstractScopes owns its DbgScope*s.
DenseMap<MDNode *, DbgScope *> AbstractScopes; DenseMap<MDNode *, DbgScope *> AbstractScopes;
SmallVector<DbgScope *, 4>AbstractScopesList; SmallVector<DbgScope *, 4>AbstractScopesList;
/// AbstractVariables - Collection on abstract variables. /// AbstractVariables - Collection on abstract variables. Owned by the
/// DbgScopes in AbstractScopes.
DenseMap<MDNode *, DbgVariable *> AbstractVariables; DenseMap<MDNode *, DbgVariable *> AbstractVariables;
/// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked /// InliendSubprogramDIEs - Collection of subprgram DIEs that are marked
@ -225,7 +227,7 @@ class DwarfDebug : public DwarfPrinter {
/// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
/// information entry. /// information entry.
DIEEntry *createDIEEntry(DIE *Entry = NULL); DIEEntry *createDIEEntry(DIE *Entry);
/// addUInt - Add an unsigned integer attribute data and value. /// addUInt - Add an unsigned integer attribute data and value.
/// ///