/// updateInlinedAtInfo - Helper function used by fixupLineNumbers to /// recursively update InlinedAtEntry of a DebugLoc. static DebugLoc updateInlinedAtInfo(const DebugLoc &DL, const DebugLoc &InlinedAtDL, LLVMContext &Ctx) { if (MDNode *IA = DL.getInlinedAt(Ctx)) { DebugLoc NewInlinedAtDL = updateInlinedAtInfo(DebugLoc::getFromDILocation(IA), InlinedAtDL, Ctx); return DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(Ctx), NewInlinedAtDL.getAsMDNode(Ctx)); } return DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(Ctx), InlinedAtDL.getAsMDNode(Ctx)); }
static void print_source_line(raw_ostream &stream, DebugLoc Loc) { MDNode *inlinedAt = Loc.getInlinedAt(jl_LLVMContext); if (inlinedAt != NULL) { DebugLoc inlineloc = DebugLoc::getFromDILocation(inlinedAt); stream << "Source line: " << inlineloc.getLine() << "\n"; DILexicalBlockFile innerscope = DILexicalBlockFile(Loc.getScope(jl_LLVMContext)); stream << "Source line: [inline] " << innerscope.getFilename().str().c_str() << ':' << Loc.getLine() << "\n"; } else { stream << "Source line: " << Loc.getLine() << "\n"; } }
uint64_t Disassembler::getDebugOffset(const DebugLoc &Loc) const { MDNode *Scope = Loc.getScope(*MC->getContext()); if (Scope == NULL || Scope->getNumOperands() != 2) { errs() << "Error: Scope not set properly on Debug Offset.\n"; return 0; } if (ConstantInt *OffsetVal = dyn_cast<ConstantInt>(Scope->getOperand(1))) { return OffsetVal->getZExtValue(); } errs() << "Could not decode DebugOffset Value as a ConstantInt!\n"; return 0; }
void JITEmitter::processDebugLoc(DebugLoc DL, bool BeforePrintingInsn) { if (DL.isUnknown()) return; if (!BeforePrintingInsn) return; const LLVMContext &Context = EmissionDetails.MF->getFunction()->getContext(); if (DL.getScope(Context) != 0 && PrevDL != DL) { JITEvent_EmittedFunctionDetails::LineStart NextLine; NextLine.Address = getCurrentPCValue(); NextLine.Loc = DL; EmissionDetails.LineStarts.push_back(NextLine); } PrevDL = DL; }
/// processModule - Process entire module and collect debug info. void DebugInfoFinder::processModule(Module &M) { if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) addCompileUnit(DICompileUnit(CU_Nodes->getOperand(i))); 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; ++BI) { if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI)) processDeclare(DDI); DebugLoc Loc = BI->getDebugLoc(); if (Loc.isUnknown()) continue; LLVMContext &Ctx = BI->getContext(); DIDescriptor Scope(Loc.getScope(Ctx)); if (Scope.isCompileUnit()) addCompileUnit(DICompileUnit(Scope)); else if (Scope.isSubprogram()) processSubprogram(DISubprogram(Scope)); else if (Scope.isLexicalBlock()) processLexicalBlock(DILexicalBlock(Scope)); if (MDNode *IA = Loc.getInlinedAt(Ctx)) processLocation(DILocation(IA)); } if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv")) { for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { DIGlobalVariable DIG(cast<MDNode>(NMD->getOperand(i))); if (addGlobalVariable(DIG)) { if (DIG.getVersion() <= LLVMDebugVersion10) addCompileUnit(DIG.getCompileUnit()); processType(DIG.getType()); } } } if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp")) for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) processSubprogram(DISubprogram(NMD->getOperand(i))); }
void Matcher::processInst(Function *F) { for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; FI++) { /** Get each instruction's scope information **/ for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; BI++) { DebugLoc Loc = BI->getDebugLoc(); if (Loc.isUnknown()) continue; LLVMContext & Ctx = BI->getContext(); DIDescriptor Scope(Loc.getScope(Ctx)); if (Scope.isLexicalBlock()) { DILexicalBlock DILB(Scope); errs() << "Block :" << DILB.getLineNumber() << ", " << DILB.getColumnNumber() << "\n"; } } } }
static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, const LLVMContext &Ctx) { if (!DL.isUnknown()) { // Print source line info. DIScope Scope(DL.getScope(Ctx)); assert(Scope.isScope() && "Scope of a DebugLoc should be a DIScope."); // Omit the directory, because it's likely to be long and uninteresting. CommentOS << Scope.getFilename(); CommentOS << ':' << DL.getLine(); if (DL.getCol() != 0) CommentOS << ':' << DL.getCol(); DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx)); if (!InlinedAtDL.isUnknown()) { CommentOS << " @[ "; printDebugLoc(InlinedAtDL, CommentOS, Ctx); CommentOS << " ]"; } } }
static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, const LLVMContext &Ctx) { if (!DL) return; auto *Scope = cast<MDScope>(DL.getScope()); // Omit the directory, because it's likely to be long and uninteresting. CommentOS << Scope->getFilename(); CommentOS << ':' << DL.getLine(); if (DL.getCol() != 0) CommentOS << ':' << DL.getCol(); DebugLoc InlinedAtDL = DL.getInlinedAt(); if (!InlinedAtDL) return; CommentOS << " @[ "; printDebugLoc(InlinedAtDL, CommentOS, Ctx); CommentOS << " ]"; }
void WinCodeViewLineTables::maybeRecordLocation(DebugLoc DL, const MachineFunction *MF) { const MDNode *Scope = DL.getScope(); if (!Scope) return; StringRef Filename = getFullFilepath(Scope); // Skip this instruction if it has the same file:line as the previous one. assert(CurFn); if (!CurFn->Instrs.empty()) { const InstrInfoTy &LastInstr = InstrInfo[CurFn->Instrs.back()]; if (LastInstr.Filename == Filename && LastInstr.LineNumber == DL.getLine()) return; } FileNameRegistry.add(Filename); MCSymbol *MCL = Asm->MMI->getContext().CreateTempSymbol(); Asm->OutStreamer.EmitLabel(MCL); CurFn->Instrs.push_back(MCL); InstrInfo[MCL] = InstrInfoTy(Filename, DL.getLine()); }
static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, const LLVMContext &Ctx) { if (!DL) return; DIScope Scope(DL.getScope()); assert(Scope.isScope() && "Scope of a DebugLoc should be a DIScope."); // Omit the directory, because it's likely to be long and uninteresting. CommentOS << Scope.getFilename(); CommentOS << ':' << DL.getLine(); if (DL.getCol() != 0) CommentOS << ':' << DL.getCol(); DebugLoc InlinedAtDL = DL.getInlinedAt(); if (!InlinedAtDL) return; CommentOS << " @[ "; printDebugLoc(InlinedAtDL, CommentOS, Ctx); CommentOS << " ]"; }
void getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd, std::string &FileName) { LineBegin = -1; LineEnd = 0; for (const BasicBlock *BB : R->blocks()) for (const Instruction &Inst : *BB) { DebugLoc DL = Inst.getDebugLoc(); if (!DL) continue; auto *Scope = cast<DIScope>(DL.getScope()); if (FileName.empty()) FileName = Scope->getFilename(); unsigned NewLine = DL.getLine(); LineBegin = std::min(LineBegin, NewLine); LineEnd = std::max(LineEnd, NewLine); } }
void DSMonitor::watch(DSNodeHandle N, std::vector<Value*> VS, std::string M) { if (N.isNull() || N.getNode()->isCollapsedNode()) { unwatch(); return; } this->N = N; this->VS = VS; this->message = M; DSGraph *G = N.getNode()->getParentGraph(); caption = getCaption(N.getNode(), G); if (!VS.empty()) { Instruction *I = getInstruction(VS[0]); if (I && I->getMetadata("dbg")) { const DebugLoc DL = I->getDebugLoc(); auto *scope = cast<DIScope>(DL.getScope()); location = scope->getFilename().str() + ":" + std::to_string(DL.getLine()) + ":" + std::to_string(DL.getCol()); } } }
void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) { if (!MN->memoperands_empty()) { OS << "<"; OS << "Mem:"; for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(), e = MN->memoperands_end(); i != e; ++i) { OS << **i; if (llvm::next(i) != e) OS << " "; } OS << ">"; } } else if (const ShuffleVectorSDNode *SVN = dyn_cast<ShuffleVectorSDNode>(this)) { OS << "<"; for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) { int Idx = SVN->getMaskElt(i); if (i) OS << ","; if (Idx < 0) OS << "u"; else OS << Idx; } OS << ">"; } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) { OS << '<' << CSDN->getAPIntValue() << '>'; } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) { if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle) OS << '<' << CSDN->getValueAPF().convertToFloat() << '>'; else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble) OS << '<' << CSDN->getValueAPF().convertToDouble() << '>'; else { OS << "<APFloat("; CSDN->getValueAPF().bitcastToAPInt().dump(); OS << ")>"; } } else if (const GlobalAddressSDNode *GADN = dyn_cast<GlobalAddressSDNode>(this)) { int64_t offset = GADN->getOffset(); OS << '<'; WriteAsOperand(OS, GADN->getGlobal()); OS << '>'; if (offset > 0) OS << " + " << offset; else OS << " " << offset; if (unsigned int TF = GADN->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) { OS << "<" << FIDN->getIndex() << ">"; } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) { OS << "<" << JTDN->getIndex() << ">"; if (unsigned int TF = JTDN->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){ int offset = CP->getOffset(); if (CP->isMachineConstantPoolEntry()) OS << "<" << *CP->getMachineCPVal() << ">"; else OS << "<" << *CP->getConstVal() << ">"; if (offset > 0) OS << " + " << offset; else OS << " " << offset; if (unsigned int TF = CP->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) { OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">"; if (unsigned TF = TI->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) { OS << "<"; const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); if (LBB) OS << LBB->getName() << " "; OS << (const void*)BBDN->getBasicBlock() << ">"; } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) { OS << ' ' << PrintReg(R->getReg(), G ? G->getTarget().getRegisterInfo() :0); } else if (const ExternalSymbolSDNode *ES = dyn_cast<ExternalSymbolSDNode>(this)) { OS << "'" << ES->getSymbol() << "'"; if (unsigned int TF = ES->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) { if (M->getValue()) OS << "<" << M->getValue() << ">"; else OS << "<null>"; } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) { if (MD->getMD()) OS << "<" << MD->getMD() << ">"; else OS << "<null>"; } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) { OS << ":" << N->getVT().getEVTString(); } else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) { OS << "<" << *LD->getMemOperand(); bool doExt = true; switch (LD->getExtensionType()) { default: doExt = false; break; case ISD::EXTLOAD: OS << ", anyext"; break; case ISD::SEXTLOAD: OS << ", sext"; break; case ISD::ZEXTLOAD: OS << ", zext"; break; } if (doExt) OS << " from " << LD->getMemoryVT().getEVTString(); const char *AM = getIndexedModeName(LD->getAddressingMode()); if (*AM) OS << ", " << AM; OS << ">"; } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) { OS << "<" << *ST->getMemOperand(); if (ST->isTruncatingStore()) OS << ", trunc to " << ST->getMemoryVT().getEVTString(); const char *AM = getIndexedModeName(ST->getAddressingMode()); if (*AM) OS << ", " << AM; OS << ">"; } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) { OS << "<" << *M->getMemOperand() << ">"; } else if (const BlockAddressSDNode *BA = dyn_cast<BlockAddressSDNode>(this)) { OS << "<"; WriteAsOperand(OS, BA->getBlockAddress()->getFunction(), false); OS << ", "; WriteAsOperand(OS, BA->getBlockAddress()->getBasicBlock(), false); OS << ">"; if (unsigned int TF = BA->getTargetFlags()) OS << " [TF=" << TF << ']'; } if (G) if (unsigned Order = G->GetOrdering(this)) OS << " [ORD=" << Order << ']'; if (getNodeId() != -1) OS << " [ID=" << getNodeId() << ']'; DebugLoc dl = getDebugLoc(); if (G && !dl.isUnknown()) { DIScope Scope(dl.getScope(G->getMachineFunction().getFunction()->getContext())); OS << " dbg:"; // Omit the directory, since it's usually long and uninteresting. if (Scope.Verify()) OS << Scope.getFilename(); else OS << "<unknown>"; OS << ':' << dl.getLine(); if (dl.getCol() != 0) OS << ':' << dl.getCol(); } }