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
//------------------------------------------------------------------
static bool ResolveExecutableInBundle(FileSpec &file);
- //------------------------------------------------------------------
- /// Set a string that can be displayed if host application crashes.
- ///
- /// Some operating systems have the ability to print a description
- /// for shared libraries when a program crashes. If the host OS
- /// supports such a mechanism, it should be implemented to help
- /// with crash triage.
- ///
- /// @param[in] format
- /// A printf format that will be used to form a new crash
- /// description string.
- //------------------------------------------------------------------
- static void SetCrashDescriptionWithFormat(const char *format, ...)
- __attribute__((format(printf, 1, 2)));
-
- static void SetCrashDescription(const char *description);
-
static uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &proc_infos);
"-DCMAKE_C_FLAGS={}".format(get_c_flags()),
"-DCMAKE_CXX_FLAGS={}".format(get_cxx_flags()),
"-DCMAKE_EXE_LINKER_FLAGS={}".format(get_exe_linker_flags()),
- "-DCMAKE_SHARED_LINKER_FLAGS={}".format(get_shared_linker_flags())]
+ "-DCMAKE_SHARED_LINKER_FLAGS={}".format(get_shared_linker_flags()),
+ "-DHAVE_CRASHREPORTER_INFO=1"]
deployment_target = get_deployment_target()
if deployment_target:
cmake_flags.append(
#include "lldb/API/SBValue.h"
#include "lldb/API/SBVariablesOptions.h"
+#include "llvm/Support/PrettyStackTrace.h"
+
using namespace lldb;
using namespace lldb_private;
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(),
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 "
#include "../source/Commands/CommandObjectBreakpoint.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Regex.h"
using namespace lldb;
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(),
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 "
return false;
}
-void Host::SetCrashDescriptionWithFormat(const char *format, ...) {}
-
-void Host::SetCrashDescription(const char *description) {}
-
#endif
const UnixSignalsSP &Host::GetUnixSignals() {
#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__)
#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() {}
}
#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
#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;
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);
}
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,
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;
cxx_method_decl),
die);
- Host::SetCrashDescription(NULL);
-
ClangASTMetadata metadata;
metadata.SetUserID(die.GetID());