diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/llvm12/tools/llvm-symbolizer | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/tools/llvm-symbolizer')
-rw-r--r-- | contrib/libs/llvm12/tools/llvm-symbolizer/llvm-symbolizer.cpp | 332 | ||||
-rw-r--r-- | contrib/libs/llvm12/tools/llvm-symbolizer/ya.make | 42 |
2 files changed, 187 insertions, 187 deletions
diff --git a/contrib/libs/llvm12/tools/llvm-symbolizer/llvm-symbolizer.cpp b/contrib/libs/llvm12/tools/llvm-symbolizer/llvm-symbolizer.cpp index 8734c2d740..394fc5d1a7 100644 --- a/contrib/libs/llvm12/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/contrib/libs/llvm12/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -1,43 +1,43 @@ -//===-- llvm-symbolizer.cpp - Simple addr2line-like symbolizer ------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This utility works much like "addr2line". It is able of transforming -// tuples (module name, module offset) to code locations (function name, -// file, line number, column number). It is targeted for compiler-rt tools -// (especially AddressSanitizer and ThreadSanitizer) that can use it -// to symbolize stack traces in their error reports. -// -//===----------------------------------------------------------------------===// - +//===-- llvm-symbolizer.cpp - Simple addr2line-like symbolizer ------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This utility works much like "addr2line". It is able of transforming +// tuples (module name, module offset) to code locations (function name, +// file, line number, column number). It is targeted for compiler-rt tools +// (especially AddressSanitizer and ThreadSanitizer) that can use it +// to symbolize stack traces in their error reports. +// +//===----------------------------------------------------------------------===// + #include "Opts.inc" -#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Config/config.h" -#include "llvm/DebugInfo/Symbolize/DIPrinter.h" -#include "llvm/DebugInfo/Symbolize/Symbolize.h" +#include "llvm/DebugInfo/Symbolize/DIPrinter.h" +#include "llvm/DebugInfo/Symbolize/Symbolize.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" -#include "llvm/Support/COM.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/InitLLVM.h" -#include "llvm/Support/Path.h" +#include "llvm/Support/COM.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/Path.h" #include "llvm/Support/StringSaver.h" -#include "llvm/Support/raw_ostream.h" -#include <algorithm> -#include <cstdio> -#include <cstring> -#include <string> - -using namespace llvm; -using namespace symbolize; - +#include "llvm/Support/raw_ostream.h" +#include <algorithm> +#include <cstdio> +#include <cstring> +#include <string> + +using namespace llvm; +using namespace symbolize; + namespace { enum ID { OPT_INVALID = 0, // This is not an option ID. @@ -47,11 +47,11 @@ enum ID { #include "Opts.inc" #undef OPTION }; - + #define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; #include "Opts.inc" #undef PREFIX - + static const opt::OptTable::Info InfoTable[] = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ @@ -63,139 +63,139 @@ static const opt::OptTable::Info InfoTable[] = { #include "Opts.inc" #undef OPTION }; - + class SymbolizerOptTable : public opt::OptTable { public: SymbolizerOptTable() : OptTable(InfoTable, true) {} }; } // namespace - -static cl::list<std::string> ClInputAddresses(cl::Positional, - cl::desc("<input addresses>..."), - cl::ZeroOrMore); - -template<typename T> -static bool error(Expected<T> &ResOrErr) { - if (ResOrErr) - return false; - logAllUnhandledErrors(ResOrErr.takeError(), errs(), - "LLVMSymbolizer: error reading file: "); - return true; -} - -enum class Command { - Code, - Data, - Frame, -}; - + +static cl::list<std::string> ClInputAddresses(cl::Positional, + cl::desc("<input addresses>..."), + cl::ZeroOrMore); + +template<typename T> +static bool error(Expected<T> &ResOrErr) { + if (ResOrErr) + return false; + logAllUnhandledErrors(ResOrErr.takeError(), errs(), + "LLVMSymbolizer: error reading file: "); + return true; +} + +enum class Command { + Code, + Data, + Frame, +}; + static bool parseCommand(StringRef BinaryName, bool IsAddr2Line, StringRef InputString, Command &Cmd, - std::string &ModuleName, uint64_t &ModuleOffset) { - const char kDelimiters[] = " \n\r"; - ModuleName = ""; - if (InputString.consume_front("CODE ")) { - Cmd = Command::Code; - } else if (InputString.consume_front("DATA ")) { - Cmd = Command::Data; - } else if (InputString.consume_front("FRAME ")) { - Cmd = Command::Frame; - } else { - // If no cmd, assume it's CODE. - Cmd = Command::Code; - } - const char *Pos = InputString.data(); - // Skip delimiters and parse input filename (if needed). + std::string &ModuleName, uint64_t &ModuleOffset) { + const char kDelimiters[] = " \n\r"; + ModuleName = ""; + if (InputString.consume_front("CODE ")) { + Cmd = Command::Code; + } else if (InputString.consume_front("DATA ")) { + Cmd = Command::Data; + } else if (InputString.consume_front("FRAME ")) { + Cmd = Command::Frame; + } else { + // If no cmd, assume it's CODE. + Cmd = Command::Code; + } + const char *Pos = InputString.data(); + // Skip delimiters and parse input filename (if needed). if (BinaryName.empty()) { - Pos += strspn(Pos, kDelimiters); - if (*Pos == '"' || *Pos == '\'') { - char Quote = *Pos; - Pos++; - const char *End = strchr(Pos, Quote); - if (!End) - return false; - ModuleName = std::string(Pos, End - Pos); - Pos = End + 1; - } else { - int NameLength = strcspn(Pos, kDelimiters); - ModuleName = std::string(Pos, NameLength); - Pos += NameLength; - } - } else { + Pos += strspn(Pos, kDelimiters); + if (*Pos == '"' || *Pos == '\'') { + char Quote = *Pos; + Pos++; + const char *End = strchr(Pos, Quote); + if (!End) + return false; + ModuleName = std::string(Pos, End - Pos); + Pos = End + 1; + } else { + int NameLength = strcspn(Pos, kDelimiters); + ModuleName = std::string(Pos, NameLength); + Pos += NameLength; + } + } else { ModuleName = BinaryName.str(); - } - // Skip delimiters and parse module offset. - Pos += strspn(Pos, kDelimiters); - int OffsetLength = strcspn(Pos, kDelimiters); - StringRef Offset(Pos, OffsetLength); - // GNU addr2line assumes the offset is hexadecimal and allows a redundant - // "0x" or "0X" prefix; do the same for compatibility. - if (IsAddr2Line) - Offset.consume_front("0x") || Offset.consume_front("0X"); - return !Offset.getAsInteger(IsAddr2Line ? 16 : 0, ModuleOffset); -} - + } + // Skip delimiters and parse module offset. + Pos += strspn(Pos, kDelimiters); + int OffsetLength = strcspn(Pos, kDelimiters); + StringRef Offset(Pos, OffsetLength); + // GNU addr2line assumes the offset is hexadecimal and allows a redundant + // "0x" or "0X" prefix; do the same for compatibility. + if (IsAddr2Line) + Offset.consume_front("0x") || Offset.consume_front("0X"); + return !Offset.getAsInteger(IsAddr2Line ? 16 : 0, ModuleOffset); +} + static void symbolizeInput(const opt::InputArgList &Args, uint64_t AdjustVMA, bool IsAddr2Line, DIPrinter::OutputStyle OutputStyle, StringRef InputString, LLVMSymbolizer &Symbolizer, DIPrinter &Printer) { - Command Cmd; - std::string ModuleName; - uint64_t Offset = 0; + Command Cmd; + std::string ModuleName; + uint64_t Offset = 0; if (!parseCommand(Args.getLastArgValue(OPT_obj_EQ), IsAddr2Line, StringRef(InputString), Cmd, ModuleName, Offset)) { - outs() << InputString << "\n"; - return; - } - + outs() << InputString << "\n"; + return; + } + if (Args.hasArg(OPT_addresses)) { - outs() << "0x"; - outs().write_hex(Offset); + outs() << "0x"; + outs().write_hex(Offset); StringRef Delimiter = Args.hasArg(OPT_pretty_print) ? ": " : "\n"; - outs() << Delimiter; - } + outs() << Delimiter; + } Offset -= AdjustVMA; - if (Cmd == Command::Data) { - auto ResOrErr = Symbolizer.symbolizeData( - ModuleName, {Offset, object::SectionedAddress::UndefSection}); - Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get()); - } else if (Cmd == Command::Frame) { - auto ResOrErr = Symbolizer.symbolizeFrame( - ModuleName, {Offset, object::SectionedAddress::UndefSection}); - if (!error(ResOrErr)) { - for (DILocal Local : *ResOrErr) - Printer << Local; - if (ResOrErr->empty()) - outs() << "??\n"; - } + if (Cmd == Command::Data) { + auto ResOrErr = Symbolizer.symbolizeData( + ModuleName, {Offset, object::SectionedAddress::UndefSection}); + Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get()); + } else if (Cmd == Command::Frame) { + auto ResOrErr = Symbolizer.symbolizeFrame( + ModuleName, {Offset, object::SectionedAddress::UndefSection}); + if (!error(ResOrErr)) { + for (DILocal Local : *ResOrErr) + Printer << Local; + if (ResOrErr->empty()) + outs() << "??\n"; + } } else if (Args.hasFlag(OPT_inlines, OPT_no_inlines, !IsAddr2Line)) { - auto ResOrErr = Symbolizer.symbolizeInlinedCode( - ModuleName, {Offset, object::SectionedAddress::UndefSection}); - Printer << (error(ResOrErr) ? DIInliningInfo() : ResOrErr.get()); + auto ResOrErr = Symbolizer.symbolizeInlinedCode( + ModuleName, {Offset, object::SectionedAddress::UndefSection}); + Printer << (error(ResOrErr) ? DIInliningInfo() : ResOrErr.get()); } else if (OutputStyle == DIPrinter::OutputStyle::GNU) { // With PrintFunctions == FunctionNameKind::LinkageName (default) // and UseSymbolTable == true (also default), Symbolizer.symbolizeCode() - // may override the name of an inlined function with the name of the topmost - // caller function in the inlining chain. This contradicts the existing - // behavior of addr2line. Symbolizer.symbolizeInlinedCode() overrides only - // the topmost function, which suits our needs better. - auto ResOrErr = Symbolizer.symbolizeInlinedCode( - ModuleName, {Offset, object::SectionedAddress::UndefSection}); + // may override the name of an inlined function with the name of the topmost + // caller function in the inlining chain. This contradicts the existing + // behavior of addr2line. Symbolizer.symbolizeInlinedCode() overrides only + // the topmost function, which suits our needs better. + auto ResOrErr = Symbolizer.symbolizeInlinedCode( + ModuleName, {Offset, object::SectionedAddress::UndefSection}); if (!ResOrErr || ResOrErr->getNumberOfFrames() == 0) { error(ResOrErr); Printer << DILineInfo(); } else { Printer << ResOrErr->getFrame(0); } - } else { - auto ResOrErr = Symbolizer.symbolizeCode( - ModuleName, {Offset, object::SectionedAddress::UndefSection}); - Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get()); - } + } else { + auto ResOrErr = Symbolizer.symbolizeCode( + ModuleName, {Offset, object::SectionedAddress::UndefSection}); + Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get()); + } if (OutputStyle == DIPrinter::OutputStyle::LLVM) - outs() << "\n"; -} - + outs() << "\n"; +} + static void printHelp(StringRef ToolName, const SymbolizerOptTable &Tbl, raw_ostream &OS) { const char HelpText[] = " [options] addresses..."; @@ -204,7 +204,7 @@ static void printHelp(StringRef ToolName, const SymbolizerOptTable &Tbl, // TODO Replace this with OptTable API once it adds extrahelp support. OS << "\nPass @FILE as argument to read options from FILE.\n"; } - + static opt::InputArgList parseOptions(int Argc, char *Argv[], bool IsAddr2Line, StringSaver &Saver, SymbolizerOptTable &Tbl) { @@ -231,7 +231,7 @@ static opt::InputArgList parseOptions(int Argc, char *Argv[], bool IsAddr2Line, cl::PrintVersionMessage(); exit(0); } - + return Args; } @@ -246,9 +246,9 @@ static void parseIntArg(const opt::InputArgList &Args, int ID, T &Value) { } } else { Value = 0; - } + } } - + static FunctionNameKind decideHowToPrintFunctions(const opt::InputArgList &Args, bool IsAddr2Line) { if (Args.hasArg(OPT_functions)) @@ -260,18 +260,18 @@ static FunctionNameKind decideHowToPrintFunctions(const opt::InputArgList &Args, .Default(FunctionNameKind::LinkageName); return IsAddr2Line ? FunctionNameKind::None : FunctionNameKind::LinkageName; } - + int main(int argc, char **argv) { InitLLVM X(argc, argv); sys::InitializeCOMRAII COM(sys::COMThreadingMode::MultiThreaded); - + bool IsAddr2Line = sys::path::stem(argv[0]).contains("addr2line"); BumpPtrAllocator A; StringSaver Saver(A); SymbolizerOptTable Tbl; opt::InputArgList Args = parseOptions(argc, argv, IsAddr2Line, Saver, Tbl); - LLVMSymbolizer::Options Opts; + LLVMSymbolizer::Options Opts; uint64_t AdjustVMA; unsigned SourceContextLines; parseIntArg(Args, OPT_adjust_vma_EQ, AdjustVMA); @@ -302,16 +302,16 @@ int main(int argc, char **argv) { } #endif Opts.UseSymbolTable = true; - + for (const opt::Arg *A : Args.filtered(OPT_dsym_hint_EQ)) { StringRef Hint(A->getValue()); if (sys::path::extension(Hint) == ".dSYM") { Opts.DsymHints.emplace_back(Hint); - } else { + } else { errs() << "Warning: invalid dSYM hint: \"" << Hint << "\" (must have the '.dSYM' extension).\n"; - } - } + } + } auto OutputStyle = IsAddr2Line ? DIPrinter::OutputStyle::GNU : DIPrinter::OutputStyle::LLVM; @@ -321,30 +321,30 @@ int main(int argc, char **argv) { : DIPrinter::OutputStyle::LLVM; } - LLVMSymbolizer Symbolizer(Opts); + LLVMSymbolizer Symbolizer(Opts); DIPrinter Printer(outs(), Opts.PrintFunctions != FunctionNameKind::None, Args.hasArg(OPT_pretty_print), SourceContextLines, Args.hasArg(OPT_verbose), OutputStyle); - + std::vector<std::string> InputAddresses = Args.getAllArgValues(OPT_INPUT); if (InputAddresses.empty()) { - const int kMaxInputStringLength = 1024; - char InputString[kMaxInputStringLength]; - - while (fgets(InputString, sizeof(InputString), stdin)) { - // Strip newline characters. - std::string StrippedInputString(InputString); + const int kMaxInputStringLength = 1024; + char InputString[kMaxInputStringLength]; + + while (fgets(InputString, sizeof(InputString), stdin)) { + // Strip newline characters. + std::string StrippedInputString(InputString); llvm::erase_if(StrippedInputString, [](char c) { return c == '\r' || c == '\n'; }); symbolizeInput(Args, AdjustVMA, IsAddr2Line, OutputStyle, StrippedInputString, Symbolizer, Printer); - outs().flush(); - } - } else { + outs().flush(); + } + } else { for (StringRef Address : InputAddresses) symbolizeInput(Args, AdjustVMA, IsAddr2Line, OutputStyle, Address, Symbolizer, Printer); - } - - return 0; -} + } + + return 0; +} diff --git a/contrib/libs/llvm12/tools/llvm-symbolizer/ya.make b/contrib/libs/llvm12/tools/llvm-symbolizer/ya.make index 1f13f78269..35bf52aeca 100644 --- a/contrib/libs/llvm12/tools/llvm-symbolizer/ya.make +++ b/contrib/libs/llvm12/tools/llvm-symbolizer/ya.make @@ -1,17 +1,17 @@ -# Generated by devtools/yamaker. - -PROGRAM() - +# Generated by devtools/yamaker. + +PROGRAM() + OWNER( orivej g:cpp-contrib ) - + LICENSE(Apache-2.0 WITH LLVM-exception) - + LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -PEERDIR( +PEERDIR( contrib/libs/llvm12 contrib/libs/llvm12/include contrib/libs/llvm12/lib/BinaryFormat @@ -31,19 +31,19 @@ PEERDIR( contrib/libs/llvm12/lib/Remarks contrib/libs/llvm12/lib/Support contrib/libs/llvm12/lib/TextAPI/MachO -) - -ADDINCL( +) + +ADDINCL( ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/tools/llvm-symbolizer contrib/libs/llvm12/tools/llvm-symbolizer -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - -SRCS( - llvm-symbolizer.cpp -) - -END() +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + llvm-symbolizer.cpp +) + +END() |