void DebugInfoFinder::processModule(const Module &M) { InitializeTypeMap(M); if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) { for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(i)); addCompileUnit(CU); for (DIGlobalVariable DIG : CU->getGlobalVariables()) { if (addGlobalVariable(DIG)) { processScope(DIG.getContext()); processType(DIG.getType().resolve(TypeIdentifierMap)); } } for (auto *SP : CU->getSubprograms()) processSubprogram(SP); for (auto *ET : CU->getEnumTypes()) processType(ET); for (auto *RT : CU->getRetainedTypes()) processType(RT); for (DIImportedEntity Import : CU->getImportedEntities()) { DIDescriptor Entity = Import.getEntity().resolve(TypeIdentifierMap); if (auto *T = dyn_cast<MDType>(Entity)) processType(T); else if (auto *SP = dyn_cast<MDSubprogram>(Entity)) processSubprogram(SP); else if (auto *NS = dyn_cast<MDNamespace>(Entity)) processScope(NS->getScope()); } } } }
void Matcher::processSubprograms(DICompileUnit &DICU) { if (DICU.getRunTimeVersion() > LLVMDebugVersion10) { DIArray SPs = DICU.getSubprograms(); for (unsigned i = 0, e = SPs.getNumElements(); i != e; i++) { DISubprogram DISP(SPs.getElement(i)); DISPCopy Copy(DISP); if (Copy.name.empty() || Copy.filename.empty() || Copy.linenumber == 0) continue; Copy.lastline = ScopeInfoFinder::getLastLine(Copy.function); MySPs.push_back(Copy); } } }
llvm::DenseMap<const llvm::Function *, llvm::DISubprogram> llvm::makeSubprogramMap(const Module &M) { DenseMap<const Function *, DISubprogram> R; NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu"); if (!CU_Nodes) return R; for (MDNode *N : CU_Nodes->operands()) { DICompileUnit CUNode = cast<MDCompileUnit>(N); for (DISubprogram SP : CUNode->getSubprograms()) { if (Function *F = SP.getFunction()) R.insert(std::make_pair(F, SP)); } } return R; }