summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-05-20 20:15:17 +0000
committerChris Bieneman <beanz@apple.com>2016-05-20 20:15:17 +0000
commitbf0e75a50e035fa441200d62f3a78a7edf8fe45f (patch)
treeb232b039e88755a07756628f52af7e71bde47a86
parentae359d99fbe6ea796996aff21793650811d57598 (diff)
Revert "Work around a glibc bug: backtrace() spuriously fails if..."
This commit has been breaking the FreeBSD bots: http://lab.llvm.org:8011/builders/lld-x86_64-freebsd This reverts commit r269992. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270267 91177308-0d34-0410-b5e6-96231b3b80d8
-rwxr-xr-xcmake/config-ix.cmake1
-rw-r--r--lib/Support/Unix/Signals.inc55
2 files changed, 4 insertions, 52 deletions
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index b3f225f0740..7d5277517a9 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -144,7 +144,6 @@ endif()
# function checks
check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE)
-check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE_UNWIND_BACKTRACE)
check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc
index 27f3414ce57..061cdb3da21 100644
--- a/lib/Support/Unix/Signals.inc
+++ b/lib/Support/Unix/Signals.inc
@@ -45,9 +45,6 @@
#if HAVE_LINK_H
#include <link.h>
#endif
-#if HAVE_UNWIND_BACKTRACE
-#include <unwind.h>
-#endif
using namespace llvm;
@@ -312,61 +309,17 @@ static bool findModulesAndOffsets(void **StackTrace, int Depth,
}
#endif // defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) && ...
-#if defined(ENABLE_BACKTRACES) && defined(HAVE_UNWIND_BACKTRACE)
-static int unwindBacktrace(void **StackTrace, int MaxEntries) {
- if (MaxEntries < 0)
- return 0;
-
- // Skip the first frame ('unwindBacktrace' itself).
- int Entries = -1;
-
- auto HandleFrame = [&](_Unwind_Context *Context) -> _Unwind_Reason_Code {
- // Apparently we need to detect reaching the end of the stack ourselves.
- void *IP = (void *)_Unwind_GetIP(Context);
- if (!IP)
- return _URC_END_OF_STACK;
-
- assert(Entries < MaxEntries && "recursively called after END_OF_STACK?");
- if (Entries >= 0)
- StackTrace[Entries] = IP;
-
- if (++Entries == MaxEntries)
- return _URC_END_OF_STACK;
- return _URC_NO_REASON;
- };
-
- _Unwind_Backtrace(
- [](_Unwind_Context *Context, void *Handler) {
- return (*static_cast<decltype(HandleFrame) *>(Handler))(Context);
- },
- static_cast<void *>(&HandleFrame));
- return std::max(Entries, 0);
-}
-#endif
-
// PrintStackTrace - In the case of a program crash or fault, print out a stack
// trace so that the user has an indication of why and where we died.
//
// On glibc systems we have the 'backtrace' function, which works nicely, but
// doesn't demangle symbols.
void llvm::sys::PrintStackTrace(raw_ostream &OS) {
-#if defined(ENABLE_BACKTRACES)
- static void *StackTrace[256];
- int depth = 0;
-#if defined(HAVE_BACKTRACE)
+#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
+ static void* StackTrace[256];
// Use backtrace() to output a backtrace on Linux systems with glibc.
- if (!depth)
- depth = backtrace(StackTrace, static_cast<int>(array_lengthof(StackTrace)));
-#endif
-#if defined(HAVE_UNWIND_BACKTRACE)
- // Try _Unwind_Backtrace() if backtrace() failed.
- if (!depth)
- depth = unwindBacktrace(StackTrace,
+ int depth = backtrace(StackTrace,
static_cast<int>(array_lengthof(StackTrace)));
-#endif
- if (!depth)
- return;
-
if (printSymbolizedStackTrace(StackTrace, depth, OS))
return;
#if HAVE_DLFCN_H && __GNUG__
@@ -416,7 +369,7 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS) {
}
OS << '\n';
}
-#elif defined(HAVE_BACKTRACE)
+#else
backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO);
#endif
#endif