diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -1006,16 +1006,18 @@ void BTFDebug::constructLineInfo(const DIFile *File, MCSymbol *Label, uint32_t Line, uint32_t Column) { - std::string FileName = populateFileContent(File); BTFLineInfo LineInfo; LineInfo.Label = Label; - LineInfo.FileNameOff = addString(FileName); - // If file content is not available, let LineOff = 0. - if (Line < FileContent[FileName].size()) - LineInfo.LineOff = addString(FileContent[FileName][Line]); - else - LineInfo.LineOff = 0; + LineInfo.FileNameOff = 0; + LineInfo.LineOff = 0; + if (File) { + std::string FileName = populateFileContent(File); + LineInfo.FileNameOff = addString(FileName); + // If file content is not available, let LineOff = 0. + if (Line < FileContent[FileName].size()) + LineInfo.LineOff = addString(FileContent[FileName][Line]); + } LineInfo.LineNum = Line; LineInfo.ColumnNum = Column; LineInfoTable[SecNameOff].push_back(LineInfo); @@ -1372,9 +1374,15 @@ // This instruction will be skipped, no LineInfo has // been generated, construct one based on function signature. if (LineInfoGenerated == false) { - auto *S = MI->getMF()->getFunction().getSubprogram(); + const Function &F = MI->getMF()->getFunction(); + auto *S = F.getSubprogram(); MCSymbol *FuncLabel = Asm->getFunctionBegin(); - constructLineInfo(S->getFile(), FuncLabel, S->getLine(), 0); + // The callee may not have been compiled with debug info. + if (S) { + constructLineInfo(S->getFile(), FuncLabel, S->getLine(), 0); + } else { + constructLineInfo(nullptr, FuncLabel, 0, 0); + } LineInfoGenerated = true; }