Symbolize: Replace the Options constructor with in-class initialization. NFCI.

This is not only less code but also clearer at the use site.

Differential Revision: https://reviews.llvm.org/D63113

llvm-svn: 363024
This commit is contained in:
Peter Collingbourne 2019-06-11 02:31:54 +00:00
parent fc2b5c40ae
commit a2048f868d
8 changed files with 22 additions and 35 deletions

View File

@ -35,25 +35,17 @@ using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
class LLVMSymbolizer {
public:
struct Options {
FunctionNameKind PrintFunctions;
bool UseSymbolTable : 1;
bool Demangle : 1;
bool RelativeAddresses : 1;
FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName;
bool UseSymbolTable = true;
bool Demangle = true;
bool RelativeAddresses = false;
std::string DefaultArch;
std::vector<std::string> DsymHints;
std::string FallbackDebugPath;
Options(FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName,
bool UseSymbolTable = true, bool Demangle = true,
bool RelativeAddresses = false, std::string DefaultArch = "",
std::string FallbackDebugPath = "")
: PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable),
Demangle(Demangle), RelativeAddresses(RelativeAddresses),
DefaultArch(std::move(DefaultArch)),
FallbackDebugPath(std::move(FallbackDebugPath)) {}
};
LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
LLVMSymbolizer() = default;
LLVMSymbolizer(const Options &Opts) : Opts(Opts) {}
~LLVMSymbolizer() {
flush();

View File

@ -529,9 +529,10 @@ private:
public:
SourcePrinter() = default;
SourcePrinter(const ObjectFile *Obj, StringRef DefaultArch) : Obj(Obj) {
symbolize::LLVMSymbolizer::Options SymbolizerOpts(
DILineInfoSpecifier::FunctionNameKind::None, true, false, false,
DefaultArch);
symbolize::LLVMSymbolizer::Options SymbolizerOpts;
SymbolizerOpts.PrintFunctions = DILineInfoSpecifier::FunctionNameKind::None;
SymbolizerOpts.Demangle = false;
SymbolizerOpts.DefaultArch = DefaultArch;
Symbolizer.reset(new symbolize::LLVMSymbolizer(SymbolizerOpts));
}
virtual ~SourcePrinter() = default;

View File

@ -268,9 +268,13 @@ int main(int argc, char **argv) {
if (ClNoDemangle.getPosition() > ClDemangle.getPosition())
ClDemangle = !ClNoDemangle;
LLVMSymbolizer::Options Opts(ClPrintFunctions, ClUseSymbolTable, ClDemangle,
ClUseRelativeAddress, ClDefaultArch,
ClFallbackDebugPath);
LLVMSymbolizer::Options Opts;
Opts.PrintFunctions = ClPrintFunctions;
Opts.UseSymbolTable = ClUseSymbolTable;
Opts.Demangle = ClDemangle;
Opts.RelativeAddresses = ClUseRelativeAddress;
Opts.DefaultArch = ClDefaultArch;
Opts.FallbackDebugPath = ClFallbackDebugPath;
for (const auto &hint : ClDsymHint) {
if (sys::path::extension(hint) == ".dSYM") {

View File

@ -427,9 +427,7 @@ static CommandRegistration Unused(&Account, []() -> Error {
Twine("Cannot open file '") + AccountOutput + "' for writing.", EC);
const auto &FunctionAddresses = Map.getFunctionAddresses();
symbolize::LLVMSymbolizer::Options Opts(
symbolize::FunctionNameKind::LinkageName, true, true, false, "");
symbolize::LLVMSymbolizer Symbolizer(Opts);
symbolize::LLVMSymbolizer Symbolizer;
llvm::xray::FuncIdConversionHelper FuncIdHelper(AccountInstrMap, Symbolizer,
FunctionAddresses);
xray::LatencyAccountant FCA(FuncIdHelper, AccountDeduceSiblingCalls);

View File

@ -380,9 +380,7 @@ static CommandRegistration Unused(&Convert, []() -> Error {
}
const auto &FunctionAddresses = Map.getFunctionAddresses();
symbolize::LLVMSymbolizer::Options Opts(
symbolize::FunctionNameKind::LinkageName, true, true, false, "");
symbolize::LLVMSymbolizer Symbolizer(Opts);
symbolize::LLVMSymbolizer Symbolizer;
llvm::xray::FuncIdConversionHelper FuncIdHelper(ConvertInstrMap, Symbolizer,
FunctionAddresses);
llvm::xray::TraceConverter TC(FuncIdHelper, ConvertSymbolize);

View File

@ -86,9 +86,7 @@ static CommandRegistration Unused(&Extract, []() -> Error {
Twine("Cannot open file '") + ExtractOutput + "' for writing.", EC);
const auto &FunctionAddresses =
InstrumentationMapOrError->getFunctionAddresses();
symbolize::LLVMSymbolizer::Options Opts(
symbolize::FunctionNameKind::LinkageName, true, true, false, "");
symbolize::LLVMSymbolizer Symbolizer(Opts);
symbolize::LLVMSymbolizer Symbolizer;
llvm::xray::FuncIdConversionHelper FuncIdHelper(ExtractInput, Symbolizer,
FunctionAddresses);
exportAsYAML(*InstrumentationMapOrError, OS, FuncIdHelper);

View File

@ -436,9 +436,7 @@ Expected<GraphRenderer> GraphRenderer::Factory::getGraphRenderer() {
const auto &FunctionAddresses = Map.getFunctionAddresses();
symbolize::LLVMSymbolizer::Options Opts(
symbolize::FunctionNameKind::LinkageName, true, true, false, "");
symbolize::LLVMSymbolizer Symbolizer(Opts);
symbolize::LLVMSymbolizer Symbolizer;
const auto &Header = Trace.getFileHeader();
llvm::xray::FuncIdConversionHelper FuncIdHelper(InstrMap, Symbolizer,

View File

@ -720,9 +720,7 @@ static CommandRegistration Unused(&Stack, []() -> Error {
"-all-stacks."),
std::make_error_code(std::errc::invalid_argument));
symbolize::LLVMSymbolizer::Options Opts(
symbolize::FunctionNameKind::LinkageName, true, true, false, "");
symbolize::LLVMSymbolizer Symbolizer(Opts);
symbolize::LLVMSymbolizer Symbolizer;
FuncIdConversionHelper FuncIdHelper(StacksInstrMap, Symbolizer,
Map.getFunctionAddresses());
// TODO: Someday, support output to files instead of just directly to