mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
Cleanup the plumbing for DILineInfoSpecifier. [NFC]
Summary: 1. FileLineInfoSpecifier::Default isn't the default for anything. Rename to RawValue, which accurately reflects its role. 2. Most functions that take a part of a FileLineInfoSpecifier end up constructing a full one later or plumb two values through. Make them all just take a complete FileLineInfoSpecifier. 3. Printing basenames only was handled differently from all other variants, make it parallel to all the other variants. Reviewers: jhenderson Subscribers: hiraditya, MaskRay, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76394
This commit is contained in:
parent
933279999d
commit
7d98860ec6
@ -136,7 +136,11 @@ enum class DINameKind { None, ShortName, LinkageName };
|
|||||||
struct DILineInfoSpecifier {
|
struct DILineInfoSpecifier {
|
||||||
enum class FileLineInfoKind {
|
enum class FileLineInfoKind {
|
||||||
None,
|
None,
|
||||||
Default,
|
// RawValue is whatever the compiler stored in the filename table. Could be
|
||||||
|
// a full path, could be something else.
|
||||||
|
RawValue,
|
||||||
|
BaseNameOnly,
|
||||||
|
// Relative to the compilation directory.
|
||||||
RelativeFilePath,
|
RelativeFilePath,
|
||||||
AbsoluteFilePath
|
AbsoluteFilePath
|
||||||
};
|
};
|
||||||
@ -145,7 +149,7 @@ struct DILineInfoSpecifier {
|
|||||||
FileLineInfoKind FLIKind;
|
FileLineInfoKind FLIKind;
|
||||||
FunctionNameKind FNKind;
|
FunctionNameKind FNKind;
|
||||||
|
|
||||||
DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default,
|
DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::RawValue,
|
||||||
FunctionNameKind FNKind = FunctionNameKind::None)
|
FunctionNameKind FNKind = FunctionNameKind::None)
|
||||||
: FLIKind(FLIKind), FNKind(FNKind) {}
|
: FLIKind(FLIKind), FNKind(FNKind) {}
|
||||||
};
|
};
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#ifndef LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H
|
#ifndef LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H
|
||||||
#define LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H
|
#define LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H
|
||||||
|
|
||||||
|
#include "llvm/DebugInfo/DIContext.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -34,7 +35,6 @@ private:
|
|||||||
bool PrintPretty;
|
bool PrintPretty;
|
||||||
int PrintSourceContext;
|
int PrintSourceContext;
|
||||||
bool Verbose;
|
bool Verbose;
|
||||||
bool Basenames;
|
|
||||||
OutputStyle Style;
|
OutputStyle Style;
|
||||||
|
|
||||||
void print(const DILineInfo &Info, bool Inlined);
|
void print(const DILineInfo &Info, bool Inlined);
|
||||||
@ -43,11 +43,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
DIPrinter(raw_ostream &OS, bool PrintFunctionNames = true,
|
DIPrinter(raw_ostream &OS, bool PrintFunctionNames = true,
|
||||||
bool PrintPretty = false, int PrintSourceContext = 0,
|
bool PrintPretty = false, int PrintSourceContext = 0,
|
||||||
bool Verbose = false, bool Basenames = false,
|
bool Verbose = false, OutputStyle Style = OutputStyle::LLVM)
|
||||||
OutputStyle Style = OutputStyle::LLVM)
|
|
||||||
: OS(OS), PrintFunctionNames(PrintFunctionNames),
|
: OS(OS), PrintFunctionNames(PrintFunctionNames),
|
||||||
PrintPretty(PrintPretty), PrintSourceContext(PrintSourceContext),
|
PrintPretty(PrintPretty), PrintSourceContext(PrintSourceContext),
|
||||||
Verbose(Verbose), Basenames(Basenames), Style(Style) {}
|
Verbose(Verbose), Style(Style) {}
|
||||||
|
|
||||||
DIPrinter &operator<<(const DILineInfo &Info);
|
DIPrinter &operator<<(const DILineInfo &Info);
|
||||||
DIPrinter &operator<<(const DIInliningInfo &Info);
|
DIPrinter &operator<<(const DIInliningInfo &Info);
|
||||||
@ -58,4 +57,3 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -25,11 +25,12 @@ public:
|
|||||||
virtual ~SymbolizableModule() = default;
|
virtual ~SymbolizableModule() = default;
|
||||||
|
|
||||||
virtual DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
|
virtual DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
|
||||||
FunctionNameKind FNKind,
|
DILineInfoSpecifier LineInfoSpecifier,
|
||||||
bool UseSymbolTable) const = 0;
|
bool UseSymbolTable) const = 0;
|
||||||
virtual DIInliningInfo
|
virtual DIInliningInfo
|
||||||
symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
|
symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
|
||||||
FunctionNameKind FNKind, bool UseSymbolTable) const = 0;
|
DILineInfoSpecifier LineInfoSpecifier,
|
||||||
|
bool UseSymbolTable) const = 0;
|
||||||
virtual DIGlobal
|
virtual DIGlobal
|
||||||
symbolizeData(object::SectionedAddress ModuleOffset) const = 0;
|
symbolizeData(object::SectionedAddress ModuleOffset) const = 0;
|
||||||
virtual std::vector<DILocal>
|
virtual std::vector<DILocal>
|
||||||
|
@ -32,11 +32,13 @@ namespace symbolize {
|
|||||||
using namespace object;
|
using namespace object;
|
||||||
|
|
||||||
using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
|
using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
|
||||||
|
using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
|
||||||
|
|
||||||
class LLVMSymbolizer {
|
class LLVMSymbolizer {
|
||||||
public:
|
public:
|
||||||
struct Options {
|
struct Options {
|
||||||
FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName;
|
FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName;
|
||||||
|
FileLineInfoKind PathStyle = FileLineInfoKind::AbsoluteFilePath;
|
||||||
bool UseSymbolTable = true;
|
bool UseSymbolTable = true;
|
||||||
bool Demangle = true;
|
bool Demangle = true;
|
||||||
bool RelativeAddresses = false;
|
bool RelativeAddresses = false;
|
||||||
|
@ -1209,11 +1209,15 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
|
|||||||
if (!Name)
|
if (!Name)
|
||||||
return false;
|
return false;
|
||||||
StringRef FileName = *Name;
|
StringRef FileName = *Name;
|
||||||
if (Kind == FileLineInfoKind::Default ||
|
if (Kind == FileLineInfoKind::RawValue ||
|
||||||
isPathAbsoluteOnWindowsOrPosix(FileName)) {
|
isPathAbsoluteOnWindowsOrPosix(FileName)) {
|
||||||
Result = std::string(FileName);
|
Result = std::string(FileName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (Kind == FileLineInfoKind::BaseNameOnly) {
|
||||||
|
Result = std::string(llvm::sys::path::filename(FileName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
SmallString<16> FilePath;
|
SmallString<16> FilePath;
|
||||||
StringRef IncludeDir;
|
StringRef IncludeDir;
|
||||||
|
@ -73,8 +73,6 @@ void DIPrinter::print(const DILineInfo &Info, bool Inlined) {
|
|||||||
std::string Filename = Info.FileName;
|
std::string Filename = Info.FileName;
|
||||||
if (Filename == DILineInfo::BadString)
|
if (Filename == DILineInfo::BadString)
|
||||||
Filename = DILineInfo::Addr2LineBadString;
|
Filename = DILineInfo::Addr2LineBadString;
|
||||||
else if (Basenames)
|
|
||||||
Filename = std::string(llvm::sys::path::filename(Filename));
|
|
||||||
if (!Verbose) {
|
if (!Verbose) {
|
||||||
OS << Filename << ":" << Info.Line;
|
OS << Filename << ":" << Info.Line;
|
||||||
if (Style == OutputStyle::LLVM)
|
if (Style == OutputStyle::LLVM)
|
||||||
|
@ -35,12 +35,6 @@ using namespace llvm;
|
|||||||
using namespace object;
|
using namespace object;
|
||||||
using namespace symbolize;
|
using namespace symbolize;
|
||||||
|
|
||||||
static DILineInfoSpecifier
|
|
||||||
getDILineInfoSpecifier(FunctionNameKind FNKind) {
|
|
||||||
return DILineInfoSpecifier(
|
|
||||||
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, FNKind);
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorOr<std::unique_ptr<SymbolizableObjectFile>>
|
ErrorOr<std::unique_ptr<SymbolizableObjectFile>>
|
||||||
SymbolizableObjectFile::create(const object::ObjectFile *Obj,
|
SymbolizableObjectFile::create(const object::ObjectFile *Obj,
|
||||||
std::unique_ptr<DIContext> DICtx,
|
std::unique_ptr<DIContext> DICtx,
|
||||||
@ -251,16 +245,16 @@ bool SymbolizableObjectFile::shouldOverrideWithSymbolTable(
|
|||||||
|
|
||||||
DILineInfo
|
DILineInfo
|
||||||
SymbolizableObjectFile::symbolizeCode(object::SectionedAddress ModuleOffset,
|
SymbolizableObjectFile::symbolizeCode(object::SectionedAddress ModuleOffset,
|
||||||
FunctionNameKind FNKind,
|
DILineInfoSpecifier LineInfoSpecifier,
|
||||||
bool UseSymbolTable) const {
|
bool UseSymbolTable) const {
|
||||||
if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
|
if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
|
||||||
ModuleOffset.SectionIndex =
|
ModuleOffset.SectionIndex =
|
||||||
getModuleSectionIndexForAddress(ModuleOffset.Address);
|
getModuleSectionIndexForAddress(ModuleOffset.Address);
|
||||||
DILineInfo LineInfo = DebugInfoContext->getLineInfoForAddress(
|
DILineInfo LineInfo =
|
||||||
ModuleOffset, getDILineInfoSpecifier(FNKind));
|
DebugInfoContext->getLineInfoForAddress(ModuleOffset, LineInfoSpecifier);
|
||||||
|
|
||||||
// Override function name from symbol table if necessary.
|
// Override function name from symbol table if necessary.
|
||||||
if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) {
|
if (shouldOverrideWithSymbolTable(LineInfoSpecifier.FNKind, UseSymbolTable)) {
|
||||||
std::string FunctionName;
|
std::string FunctionName;
|
||||||
uint64_t Start, Size;
|
uint64_t Start, Size;
|
||||||
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset.Address,
|
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset.Address,
|
||||||
@ -272,20 +266,20 @@ SymbolizableObjectFile::symbolizeCode(object::SectionedAddress ModuleOffset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DIInliningInfo SymbolizableObjectFile::symbolizeInlinedCode(
|
DIInliningInfo SymbolizableObjectFile::symbolizeInlinedCode(
|
||||||
object::SectionedAddress ModuleOffset, FunctionNameKind FNKind,
|
object::SectionedAddress ModuleOffset,
|
||||||
bool UseSymbolTable) const {
|
DILineInfoSpecifier LineInfoSpecifier, bool UseSymbolTable) const {
|
||||||
if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
|
if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
|
||||||
ModuleOffset.SectionIndex =
|
ModuleOffset.SectionIndex =
|
||||||
getModuleSectionIndexForAddress(ModuleOffset.Address);
|
getModuleSectionIndexForAddress(ModuleOffset.Address);
|
||||||
DIInliningInfo InlinedContext = DebugInfoContext->getInliningInfoForAddress(
|
DIInliningInfo InlinedContext = DebugInfoContext->getInliningInfoForAddress(
|
||||||
ModuleOffset, getDILineInfoSpecifier(FNKind));
|
ModuleOffset, LineInfoSpecifier);
|
||||||
|
|
||||||
// Make sure there is at least one frame in context.
|
// Make sure there is at least one frame in context.
|
||||||
if (InlinedContext.getNumberOfFrames() == 0)
|
if (InlinedContext.getNumberOfFrames() == 0)
|
||||||
InlinedContext.addFrame(DILineInfo());
|
InlinedContext.addFrame(DILineInfo());
|
||||||
|
|
||||||
// Override the function name in lower frame with name from symbol table.
|
// Override the function name in lower frame with name from symbol table.
|
||||||
if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) {
|
if (shouldOverrideWithSymbolTable(LineInfoSpecifier.FNKind, UseSymbolTable)) {
|
||||||
std::string FunctionName;
|
std::string FunctionName;
|
||||||
uint64_t Start, Size;
|
uint64_t Start, Size;
|
||||||
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset.Address,
|
if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset.Address,
|
||||||
|
@ -35,10 +35,10 @@ public:
|
|||||||
bool UntagAddresses);
|
bool UntagAddresses);
|
||||||
|
|
||||||
DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
|
DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
|
||||||
FunctionNameKind FNKind,
|
DILineInfoSpecifier LineInfoSpecifier,
|
||||||
bool UseSymbolTable) const override;
|
bool UseSymbolTable) const override;
|
||||||
DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
|
DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
|
||||||
FunctionNameKind FNKind,
|
DILineInfoSpecifier LineInfoSpecifier,
|
||||||
bool UseSymbolTable) const override;
|
bool UseSymbolTable) const override;
|
||||||
DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override;
|
DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override;
|
||||||
std::vector<DILocal>
|
std::vector<DILocal>
|
||||||
|
@ -51,8 +51,9 @@ LLVMSymbolizer::symbolizeCodeCommon(SymbolizableModule *Info,
|
|||||||
if (Opts.RelativeAddresses)
|
if (Opts.RelativeAddresses)
|
||||||
ModuleOffset.Address += Info->getModulePreferredBase();
|
ModuleOffset.Address += Info->getModulePreferredBase();
|
||||||
|
|
||||||
DILineInfo LineInfo = Info->symbolizeCode(ModuleOffset, Opts.PrintFunctions,
|
DILineInfo LineInfo = Info->symbolizeCode(
|
||||||
Opts.UseSymbolTable);
|
ModuleOffset, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
|
||||||
|
Opts.UseSymbolTable);
|
||||||
if (Opts.Demangle)
|
if (Opts.Demangle)
|
||||||
LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info);
|
LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info);
|
||||||
return LineInfo;
|
return LineInfo;
|
||||||
@ -103,7 +104,8 @@ LLVMSymbolizer::symbolizeInlinedCode(const std::string &ModuleName,
|
|||||||
ModuleOffset.Address += Info->getModulePreferredBase();
|
ModuleOffset.Address += Info->getModulePreferredBase();
|
||||||
|
|
||||||
DIInliningInfo InlinedContext = Info->symbolizeInlinedCode(
|
DIInliningInfo InlinedContext = Info->symbolizeInlinedCode(
|
||||||
ModuleOffset, Opts.PrintFunctions, Opts.UseSymbolTable);
|
ModuleOffset, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions),
|
||||||
|
Opts.UseSymbolTable);
|
||||||
if (Opts.Demangle) {
|
if (Opts.Demangle) {
|
||||||
for (int i = 0, n = InlinedContext.getNumberOfFrames(); i < n; i++) {
|
for (int i = 0, n = InlinedContext.getNumberOfFrames(); i < n; i++) {
|
||||||
auto *Frame = InlinedContext.getMutableFrame(i);
|
auto *Frame = InlinedContext.getMutableFrame(i);
|
||||||
|
@ -309,6 +309,9 @@ int main(int argc, char **argv) {
|
|||||||
Opts.FallbackDebugPath = ClFallbackDebugPath;
|
Opts.FallbackDebugPath = ClFallbackDebugPath;
|
||||||
Opts.DWPName = ClDwpName;
|
Opts.DWPName = ClDwpName;
|
||||||
Opts.DebugFileDirectory = ClDebugFileDirectory;
|
Opts.DebugFileDirectory = ClDebugFileDirectory;
|
||||||
|
Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
|
||||||
|
if (ClBasenames)
|
||||||
|
Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::BaseNameOnly;
|
||||||
|
|
||||||
for (const auto &hint : ClDsymHint) {
|
for (const auto &hint : ClDsymHint) {
|
||||||
if (sys::path::extension(hint) == ".dSYM") {
|
if (sys::path::extension(hint) == ".dSYM") {
|
||||||
@ -322,7 +325,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None,
|
DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None,
|
||||||
ClPrettyPrint, ClPrintSourceContextLines, ClVerbose,
|
ClPrettyPrint, ClPrintSourceContextLines, ClVerbose,
|
||||||
ClBasenames, ClOutputStyle);
|
ClOutputStyle);
|
||||||
|
|
||||||
if (ClInputAddresses.empty()) {
|
if (ClInputAddresses.empty()) {
|
||||||
const int kMaxInputStringLength = 1024;
|
const int kMaxInputStringLength = 1024;
|
||||||
|
@ -1324,7 +1324,12 @@ TEST_F(DebugLineBasicFixture, PrintPathsProperly) {
|
|||||||
EXPECT_TRUE((*ExpectedLineTable)
|
EXPECT_TRUE((*ExpectedLineTable)
|
||||||
->Prologue.getFileNameByIndex(
|
->Prologue.getFileNameByIndex(
|
||||||
1, CompDir,
|
1, CompDir,
|
||||||
DILineInfoSpecifier::FileLineInfoKind::Default, Result));
|
DILineInfoSpecifier::FileLineInfoKind::RawValue, Result));
|
||||||
|
EXPECT_TRUE((*ExpectedLineTable)
|
||||||
|
->Prologue.getFileNameByIndex(
|
||||||
|
1, CompDir,
|
||||||
|
DILineInfoSpecifier::FileLineInfoKind::BaseNameOnly,
|
||||||
|
Result));
|
||||||
EXPECT_STREQ(Result.c_str(), "b file");
|
EXPECT_STREQ(Result.c_str(), "b file");
|
||||||
EXPECT_TRUE((*ExpectedLineTable)
|
EXPECT_TRUE((*ExpectedLineTable)
|
||||||
->Prologue.getFileNameByIndex(
|
->Prologue.getFileNameByIndex(
|
||||||
|
Loading…
Reference in New Issue
Block a user