diff --git a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h --- a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h +++ b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h @@ -34,6 +34,7 @@ struct Request { StringRef ModuleName; std::optional Address; + StringRef Symbol; }; class DIPrinter { @@ -46,6 +47,8 @@ virtual void print(const Request &Request, const DIGlobal &Global) = 0; virtual void print(const Request &Request, const std::vector &Locals) = 0; + virtual void print(const Request &Request, + const std::vector &Locations) = 0; virtual void printInvalidCommand(const Request &Request, StringRef Command) = 0; @@ -94,6 +97,8 @@ void print(const Request &Request, const DIGlobal &Global) override; void print(const Request &Request, const std::vector &Locals) override; + void print(const Request &Request, + const std::vector &Locations) override; void printInvalidCommand(const Request &Request, StringRef Command) override; @@ -146,6 +151,8 @@ void print(const Request &Request, const DIGlobal &Global) override; void print(const Request &Request, const std::vector &Locals) override; + void print(const Request &Request, + const std::vector &Locations) override; void printInvalidCommand(const Request &Request, StringRef Command) override; diff --git a/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h b/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h --- a/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h +++ b/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h @@ -36,6 +36,9 @@ virtual std::vector symbolizeFrame(object::SectionedAddress ModuleOffset) const = 0; + virtual std::vector + findSymbol(StringRef Symbol) const = 0; + // Return true if this is a 32-bit x86 PE COFF module. virtual bool isWin32Module() const = 0; diff --git a/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableObjectFile.h b/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableObjectFile.h --- a/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableObjectFile.h +++ b/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableObjectFile.h @@ -43,6 +43,8 @@ DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override; std::vector symbolizeFrame(object::SectionedAddress ModuleOffset) const override; + std::vector + findSymbol(StringRef Symbol) const override; // Return true if this is a 32-bit x86 PE COFF module. bool isWin32Module() const override; diff --git a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h --- a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h +++ b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h @@ -104,6 +104,14 @@ Expected> symbolizeFrame(ArrayRef BuildID, object::SectionedAddress ModuleOffset); + + Expected> findSymbol(const ObjectFile &Obj, + StringRef Symbol); + Expected> findSymbol(const std::string &ModuleName, + StringRef Symbol); + Expected> findSymbol(ArrayRef BuildID, + StringRef Symbol); + void flush(); // Evict entries from the binary cache until it is under the maximum size @@ -139,6 +147,9 @@ Expected> symbolizeFrameCommon(const T &ModuleSpecifier, object::SectionedAddress ModuleOffset); + template + Expected> findSymbolCommon(const T &ModuleSpecifier, + StringRef Symbol); /// Returns a SymbolizableModule or an error if loading debug info failed. /// Only one attempt is made to load a module, and errors during loading are diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp --- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp +++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp @@ -260,6 +260,16 @@ printFooter(); } +void PlainPrinterBase::print(const Request &Request, + const std::vector &Locations) { + if (Locations.empty()) + OS << DILineInfo::Addr2LineBadString << ":0\n"; + else + for (const DILineInfo &L : Locations) + print(L, false); + printFooter(); +} + void PlainPrinterBase::printInvalidCommand(const Request &Request, StringRef Command) { OS << Command << '\n'; @@ -278,6 +288,8 @@ static json::Object toJSON(const Request &Request, StringRef ErrorMsg = "") { json::Object Json({{"ModuleName", Request.ModuleName.str()}}); + if (!Request.Symbol.empty()) + Json["SymName"] = Request.Symbol.str(); if (Request.Address) Json["Address"] = toHex(*Request.Address); if (!ErrorMsg.empty()) @@ -367,6 +379,19 @@ printJSON(std::move(Json)); } +void JSONPrinter::print(const Request &Request, + const std::vector &Locations) { + json::Array Definitions; + for (const DILineInfo &L : Locations) + Definitions.push_back(toJSON(L)); + json::Object Json = toJSON(Request); + Json["Loc"] = std::move(Definitions); + if (ObjectList) + ObjectList->push_back(std::move(Json)); + else + printJSON(std::move(Json)); +} + void JSONPrinter::printInvalidCommand(const Request &Request, StringRef Command) { printError(Request, diff --git a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp --- a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp +++ b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp @@ -351,6 +351,18 @@ return DebugInfoContext->getLocalsForAddress(ModuleOffset); } +std::vector +SymbolizableObjectFile::findSymbol(StringRef Symbol) const { + std::vector Result; + for (const SymbolDesc &Sym : Symbols) + if (Sym.Name.equals(Symbol)) { + object::SectionedAddress A{Sym.Addr, + getModuleSectionIndexForAddress(Sym.Addr)}; + Result.push_back(A); + } + return Result; +} + /// Search for the first occurence of specified Address in ObjectFile. uint64_t SymbolizableObjectFile::getModuleSectionIndexForAddress( uint64_t Address) const { diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -230,6 +230,50 @@ return symbolizeFrameCommon(BuildID, ModuleOffset); } +template +Expected> +LLVMSymbolizer::findSymbolCommon(const T &ModuleSpecifier, StringRef Symbol) { + auto InfoOrErr = getOrCreateModuleInfo(ModuleSpecifier); + if (!InfoOrErr) + return InfoOrErr.takeError(); + + SymbolizableModule *Info = *InfoOrErr; + std::vector Result; + + // A null module means an error has already been reported. Return an empty + // result. + if (!Info) + return Result; + + for (object::SectionedAddress A : Info->findSymbol(Symbol)) { + DILineInfo LineInfo = Info->symbolizeCode( + A, DILineInfoSpecifier(Opts.PathStyle, Opts.PrintFunctions), + Opts.UseSymbolTable); + if (LineInfo.FileName != DILineInfo::BadString) { + if (Opts.Demangle) + LineInfo.FunctionName = DemangleName(LineInfo.FunctionName, Info); + Result.push_back(LineInfo); + } + } + + return Result; +} + +Expected> +LLVMSymbolizer::findSymbol(const ObjectFile &Obj, StringRef Symbol) { + return findSymbolCommon(Obj, Symbol); +} + +Expected> +LLVMSymbolizer::findSymbol(const std::string &ModuleName, StringRef Symbol) { + return findSymbolCommon(ModuleName, Symbol); +} + +Expected> +LLVMSymbolizer::findSymbol(ArrayRef BuildID, StringRef Symbol) { + return findSymbolCommon(BuildID, Symbol); +} + void LLVMSymbolizer::flush() { ObjectForUBPathAndArch.clear(); LRUBinaries.clear(); diff --git a/llvm/test/tools/llvm-symbolizer/Inputs/addr2.inp b/llvm/test/tools/llvm-symbolizer/Inputs/addr2.inp new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/Inputs/addr2.inp @@ -0,0 +1,3 @@ +0some text +0x40054d +0some text2 diff --git a/llvm/test/tools/llvm-symbolizer/invalid-input-address.test b/llvm/test/tools/llvm-symbolizer/invalid-input-address.test --- a/llvm/test/tools/llvm-symbolizer/invalid-input-address.test +++ b/llvm/test/tools/llvm-symbolizer/invalid-input-address.test @@ -15,9 +15,12 @@ RUN: llvm-symbolizer --obj=%p/Inputs/addr.exe @%t.rsp | FileCheck --check-prefix=BAD-INPUT %s # Test bad input address values for the GNU-compatible version. -RUN: llvm-addr2line --obj=%p/Inputs/addr.exe < %t.inp | FileCheck --check-prefix=BAD-INPUT %s -RUN: llvm-addr2line --obj=%p/Inputs/addr.exe "some text" "some text2" | FileCheck --check-prefix=BAD-INPUT %s -RUN: llvm-addr2line --obj=%p/Inputs/addr.exe @%t.rsp | FileCheck --check-prefix=BAD-INPUT %s +RUN: llvm-addr2line --obj=%p/Inputs/addr.exe < %t.inp | FileCheck --check-prefix=BAD-INPUT-GNU %s +RUN: llvm-addr2line --obj=%p/Inputs/addr.exe "some text" "some text2" | FileCheck --check-prefix=BAD-INPUT-GNU %s +RUN: llvm-addr2line --obj=%p/Inputs/addr.exe @%t.rsp | FileCheck --check-prefix=BAD-INPUT-GNU %s BAD-INPUT: some text BAD-INPUT-NEXT: some text2 + +BAD-INPUT-GNU: ??:0 +BAD-INPUT-GNU-NEXT: ??:0 diff --git a/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test b/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test --- a/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test +++ b/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test @@ -9,7 +9,7 @@ RUN: | FileCheck %s --check-prefix=LLVM RUN: llvm-symbolizer --output-style=GNU -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \ -RUN: | FileCheck %s --check-prefix=GNU +RUN: | FileCheck %s --check-prefix=GNUOUT RUN: llvm-addr2line -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \ RUN: | FileCheck %s --check-prefix=GNU @@ -18,11 +18,18 @@ RUN: | FileCheck %s --check-prefix=GNU RUN: llvm-addr2line --output-style=LLVM -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \ -RUN: | FileCheck %s --check-prefix=LLVM +RUN: | FileCheck %s --check-prefix=LLVMOUT LLVM: x.c:14:0 LLVM-EMPTY: LLVM-NEXT: some text2 GNU: x.c:14 -GNU-NEXT: some text2 +GNU-NEXT: ??:0 + +GNUOUT: x.c:14 +GNUOUT-NEXT: some text2 + +LLVMOUT: x.c:14:0 +LLVMOUT-EMPTY: +LLVMOUT-NEXT: ??:0 diff --git a/llvm/test/tools/llvm-symbolizer/output-style-json-code.test b/llvm/test/tools/llvm-symbolizer/output-style-json-code.test --- a/llvm/test/tools/llvm-symbolizer/output-style-json-code.test +++ b/llvm/test/tools/llvm-symbolizer/output-style-json-code.test @@ -43,21 +43,21 @@ ## Also check the last test case with llvm-adr2line. ## The expected result is the same with -f -i. -# RUN: llvm-addr2line --output-style=JSON -f -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp | \ +# RUN: llvm-addr2line --output-style=JSON -f -i -e %p/Inputs/addr.exe < %p/Inputs/addr2.inp | \ # RUN: FileCheck %s --check-prefix=INLINE-A2L --strict-whitespace --match-full-lines --implicit-check-not={{.}} ## Invalid first argument before any valid one. -# INLINE-A2L:{"Error":{"Message":"unable to parse arguments: some text"},"ModuleName":"{{.*}}/Inputs/addr.exe"} +# INLINE-A2L:{"Error":{"Message":"unable to parse arguments: 0some text"},"ModuleName":"{{.*}}/Inputs/addr.exe"} ## Resolve valid address. # INLINE-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inctwo","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"inc","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"main","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]} ## Invalid argument after a valid one. -# INLINE-A2L-NEXT:{"Error":{"Message":"unable to parse arguments: some text2"},"ModuleName":"{{.*}}/Inputs/addr.exe"} +# INLINE-A2L-NEXT:{"Error":{"Message":"unable to parse arguments: 0some text2"},"ModuleName":"{{.*}}/Inputs/addr.exe"} ## Note llvm-addr2line without -f does not print the function name in JSON too. -# RUN: llvm-addr2line --output-style=JSON -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp | \ +# RUN: llvm-addr2line --output-style=JSON -i -e %p/Inputs/addr.exe < %p/Inputs/addr2.inp | \ # RUN: FileCheck %s --check-prefix=NO-FUNC-A2L --strict-whitespace --match-full-lines --implicit-check-not={{.}} ## Invalid first argument before any valid one. -# NO-FUNC-A2L:{"Error":{"Message":"unable to parse arguments: some text"},"ModuleName":"{{.*}}/Inputs/addr.exe"} +# NO-FUNC-A2L:{"Error":{"Message":"unable to parse arguments: 0some text"},"ModuleName":"{{.*}}/Inputs/addr.exe"} ## Resolve valid address. # NO-FUNC-A2L-NEXT:{"Address":"0x40054d","ModuleName":"{{.*}}/Inputs/addr.exe","Symbol":[{"Column":3,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":3,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":2},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":7,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":6},{"Column":0,"Discriminator":0,"FileName":"/tmp{{/|\\\\}}x.c","FunctionName":"","Line":14,"StartAddress":"0x400540","StartFileName":"/tmp{{/|\\\\}}x.c","StartLine":12}]} ## Invalid argument after a valid one. -# NO-FUNC-A2L-NEXT:{"Error":{"Message":"unable to parse arguments: some text2"},"ModuleName":"{{.*}}/Inputs/addr.exe"} +# NO-FUNC-A2L-NEXT:{"Error":{"Message":"unable to parse arguments: 0some text2"},"ModuleName":"{{.*}}/Inputs/addr.exe"} diff --git a/llvm/test/tools/llvm-symbolizer/sym.test b/llvm/test/tools/llvm-symbolizer/sym.test --- a/llvm/test/tools/llvm-symbolizer/sym.test +++ b/llvm/test/tools/llvm-symbolizer/sym.test @@ -66,7 +66,7 @@ #ZERO: ?? #ZERO: ??:0:0 # -#A2L: some text +#A2L: ??:0 #A2L_A-NEXT: 0x40054d #A2L_F-NEXT: inctwo #A2L-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}} @@ -74,9 +74,9 @@ #A2L_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}} #A2L_FI-NEXT: main #A2L_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}} -#A2L-NEXT: some text2 +#A2L-NEXT: ??:0 -#A2LP: some text +#A2LP: ??:0 #A2LP_A-NEXT: 0x40054d: {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}} #A2LP_F-NEXT: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}} #A2LP_AF-NEXT: 0x40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}} @@ -84,4 +84,4 @@ #A2LP_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}} #A2LP_FI-NEXT: (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}} #A2LP_FI-NEXT: (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}} -#A2LP-NEXT: some text2 +#A2LP-NEXT: ??:0 diff --git a/llvm/test/tools/llvm-symbolizer/symbol-search.test b/llvm/test/tools/llvm-symbolizer/symbol-search.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/symbol-search.test @@ -0,0 +1,26 @@ +# This test uses ELF shared object `Inputs/symbols.so` built for x86_64 using +# the instructions from `Inputs/symbols.h`. + +RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so "SYMBOL func_01" | FileCheck --check-prefix=PRFUNC %s +#PRFUNC: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12 + +RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so --pretty-print "SYMBOL func_01" | FileCheck --check-prefix=PRETTY %s +#PRETTY: func_01 at /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12 + +RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so "SYMBOL func_666" | FileCheck --check-prefix=INEXISTENT %s +#INEXISTENT: ?? + +RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so "SYMBOL func_01" "SYMBOL func_02" | FileCheck --check-prefix=FUNCS %s +#FUNCS: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12 +#FUNCS: /tmp/dbginfo{{[/\]+}}symbols.part2.cpp:10 + +RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so "SYMBOL _ZL14static_func_01i" | FileCheck --check-prefix=MULTI %s +#MULTI: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:7 +#MULTI: /tmp/dbginfo{{[/\]+}}symbols.part2.cpp:5 + +RUN: llvm-addr2line -e %p/Inputs/symbols.so func_01 | FileCheck --check-prefix=A2L0 %s +#A2L0: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12 + +RUN: llvm-addr2line -e %p/Inputs/symbols.so static_func | FileCheck --check-prefix=A2LMULTI %s +#A2LMULTI: /tmp/dbginfo{{[/\]+}}symbols.part3.c:4 +#A2LMULTI-NEXT: /tmp/dbginfo{{[/\]+}}symbols.part4.c:4 diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp --- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -120,6 +120,7 @@ Code, Data, Frame, + Symbol, }; static void enableDebuginfod(LLVMSymbolizer &Symbolizer, @@ -138,7 +139,7 @@ static bool parseCommand(StringRef BinaryName, bool IsAddr2Line, StringRef InputString, Command &Cmd, std::string &ModuleName, object::BuildID &BuildID, - uint64_t &ModuleOffset) { + StringRef &Symbol, uint64_t &ModuleOffset) { const char kDelimiters[] = " \n\r"; ModuleName = ""; if (InputString.consume_front("CODE ")) { @@ -147,6 +148,8 @@ Cmd = Command::Data; } else if (InputString.consume_front("FRAME ")) { Cmd = Command::Frame; + } else if (InputString.consume_front("SYMBOL ")) { + Cmd = Command::Symbol; } else { // If no cmd, assume it's CODE. Cmd = Command::Code; @@ -200,26 +203,47 @@ Pos = InputString.data(); ModuleName = BinaryName.str(); } - // Skip delimiters and parse module offset. + + // Parse address, which can be specified as an offset in module or as a + // symbol. 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. + bool StartsWithHexPrefix = false; if (IsAddr2Line) - Offset.consume_front("0x") || Offset.consume_front("0X"); - return !Offset.getAsInteger(IsAddr2Line ? 16 : 0, ModuleOffset); + StartsWithHexPrefix = + Offset.consume_front("0x") || Offset.consume_front("0X"); + if (!Offset.getAsInteger(IsAddr2Line ? 16 : 0, ModuleOffset)) { + // Module offset is an address. + Symbol = StringRef(); + return true; + } + // If address specification starts with a digit, but is not a number, consider + // it as invalid. + if (Offset.empty() || StartsWithHexPrefix || std::isdigit(Offset.front())) + return false; + // Address specification is a symbol if addr2line compatibility mode in on. + // Otherwise treat it as an error for compatibility with previous versions of + // llvm-symbolizer. + if (IsAddr2Line || Cmd == Command::Symbol) { + Symbol = Offset; + ModuleOffset = 0; + return true; + } + return false; } template void executeCommand(StringRef ModuleName, const T &ModuleSpec, Command Cmd, - uint64_t Offset, uint64_t AdjustVMA, bool ShouldInline, - OutputStyle Style, LLVMSymbolizer &Symbolizer, - DIPrinter &Printer) { + StringRef Symbol, uint64_t Offset, uint64_t AdjustVMA, + bool ShouldInline, OutputStyle Style, + LLVMSymbolizer &Symbolizer, DIPrinter &Printer) { uint64_t AdjustedOffset = Offset - AdjustVMA; object::SectionedAddress Address = {AdjustedOffset, object::SectionedAddress::UndefSection}; - Request SymRequest = {ModuleName, Offset}; + Request SymRequest = {ModuleName, Offset, Symbol}; if (Cmd == Command::Data) { Expected ResOrErr = Symbolizer.symbolizeData(ModuleSpec, Address); print(SymRequest, ResOrErr, Printer); @@ -227,6 +251,10 @@ Expected> ResOrErr = Symbolizer.symbolizeFrame(ModuleSpec, Address); print(SymRequest, ResOrErr, Printer); + } else if (Cmd == Command::Symbol || !Symbol.empty()) { + Expected> ResOrErr = + Symbolizer.findSymbol(ModuleSpec, Symbol); + print(SymRequest, ResOrErr, Printer); } else if (ShouldInline) { Expected ResOrErr = Symbolizer.symbolizeInlinedCode(ModuleSpec, Address); @@ -263,9 +291,12 @@ std::string ModuleName; object::BuildID BuildID(IncomingBuildID.begin(), IncomingBuildID.end()); uint64_t Offset = 0; + StringRef Symbol; if (!parseCommand(Args.getLastArgValue(OPT_obj_EQ), IsAddr2Line, - StringRef(InputString), Cmd, ModuleName, BuildID, Offset)) { - Printer.printInvalidCommand({ModuleName, std::nullopt}, InputString); + StringRef(InputString), Cmd, ModuleName, BuildID, Symbol, + Offset)) { + Printer.printInvalidCommand({ModuleName, std::nullopt, Symbol}, + InputString); return; } bool ShouldInline = Args.hasFlag(OPT_inlines, OPT_no_inlines, !IsAddr2Line); @@ -274,11 +305,11 @@ if (!Args.hasArg(OPT_no_debuginfod)) enableDebuginfod(Symbolizer, Args); std::string BuildIDStr = toHex(BuildID); - executeCommand(BuildIDStr, BuildID, Cmd, Offset, AdjustVMA, ShouldInline, - Style, Symbolizer, Printer); + executeCommand(BuildIDStr, BuildID, Cmd, Symbol, Offset, AdjustVMA, + ShouldInline, Style, Symbolizer, Printer); } else { - executeCommand(ModuleName, ModuleName, Cmd, Offset, AdjustVMA, ShouldInline, - Style, Symbolizer, Printer); + executeCommand(ModuleName, ModuleName, Cmd, Symbol, Offset, AdjustVMA, + ShouldInline, Style, Symbolizer, Printer); } } diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp --- a/llvm/unittests/ProfileData/MemProfTest.cpp +++ b/llvm/unittests/ProfileData/MemProfTest.cpp @@ -24,6 +24,7 @@ using ::llvm::DILineInfo; using ::llvm::DILineInfoSpecifier; using ::llvm::DILocal; +using ::llvm::StringRef; using ::llvm::memprof::CallStackMap; using ::llvm::memprof::Frame; using ::llvm::memprof::FrameId; @@ -56,6 +57,9 @@ virtual std::vector symbolizeFrame(SectionedAddress) const { llvm_unreachable("unused"); } + virtual std::vector findSymbol(StringRef Symbol) const { + llvm_unreachable("unused"); + } virtual bool isWin32Module() const { llvm_unreachable("unused"); } virtual uint64_t getModulePreferredBase() const { llvm_unreachable("unused");