Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/include/llvm/DebugInfo/BTF/BTFContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class BTFContext final : public DIContext {
// BTF is no DWARF, so ignore this operation for now.
}

DILineInfo getLineInfoForAddress(
std::optional<DILineInfo> getLineInfoForAddress(
object::SectionedAddress Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;

DILineInfo
std::optional<DILineInfo>
getLineInfoForDataAddress(object::SectionedAddress Address) override;

DILineInfoTable getLineInfoForAddressRange(
Expand Down
6 changes: 4 additions & 2 deletions llvm/include/llvm/DebugInfo/DIContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,12 @@ class DIContext {
return true;
}

virtual DILineInfo getLineInfoForAddress(
// For getLineInfoForAddress and getLineInfoForDataAddress, std::nullopt is
// returned when debug info is missing for the given address.
virtual std::optional<DILineInfo> getLineInfoForAddress(
object::SectionedAddress Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
virtual DILineInfo
virtual std::optional<DILineInfo>
getLineInfoForDataAddress(object::SectionedAddress Address) = 0;
virtual DILineInfoTable getLineInfoForAddressRange(
object::SectionedAddress Address, uint64_t Size,
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ class DWARFContext : public DIContext {
/// executable's debug info.
DIEsForAddress getDIEsForAddress(uint64_t Address, bool CheckDWO = false);

DILineInfo getLineInfoForAddress(
std::optional<DILineInfo> getLineInfoForAddress(
object::SectionedAddress Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
DILineInfo
std::optional<DILineInfo>
getLineInfoForDataAddress(object::SectionedAddress Address) override;
DILineInfoTable getLineInfoForAddressRange(
object::SectionedAddress Address, uint64_t Size,
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/DebugInfo/PDB/PDBContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ namespace pdb {

void dump(raw_ostream &OS, DIDumpOptions DIDumpOpts) override;

DILineInfo getLineInfoForAddress(
std::optional<DILineInfo> getLineInfoForAddress(
object::SectionedAddress Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
DILineInfo
std::optional<DILineInfo>
getLineInfoForDataAddress(object::SectionedAddress Address) override;
DILineInfoTable getLineInfoForAddressRange(
object::SectionedAddress Address, uint64_t Size,
Expand Down
12 changes: 7 additions & 5 deletions llvm/lib/DebugInfo/BTF/BTFContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ using namespace llvm;
using object::ObjectFile;
using object::SectionedAddress;

DILineInfo BTFContext::getLineInfoForAddress(SectionedAddress Address,
DILineInfoSpecifier Specifier) {
std::optional<DILineInfo>
BTFContext::getLineInfoForAddress(SectionedAddress Address,
DILineInfoSpecifier Specifier) {
const BTF::BPFLineInfo *LineInfo = BTF.findLineInfo(Address);
DILineInfo Result;
if (!LineInfo)
return Result;
return std::nullopt;

Result.LineSource = BTF.findString(LineInfo->LineOff);
Result.FileName = BTF.findString(LineInfo->FileNameOff);
Expand All @@ -34,9 +35,10 @@ DILineInfo BTFContext::getLineInfoForAddress(SectionedAddress Address,
return Result;
}

DILineInfo BTFContext::getLineInfoForDataAddress(SectionedAddress Address) {
std::optional<DILineInfo>
BTFContext::getLineInfoForDataAddress(SectionedAddress Address) {
// BTF does not convey such information.
return {};
return std::nullopt;
}

DILineInfoTable
Expand Down
24 changes: 14 additions & 10 deletions llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,40 +1730,44 @@ DWARFContext::getLocalsForAddress(object::SectionedAddress Address) {
return Result;
}

DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
DILineInfoSpecifier Spec) {
DILineInfo Result;
std::optional<DILineInfo>
DWARFContext::getLineInfoForAddress(object::SectionedAddress Address,
DILineInfoSpecifier Spec) {
DWARFCompileUnit *CU = getCompileUnitForCodeAddress(Address.Address);
if (!CU)
return Result;
return std::nullopt;

getFunctionNameAndStartLineForAddress(
DILineInfo Result;
bool HasDebugInfoForAddress = getFunctionNameAndStartLineForAddress(
CU, Address.Address, Spec.FNKind, Spec.FLIKind, Result.FunctionName,
Result.StartFileName, Result.StartLine, Result.StartAddress);
if (Spec.FLIKind != FileLineInfoKind::None) {
if (const DWARFLineTable *LineTable = getLineTableForUnit(CU)) {
LineTable->getFileLineInfoForAddress(
HasDebugInfoForAddress |= LineTable->getFileLineInfoForAddress(
{Address.Address, Address.SectionIndex}, Spec.ApproximateLine,
CU->getCompilationDir(), Spec.FLIKind, Result);
}
}
if (!HasDebugInfoForAddress)
return std::nullopt;

return Result;
}

DILineInfo
std::optional<DILineInfo>
DWARFContext::getLineInfoForDataAddress(object::SectionedAddress Address) {
DILineInfo Result;
DWARFCompileUnit *CU = getCompileUnitForDataAddress(Address.Address);
if (!CU)
return Result;
return std::nullopt;

if (DWARFDie Die = CU->getVariableForAddress(Address.Address)) {
DILineInfo Result;
Result.FileName = Die.getDeclFile(FileLineInfoKind::AbsoluteFilePath);
Result.Line = Die.getDeclLine();
return Result;
}

return Result;
return std::nullopt;
}

DILineInfoTable DWARFContext::getLineInfoForAddressRange(
Expand Down
7 changes: 5 additions & 2 deletions llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,11 @@ llvm::Error DwarfTransformer::verify(StringRef GsymPath,
DICtx.getInliningInfoForAddress(SectAddr, DLIS);
uint32_t NumDwarfInlineInfos = DwarfInlineInfos.getNumberOfFrames();
if (NumDwarfInlineInfos == 0) {
DwarfInlineInfos.addFrame(
DICtx.getLineInfoForAddress(SectAddr, DLIS));
if (std::optional<DILineInfo> DwarfLineInfo =
DICtx.getLineInfoForAddress(SectAddr, DLIS))
DwarfInlineInfos.addFrame(*DwarfLineInfo);
else
DwarfInlineInfos.addFrame(DILineInfo());
}

// Check for 1 entry that has no file and line info
Expand Down
27 changes: 17 additions & 10 deletions llvm/lib/DebugInfo/PDB/PDBContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ PDBContext::PDBContext(const COFFObjectFile &Object,

void PDBContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts){}

DILineInfo PDBContext::getLineInfoForAddress(object::SectionedAddress Address,
DILineInfoSpecifier Specifier) {
std::optional<DILineInfo>
PDBContext::getLineInfoForAddress(object::SectionedAddress Address,
DILineInfoSpecifier Specifier) {
DILineInfo Result;
Result.FunctionName = getFunctionName(Address.Address, Specifier.FNKind);

Expand Down Expand Up @@ -64,11 +65,11 @@ DILineInfo PDBContext::getLineInfoForAddress(object::SectionedAddress Address,
return Result;
}

DILineInfo
std::optional<DILineInfo>
PDBContext::getLineInfoForDataAddress(object::SectionedAddress Address) {
// Unimplemented. S_GDATA and S_LDATA in CodeView (used to describe global
// variables) aren't capable of carrying line information.
return DILineInfo();
return std::nullopt;
}

DILineInfoTable
Expand All @@ -84,9 +85,11 @@ PDBContext::getLineInfoForAddressRange(object::SectionedAddress Address,
return Table;

while (auto LineInfo = LineNumbers->getNext()) {
DILineInfo LineEntry = getLineInfoForAddress(
std::optional<DILineInfo> LineEntry = getLineInfoForAddress(
{LineInfo->getVirtualAddress(), Address.SectionIndex}, Specifier);
Table.push_back(std::make_pair(LineInfo->getVirtualAddress(), LineEntry));
if (LineEntry)
Table.push_back(
std::make_pair(LineInfo->getVirtualAddress(), *LineEntry));
}
return Table;
}
Expand All @@ -95,19 +98,22 @@ DIInliningInfo
PDBContext::getInliningInfoForAddress(object::SectionedAddress Address,
DILineInfoSpecifier Specifier) {
DIInliningInfo InlineInfo;
DILineInfo CurrentLine = getLineInfoForAddress(Address, Specifier);
std::optional<DILineInfo> CurrentLine =
getLineInfoForAddress(Address, Specifier);

// Find the function at this address.
std::unique_ptr<PDBSymbol> ParentFunc =
Session->findSymbolByAddress(Address.Address, PDB_SymType::Function);
if (!ParentFunc) {
InlineInfo.addFrame(CurrentLine);
if (CurrentLine)
InlineInfo.addFrame(*CurrentLine);
return InlineInfo;
}

auto Frames = ParentFunc->findInlineFramesByVA(Address.Address);
if (!Frames || Frames->getChildCount() == 0) {
InlineInfo.addFrame(CurrentLine);
if (CurrentLine)
InlineInfo.addFrame(*CurrentLine);
return InlineInfo;
}

Expand All @@ -131,7 +137,8 @@ PDBContext::getInliningInfoForAddress(object::SectionedAddress Address,
InlineInfo.addFrame(LineInfo);
}

InlineInfo.addFrame(CurrentLine);
if (CurrentLine)
InlineInfo.addFrame(*CurrentLine);
return InlineInfo;
}

Expand Down
16 changes: 10 additions & 6 deletions llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,11 @@ SymbolizableObjectFile::symbolizeCode(object::SectionedAddress ModuleOffset,
if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
ModuleOffset.SectionIndex =
getModuleSectionIndexForAddress(ModuleOffset.Address);
DILineInfo LineInfo =
DebugInfoContext->getLineInfoForAddress(ModuleOffset, LineInfoSpecifier);
DILineInfo LineInfo;
if (std::optional<DILineInfo> DBGLineInfo =
DebugInfoContext->getLineInfoForAddress(ModuleOffset,
LineInfoSpecifier))
LineInfo = *DBGLineInfo;

// Override function name from symbol table if necessary.
if (shouldOverrideWithSymbolTable(LineInfoSpecifier.FNKind, UseSymbolTable)) {
Expand Down Expand Up @@ -334,10 +337,11 @@ DIGlobal SymbolizableObjectFile::symbolizeData(
Res.DeclFile = FileName;

// Try and get a better filename:lineno pair from the debuginfo, if present.
DILineInfo DL = DebugInfoContext->getLineInfoForDataAddress(ModuleOffset);
if (DL.Line != 0) {
Res.DeclFile = DL.FileName;
Res.DeclLine = DL.Line;
std::optional<DILineInfo> DL =
DebugInfoContext->getLineInfoForDataAddress(ModuleOffset);
if (DL && DL->Line != 0) {
Res.DeclFile = DL->FileName;
Res.DeclLine = DL->Line;
}
return Res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ static VTuneMethodBatch getMethodBatch(LinkGraph &G, bool EmitDebugInfo) {
SAddr, Sym->getSize(),
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
Method.SourceFileSI = Batch.Strings.size();
Batch.Strings.push_back(DC->getLineInfoForAddress(SAddr).FileName);
if (std::optional<DILineInfo> LineInfo = DC->getLineInfoForAddress(SAddr))
Batch.Strings.push_back(LineInfo->FileName);
else
Batch.Strings.push_back(DILineInfo::BadString);
for (auto &LInfo : LinesInfo) {
Method.LineTable.push_back(
std::pair<unsigned, unsigned>{/*unsigned*/ Sym->getOffset(),
Expand Down
6 changes: 4 additions & 2 deletions llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,11 @@ static bool lookup(ObjectFile &Obj, DWARFContext &DICtx, uint64_t Address,

// TODO: it is neccessary to set proper SectionIndex here.
// object::SectionedAddress::UndefSection works for only absolute addresses.
if (DILineInfo LineInfo = DICtx.getLineInfoForAddress(
DILineInfo LineInfo;
if (std::optional<DILineInfo> DBGLineInfo = DICtx.getLineInfoForAddress(
{Lookup, object::SectionedAddress::UndefSection}))
LineInfo.dump(OS);
LineInfo = *DBGLineInfo;
LineInfo.dump(OS);

return true;
}
Expand Down
11 changes: 6 additions & 5 deletions llvm/tools/llvm-objdump/MachODump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7594,7 +7594,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
else
outs() << SymName << ":\n";

DILineInfo lastLine;
std::optional<DILineInfo> lastLine;
for (uint64_t Index = Start; Index < End; Index += Size) {
MCInst Inst;

Expand Down Expand Up @@ -7646,11 +7646,12 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,

// Print debug info.
if (diContext) {
DILineInfo dli = diContext->getLineInfoForAddress({PC, SectIdx});
std::optional<DILineInfo> dli =
diContext->getLineInfoForAddress({PC, SectIdx});
// Print valid line info if it changed.
if (dli != lastLine && dli.Line != 0)
outs() << "\t## " << dli.FileName << ':' << dli.Line << ':'
<< dli.Column;
if (dli && dli != lastLine && dli->Line != 0)
outs() << "\t## " << dli->FileName << ':' << dli->Line << ':'
<< dli->Column;
lastLine = dli;
}
outs() << "\n";
Expand Down
20 changes: 9 additions & 11 deletions llvm/unittests/DebugInfo/BTF/BTFParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,15 @@ TEST(BTFParserTest, btfContext) {
BTFParser BTF;
std::unique_ptr<BTFContext> Ctx = BTFContext::create(Mock.makeObj());

DILineInfo I1 = Ctx->getLineInfoForAddress({16, 1});
EXPECT_EQ(I1.Line, 7u);
EXPECT_EQ(I1.Column, 1u);
EXPECT_EQ(I1.FileName, "a.c");
EXPECT_EQ(I1.LineSource, "first line");

DILineInfo I2 = Ctx->getLineInfoForAddress({24, 1});
EXPECT_EQ(I2.Line, 0u);
EXPECT_EQ(I2.Column, 0u);
EXPECT_EQ(I2.FileName, DILineInfo::BadString);
EXPECT_EQ(I2.LineSource, std::nullopt);
std::optional<DILineInfo> I1 = Ctx->getLineInfoForAddress({16, 1});
EXPECT_TRUE(I1.has_value());
EXPECT_EQ(I1->Line, 7u);
EXPECT_EQ(I1->Column, 1u);
EXPECT_EQ(I1->FileName, "a.c");
EXPECT_EQ(I1->LineSource, "first line");

std::optional<DILineInfo> I2 = Ctx->getLineInfoForAddress({24, 1});
EXPECT_FALSE(I2.has_value());
}

static uint32_t mkInfo(uint32_t Kind) { return Kind << 24; }
Expand Down