Adopt PrettyStackTrace in LLDB
LLDB needs some minor changes to adopt PrettyStackTrace after https://reviews.llvm.org/D27683.
We remove our own SetCrashDescription() function and use LLVM-provided RAII objects instead.
We also make sure LLDB doesn't define __crashtracer_info__ which would collide with LLVM's definition.
Differential Revision: https://reviews.llvm.org/D27735
llvm-svn: 289711
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 1845b12..5500c33 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -52,6 +52,8 @@
#include "lldb/API/SBValue.h"
#include "lldb/API/SBVariablesOptions.h"
+#include "llvm/Support/PrettyStackTrace.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -1288,10 +1290,11 @@
if (stop_locker.TryLock(&process->GetRunLock())) {
frame = exe_ctx.GetFramePtr();
if (frame) {
+ std::unique_ptr<llvm::PrettyStackTraceFormat> PST;
if (target->GetDisplayExpressionsInCrashlogs()) {
StreamString frame_description;
frame->DumpUsingSettingsFormat(&frame_description);
- Host::SetCrashDescriptionWithFormat(
+ PST = llvm::make_unique<llvm::PrettyStackTraceFormat>(
"SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value "
"= %u) %s",
expr, options.GetFetchDynamicValue(),
@@ -1301,9 +1304,6 @@
exe_results = target->EvaluateExpression(expr, frame, expr_value_sp,
options.ref());
expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
-
- if (target->GetDisplayExpressionsInCrashlogs())
- Host::SetCrashDescription(nullptr);
} else {
if (log)
log->Printf("SBFrame::EvaluateExpression () => error: could not "
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index a620f6f..211f77a 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -64,6 +64,7 @@
#include "../source/Commands/CommandObjectBreakpoint.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Regex.h"
using namespace lldb;
@@ -2129,7 +2130,7 @@
StreamString frame_description;
if (frame)
frame->DumpUsingSettingsFormat(&frame_description);
- Host::SetCrashDescriptionWithFormat(
+ llvm::PrettyStackTraceFormat PST(
"SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = "
"%u) %s",
expr, options.GetFetchDynamicValue(),
@@ -2139,9 +2140,6 @@
target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
-#ifdef LLDB_CONFIGURATION_DEBUG
- Host::SetCrashDescription(NULL);
-#endif
} else {
if (log)
log->Printf("SBTarget::EvaluateExpression () => error: could not "
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index f0d7e2e..6d0ad01 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -999,10 +999,6 @@
return false;
}
-void Host::SetCrashDescriptionWithFormat(const char *format, ...) {}
-
-void Host::SetCrashDescription(const char *description) {}
-
#endif
const UnixSignalsSP &Host::GetUnixSignals() {
diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm
index 6c0a44b..99bc7ec 100644
--- a/lldb/source/Host/macosx/Host.mm
+++ b/lldb/source/Host/macosx/Host.mm
@@ -537,47 +537,6 @@
#endif // #if !defined(__arm__) && !defined(__arm64__) && !defined(__aarch64__)
-// On MacOSX CrashReporter will display a string for each shared library if
-// the shared library has an exported symbol named "__crashreporter_info__".
-
-static std::mutex &GetCrashReporterMutex() {
- static std::mutex g_mutex;
- return g_mutex;
-}
-
-extern "C" {
-const char *__crashreporter_info__ = NULL;
-}
-
-asm(".desc ___crashreporter_info__, 0x10");
-
-void Host::SetCrashDescriptionWithFormat(const char *format, ...) {
- static StreamString g_crash_description;
- std::lock_guard<std::mutex> guard(GetCrashReporterMutex());
-
- if (format) {
- va_list args;
- va_start(args, format);
- g_crash_description.GetString() = llvm::StringRef("");
- g_crash_description.PrintfVarArg(format, args);
- va_end(args);
- __crashreporter_info__ = g_crash_description.GetData();
- } else {
- __crashreporter_info__ = NULL;
- }
-}
-
-void Host::SetCrashDescription(const char *cstr) {
- std::lock_guard<std::mutex> guard(GetCrashReporterMutex());
- static std::string g_crash_description;
- if (cstr) {
- g_crash_description.assign(cstr);
- __crashreporter_info__ = g_crash_description.c_str();
- } else {
- __crashreporter_info__ = NULL;
- }
-}
-
bool Host::OpenFileInExternalEditor(const FileSpec &file_spec,
uint32_t line_no) {
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
diff --git a/lldb/source/Initialization/SystemInitializerCommon.cpp b/lldb/source/Initialization/SystemInitializerCommon.cpp
index 5bf4cea..1139955 100644
--- a/lldb/source/Initialization/SystemInitializerCommon.cpp
+++ b/lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -35,18 +35,13 @@
#include "lldb/Host/windows/windows.h"
#endif
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/TargetSelect.h"
#include <string>
using namespace lldb_private;
-static void fatal_error_handler(void *user_data, const std::string &reason,
- bool gen_crash_diag) {
- Host::SetCrashDescription(reason.c_str());
- ::abort();
-}
-
SystemInitializerCommon::SystemInitializerCommon() {}
SystemInitializerCommon::~SystemInitializerCommon() {}
@@ -74,12 +69,11 @@
}
#endif
+ llvm::EnablePrettyStackTrace();
Log::Initialize();
HostInfo::Initialize();
Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
- llvm::install_fatal_error_handler(fatal_error_handler, 0);
-
process_gdb_remote::ProcessGDBRemoteLog::Initialize();
// Initialize plug-ins
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 305d6a9..a805572 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -72,6 +72,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/PrettyStackTrace.h"
using namespace lldb;
using namespace lldb_private;
@@ -1526,13 +1527,8 @@
std::string original_command_string(command_line);
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_COMMANDS));
- Host::SetCrashDescriptionWithFormat("HandleCommand(command = \"%s\")",
- command_line);
-
- // Make a scoped cleanup object that will clear the crash description string
- // on exit of this function.
- lldb_utility::CleanUp<const char *> crash_description_cleanup(
- nullptr, Host::SetCrashDescription);
+ llvm::PrettyStackTraceFormat PST("HandleCommand(command = \"%s\")",
+ command_line);
if (log)
log->Printf("Processing command: %s", command_line);
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index c5a62d5..5289808 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1473,8 +1473,7 @@
}
if (add_method) {
- // REMOVE THE CRASH DESCRIPTION BELOW
- Host::SetCrashDescriptionWithFormat(
+ llvm::PrettyStackTraceFormat PST(
"SymbolFileDWARF::ParseType() is adding a method "
"%s to class %s in DIE 0x%8.8" PRIx64 " from %s",
type_name_cstr,
@@ -1492,12 +1491,12 @@
if (accessibility == eAccessNone)
accessibility = eAccessPublic;
- clang::CXXMethodDecl *cxx_method_decl;
- cxx_method_decl = m_ast.AddMethodToCXXRecordType(
- class_opaque_type.GetOpaqueQualType(),
- type_name_cstr, clang_type, accessibility,
- is_virtual, is_static, is_inline, is_explicit,
- is_attr_used, is_artificial);
+ clang::CXXMethodDecl *cxx_method_decl =
+ m_ast.AddMethodToCXXRecordType(
+ class_opaque_type.GetOpaqueQualType(),
+ type_name_cstr, clang_type, accessibility,
+ is_virtual, is_static, is_inline, is_explicit,
+ is_attr_used, is_artificial);
type_handled = cxx_method_decl != NULL;
@@ -1507,8 +1506,6 @@
cxx_method_decl),
die);
- Host::SetCrashDescription(NULL);
-
ClangASTMetadata metadata;
metadata.SetUserID(die.GetID());