Immutable DILineInfo doesn't bring any benefits and complicates
code. Also, use std::string instead of SmallString<16> for file
and function names - their length can vary significantly.
No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206654
91177308-0d34-0410-b5e6-
96231b3b80d8
#define LLVM_DEBUGINFO_DICONTEXT_H
#include "llvm/ADT/DenseMap.h"
#define LLVM_DEBUGINFO_DICONTEXT_H
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/RelocVisitor.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/RelocVisitor.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DataTypes.h"
namespace llvm {
class raw_ostream;
/// DILineInfo - a format-neutral container for source line information.
namespace llvm {
class raw_ostream;
/// DILineInfo - a format-neutral container for source line information.
-class DILineInfo {
- SmallString<16> FileName;
- SmallString<16> FunctionName;
+struct DILineInfo {
+ std::string FileName;
+ std::string FunctionName;
uint32_t Line;
uint32_t Column;
uint32_t Line;
uint32_t Column;
- : FileName("<invalid>"), FunctionName("<invalid>"),
- Line(0), Column(0) {}
- DILineInfo(StringRef fileName, StringRef functionName, uint32_t line,
- uint32_t column)
- : FileName(fileName), FunctionName(functionName), Line(line),
- Column(column) {}
-
- const char *getFileName() { return FileName.c_str(); }
- const char *getFunctionName() { return FunctionName.c_str(); }
- uint32_t getLine() const { return Line; }
- uint32_t getColumn() const { return Column; }
+ : FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0) {}
bool operator==(const DILineInfo &RHS) const {
return Line == RHS.Line && Column == RHS.Column &&
bool operator==(const DILineInfo &RHS) const {
return Line == RHS.Line && Column == RHS.Column &&
- FileName.equals(RHS.FileName) &&
- FunctionName.equals(RHS.FunctionName);
+ FileName == RHS.FileName && FunctionName == RHS.FunctionName;
}
bool operator!=(const DILineInfo &RHS) const {
return !(*this == RHS);
}
bool operator!=(const DILineInfo &RHS) const {
return !(*this == RHS);
const DWARFLineTable *LineTable,
uint64_t Address,
bool NeedsAbsoluteFilePath,
const DWARFLineTable *LineTable,
uint64_t Address,
bool NeedsAbsoluteFilePath,
- std::string &FileName,
- uint32_t &Line, uint32_t &Column) {
if (!CU || !LineTable)
return false;
// Get the index of row we're looking for in the line table.
if (!CU || !LineTable)
return false;
// Get the index of row we're looking for in the line table.
return false;
// Take file number and line/column from the row.
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
return false;
// Take file number and line/column from the row.
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
- if (!getFileNameForCompileUnit(CU, LineTable, Row.File,
- NeedsAbsoluteFilePath, FileName))
+ if (!getFileNameForCompileUnit(CU, LineTable, Row.File, NeedsAbsoluteFilePath,
+ Result.FileName))
- Line = Row.Line;
- Column = Row.Column;
+ Result.Line = Row.Line;
+ Result.Column = Row.Column;
+static bool getFunctionNameForAddress(DWARFCompileUnit *CU, uint64_t Address,
+ std::string &FunctionName) {
+ // The address may correspond to instruction in some inlined function,
+ // so we have to build the chain of inlined functions and take the
+ // name of the topmost function in it.
+ const DWARFDebugInfoEntryInlinedChain &InlinedChain =
+ CU->getInlinedChainForAddress(Address);
+ if (InlinedChain.DIEs.size() == 0)
+ return false;
+ const DWARFDebugInfoEntryMinimal &TopFunctionDIE = InlinedChain.DIEs[0];
+ if (const char *Name = TopFunctionDIE.getSubroutineName(InlinedChain.U)) {
+ FunctionName = Name;
+ return true;
+ }
+ return false;
+}
+
DILineInfo DWARFContext::getLineInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier) {
DILineInfo DWARFContext::getLineInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier) {
DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
if (!CU)
DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
if (!CU)
- return DILineInfo();
- std::string FileName = "<invalid>";
- std::string FunctionName = "<invalid>";
- uint32_t Line = 0;
- uint32_t Column = 0;
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
- // The address may correspond to instruction in some inlined function,
- // so we have to build the chain of inlined functions and take the
- // name of the topmost function in it.
- const DWARFDebugInfoEntryInlinedChain &InlinedChain =
- CU->getInlinedChainForAddress(Address);
- if (InlinedChain.DIEs.size() > 0) {
- const DWARFDebugInfoEntryMinimal &TopFunctionDIE = InlinedChain.DIEs[0];
- if (const char *Name = TopFunctionDIE.getSubroutineName(InlinedChain.U))
- FunctionName = Name;
- }
+ getFunctionNameForAddress(CU, Address, Result.FunctionName);
}
if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
const DWARFLineTable *LineTable = getLineTableForCompileUnit(CU);
const bool NeedsAbsoluteFilePath =
Specifier.needs(DILineInfoSpecifier::AbsoluteFilePath);
}
if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
const DWARFLineTable *LineTable = getLineTableForCompileUnit(CU);
const bool NeedsAbsoluteFilePath =
Specifier.needs(DILineInfoSpecifier::AbsoluteFilePath);
- getFileLineInfoForCompileUnit(CU, LineTable, Address,
- NeedsAbsoluteFilePath,
- FileName, Line, Column);
+ getFileLineInfoForCompileUnit(CU, LineTable, Address, NeedsAbsoluteFilePath,
+ Result);
- return DILineInfo(StringRef(FileName), StringRef(FunctionName),
- Line, Column);
}
DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address,
}
DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address,
std::string FunctionName = "<invalid>";
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
std::string FunctionName = "<invalid>";
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
- // The address may correspond to instruction in some inlined function,
- // so we have to build the chain of inlined functions and take the
- // name of the topmost function in it.
- const DWARFDebugInfoEntryInlinedChain &InlinedChain =
- CU->getInlinedChainForAddress(Address);
- if (InlinedChain.DIEs.size() > 0) {
- const DWARFDebugInfoEntryMinimal &TopFunctionDIE = InlinedChain.DIEs[0];
- if (const char *Name = TopFunctionDIE.getSubroutineName(InlinedChain.U))
- FunctionName = Name;
- }
+ getFunctionNameForAddress(CU, Address, FunctionName);
}
// If the Specifier says we don't need FileLineInfo, just
// return the top-most function at the starting address.
if (!Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
}
// If the Specifier says we don't need FileLineInfo, just
// return the top-most function at the starting address.
if (!Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
- Lines.push_back(
- std::make_pair(Address, DILineInfo("<invalid>", FunctionName, 0, 0)));
+ DILineInfo Result;
+ Result.FunctionName = FunctionName;
+ Lines.push_back(std::make_pair(Address, Result));
for (uint32_t RowIndex : RowVector) {
// Take file number and line/column from the row.
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
for (uint32_t RowIndex : RowVector) {
// Take file number and line/column from the row.
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
- std::string FileName = "<invalid>";
- getFileNameForCompileUnit(CU, LineTable, Row.File,
- NeedsAbsoluteFilePath, FileName);
- Lines.push_back(std::make_pair(
- Row.Address, DILineInfo(FileName, FunctionName, Row.Line, Row.Column)));
+ DILineInfo Result;
+ getFileNameForCompileUnit(CU, LineTable, Row.File, NeedsAbsoluteFilePath,
+ Result.FileName);
+ Result.FunctionName = FunctionName;
+ Result.Line = Row.Line;
+ Result.Column = Row.Column;
+ Lines.push_back(std::make_pair(Row.Address, Result));
const DWARFLineTable *LineTable = nullptr;
for (uint32_t i = 0, n = InlinedChain.DIEs.size(); i != n; i++) {
const DWARFDebugInfoEntryMinimal &FunctionDIE = InlinedChain.DIEs[i];
const DWARFLineTable *LineTable = nullptr;
for (uint32_t i = 0, n = InlinedChain.DIEs.size(); i != n; i++) {
const DWARFDebugInfoEntryMinimal &FunctionDIE = InlinedChain.DIEs[i];
- std::string FileName = "<invalid>";
- std::string FunctionName = "<invalid>";
- uint32_t Line = 0;
- uint32_t Column = 0;
// Get function name if necessary.
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
if (const char *Name = FunctionDIE.getSubroutineName(InlinedChain.U))
// Get function name if necessary.
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
if (const char *Name = FunctionDIE.getSubroutineName(InlinedChain.U))
+ Frame.FunctionName = Name;
}
if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
const bool NeedsAbsoluteFilePath =
}
if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
const bool NeedsAbsoluteFilePath =
// For the topmost routine, get file/line info from line table.
getFileLineInfoForCompileUnit(CU, LineTable, Address,
NeedsAbsoluteFilePath,
// For the topmost routine, get file/line info from line table.
getFileLineInfoForCompileUnit(CU, LineTable, Address,
NeedsAbsoluteFilePath,
- FileName, Line, Column);
} else {
// Otherwise, use call file, call line and call column from
// previous DIE in inlined chain.
getFileNameForCompileUnit(CU, LineTable, CallFile,
} else {
// Otherwise, use call file, call line and call column from
// previous DIE in inlined chain.
getFileNameForCompileUnit(CU, LineTable, CallFile,
- NeedsAbsoluteFilePath, FileName);
- Line = CallLine;
- Column = CallColumn;
+ NeedsAbsoluteFilePath, Frame.FileName);
+ Frame.Line = CallLine;
+ Frame.Column = CallColumn;
}
// Get call file/line/column of a current DIE.
if (i + 1 < n) {
}
// Get call file/line/column of a current DIE.
if (i + 1 < n) {
- DILineInfo Frame(StringRef(FileName), StringRef(FunctionName),
- Line, Column);
InliningInfo.addFrame(Frame);
}
return InliningInfo;
InliningInfo.addFrame(Frame);
}
return InliningInfo;
static void PrintDILineInfo(DILineInfo dli) {
if (PrintFunctions)
static void PrintDILineInfo(DILineInfo dli) {
if (PrintFunctions)
- outs() << (dli.getFunctionName() ? dli.getFunctionName() : "<unknown>")
- << "\n";
- outs() << (dli.getFileName() ? dli.getFileName() : "<unknown>") << ':'
- << dli.getLine() << ':' << dli.getColumn() << '\n';
+ outs() << dli.FunctionName << "\n";
+ outs() << dli.FileName << ':' << dli.Line << ':' << dli.Column << '\n';
}
static void DumpInput(const StringRef &Filename) {
}
static void DumpInput(const StringRef &Filename) {
DILineInfo dli =
diContext->getLineInfoForAddress(SectAddress + Index);
// Print valid line info if it changed.
DILineInfo dli =
diContext->getLineInfoForAddress(SectAddress + Index);
// Print valid line info if it changed.
- if (dli != lastLine && dli.getLine() != 0)
- outs() << "\t## " << dli.getFileName() << ':'
- << dli.getLine() << ':' << dli.getColumn();
+ if (dli != lastLine && dli.Line != 0)
+ outs() << "\t## " << dli.FileName << ':' << dli.Line << ':'
+ << dli.Column;
lastLine = dli;
}
outs() << "\n";
lastLine = dli;
}
outs() << "\n";
DILineInfoTable::iterator End = Lines.end();
for (DILineInfoTable::iterator It = Begin; It != End; ++It) {
outs() << " Line info @ " << It->first - Addr << ": "
DILineInfoTable::iterator End = Lines.end();
for (DILineInfoTable::iterator It = Begin; It != End; ++It) {
outs() << " Line info @ " << It->first - Addr << ": "
- << It->second.getFileName()
- << ", line:" << It->second.getLine() << "\n";
+ << It->second.FileName << ", line:" << It->second.Line << "\n";
-static void patchFunctionNameInDILineInfo(const std::string &NewFunctionName,
- DILineInfo &LineInfo) {
- std::string FileName = LineInfo.getFileName();
- LineInfo = DILineInfo(StringRef(FileName), StringRef(NewFunctionName),
- LineInfo.getLine(), LineInfo.getColumn());
-}
-
ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
: Module(Obj), DebugInfoContext(DICtx) {
for (const SymbolRef &Symbol : Module->symbols()) {
ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
: Module(Obj), DebugInfoContext(DICtx) {
for (const SymbolRef &Symbol : Module->symbols()) {
uint64_t Start, Size;
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset,
FunctionName, Start, Size)) {
uint64_t Start, Size;
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset,
FunctionName, Start, Size)) {
- patchFunctionNameInDILineInfo(FunctionName, LineInfo);
+ LineInfo.FunctionName = FunctionName;
uint64_t Start, Size;
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset,
FunctionName, Start, Size)) {
uint64_t Start, Size;
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset,
FunctionName, Start, Size)) {
- patchFunctionNameInDILineInfo(FunctionName, LineInfo);
+ LineInfo.FunctionName = FunctionName;
}
}
PatchedInlinedContext.addFrame(LineInfo);
}
}
PatchedInlinedContext.addFrame(LineInfo);
static const std::string kDILineInfoBadString = "<invalid>";
std::stringstream Result;
if (Opts.PrintFunctions) {
static const std::string kDILineInfoBadString = "<invalid>";
std::stringstream Result;
if (Opts.PrintFunctions) {
- std::string FunctionName = LineInfo.getFunctionName();
+ std::string FunctionName = LineInfo.FunctionName;
if (FunctionName == kDILineInfoBadString)
FunctionName = kBadString;
else if (Opts.Demangle)
FunctionName = DemangleName(FunctionName);
Result << FunctionName << "\n";
}
if (FunctionName == kDILineInfoBadString)
FunctionName = kBadString;
else if (Opts.Demangle)
FunctionName = DemangleName(FunctionName);
Result << FunctionName << "\n";
}
- std::string Filename = LineInfo.getFileName();
+ std::string Filename = LineInfo.FileName;
if (Filename == kDILineInfoBadString)
Filename = kBadString;
if (Filename == kDILineInfoBadString)
Filename = kBadString;
- Result << Filename << ":" << LineInfo.getLine() << ":" << LineInfo.getColumn()
- << "\n";
+ Result << Filename << ":" << LineInfo.Line << ":" << LineInfo.Column << "\n";