aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-12-02[tools] Use std::nullopt instead of None (NFC)Kazu Hirata1-3/+3
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-09-28[NFC] [Object] Create library to fetch debug info by build ID.Daniel Thornburgh1-15/+15
This creates a library for fetching debug info by build ID, whether locally or remotely via debuginfod. The functionality was refactored out of existing code in the Symboliize library. Existing utilities were refactored to use this library. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D132504
2022-09-28[iwyu] Move <iostream> out of llvm/DebugInfo/Symbolize/Markup.h headerserge-sans-paille1-0/+1
It's only used in the implementation. No functional change intended.
2022-08-04[Symbolizer] Implement data symbolizer markup element.Daniel Thornburgh1-14/+14
This connects the Symbolizer to the markup filter and enables the first working end-to-end flow using the filter. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D130187
2022-07-22[Symbolizer] Fix use-after-freeBenjamin Kramer1-1/+2
MarkupFilter keeps a reference to the last filtered StringRef. Just keep it alive a bit longer. Found by asan.
2022-07-21[Symbolizer] Implement contextual symbolizer markup elements.Daniel Thornburgh1-9/+3
This change implements the contextual symbolizer markup elements: reset, module, and mmap. These provide information about the runtime context of the binary necessary to resolve addresses to symbolic values. Summary information is printed to the output about this context. Multiple mmap elements for the same module line are coalesced together. The standard requires that such elements occur on their own lines to allow for this; accordingly, anything after a contextual element on a line is silently discarded. Implementing this cleanly requires that the filter drive the parser; this allows skipped sections to avoid being parsed. This also makes the filter quite a bit easier to use, at the cost of some unused flexibility. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D129519
2022-06-27[Symbolize] Add log markup --filter to llvm-symbolizer.Daniel Thornburgh1-0/+34
This adds a --filter option to llvm-symbolizer. This takes log-bearing symbolizer markup from stdin and writes a human-readable version to stdout. For now, this only implements the "symbol" markup tag; all others are passed through unaltered. This is a proof-of-concept bit of functionalty; implement the various tags is more-or-less just a matter of hooking up various parts of the Symbolize library to the architecture established here. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D126980
2022-02-25[Debuginfod] Add BUILD_ID syntax to llvm-symbolizer.Daniel Thornburgh1-48/+83
This adds a BUILD_ID prefix to the llvm-symbolizer stdin and argument syntax. The prefix causes the given binary name to be interpreted as a build ID instead of an object file path. The semantics are analagous to the behavior of --obj and --build-id. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D119901
2022-02-25[Symbolize] LRU cache binaries in llvm-symbolizer.Daniel Thornburgh1-0/+3
This change adds a simple LRU cache to the Symbolize class to put a cap on llvm-symbolizer memory usage. Previously, the Symbolizer's virtual memory footprint would grow without bound as additional binaries were referenced. I'm putting this out there early for an informal review, since there may be a dramatically different/better way to go about this. I still need to figure out a good default constant for the memory cap and benchmark the implementation against a large symbolization workload. Right now I've pegged max memory usage at zero for testing purposes, which evicts the whole cache every time. Unfortunately, it looks like StringRefs in the returned DI objects can directly refer to the contents of binaries. Accordingly, the cache pruning must be explicitly requested by the caller, as the caller must guarantee that none of the returned objects will be used afterwards. For llvm-symbolizer this a light burden; symbolization occurs line-by-line, and the returned objects are discarded after each. Implementation wise, there are a number of nested caches that depend on one another. I've implemented a simple Evictor callback system to allow derived caches to register eviction actions to occur when the underlying binaries are evicted. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D119784
2022-02-24Cleanup include: DebugInfo/Symbolizeserge-sans-paille1-0/+1
Estimation of the impact on preprocessor output after: 1067349756 before:1067487786 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120433
2022-02-09[Debuginfod] Flag-determine debuginfod lookups in llvm-symbolizer.Daniel Thornburgh1-4/+29
This change adds a pair of flags controlling whether llvm-symbolizer attempts debuginfod lookups. Lookups are attempted if --debuginfod is passed and disabled if --no-debuginfod is passed. The default behavior is made more nuanced: debuginfod lookups are now only attempted if an HTTP client is compiled in and at least one backing debuginfod URL was configured via environment variable. Previously, debuginfod lookups would always be attempted, even if there were no chance that they could succeed. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D118665
2022-02-08[Symbolizer] Add Build ID flag to llvm-symbolizer.Daniel Thornburgh1-31/+72
This adds a --build-id=<hex build ID> flag to llvm-symbolizer. If --obj is unspecified, this will attempt to look up the provided build ID using whatever mechanisms are available to the Symbolizer (typically, debuginfod). The semantics are then as if the found binary were given using the --obj flag. Reviewed By: jhenderson, phosek Differential Revision: https://reviews.llvm.org/D118633
2022-02-08[Debuginfod] [Symbolizer] Break debuginfod out of libLLVM.Daniel Thornburgh1-2/+7
Debuginfod can pull in libcurl as a dependency, which isn't appropriate for libLLVM. (See https://gitlab.freedesktop.org/mesa/mesa/-/issues/5732). This change breaks out debuginfod into a separate non-component library that can be used directly in llvm-symbolizer. The tool can inject debuginfod into the Symbolizer library via an abstract DebugInfoFetcher interface, breaking the dependency of Symbolizer on debuinfod. See https://github.com/llvm/llvm-project/issues/52731 Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D118413
2021-12-13[Symbolizer][Debuginfo] Add debuginfod client to llvm-symbolizer.Noah Shutty1-0/+3
Adds a fallback to use the debuginfod client library (386655) in `findDebugBinary`. Fixed a cast of Erorr::success() to Expected<> in debuginfod library. Added Debuginfod to Symbolize deps in gn. Updates compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh to include Debuginfod library to fix sanitizer-x86_64-linux breakage. Reviewed By: jhenderson, vitalybuka Differential Revision: https://reviews.llvm.org/D113717
2021-12-10Revert "[Symbolizer][Debuginfo] Add debuginfod client to llvm-symbolizer."Nico Weber1-3/+0
This reverts commit 5bba0fe12b2971a9cbc859f48ee6e6c1356c88b8. Makes lld depend on libcurl, see comments on https://reviews.llvm.org/D113717
2021-12-10[Symbolizer][Debuginfo] Add debuginfod client to llvm-symbolizer.Noah Shutty1-0/+3
Adds a fallback to use the debuginfod client library (386655) in `findDebugBinary`. Fixed a cast of Erorr::success() to Expected<> in debuginfod library. Added Debuginfod to Symbolize deps in gn. Updates compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh to include Debuginfod library to fix sanitizer-x86_64-linux breakage. Reviewed By: jhenderson, vitalybuka Differential Revision: https://reviews.llvm.org/D113717
2021-12-10Revert "[Symbolizer][Debuginfo] Add debuginfod client to llvm-symbolizer."Noah Shutty1-3/+0
This reverts commit e2ad4f1756027cd27f6c82db620042e9877f900c because it does not correctly fix the sanitizer buildbot breakage.
2021-12-10[Symbolizer][Debuginfo] Add debuginfod client to llvm-symbolizer.Noah Shutty1-0/+3
Adds a fallback to use the debuginfod client library (386655) in `findDebugBinary`. Fixed a cast of Erorr::success() to Expected<> in debuginfod library. Added Debuginfod to Symbolize deps in gn. Adds new symbolizer symbols to `global_symbols.txt`. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D113717
2021-12-08Revert "[Symbolizer][Debuginfo] Add debuginfod client to llvm-symbolizer."Noah Shutty1-4/+0
This reverts commit 02cc8d698c4941f8f0120ea1a5d7205fb33a312d because it caused buildbot failures. The issue appears to be simply that we need to only enable debuginfod when the HTTPClient has been initialized by the running tool, since InitLLVM does not do the initialization step anymore.
2021-12-08[Symbolizer][Debuginfo] Add debuginfod client to llvm-symbolizer.Noah Shutty1-0/+4
Adds a fallback to use the debuginfod client library (386655) in `findDebugBinary`. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D113717
2021-10-18[tools] Delete redundant 'static' from namespace scope 'static const'. NFCFangrui Song1-1/+1
2021-07-01[llvm-symbolizer] Move setGroupedShortOptions and don't ignore caseFangrui Song1-2/+3
setGroupedShortOptions in the ctor seems more popular.
2021-06-24[OptTable] Rename PrintHelp to printHelpFangrui Song1-1/+1
To be consistent with other member functions and match the coding standard.
2021-05-11* Add support for JSON output style to llvm-symbolizerAlex Orlov1-7/+12
This patch adds JSON output style to llvm-symbolizer to better support CLI automation by providing a machine readable output. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D96883
2021-04-14[llvm-symbolizer] remove unused variableNico Weber1-4/+0
This should've been removed in D83530. Differential Revision: https://reviews.llvm.org/D100434
2021-04-06[llvm-symbolizer] Don't use the same 'OutputStyle' name for the enum type ↵Simon Pilgrim1-10/+10
and instance. NFCI. This was causing some buildbot problems, e.g. http://lab.llvm.org:8011/#/builders/110/builds/2306
2021-04-05* NFC. Refactored DIPrinter for better support of new print styles.Alex Orlov1-56/+65
This patch introduces a DIPrinter interface to implement by different output style printer implementations. DIPrinterGNU and DIPrinterLLVM implement the GNU and LLVM output style printing respectively. No functional changes. This refactoring clarifies and simplifies the code, and makes a new output style addition easier. Reviewed By: jhenderson, dblaikie Differential Revision: https://reviews.llvm.org/D98994
2021-01-30[llvm-symbolizer] - Fix the crash in GNU output style with --no-inlines and ↵Georgii Rymar1-1/+6
missing input file. Fixes https://bugs.llvm.org/show_bug.cgi?id=48882. If the input file does not exist (or has a reading error), the following code will crash if there are two or more input addresses. ``` auto ResOrErr = Symbolizer.symbolizeInlinedCode( ModuleName, {Offset, object::SectionedAddress::UndefSection}); Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get().getFrame(0)); ``` For the first address, `symbolizeInlinedCode` returns an error. For the second address, `symbolizeInlinedCode` returns an empty result (not an error) and `.getFrame(0)` will crash. Differential revision: https://reviews.llvm.org/D95609
2020-12-26[llvm-cov, llvm-symbolizer] Use llvm::erase_if (NFC)Kazu Hirata1-4/+2
2020-12-15[llvm-symbolizer] Add missing include for config.hAmy Huang1-0/+1
The cmake variable LLVM_ENABLE_DIA_SDK was being used here but was undefined because config.h wasn't included. Differential Revision: https://reviews.llvm.org/D93309
2020-11-30Recommit "[llvm-symbolizer] Switch to using native symbolizer by default on ↵Amy Huang1-1/+7
Windows" This reverts commit 1b63177a56e8cd6196778d2b90295f03e96b5800.
2020-11-23Revert "[llvm-symbolizer] Switch to using native symbolizer by default on ↵Amy Huang1-7/+1
Windows" Breaks some asan tests on the buildbot. This reverts commit c74b427cb2a90309ee0c29df21ad1ca26390263c.
2020-11-23[llvm-symbolizer] Switch to using native symbolizer by default on WindowsAmy Huang1-1/+7
llvm-symbolizer used to use the DIA SDK for symbolization on Windows; this patch switches to using native symbolization, which was implemented recently. Users can still make the symbolizer use DIA by adding the `-dia` flag in the LLVM_SYMBOLIZER_OPTS environment variable. Differential Revision: https://reviews.llvm.org/D91814
2020-10-21Revert several changes related to llvm-symbolizer exiting non-zero on failure.David Blaikie1-8/+1
Seems users have enough different uses of the symbolizer where they might have unknown binaries and offsets such that "best effort" behavior is all that's expected of llvm-symbolizer - so even erroring on unknown executables and out of bounds offsets might not be suitable. This reverts commit 1de0199748ef2a20cd146c100ea1b8e6726c4767. This reverts commit a7b209a6d40d77b43a38664b1fe64513587f24c6. This reverts commit 338dd138ea4a70b52ab48e0c8aa38ec152b3569a.
2020-10-14llvm-symbolizer: Exit non-zero when DWARF parsing errors have been renderedDavid Blaikie1-0/+4
2020-10-14llvm-symbolizer: Ensure non-zero exit when an error is printedDavid Blaikie1-1/+4
(this doesn't cover all cases - libDebugInfoDWARF has a default error handler that prints errors without any exit code handling - I'll be following up with a patch for that after this)
2020-08-10[llvm-symbolizer] Add back --version and add a -v aliasFangrui Song1-3/+8
The switch from llvm::cl to OptTable (D83530) dropped --version, which is needed by some users. This patch also adds a -v alias, which is available in GNU addr2line. The version dumping is similar to llvm-objcopy --version (exotic): ``` llvm-symbolizer LLVM (http://llvm.org/): LLVM version 12.0.0git Optimized build with assertions. Default target: x86_64-unknown-linux-gnu Host CPU: skylake-avx512 ``` Reviewed By: dyung, jhenderson Differential Revision: https://reviews.llvm.org/D85624
2020-08-04[llvm-symbolizer] Switch command line parsing from llvm::cl to OptTableFangrui Song1-194/+166
for the advantage outlined by D83639 ([OptTable] Support grouped short options) Some behavior changes: * -i={0,false} is removed. Use --no-inlines instead. * --demangle={0,false} is removed. Use --no-demangle instead * -untag-addresses={0,false} is removed. Use --no-untag-addresses instead Added a higher level API OptTable::parseArgs which handles optional initial options populated from an environment variable, expands response files recursively, and parses options. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D83530
2020-05-13[NativeSession] Implement NativeSession::findSymbolByAddress.Amy Huang1-0/+5
Summary: This implements searching for function symbols and public symbols by address. More specifically, -Implements NativeSession::findSymbolByAddress for function symbols and public symbols. I think data symbols are also searched for, but isn't implemented in this patch. -Adds classes for NativeFunctionSymbol and NativePublicSymbol -Adds a '-use-native-pdb-reader' option to llvm-symbolizer, for testing purposes. Reviewers: rnk, amccarth, labath Subscribers: mgorny, hiraditya, MaskRay, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79269
2020-04-16llvm-addr2line: assume addresses on the command line are hexadecimal rather ↵Richard Smith1-7/+13
than attempting to guess the base based on the form of the number. Summary: This matches the behavior of GNU addr2line. We previously treated hexadecimal addresses as binary if they started with 0b, otherwise as octal if they started with 0, otherwise as decimal. This only affects llvm-addr2line; the behavior of llvm-symbolize is unaffected. Reviewers: ikudrin, rupprecht, jhenderson Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73306
2020-03-31Switch this function to the LLVM variable naming convention, to match the ↵Richard Smith1-15/+15
rest of the file.
2020-03-31[llvm-symbolizer] Delete unneeded option name comments. NFCFangrui Song1-7/+0
Follow-up of D76733. The code documents itself.
2020-03-31New symbolizer option to print files relative to the compilation directory.Sterling Augustine1-1/+10
Summary: New "--relative" option to allow printing files relative to the compilation directory. Reviewers: jhenderson Subscribers: MaskRay, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76733
2020-03-20Cleanup the plumbing for DILineInfoSpecifier. [NFC - Try 2]Sterling Augustine1-1/+4
2020-03-19Revert "Cleanup the plumbing for DILineInfoSpecifier. [NFC]"Sterling Augustine1-4/+1
This broke lldb. Will fix and resubmit. This reverts commit 98ff6eb679cd5a2556d990d3d629e6c03c1da6a0.
2020-03-19Cleanup the plumbing for DILineInfoSpecifier. [NFC]Sterling Augustine1-1/+4
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
2020-01-08[llvm-symbolizer]Fix printing of malformed address values not passed via stdinXuanda Yang1-2/+9
Summary: relates https://bugs.llvm.org/show_bug.cgi?id=44443 Adding missing newline when printing bad input values. Fix testcase Reviewers: jhenderson Reviewed By: jhenderson Subscribers: rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72313
2019-12-20[llvm-symbolizer] Support reading options from environmentPetr Hosek1-2/+4
llvm-symbolizer is used by sanitizers to symbolize errors discovered by sanitizer, but there's no way to pass options to llvm-symbolizer since the tool is invoked directly by the sanitizer runtime. Therefore, we don't have a way to pass options needed to find debug symbols such as -dsym-hint or -debug-file-directory. This change enables reading options from the LLVM_SYMBOLIZER_OPTS in addition to command line which can be used to pass those additional options to llvm-symbolizer invocations made by sanitizer runtime. Differential Revision: https://reviews.llvm.org/D71668
2019-12-04[llvm-symbolizer] Support debug file lookup using build IDPetr Hosek1-0/+7
Build ID is a protocol for looking up debug files that's already supported by various tools including debuggers. For example, when locating debug files, gdb would check the following directories: - /usr/lib/debug/.build-id/ab/cdef1234.debug - /usr/bin/ls.debug - /usr/bin/.debug/ls.debug - /usr/lib/debug/usr/bin/ls.debug llvm-symbolizer currently consults all of these except for build ID based one. This patch implements support for build ID lookup. The set of debug directories to search is specified by the new option: --debug-file-directory, whose name matches the debug-file-directory variable used by gdb for the same purpose. Differential Revision: https://reviews.llvm.org/D70759
2019-08-05llvm-symbolizer: Untag addresses in object files by default.Peter Collingbourne1-0/+6
Any addresses that we pass to llvm-symbolizer are going to be untagged, while any HWASAN instrumented globals are going to be tagged in the symbol table. Therefore we need to untag the addresses before using them. Differential Revision: https://reviews.llvm.org/D65769 llvm-svn: 367926