Add support to record DbgScope as inlined scope.

llvm-svn: 84134
This commit is contained in:
Devang Patel 2009-10-14 21:08:09 +00:00
parent 02f5588f62
commit 6875c5ebe4
2 changed files with 43 additions and 24 deletions

View File

@ -145,7 +145,10 @@ class DbgConcreteScope;
class VISIBILITY_HIDDEN DbgScope { class VISIBILITY_HIDDEN DbgScope {
DbgScope *Parent; // Parent to this scope. DbgScope *Parent; // Parent to this scope.
DIDescriptor Desc; // Debug info descriptor for scope. DIDescriptor Desc; // Debug info descriptor for scope.
// Either subprogram or block. // FIXME use WeakVH for Desc.
WeakVH InlinedAt; // If this scope represents inlined
// function body then this is the location
// where this body is inlined.
unsigned StartLabelID; // Label ID of the beginning of scope. unsigned StartLabelID; // Label ID of the beginning of scope.
unsigned EndLabelID; // Label ID of the end of scope. unsigned EndLabelID; // Label ID of the end of scope.
const MachineInstr *LastInsn; // Last instruction of this scope. const MachineInstr *LastInsn; // Last instruction of this scope.
@ -157,14 +160,17 @@ class VISIBILITY_HIDDEN DbgScope {
// Private state for dump() // Private state for dump()
mutable unsigned IndentLevel; mutable unsigned IndentLevel;
public: public:
DbgScope(DbgScope *P, DIDescriptor D) DbgScope(DbgScope *P, DIDescriptor D, MDNode *I = 0)
: Parent(P), Desc(D), StartLabelID(0), EndLabelID(0), LastInsn(0), : Parent(P), Desc(D), InlinedAt(I), StartLabelID(0), EndLabelID(0),
FirstInsn(0), IndentLevel(0) {} LastInsn(0), FirstInsn(0), IndentLevel(0) {}
virtual ~DbgScope(); virtual ~DbgScope();
// Accessors. // Accessors.
DbgScope *getParent() const { return Parent; } DbgScope *getParent() const { return Parent; }
DIDescriptor getDesc() const { return Desc; } DIDescriptor getDesc() const { return Desc; }
MDNode *getInlinedAt() const {
return dyn_cast_or_null<MDNode>(InlinedAt);
}
unsigned getStartLabelID() const { return StartLabelID; } unsigned getStartLabelID() const { return StartLabelID; }
unsigned getEndLabelID() const { return EndLabelID; } unsigned getEndLabelID() const { return EndLabelID; }
SmallVector<DbgScope *, 4> &getScopes() { return Scopes; } SmallVector<DbgScope *, 4> &getScopes() { return Scopes; }
@ -1296,29 +1302,39 @@ DIE *DwarfDebug::CreateDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit) {
/// getOrCreateScope - Returns the scope associated with the given descriptor. /// getOrCreateScope - Returns the scope associated with the given descriptor.
/// ///
DbgScope *DwarfDebug::getDbgScope(MDNode *N, const MachineInstr *MI) { DbgScope *DwarfDebug::getDbgScope(MDNode *N, const MachineInstr *MI,
MDNode *InlinedAt) {
DbgScope *&Slot = DbgScopeMap[N]; DbgScope *&Slot = DbgScopeMap[N];
if (Slot) return Slot; if (Slot) return Slot;
DbgScope *Parent = NULL; DbgScope *Parent = NULL;
DIDescriptor Scope(N); if (InlinedAt) {
if (Scope.isCompileUnit()) { DILocation IL(InlinedAt);
return NULL; assert (!IL.isNull() && "Invalid InlindAt location!");
} else if (Scope.isSubprogram()) { DenseMap<MDNode *, DbgScope *>::iterator DSI =
DISubprogram SP(N); DbgScopeMap.find(IL.getScope().getNode());
DIDescriptor ParentDesc = SP.getContext(); assert (DSI != DbgScopeMap.end() && "Unable to find InlineAt scope!");
if (!ParentDesc.isNull() && !ParentDesc.isCompileUnit()) Parent = DSI->second;
Parent = getDbgScope(ParentDesc.getNode(), MI); } else {
} else if (Scope.isLexicalBlock()) { DIDescriptor Scope(N);
DILexicalBlock DB(N); if (Scope.isCompileUnit()) {
DIDescriptor ParentDesc = DB.getContext(); return NULL;
if (!ParentDesc.isNull()) } else if (Scope.isSubprogram()) {
Parent = getDbgScope(ParentDesc.getNode(), MI); DISubprogram SP(N);
} else DIDescriptor ParentDesc = SP.getContext();
assert (0 && "Unexpected scope info"); if (!ParentDesc.isNull() && !ParentDesc.isCompileUnit())
Parent = getDbgScope(ParentDesc.getNode(), MI, InlinedAt);
} else if (Scope.isLexicalBlock()) {
DILexicalBlock DB(N);
DIDescriptor ParentDesc = DB.getContext();
if (!ParentDesc.isNull())
Parent = getDbgScope(ParentDesc.getNode(), MI, InlinedAt);
} else
assert (0 && "Unexpected scope info");
}
Slot = new DbgScope(Parent, DIDescriptor(N)); Slot = new DbgScope(Parent, DIDescriptor(N), InlinedAt);
Slot->setFirstInsn(MI); Slot->setFirstInsn(MI);
if (Parent) if (Parent)
@ -1795,7 +1811,10 @@ void DwarfDebug::CollectVariableInfo() {
DIVariable DV (Var); DIVariable DV (Var);
if (DV.isNull()) continue; if (DV.isNull()) continue;
unsigned VSlot = VI->second; unsigned VSlot = VI->second;
DbgScope *Scope = getDbgScope(DV.getContext().getNode(), NULL); DenseMap<MDNode *, DbgScope *>::iterator DSI =
DbgScopeMap.find(DV.getContext().getNode());
assert (DSI != DbgScopeMap.end() && "Unable to find variable scope!");
DbgScope *Scope = DSI->second;
Scope->AddVariable(new DbgVariable(DV, VSlot, false)); Scope->AddVariable(new DbgVariable(DV, VSlot, false));
} }
} }
@ -1849,7 +1868,7 @@ bool DwarfDebug::ExtractScopeInformation(MachineFunction *MF) {
// into a scope DIE at the end. // into a scope DIE at the end.
DIDescriptor D(DLT.Scope); DIDescriptor D(DLT.Scope);
if (!D.isCompileUnit()) { if (!D.isCompileUnit()) {
DbgScope *Scope = getDbgScope(DLT.Scope, MInsn); DbgScope *Scope = getDbgScope(DLT.Scope, MInsn, DLT.InlinedAtLoc);
Scope->setLastInsn(MInsn); Scope->setLastInsn(MInsn);
} }
} }

View File

@ -364,7 +364,7 @@ class VISIBILITY_HIDDEN DwarfDebug : public Dwarf {
/// getDbgScope - Returns the scope associated with the given descriptor. /// getDbgScope - Returns the scope associated with the given descriptor.
/// ///
DbgScope *getOrCreateScope(MDNode *N); DbgScope *getOrCreateScope(MDNode *N);
DbgScope *getDbgScope(MDNode *N, const MachineInstr *MI); DbgScope *getDbgScope(MDNode *N, const MachineInstr *MI, MDNode *InlinedAt);
/// ConstructDbgScope - Construct the components of a scope. /// ConstructDbgScope - Construct the components of a scope.
/// ///