summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/PrettyStackTrace.cpp
AgeCommit message (Collapse)Author
2025-10-15[llvm] Replace LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] (NFC) (#163507)Kazu Hirata
This patch replaces LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]]. Note that this patch adjusts the placement of [[maybe_unused]] to comply with the C++17 language.
2025-09-06[Support] Request including reproduction instructions in bug report message ↵Carlos Galvez
(#156958) Many times people only upload the backtrace without reproduction, making it difficult to work on the issue. Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-08-21[llvm][Support] Fix missing-field-initializer warnings for ↵Michael Buch
crashreporter_annotations_t (#154716) Use `CRASHREPORTER_ANNOTATIONS_INITIALIZER` when possible, which will handle the field initialization for us. That's what we already do in compiler-rt: https://github.com/llvm/llvm-project/blob/0c480dd4b61e285bfda4de99c77da28922e64b94/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp#L799-L817 This way we won't get these warnings when the layout of crashreporter_annotations_t changes: ``` llvm/lib/Support/PrettyStackTrace.cpp:92:65: warning: missing field 'blah' initializer [-Wmissing-field-initializers] = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 }; ^ 1 warning generated ```
2025-05-21[NFC][ADT/Support] Add {} for else when if body has {} (#140758)Rahul Joshi
2024-06-03[llvm] Replace deprecated aligned_storage with aligned byte array (#94169)Marc Auberer
`std::aligned_storage` is deprecated with C++23, see [here](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1413r3.pdf). This replaces the usages of `std::aligned_storage` within llvm (only one in ADT and one in Support) with an aligned `std::byte` array. I will provide patches for other subcomponents as well.
2023-02-24Remove uses of ATOMIC_VAR_INITFangrui Song
ATOMIC_VAR_INIT has a trivial definition `#define ATOMIC_VAR_INIT(value) (value)`, is deprecated in C17/C++20, and will be removed in newer standards.
2022-01-21Add apple-specific missing includeserge-sans-paille
2022-01-21[llvm] Cleanup header dependencies in ADT and Supportserge-sans-paille
The cleanup was manual, but assisted by "include-what-you-use". It consists in 1. Removing unused forward declaration. No impact expected. 2. Removing unused headers in .cpp files. No impact expected. 3. Removing unused headers in .h files. This removes implicit dependencies and is generally considered a good thing, but this may break downstream builds. I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the modification in the second part of the commit. 4. Replacing header inclusion by forward declaration. This has the same impact as 3. Notable changes: - llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h - llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h - llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h - llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h You may need to add some of these headers in your compilation units, if needs be. As an hint to the impact of the cleanup, running clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 8000919 lines after: 7917500 lines Reduced dependencies also helps incremental rebuilds and is more ccache friendly, something not shown by the above metric :-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2021-01-28[Support] Add some missing namespace closure comments. NFCI.Simon Pilgrim
Fixes some clang-tidy warnings.
2020-11-17Escape command line arguments in backtracesLuke Drummond
A common routine is to have the compiler crash, and attempt to rerun the cc1 command-line by copying and pasting the arguments printed by `llvm::Support::PrettyStackProgram::print`. However, these arguments are not quoted or escaped which means they must be manually edited before working correctly. This patch ensures that shell-unfriendly characters are C-escaped, and arguments with spaces are double-quoted reducing the frustration of running cc1 inside a debugger. As the quoting is C, this is "best effort for most shells", but should be fine for at least bash, zsh, csh, and cmd.exe. Reviewed by: jhenderson Differential Revision: https://reviews.llvm.org/D90759
2020-06-29[Driver] When forcing a crash print the bug report messageJohn Brawn
Commit a945037e8fd0c30e250a62211469eea6765a36ae moved the printing of the "PLEASE submit a bug report" message to the crash handler, but that means we don't print it when forcing a crash using FORCE_CLANG_DIAGNOSTICS_CRASH. Fix this by adding a function to get the bug report message and printing it when forcing a crash. Differential Revision: https://reviews.llvm.org/D81672
2020-03-26Move setBugReportMsg() out from under a conditionalLeonard Chan
Fixes a build break with LLVM_ENABLE_BACKTRACES=OFF. Differential Revision: https://reviews.llvm.org/D76893
2020-03-26Tools emit the bug report URL on crashgbreynoo
When Clang crashes a useful message is output: "PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script." A similar message is now output for all tools. Differential Revision: https://reviews.llvm.org/D74324
2020-03-02Explicitly include <cassert> when using assertJoerg Sonnenberger
Depending on the OS used, a module-enabled build can fail due to the special handling <cassert> gets as textual header.
2019-07-25Make GCC happy about attribute locationJF Bastien
It doesn't like function attributes on definitions, only declarations. llvm-svn: 367036
2019-07-25Fix unused function from r367031JF Bastien
llvm-svn: 367035
2019-07-25CrashHandler: be careful about crashing while handlingJF Bastien
Summary: Looking at the current Apple-specific code for crash handling it does a few silly things that I think we should avoid while handling crashes: * Try real hard not to allocate. * Set the global crash reporter string early so that any crash while generating the stack trace will still report some info. * Prevent reordering of operations in the current thread. <rdar://problem/53503334> Subscribers: hiraditya, jkorous, dexonsmith, llvm-commits, beanz, Bigcheese, thakis, lattner, jordan_rose Tags: #llvm Differential Revision: https://reviews.llvm.org/D65235 llvm-svn: 367031
2019-07-12Add missing <atomic> include to appease MSVC builds.Simon Pilgrim
llvm-svn: 365914
2019-07-12Support for dumping current PrettyStackTrace on SIGINFO (Ctrl-T)Jordan Rose
Support SIGINFO (and SIGUSR1 for POSIX purposes) to tell what long-running jobs are doing, as inspired by BSD tools (including on macOS), by dumping the current PrettyStackTrace. This adds a new kind of signal handler for non-fatal "info" signals, similar to the "interrupt" handler that already exists for SIGINT (Ctrl-C). It then uses that handler to update a "generation count" managed by the PrettyStackTrace infrastructure, which is then checked whenever a PrettyStackTraceEntry is pushed or popped on each thread. If the generation has changed---i.e. if the user has pressed Ctrl-T---the stack trace is dumped, though unfortunately it can't include the deepest entry because that one is currently being constructed/destructed. https://reviews.llvm.org/D63750 llvm-svn: 365911
2019-07-03Remove some autoconf references from docs and commentsSven van Haastregt
The autoconf build system support has been removed a while ago, remove some outdated references. Differential Revision: https://reviews.llvm.org/D63608 llvm-svn: 365013
2019-02-27Support: enable backtraces on WindowsSaleem Abdulrasool
Some platforms, e.g. Windows, support backtraces but don't have BACKTRACE. Checking for BACKTRACE prevents Windows from having backtraces. Patch by Jason Mittertreiner! llvm-svn: 354951
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-07-30Remove trailing spaceFangrui Song
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338293
2018-06-15Avoid copying PrettyStackTrace messages an extra time on Apple OSsJordan Rose
We were unnecessarily going from SmallString to std::string just to get a null-terminated C string. So just...don't do that. Crash slightly faster! llvm-svn: 334841
2018-01-30Add more initializers to quiet a clang warningDaniel Sanders
Summary: `struct crashreporter_annotations_t` gained one more `uint64_t` field in `CRASHREPORTER_ANNOTATIONS_VERSION` 5 causing an annoying clang warning: ``` llvm/lib/Support/PrettyStackTrace.cpp:92:65: warning: missing field 'abort_cause' initializer [-Wmissing-field-initializers] = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 }; ^ 1 warning generated ``` Let's fix it. Patch by Roman Tereshin Reviewers: qcolombet, echristo, beanz, dexonsmith Reviewed By: echristo Subscribers: dsanders, dexonsmith, beanz, echristo, qcolombet, llvm-commits Differential Revision: https://reviews.llvm.org/D42268 llvm-svn: 323777
2017-06-06Sort the remaining #include lines in include/... and lib/....Chandler Carruth
I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
2017-04-29Include <cstdio> in PrettyStackTrace.cpp, since it uses vsnprintf(3).Dimitry Andric
llvm-svn: 301760
2016-12-14Include <cstdarg> in PrettyStackTrace.cpp, fixing the bots.Sean Callanan
llvm-svn: 289691
2016-12-14Prepare PrettyStackTrace for LLDB adoptionSean Callanan
This patch fixes the linkage for __crashtracer_info__, making it have the proper mangling (extern "C") and linkage (private extern). It also adds a new PrettyStackTrace type, allowing LLDB to adopt this instead of Host::SetCrashDescriptionWithFormat(). Without this patch, CrashTracer on macOS won't pick up pretty stack traces from any LLVM client. An LLDB commit adopting this API will follow shortly. Differential Revision: https://reviews.llvm.org/D27683 llvm-svn: 289689
2016-12-07Fix the apple build issue caused by r288956Chris Bieneman
Should be checking if HAVE_CRASHREPORTERCLIENT_H is defined not relying on it having a value. llvm-svn: 288963
2016-09-30Convert ENABLE_BACKTRACES into a 0/1 definition.Joerg Sonnenberger
llvm-svn: 282918
2016-05-27Use C++ casts to avoid a warningSanjoy Das
warning: cast from type ‘const void*’ to type ‘llvm::PrettyStackTraceEntry*’ casts away qualifiers [-Wcast-qual] PrettyStackTraceHead = (PrettyStackTraceEntry*)Top; llvm-svn: 271069
2016-05-26Don't use recursion to print out the PrettyStackTrace after a crash. If theRichard Smith
crash was due to a stack overflow, chances are good that this would also cause a stack overflow. llvm-svn: 270903
2015-12-18Reorganize the C API headers to improve build times.Eric Christopher
Type specific declarations have been moved to Type.h and error handling routines have been moved to ErrorHandling.h. Both are included in Core.h so nothing should change for projects directly including the headers, but transitive dependencies may be affected. llvm-svn: 255965
2015-08-07Add functions to save and restore the PrettyStackTrace state.Nico Weber
PrettyStackTraceHead is a LLVM_THREAD_LOCAL, which means it's just a global in LLVM_ENABLE_THREADS=NO builds. If a CrashRecoveryContext is used with code that uses PrettyStackEntries, and a crash happens, PrettyStackTraceHead is currently not reset to its pre-crash value. These functions make it possible to add a cleanup to such code that does this. (Not reseting the value then causes the assert in ~PrettyStackTraceEntry() to fire if the code outside of the CrashRecoveryContext also uses PrettyStackEntries -- for example, clang when building a module.) Part of PR11974. llvm-svn: 244338
2015-01-29Fix the preprocessor checks used to determine if backtraces have been enabled.Owen Anderson
llvm-svn: 227424
2015-01-29Use the existing build configuration parameter ENABLE_BACKTRACE to compile ↵Owen Anderson
out all pretty stack trace support when backtraces are disabled. This has the nice secondary effect of allowing LLVM to continue to build for targets without __thread or thread_local support to continue to work so long as they build without support for backtraces. llvm-svn: 227423
2015-01-29[LPM] Clean up the use of TLS in pretty stack trace and disable itChandler Carruth
entirely when threads are not enabled. This should allow anyone who needs to bootstrap or cope with a host loader without TLS support to limp along without threading support. There is still some bug in the PPC TLS stuff that is not worked around. I'm getting access to a machine to reproduce and debug this further. There is some chance that I'll have to add a terrible workaround for PPC. There is also some problem with iOS, but I have no ability to really evaluate what the issue is there. I'm leaving it to folks maintaining that platform to suggest a path forward -- personally I don't see any useful path forward that supports threading in LLVM but does so without support for *very basic* TLS. Note that we don't need more than some pointers, and we don't need constructors, destructors, or any of the other fanciness which remains widely unimplemented. llvm-svn: 227411
2015-01-28[LPM] Fix the PPC attribute to be spelled 'global-dynamic'. This shouldChandler Carruth
let the build bot make finish compiling stage2. llvm-svn: 227391
2015-01-28[LPM] Try to work around a bug with local-dynamic TLS on PowerPC 64.Chandler Carruth
Sadly, this precludes optimizing it down to initial-exec or local-exec when statically linking, and in general makes the code slower on PPC 64, but there's nothing else for it until we can arrange to produce the correct bits for the linker. Lots of thanks to Ulirch for tracking this down and Bill for working on the long-term fix to LLVM so that we can relegate this to old host clang versions. I'll be watching the PPC build bots to make sure this effectively revives them. llvm-svn: 227352
2015-01-28[LPM] Rip all of ManagedStatic and ThreadLocal out of the pretty stackChandler Carruth
tracing code. Managed static was just insane overhead for this. We took memory fences and external function calls in every path that pushed a pretty stack frame. This includes a multitude of layers setting up and tearing down passes, the parser in Clang, everywhere. For the regression test suite or low-overhead JITs, this was contributing to really significant overhead. Even the LLVM ThreadLocal is really overkill here because it uses pthread_{set,get}_specific logic, and has careful code to both allocate and delete the thread local data. We don't actually want any of that, and this code in particular has problems coping with deallocation. What we want is a single TLS pointer that is valid to use during global construction and during global destruction, any time we want. That is exactly what every host compiler and OS we use has implemented for a long time, and what was standardized in C++11. Even though not all of our host compilers support the thread_local keyword, we can directly use the platform-specific keywords to get the minimal functionality needed. Provided this limited trial survives the build bots, I will move this to Compiler.h so it is more widely available as a light weight if limited alternative to the ThreadLocal class. Many thanks to David Majnemer for helping me think through the implications across platforms and craft the MSVC-compatible syntax. The end result is *substantially* faster. When running llc in a tight loop over a small IR file targeting the aarch64 backend, this improves its performance by over 10% for me. It also seems likely to fix the remaining regressions seen by JIT users with threading enabled. This may actually have more impact on real-world compile times due to the use of the pretty stack tracing utility throughout the rest of Clang or LLVM, but I've not collected any detailed measurements. llvm-svn: 227300
2014-04-09[C++11] Replace some comparisons with 'nullptr' with simple boolean checks ↵Craig Topper
to reduce verbosity. llvm-svn: 205829
2014-04-07[C++11] Make use of 'nullptr' in the Support library.Craig Topper
llvm-svn: 205697
2014-01-07Re-sort all of the includes with ./utils/sort_includes.py so thatChandler Carruth
subsequent changes are easier to review. About to fix some layering issues, and wanted to separate out the necessary churn. Also comment and sink the include of "Windows.h" in three .inc files to match the usage in Memory.inc. llvm-svn: 198685
2013-11-04Make the pretty stack trace be an opt-in, rather than opt-out, facility. ↵Filip Pizlo
Enable pretty stack traces by default if you use PrettyStackTraceProgram, so that existing LLVM-based tools will continue to get it without any changes. llvm-svn: 193971
2013-11-03When LLVM is embedded in a larger application, it's not OK for LLVM to ↵Filip Pizlo
intercept crashes. LLVM already has the ability to disable this functionality. This patch exposes it via the C API. llvm-svn: 193937
2013-09-13Make PrettyStackTraceEntry use ManagedStatic for its ThreadLocal.Filip Pizlo
This was somewhat tricky because ~PrettyStackTraceEntry() may run after llvm_shutdown() has been called. This is rare and only happens for a common idiom used in the main() functions of command-line tools. This works around the idiom by skipping the stack clean-up if the PrettyStackTraceHead ManagedStatic is not constructed (i.e. llvm_shutdown() has been called). llvm-svn: 190730
2013-03-26Add a new watchdog timer interface. The interface does not permit handling ↵Nick Lewycky
timeouts, so it's only really useful if you're going to crash anyways. Use it in the pretty stack trace printer to kill the compiler if we hang while printing the stack trace. llvm-svn: 177962
2012-12-03Use the new script to sort the includes of every file under lib.Chandler Carruth
Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] llvm-svn: 169131
2011-10-05Add more initializers to quiet a clang warning.Eric Christopher
llvm-svn: 141163