https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
}
if (config->machine == I386)
var.consume_front("_");
- Optional<std::pair<std::string, unsigned>> ret = dwarf->getVariableLoc(var);
+ std::optional<std::pair<std::string, unsigned>> ret =
+ dwarf->getVariableLoc(var);
if (!ret)
return std::nullopt;
return std::make_pair(saver().save(ret->first), ret->second);
// Used only for DWARF debug info, which is not common (except in MinGW
// environments).
-Optional<DILineInfo> ObjFile::getDILineInfo(uint32_t offset,
- uint32_t sectionIndex) {
+std::optional<DILineInfo> ObjFile::getDILineInfo(uint32_t offset,
+ uint32_t sectionIndex) {
if (!dwarf) {
dwarf = make<DWARFCache>(DWARFContext::create(*getCOFFObj()));
if (!dwarf)
std::optional<std::pair<StringRef, uint32_t>>
getVariableLocation(StringRef var);
- llvm::Optional<llvm::DILineInfo> getDILineInfo(uint32_t offset,
- uint32_t sectionIndex);
+ std::optional<llvm::DILineInfo> getDILineInfo(uint32_t offset,
+ uint32_t sectionIndex);
private:
const coff_section* getSection(uint32_t i);
static std::optional<std::pair<StringRef, uint32_t>>
getFileLineDwarf(const SectionChunk *c, uint32_t addr) {
- Optional<DILineInfo> optionalLineInfo =
+ std::optional<DILineInfo> optionalLineInfo =
c->file->getDILineInfo(addr, c->getSectionNumber() - 1);
if (!optionalLineInfo)
return std::nullopt;
// Returns the pair of file name and line number describing location of data
// object (variable, array, etc) definition.
-Optional<std::pair<std::string, unsigned>>
+std::optional<std::pair<std::string, unsigned>>
DWARFCache::getVariableLoc(StringRef name) {
// Return if we have no debug information about data object.
auto it = variableLoc.find(name);
if (it == variableLoc.end())
- return None;
+ return std::nullopt;
// Take file name string from line table.
std::string fileName;
if (!it->second.lt->getFileNameByIndex(
it->second.file, {},
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, fileName))
- return None;
+ return std::nullopt;
return std::make_pair(fileName, it->second.line);
}
// Returns source line information for a given offset
// using DWARF debug info.
-Optional<DILineInfo> DWARFCache::getDILineInfo(uint64_t offset,
- uint64_t sectionIndex) {
+std::optional<DILineInfo> DWARFCache::getDILineInfo(uint64_t offset,
+ uint64_t sectionIndex) {
DILineInfo info;
for (const llvm::DWARFDebugLine::LineTable *lt : lineTables) {
if (lt->getFileLineInfoForAddress(
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, info))
return info;
}
- return None;
+ return std::nullopt;
}
} // namespace lld
// to llvm since it has no idea about InputSection.
template <class ELFT>
template <class RelTy>
-Optional<RelocAddrEntry>
+std::optional<RelocAddrEntry>
LLDDwarfObj<ELFT>::findAux(const InputSectionBase &sec, uint64_t pos,
ArrayRef<RelTy> rels) const {
auto it =
}
template <class ELFT>
-Optional<RelocAddrEntry> LLDDwarfObj<ELFT>::find(const llvm::DWARFSection &s,
- uint64_t pos) const {
+std::optional<RelocAddrEntry>
+LLDDwarfObj<ELFT>::find(const llvm::DWARFSection &s, uint64_t pos) const {
auto &sec = static_cast<const LLDDWARFSection &>(s);
const RelsOrRelas<ELFT> rels = sec.sec->template relsOrRelas<ELFT>();
if (rels.areRelocsRel())
return ELFT::TargetEndianness == llvm::support::little;
}
- llvm::Optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,
- uint64_t pos) const override;
+ std::optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,
+ uint64_t pos) const override;
private:
template <class RelTy>
- llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &sec,
- uint64_t pos,
- ArrayRef<RelTy> rels) const;
+ std::optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &sec,
+ uint64_t pos,
+ ArrayRef<RelTy> rels) const;
LLDDWARFSection gnuPubnamesSection;
LLDDWARFSection gnuPubtypesSection;
InputSectionBase &sec, uint64_t offset) {
// In DWARF, functions and variables are stored to different places.
// First, look up a function for a given offset.
- if (Optional<DILineInfo> info = file.getDILineInfo(&sec, offset))
+ if (std::optional<DILineInfo> info = file.getDILineInfo(&sec, offset))
return createFileLineMsg(info->FileName, info->Line);
// If it failed, look up again as a variable.
- if (Optional<std::pair<std::string, unsigned>> fileLine =
+ if (std::optional<std::pair<std::string, unsigned>> fileLine =
file.getVariableLoc(sym.getName()))
return createFileLineMsg(fileLine->first, fileLine->second);
// Returns the pair of file name and line number describing location of data
// object (variable, array, etc) definition.
template <class ELFT>
-Optional<std::pair<std::string, unsigned>>
+std::optional<std::pair<std::string, unsigned>>
ObjFile<ELFT>::getVariableLoc(StringRef name) {
return getDwarf()->getVariableLoc(name);
}
// Returns source line information for a given offset
// using DWARF debug info.
template <class ELFT>
-Optional<DILineInfo> ObjFile<ELFT>::getDILineInfo(InputSectionBase *s,
- uint64_t offset) {
+std::optional<DILineInfo> ObjFile<ELFT>::getDILineInfo(InputSectionBase *s,
+ uint64_t offset) {
// Detect SectionIndex for specified section.
uint64_t sectionIndex = object::SectionedAddress::UndefSection;
ArrayRef<InputSectionBase *> sections = s->file->getSections();
return getSymbol(symIndex);
}
- llvm::Optional<llvm::DILineInfo> getDILineInfo(InputSectionBase *, uint64_t);
- llvm::Optional<std::pair<std::string, unsigned>> getVariableLoc(StringRef name);
+ std::optional<llvm::DILineInfo> getDILineInfo(InputSectionBase *, uint64_t);
+ std::optional<std::pair<std::string, unsigned>>
+ getVariableLoc(StringRef name);
// Name of source file obtained from STT_FILE symbol value,
// or empty string if there is no such symbol in object file
public:
bool isLittleEndian() const override { return true; }
- llvm::Optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,
- uint64_t pos) const override {
+ std::optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,
+ uint64_t pos) const override {
// TODO: implement this
- return llvm::None;
+ return std::nullopt;
}
void forEachInfoSections(
};
// First, look up a function for a given offset.
- if (Optional<DILineInfo> li = dwarf->getDILineInfo(
+ if (std::optional<DILineInfo> li = dwarf->getDILineInfo(
section.addr + off, object::SectionedAddress::UndefSection))
return createMsg(li->FileName, li->Line);
if (!symName.empty() && symName[0] == '_')
symName = symName.substr(1);
- if (Optional<std::pair<std::string, unsigned>> fileLine =
+ if (std::optional<std::pair<std::string, unsigned>> fileLine =
dwarf->getVariableLoc(symName))
return createMsg(fileLine->first, fileLine->second);
}
class DWARFCache {
public:
DWARFCache(std::unique_ptr<llvm::DWARFContext> dwarf);
- llvm::Optional<llvm::DILineInfo> getDILineInfo(uint64_t offset,
- uint64_t sectionIndex);
- llvm::Optional<std::pair<std::string, unsigned>>
+ std::optional<llvm::DILineInfo> getDILineInfo(uint64_t offset,
+ uint64_t sectionIndex);
+ std::optional<std::pair<std::string, unsigned>>
getVariableLoc(StringRef name);
llvm::DWARFContext *getContext() { return dwarf.get(); }
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
#include "llvm/Object/ObjectFile.h"
+#include <optional>
namespace llvm {
// This is responsible for low level access to the object file. It
virtual StringRef getCUIndexSection() const { return ""; }
virtual StringRef getGdbIndexSection() const { return ""; }
virtual StringRef getTUIndexSection() const { return ""; }
- virtual Optional<RelocAddrEntry> find(const DWARFSection &Sec,
- uint64_t Pos) const = 0;
+ virtual std::optional<RelocAddrEntry> find(const DWARFSection &Sec,
+ uint64_t Pos) const = 0;
};
} // namespace llvm
S.IsNameUnique = false;
}
- Optional<RelocAddrEntry> find(const DWARFSection &S,
- uint64_t Pos) const override {
+ std::optional<RelocAddrEntry> find(const DWARFSection &S,
+ uint64_t Pos) const override {
auto &Sec = static_cast<const DWARFSectionMap &>(S);
RelocAddrMap::const_iterator AI = Sec.Relocs.find(Pos);
if (AI == Sec.Relocs.end())
- return None;
+ return std::nullopt;
return AI->second;
}
return getUnsigned(Off, Size, Err);
ErrorAsOutParameter ErrAsOut(Err);
- Optional<RelocAddrEntry> E = Obj->find(*Section, *Off);
+ std::optional<RelocAddrEntry> E = Obj->find(*Section, *Off);
uint64_t LocData = getUnsigned(Off, Size, Err);
if (!E || (Err && *Err))
return LocData;