[Lldb-commits] [lldb] r289711 - Adopt PrettyStackTrace in LLDB

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 14 13:31:32 PST 2016


Author: spyffe
Date: Wed Dec 14 15:31:31 2016
New Revision: 289711

URL: http://llvm.org/viewvc/llvm-project?rev=289711&view=rev
Log:
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

Modified:
    lldb/trunk/include/lldb/Host/Host.h
    lldb/trunk/scripts/Xcode/build-llvm.py
    lldb/trunk/source/API/SBFrame.cpp
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Host/macosx/Host.mm
    lldb/trunk/source/Initialization/SystemInitializerCommon.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Modified: lldb/trunk/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Wed Dec 14 15:31:31 2016
@@ -183,23 +183,6 @@ public:
   //------------------------------------------------------------------
   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);
 

Modified: lldb/trunk/scripts/Xcode/build-llvm.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Xcode/build-llvm.py?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/scripts/Xcode/build-llvm.py (original)
+++ lldb/trunk/scripts/Xcode/build-llvm.py Wed Dec 14 15:31:31 2016
@@ -346,7 +346,8 @@ def cmake_flags():
                     "-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(

Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Wed Dec 14 15:31:31 2016
@@ -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 @@ lldb::SBValue SBFrame::EvaluateExpressio
     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 @@ lldb::SBValue SBFrame::EvaluateExpressio
         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 "

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Wed Dec 14 15:31:31 2016
@@ -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 @@ lldb::SBValue SBTarget::EvaluateExpressi
       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 @@ lldb::SBValue SBTarget::EvaluateExpressi
           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 "

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Wed Dec 14 15:31:31 2016
@@ -999,10 +999,6 @@ bool Host::OpenFileInExternalEditor(cons
   return false;
 }
 
-void Host::SetCrashDescriptionWithFormat(const char *format, ...) {}
-
-void Host::SetCrashDescription(const char *description) {}
-
 #endif
 
 const UnixSignalsSP &Host::GetUnixSignals() {

Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Wed Dec 14 15:31:31 2016
@@ -537,47 +537,6 @@ LaunchInNewTerminalWithAppleScript(const
 
 #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__)

Modified: lldb/trunk/source/Initialization/SystemInitializerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Initialization/SystemInitializerCommon.cpp?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/source/Initialization/SystemInitializerCommon.cpp (original)
+++ lldb/trunk/source/Initialization/SystemInitializerCommon.cpp Wed Dec 14 15:31:31 2016
@@ -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 @@ void SystemInitializerCommon::Initialize
   }
 #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

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Dec 14 15:31:31 2016
@@ -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 @@ bool CommandInterpreter::HandleCommand(c
   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);

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=289711&r1=289710&r2=289711&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Wed Dec 14 15:31:31 2016
@@ -1473,8 +1473,7 @@ TypeSP DWARFASTParserClang::ParseTypeFro
                         }
 
                         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 @@ TypeSP DWARFASTParserClang::ParseTypeFro
                           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 @@ TypeSP DWARFASTParserClang::ParseTypeFro
                                     cxx_method_decl),
                                 die);
 
-                            Host::SetCrashDescription(NULL);
-
                             ClangASTMetadata metadata;
                             metadata.SetUserID(die.GetID());
 




More information about the lldb-commits mailing list