From a63b6dd93c1ef78e647dbd221a5a3b14ff363102 Mon Sep 17 00:00:00 2001
From: Lynx Linden <lynx@lindenlab.com>
Date: Wed, 26 May 2010 14:43:27 +0100
Subject: [PATCH] Hooked up Google Breakpad for the Linux client too.

Using Alain's Darwin reporter callback was all that was needed.

Also replaced the call that exposed the breakpad exception class
with a call to just write out the minidump, as that was the only
reason for exposing it. Now clients don't need to know about
Google Breakpad.
---
 indra/llcommon/llapp.cpp      | 32 ++++++++++----------------------
 indra/llcommon/llapp.h        |  4 ++--
 indra/newview/llappviewer.cpp |  8 +++++---
 3 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index 9ea1a18e5fe..6f4acd49b1e 100644
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -68,7 +68,7 @@ void setup_signals();
 void default_unix_signal_handler(int signum, siginfo_t *info, void *);
 
 // Called by breakpad exception handler after the minidump has been generated.
-bool darwin_post_minidump_callback(const char *dump_dir,
+bool unix_post_minidump_callback(const char *dump_dir,
 					  const char *minidump_id,
 					  void *context, bool succeeded);
 # if LL_DARWIN
@@ -282,19 +282,11 @@ void LLApp::setupErrorHandling()
 	// occasionally checks to see if the app is in an error state, and sees if it needs to be run.
 
 #if LL_WINDOWS
-	// Windows doesn't have the same signal handling mechanisms as UNIX, thus APR doesn't provide
-	// a signal handling thread implementation.
-	// What we do is install an unhandled exception handler, which will try to do the right thing
-	// in the case of an error (generate a minidump)
-
-	// Disable this until the viewer gets ported so server crashes can be JIT debugged.
-	//LPTOP_LEVEL_EXCEPTION_FILTER prev_filter;
-	//prev_filter = SetUnhandledExceptionFilter(default_windows_exception_handler);
-
 	// This sets a callback to handle w32 signals to the console window.
 	// The viewer shouldn't be affected, sicne its a windowed app.
 	SetConsoleCtrlHandler( (PHANDLER_ROUTINE) ConsoleCtrlHandler, TRUE);
 
+	// Install the Google Breakpad crash handler for Windows
 	if(mExceptionHandler == 0)
 	{
 		llwarns << "adding breakpad exception handler" << llendl;
@@ -309,18 +301,14 @@ void LLApp::setupErrorHandling()
 	// There are two different classes of signals.  Synchronous signals are delivered to a specific
 	// thread, asynchronous signals can be delivered to any thread (in theory)
 	//
-
 	setup_signals();
-
 	
-#ifdef LL_DARWIN
-	// Add google breakpad exception handler configured for Darwin.
+	// Add google breakpad exception handler configured for Darwin/Linux.
 	if(mExceptionHandler == 0)
 	{
 		std::string dumpPath = "/tmp/";
-		mExceptionHandler = new google_breakpad::ExceptionHandler(dumpPath, 0, &darwin_post_minidump_callback, 0, true);
+		mExceptionHandler = new google_breakpad::ExceptionHandler(dumpPath, 0, &unix_post_minidump_callback, 0, true);
 	}
-#endif
 #endif
 
 	startErrorThread();
@@ -373,7 +361,6 @@ void LLApp::runErrorHandler()
 	LLApp::setStopped();
 }
 
-
 // static
 void LLApp::setStatus(EAppStatus status)
 {
@@ -393,6 +380,10 @@ void LLApp::setError()
 	}
 }
 
+void LLApp::writeMiniDump()
+{
+	mExceptionHandler->WriteMinidump();
+}
 
 // static
 void LLApp::setQuitting()
@@ -802,10 +793,7 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *)
 	}
 }
 
-#endif // !WINDOWS
-
-#ifdef LL_DARWIN
-bool darwin_post_minidump_callback(const char *dump_dir,
+bool unix_post_minidump_callback(const char *dump_dir,
 					  const char *minidump_id,
 					  void *context, bool succeeded)
 {
@@ -833,7 +821,7 @@ bool darwin_post_minidump_callback(const char *dump_dir,
 	LLApp::runErrorHandler();
 	return true;
 }
-#endif
+#endif // !WINDOWS
 
 #ifdef LL_WINDOWS
 bool windows_post_minidump_callback(const wchar_t* dump_path,
diff --git a/indra/llcommon/llapp.h b/indra/llcommon/llapp.h
index 8b2dc1ab72b..7b1144ebf15 100644
--- a/indra/llcommon/llapp.h
+++ b/indra/llcommon/llapp.h
@@ -237,9 +237,9 @@ class LL_COMMON_API LLApp : public LLOptionInterface
 	//@}
 	
 	//
-	// Expose exception handler.
+	// Write out a Google Breakpad minidump file.
 	//
-	google_breakpad::ExceptionHandler * getExceptionHandler(void) { return mExceptionHandler; }
+	void writeMiniDump();
 
 #if !LL_WINDOWS
 	//
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 7cdd8ca309a..0484659793a 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -102,7 +102,6 @@
 
 // Third party library includes
 #include <boost/bind.hpp>
-#include <google_breakpad/exception_handler.h>
 
 
 #if LL_WINDOWS
@@ -2582,7 +2581,10 @@ void LLAppViewer::handleViewerCrash()
 	gDebugInfo["FirstLogin"] = (LLSD::Boolean) gAgent.isFirstLogin();
 	gDebugInfo["FirstRunThisInstall"] = gSavedSettings.getBOOL("FirstRunThisInstall");
 
-	if(pApp->minidump_path[0] != 0) gDebugInfo["MinidumpPath"] = pApp->minidump_path;
+	if(pApp->minidump_path[0] != 0)
+	{
+		gDebugInfo["MinidumpPath"] = pApp->minidump_path;
+	}
 	
 	if(gLogoutInProgress)
 	{
@@ -3290,7 +3292,7 @@ void LLAppViewer::badNetworkHandler()
 		"www.secondlife.com/support";
 	forceDisconnect(message.str());
 	
-	LLApp::instance()->getExceptionHandler()->WriteMinidump();
+	LLApp::instance()->writeMiniDump();
 }
 
 // This routine may get called more than once during the shutdown process.
-- 
GitLab