Add support to record DbgScope as inlined scope.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84134 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2009-10-14 21:08:09 +00:00
parent d0c3832754
commit c90aefe95e
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,12 +1302,21 @@ 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;
if (InlinedAt) {
DILocation IL(InlinedAt);
assert (!IL.isNull() && "Invalid InlindAt location!");
DenseMap<MDNode *, DbgScope *>::iterator DSI =
DbgScopeMap.find(IL.getScope().getNode());
assert (DSI != DbgScopeMap.end() && "Unable to find InlineAt scope!");
Parent = DSI->second;
} else {
DIDescriptor Scope(N); DIDescriptor Scope(N);
if (Scope.isCompileUnit()) { if (Scope.isCompileUnit()) {
return NULL; return NULL;
@ -1309,16 +1324,17 @@ DbgScope *DwarfDebug::getDbgScope(MDNode *N, const MachineInstr *MI) {
DISubprogram SP(N); DISubprogram SP(N);
DIDescriptor ParentDesc = SP.getContext(); DIDescriptor ParentDesc = SP.getContext();
if (!ParentDesc.isNull() && !ParentDesc.isCompileUnit()) if (!ParentDesc.isNull() && !ParentDesc.isCompileUnit())
Parent = getDbgScope(ParentDesc.getNode(), MI); Parent = getDbgScope(ParentDesc.getNode(), MI, InlinedAt);
} else if (Scope.isLexicalBlock()) { } else if (Scope.isLexicalBlock()) {
DILexicalBlock DB(N); DILexicalBlock DB(N);
DIDescriptor ParentDesc = DB.getContext(); DIDescriptor ParentDesc = DB.getContext();
if (!ParentDesc.isNull()) if (!ParentDesc.isNull())
Parent = getDbgScope(ParentDesc.getNode(), MI); Parent = getDbgScope(ParentDesc.getNode(), MI, InlinedAt);
} else } else
assert (0 && "Unexpected scope info"); 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.
/// ///