Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 08ef020

Browse files
author
Alexey Samsonov
committed
[DWARF parser] Turn DILineInfo into a struct.
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
1 parent 037da24 commit 08ef020

File tree

6 files changed

+65
-95
lines changed

6 files changed

+65
-95
lines changed

include/llvm/DebugInfo/DIContext.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,31 @@
1616
#define LLVM_DEBUGINFO_DICONTEXT_H
1717

1818
#include "llvm/ADT/DenseMap.h"
19-
#include "llvm/ADT/SmallString.h"
2019
#include "llvm/ADT/SmallVector.h"
21-
#include "llvm/ADT/StringRef.h"
2220
#include "llvm/Object/ObjectFile.h"
2321
#include "llvm/Object/RelocVisitor.h"
2422
#include "llvm/Support/Casting.h"
2523
#include "llvm/Support/DataTypes.h"
2624

25+
#include <string>
26+
2727
namespace llvm {
2828

2929
class raw_ostream;
3030

3131
/// DILineInfo - a format-neutral container for source line information.
32-
class DILineInfo {
33-
SmallString<16> FileName;
34-
SmallString<16> FunctionName;
32+
struct DILineInfo {
33+
std::string FileName;
34+
std::string FunctionName;
3535
uint32_t Line;
3636
uint32_t Column;
37-
public:
37+
3838
DILineInfo()
39-
: FileName("<invalid>"), FunctionName("<invalid>"),
40-
Line(0), Column(0) {}
41-
DILineInfo(StringRef fileName, StringRef functionName, uint32_t line,
42-
uint32_t column)
43-
: FileName(fileName), FunctionName(functionName), Line(line),
44-
Column(column) {}
45-
46-
const char *getFileName() { return FileName.c_str(); }
47-
const char *getFunctionName() { return FunctionName.c_str(); }
48-
uint32_t getLine() const { return Line; }
49-
uint32_t getColumn() const { return Column; }
39+
: FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0) {}
5040

5141
bool operator==(const DILineInfo &RHS) const {
5242
return Line == RHS.Line && Column == RHS.Column &&
53-
FileName.equals(RHS.FileName) &&
54-
FunctionName.equals(RHS.FunctionName);
43+
FileName == RHS.FileName && FunctionName == RHS.FunctionName;
5544
}
5645
bool operator!=(const DILineInfo &RHS) const {
5746
return !(*this == RHS);

lib/DebugInfo/DWARFContext.cpp

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ static bool getFileLineInfoForCompileUnit(DWARFCompileUnit *CU,
443443
const DWARFLineTable *LineTable,
444444
uint64_t Address,
445445
bool NeedsAbsoluteFilePath,
446-
std::string &FileName,
447-
uint32_t &Line, uint32_t &Column) {
446+
DILineInfo &Result) {
448447
if (!CU || !LineTable)
449448
return false;
450449
// Get the index of row we're looking for in the line table.
@@ -453,45 +452,49 @@ static bool getFileLineInfoForCompileUnit(DWARFCompileUnit *CU,
453452
return false;
454453
// Take file number and line/column from the row.
455454
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
456-
if (!getFileNameForCompileUnit(CU, LineTable, Row.File,
457-
NeedsAbsoluteFilePath, FileName))
455+
if (!getFileNameForCompileUnit(CU, LineTable, Row.File, NeedsAbsoluteFilePath,
456+
Result.FileName))
458457
return false;
459-
Line = Row.Line;
460-
Column = Row.Column;
458+
Result.Line = Row.Line;
459+
Result.Column = Row.Column;
461460
return true;
462461
}
463462

463+
static bool getFunctionNameForAddress(DWARFCompileUnit *CU, uint64_t Address,
464+
std::string &FunctionName) {
465+
// The address may correspond to instruction in some inlined function,
466+
// so we have to build the chain of inlined functions and take the
467+
// name of the topmost function in it.
468+
const DWARFDebugInfoEntryInlinedChain &InlinedChain =
469+
CU->getInlinedChainForAddress(Address);
470+
if (InlinedChain.DIEs.size() == 0)
471+
return false;
472+
const DWARFDebugInfoEntryMinimal &TopFunctionDIE = InlinedChain.DIEs[0];
473+
if (const char *Name = TopFunctionDIE.getSubroutineName(InlinedChain.U)) {
474+
FunctionName = Name;
475+
return true;
476+
}
477+
return false;
478+
}
479+
464480
DILineInfo DWARFContext::getLineInfoForAddress(uint64_t Address,
465481
DILineInfoSpecifier Specifier) {
482+
DILineInfo Result;
483+
466484
DWARFCompileUnit *CU = getCompileUnitForAddress(Address);
467485
if (!CU)
468-
return DILineInfo();
469-
std::string FileName = "<invalid>";
470-
std::string FunctionName = "<invalid>";
471-
uint32_t Line = 0;
472-
uint32_t Column = 0;
486+
return Result;
473487
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
474-
// The address may correspond to instruction in some inlined function,
475-
// so we have to build the chain of inlined functions and take the
476-
// name of the topmost function in it.
477-
const DWARFDebugInfoEntryInlinedChain &InlinedChain =
478-
CU->getInlinedChainForAddress(Address);
479-
if (InlinedChain.DIEs.size() > 0) {
480-
const DWARFDebugInfoEntryMinimal &TopFunctionDIE = InlinedChain.DIEs[0];
481-
if (const char *Name = TopFunctionDIE.getSubroutineName(InlinedChain.U))
482-
FunctionName = Name;
483-
}
488+
getFunctionNameForAddress(CU, Address, Result.FunctionName);
484489
}
485490
if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
486491
const DWARFLineTable *LineTable = getLineTableForCompileUnit(CU);
487492
const bool NeedsAbsoluteFilePath =
488493
Specifier.needs(DILineInfoSpecifier::AbsoluteFilePath);
489-
getFileLineInfoForCompileUnit(CU, LineTable, Address,
490-
NeedsAbsoluteFilePath,
491-
FileName, Line, Column);
494+
getFileLineInfoForCompileUnit(CU, LineTable, Address, NeedsAbsoluteFilePath,
495+
Result);
492496
}
493-
return DILineInfo(StringRef(FileName), StringRef(FunctionName),
494-
Line, Column);
497+
return Result;
495498
}
496499

497500
DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address,
@@ -504,23 +507,15 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address,
504507

505508
std::string FunctionName = "<invalid>";
506509
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
507-
// The address may correspond to instruction in some inlined function,
508-
// so we have to build the chain of inlined functions and take the
509-
// name of the topmost function in it.
510-
const DWARFDebugInfoEntryInlinedChain &InlinedChain =
511-
CU->getInlinedChainForAddress(Address);
512-
if (InlinedChain.DIEs.size() > 0) {
513-
const DWARFDebugInfoEntryMinimal &TopFunctionDIE = InlinedChain.DIEs[0];
514-
if (const char *Name = TopFunctionDIE.getSubroutineName(InlinedChain.U))
515-
FunctionName = Name;
516-
}
510+
getFunctionNameForAddress(CU, Address, FunctionName);
517511
}
518512

519513
// If the Specifier says we don't need FileLineInfo, just
520514
// return the top-most function at the starting address.
521515
if (!Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
522-
Lines.push_back(
523-
std::make_pair(Address, DILineInfo("<invalid>", FunctionName, 0, 0)));
516+
DILineInfo Result;
517+
Result.FunctionName = FunctionName;
518+
Lines.push_back(std::make_pair(Address, Result));
524519
return Lines;
525520
}
526521

@@ -536,11 +531,13 @@ DILineInfoTable DWARFContext::getLineInfoForAddressRange(uint64_t Address,
536531
for (uint32_t RowIndex : RowVector) {
537532
// Take file number and line/column from the row.
538533
const DWARFDebugLine::Row &Row = LineTable->Rows[RowIndex];
539-
std::string FileName = "<invalid>";
540-
getFileNameForCompileUnit(CU, LineTable, Row.File,
541-
NeedsAbsoluteFilePath, FileName);
542-
Lines.push_back(std::make_pair(
543-
Row.Address, DILineInfo(FileName, FunctionName, Row.Line, Row.Column)));
534+
DILineInfo Result;
535+
getFileNameForCompileUnit(CU, LineTable, Row.File, NeedsAbsoluteFilePath,
536+
Result.FileName);
537+
Result.FunctionName = FunctionName;
538+
Result.Line = Row.Line;
539+
Result.Column = Row.Column;
540+
Lines.push_back(std::make_pair(Row.Address, Result));
544541
}
545542

546543
return Lines;
@@ -562,14 +559,11 @@ DIInliningInfo DWARFContext::getInliningInfoForAddress(uint64_t Address,
562559
const DWARFLineTable *LineTable = nullptr;
563560
for (uint32_t i = 0, n = InlinedChain.DIEs.size(); i != n; i++) {
564561
const DWARFDebugInfoEntryMinimal &FunctionDIE = InlinedChain.DIEs[i];
565-
std::string FileName = "<invalid>";
566-
std::string FunctionName = "<invalid>";
567-
uint32_t Line = 0;
568-
uint32_t Column = 0;
562+
DILineInfo Frame;
569563
// Get function name if necessary.
570564
if (Specifier.needs(DILineInfoSpecifier::FunctionName)) {
571565
if (const char *Name = FunctionDIE.getSubroutineName(InlinedChain.U))
572-
FunctionName = Name;
566+
Frame.FunctionName = Name;
573567
}
574568
if (Specifier.needs(DILineInfoSpecifier::FileLineInfo)) {
575569
const bool NeedsAbsoluteFilePath =
@@ -581,23 +575,21 @@ DIInliningInfo DWARFContext::getInliningInfoForAddress(uint64_t Address,
581575
// For the topmost routine, get file/line info from line table.
582576
getFileLineInfoForCompileUnit(CU, LineTable, Address,
583577
NeedsAbsoluteFilePath,
584-
FileName, Line, Column);
578+
Frame);
585579
} else {
586580
// Otherwise, use call file, call line and call column from
587581
// previous DIE in inlined chain.
588582
getFileNameForCompileUnit(CU, LineTable, CallFile,
589-
NeedsAbsoluteFilePath, FileName);
590-
Line = CallLine;
591-
Column = CallColumn;
583+
NeedsAbsoluteFilePath, Frame.FileName);
584+
Frame.Line = CallLine;
585+
Frame.Column = CallColumn;
592586
}
593587
// Get call file/line/column of a current DIE.
594588
if (i + 1 < n) {
595589
FunctionDIE.getCallerFrame(InlinedChain.U, CallFile, CallLine,
596590
CallColumn);
597591
}
598592
}
599-
DILineInfo Frame(StringRef(FileName), StringRef(FunctionName),
600-
Line, Column);
601593
InliningInfo.addFrame(Frame);
602594
}
603595
return InliningInfo;

tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ DumpType("debug-dump", cl::init(DIDT_All),
8080

8181
static void PrintDILineInfo(DILineInfo dli) {
8282
if (PrintFunctions)
83-
outs() << (dli.getFunctionName() ? dli.getFunctionName() : "<unknown>")
84-
<< "\n";
85-
outs() << (dli.getFileName() ? dli.getFileName() : "<unknown>") << ':'
86-
<< dli.getLine() << ':' << dli.getColumn() << '\n';
83+
outs() << dli.FunctionName << "\n";
84+
outs() << dli.FileName << ':' << dli.Line << ':' << dli.Column << '\n';
8785
}
8886

8987
static void DumpInput(const StringRef &Filename) {

tools/llvm-objdump/MachODump.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ static void DisassembleInputMachO2(StringRef Filename,
421421
DILineInfo dli =
422422
diContext->getLineInfoForAddress(SectAddress + Index);
423423
// Print valid line info if it changed.
424-
if (dli != lastLine && dli.getLine() != 0)
425-
outs() << "\t## " << dli.getFileName() << ':'
426-
<< dli.getLine() << ':' << dli.getColumn();
424+
if (dli != lastLine && dli.Line != 0)
425+
outs() << "\t## " << dli.FileName << ':' << dli.Line << ':'
426+
<< dli.Column;
427427
lastLine = dli;
428428
}
429429
outs() << "\n";

tools/llvm-rtdyld/llvm-rtdyld.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ static int printLineInfoForInput() {
172172
DILineInfoTable::iterator End = Lines.end();
173173
for (DILineInfoTable::iterator It = Begin; It != End; ++It) {
174174
outs() << " Line info @ " << It->first - Addr << ": "
175-
<< It->second.getFileName()
176-
<< ", line:" << It->second.getLine() << "\n";
175+
<< It->second.FileName << ", line:" << It->second.Line << "\n";
177176
}
178177
}
179178
}

tools/llvm-symbolizer/LLVMSymbolize.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ getDILineInfoSpecifierFlags(const LLVMSymbolizer::Options &Opts) {
4444
return Flags;
4545
}
4646

47-
static void patchFunctionNameInDILineInfo(const std::string &NewFunctionName,
48-
DILineInfo &LineInfo) {
49-
std::string FileName = LineInfo.getFileName();
50-
LineInfo = DILineInfo(StringRef(FileName), StringRef(NewFunctionName),
51-
LineInfo.getLine(), LineInfo.getColumn());
52-
}
53-
5447
ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
5548
: Module(Obj), DebugInfoContext(DICtx) {
5649
for (const SymbolRef &Symbol : Module->symbols()) {
@@ -130,7 +123,7 @@ DILineInfo ModuleInfo::symbolizeCode(
130123
uint64_t Start, Size;
131124
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset,
132125
FunctionName, Start, Size)) {
133-
patchFunctionNameInDILineInfo(FunctionName, LineInfo);
126+
LineInfo.FunctionName = FunctionName;
134127
}
135128
}
136129
return LineInfo;
@@ -157,7 +150,7 @@ DIInliningInfo ModuleInfo::symbolizeInlinedCode(
157150
uint64_t Start, Size;
158151
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset,
159152
FunctionName, Start, Size)) {
160-
patchFunctionNameInDILineInfo(FunctionName, LineInfo);
153+
LineInfo.FunctionName = FunctionName;
161154
}
162155
}
163156
PatchedInlinedContext.addFrame(LineInfo);
@@ -408,18 +401,17 @@ std::string LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo) const {
408401
static const std::string kDILineInfoBadString = "<invalid>";
409402
std::stringstream Result;
410403
if (Opts.PrintFunctions) {
411-
std::string FunctionName = LineInfo.getFunctionName();
404+
std::string FunctionName = LineInfo.FunctionName;
412405
if (FunctionName == kDILineInfoBadString)
413406
FunctionName = kBadString;
414407
else if (Opts.Demangle)
415408
FunctionName = DemangleName(FunctionName);
416409
Result << FunctionName << "\n";
417410
}
418-
std::string Filename = LineInfo.getFileName();
411+
std::string Filename = LineInfo.FileName;
419412
if (Filename == kDILineInfoBadString)
420413
Filename = kBadString;
421-
Result << Filename << ":" << LineInfo.getLine() << ":" << LineInfo.getColumn()
422-
<< "\n";
414+
Result << Filename << ":" << LineInfo.Line << ":" << LineInfo.Column << "\n";
423415
return Result.str();
424416
}
425417

0 commit comments

Comments
 (0)