void DisableSystemDialogsOnCrash();
/// Print the stack trace using the given \c raw_ostream object.
- void PrintStackTrace(raw_ostream &OS);
+ /// \param Depth refers to the number of stackframes to print. If not
+ /// specified, the entire frame is printed.
+ void PrintStackTrace(raw_ostream &OS, int Depth = 0);
// Run all registered signal handlers.
void RunSignalHandlers();
//
// On glibc systems we have the 'backtrace' function, which works nicely, but
// doesn't demangle symbols.
-void llvm::sys::PrintStackTrace(raw_ostream &OS) {
+void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
#if ENABLE_BACKTRACES
static void *StackTrace[256];
int depth = 0;
#endif
if (!depth)
return;
-
- if (printSymbolizedStackTrace(Argv0, StackTrace, depth, OS))
+ // If "Depth" is not provided by the caller, use the return value of
+ // backtrace() for printing a symbolized stack trace.
+ if (!Depth)
+ Depth = depth;
+ if (printSymbolizedStackTrace(Argv0, StackTrace, Depth, OS))
return;
#if HAVE_DLFCN_H && HAVE_DLADDR
int width = 0;
OS << '\n';
}
#elif defined(HAVE_BACKTRACE)
- backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO);
+ backtrace_symbols_fd(StackTrace, Depth, STDERR_FILENO);
#endif
#endif
}
StackFrame, C);
}
-void llvm::sys::PrintStackTrace(raw_ostream &OS) {
+void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
+ // FIXME: Handle "Depth" parameter to print stack trace upto specified Depth
LocalPrintStackTrace(OS, nullptr);
}
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/Triple.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
#ifdef _WIN32
llvm::CrashRecoveryContext::Disable();
}
+TEST(CrashRecoveryTest, LimitedStackTrace) {
+ std::string Res;
+ llvm::raw_string_ostream RawStream(Res);
+ PrintStackTrace(RawStream, 1);
+ std::string Str = RawStream.str();
+ // FIXME: Handle "Depth" parameter in PrintStackTrace() function
+ // to print stack trace upto a specified Depth.
+ if (!Triple(sys::getProcessTriple()).isOSWindows())
+ EXPECT_EQ(std::string::npos, Str.find("#1"));
+}
+
#ifdef _WIN32
static void raiseIt() {
RaiseException(123, EXCEPTION_NONCONTINUABLE, 0, NULL);