From: Devang Patel Date: Wed, 7 Oct 2009 22:04:08 +0000 (+0000) Subject: Extract subprogram and compile unit information from the debug info attached to an... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=beab41b874c3f15df848f9953e8e2c99182b1df8;p=oota-llvm.git Extract subprogram and compile unit information from the debug info attached to an instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83491 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/DebugInfo.h b/include/llvm/Analysis/DebugInfo.h index 53c5120de06..d494bf5f225 100644 --- a/include/llvm/Analysis/DebugInfo.h +++ b/include/llvm/Analysis/DebugInfo.h @@ -679,7 +679,10 @@ bool getLocationInfo(const Value *V, std::string &DisplayName, /// processType - Process DIType. void processType(DIType DT); - /// processSubprogram - Enumberate DISubprogram. + /// processLexicalBlock - Process DILexicalBlock. + void processLexicalBlock(DILexicalBlock LB); + + /// processSubprogram - Process DISubprogram. void processSubprogram(DISubprogram SP); /// processStopPoint - Process DbgStopPointInst. diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 1d6e3a6e44e..1436aa909e5 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -966,6 +966,12 @@ void DIFactory::InsertDeclare(Value *Storage, DIVariable D, /// processModule - Process entire module and collect debug info. void DebugInfoFinder::processModule(Module &M) { +#ifdef ATTACH_DEBUG_INFO_TO_AN_INSN + MetadataContext &TheMetadata = M.getContext().getMetadata(); + unsigned MDDbgKind = TheMetadata.getMDKind("dbg"); + if (!MDDbgKind) + return; +#endif for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI) for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE; @@ -980,6 +986,18 @@ void DebugInfoFinder::processModule(Module &M) { processRegionEnd(DRE); else if (DbgDeclareInst *DDI = dyn_cast(BI)) processDeclare(DDI); +#ifdef ATTACH_DEBUG_INFO_TO_AN_INSN + else if (MDNode *L = TheMetadata.getMD(MDDbgKind, BI)) { + DILocation Loc(L); + DIScope S(Loc.getScope().getNode()); + if (S.isCompileUnit()) + addCompileUnit(DICompileUnit(S.getNode())); + else if (S.isSubprogram()) + processSubprogram(DISubprogram(S.getNode())); + else if (S.isLexicalBlock()) + processLexicalBlock(DILexicalBlock(S.getNode())); + } +#endif } NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv"); @@ -1021,6 +1039,17 @@ void DebugInfoFinder::processType(DIType DT) { } } +/// processLexicalBlock +void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) { + if (LB.isNull()) + return; + DIScope Context = LB.getContext(); + if (Context.isLexicalBlock()) + return processLexicalBlock(DILexicalBlock(Context.getNode())); + else + return processSubprogram(DISubprogram(Context.getNode())); +} + /// processSubprogram - Process DISubprogram. void DebugInfoFinder::processSubprogram(DISubprogram SP) { if (SP.isNull())