From e38358a097a9720dbd2944a1e4808735c5839dbe Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sat, 8 Aug 2020 18:55:50 -0400
Subject: [PATCH] Rip out breakpad from llcommon

---
 indra/llcommon/llapp.cpp | 154 ++-------------------------------------
 indra/llcommon/llapp.h   |   7 --
 2 files changed, 5 insertions(+), 156 deletions(-)

diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index 7549ea45ac4..690a36a496a 100644
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -46,7 +46,6 @@
 #include "llstl.h" // for DeletePointer()
 #include "llstring.h"
 #include "lleventtimer.h"
-#include "google_breakpad/exception_handler.h"
 #include "stringize.h"
 #include "llcleanup.h"
 #include "llevents.h"
@@ -74,18 +73,6 @@ bool windows_post_minidump_callback(const wchar_t* dump_path,
 void setup_signals();
 void default_unix_signal_handler(int signum, siginfo_t *info, void *);
 
-#if LL_LINUX
-#include "google_breakpad/minidump_descriptor.h"
-static bool unix_minidump_callback(const google_breakpad::MinidumpDescriptor& minidump_desc, 
-                                   void* context, 
-                                   bool succeeded);
-#else
-// Called by breakpad exception handler after the minidump has been generated.
-bool unix_post_minidump_callback(const char *dump_dir,
-					  const char *minidump_id,
-					  void *context, bool succeeded);
-#endif
-
 # if LL_DARWIN
 /* OSX doesn't support SIGRT* */
 S32 LL_SMACKDOWN_SIGNAL = SIGUSR1;
@@ -150,8 +137,6 @@ void LLApp::commonCtor()
 	// Set the application to this instance.
 	sApplication = this;
 
-	mExceptionHandler = 0;
-	
 	// initialize the buffer to write the minidump filename to
 	// (this is used to avoid allocating memory in the crash handler)
 	memset(mMinidumpPath, 0, MAX_MINDUMP_PATH_LENGTH);
@@ -181,8 +166,6 @@ LLApp::~LLApp()
 		mThreadErrorp = NULL;
 	}
 	
-	if(mExceptionHandler != 0) delete mExceptionHandler;
-
 	SUBSYSTEM_CLEANUP(LLCommon);
 }
 
@@ -403,62 +386,6 @@ void LLApp::setupErrorHandling(bool second_instance)
 	// 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)
-	{
-		if ( second_instance )  //BUG-5707 Firing teleport from a web browser causes second 
-		{
-			mExceptionHandler = new google_breakpad::ExceptionHandler(
-															L"C:\\Temp\\",		
-															0,		//No filter
-															windows_post_minidump_callback,
-															0,
-															google_breakpad::ExceptionHandler::HANDLER_ALL);  //No custom client info.
-		}
-		else
-		{
-			LL_WARNS() << "adding breakpad exception handler" << LL_ENDL;
-
-			std::wstring wpipe_name;
-			wpipe_name =  mCrashReportPipeStr + wstringize(getPid());
-
-			const std::wstring wdump_path(utf8str_to_utf16str(mDumpPath));
-
-			int retries = 30;
-			for (; retries > 0; --retries)
-			{
-				if (mExceptionHandler != 0) delete mExceptionHandler;
-
-				mExceptionHandler = new google_breakpad::ExceptionHandler(
-															wdump_path,		
-															NULL,		//No filter
-															windows_post_minidump_callback,
-															0,
-															google_breakpad::ExceptionHandler::HANDLER_ALL,
-															MiniDumpNormal, //Generate a 'normal' minidump.
-															wpipe_name.c_str(),
-															NULL);  //No custom client info.
-				if (mExceptionHandler->IsOutOfProcess())
-				{
-					LL_INFOS("CRASHREPORT") << "Successfully attached to Out of Process exception handler." << LL_ENDL;
-					break;
-				}
-				else
-				{
-					LL_WARNS("CRASHREPORT") << "Unable to attach to Out of Process exception handler.  " << retries << " retries remaining." << LL_ENDL; 
-					::Sleep(100);  //Wait a tick and try again.
-				}
-			}
-
-			if (retries == 0) LL_WARNS("CRASHREPORT") << "Unable to attach to Out of Process exception handler." << LL_ENDL;
-		}
-
-		if (mExceptionHandler)
-		{
-			mExceptionHandler->set_handle_debug_exceptions(true);
-		}
-	}
 #endif // LL_SEND_CRASH_REPORTS && ! defined(LL_BUGSPLAT)
 #else  // ! LL_WINDOWS
 
@@ -477,10 +404,11 @@ void LLApp::setupErrorHandling(bool second_instance)
 	setup_signals();
 
 	// Add google breakpad exception handler configured for Darwin/Linux.
-	bool installHandler = true;
 #endif // ! LL_BUGSPLAT
 
 #if LL_DARWIN
+
+	bool installHandler = true;
 	// For the special case of Darwin, we do not want to install the handler if
 	// the process is being debugged as the app will exit with value ABRT (6) if
 	// we do.  Unfortunately, the code below which performs that test relies on
@@ -514,20 +442,11 @@ void LLApp::setupErrorHandling(bool second_instance)
 	}
 	#endif // ! LL_RELEASE_FOR_DOWNLOAD
 
-	if(installHandler && (mExceptionHandler == 0))
+	if(installHandler)
 	{
-		mExceptionHandler = new google_breakpad::ExceptionHandler(mDumpPath, 0, &unix_post_minidump_callback, 0, true, 0);
 	}
 #elif LL_LINUX
-	if(installHandler && (mExceptionHandler == 0))
-	{
-		if (mDumpPath.empty())
-		{
-			mDumpPath = "/tmp";
-		}
-		google_breakpad::MinidumpDescriptor desc(mDumpPath);
-	    mExceptionHandler = new google_breakpad::ExceptionHandler(desc, NULL, unix_minidump_callback, NULL, true, -1);
-	}
+
 #endif // LL_LINUX
 
 #endif // ! LL_WINDOWS
@@ -622,19 +541,6 @@ void LLApp::setMiniDumpDir(const std::string &path)
 	{
 		mDumpPath = path;
 	}
-
-	if(mExceptionHandler == 0) return;
-#ifdef LL_WINDOWS
-	std::wstring buffer(utf8str_to_utf16str(mDumpPath));
-	if (buffer.size() > MAX_MINDUMP_PATH_LENGTH) buffer.resize(MAX_MINDUMP_PATH_LENGTH);
-	mExceptionHandler->set_dump_path(buffer);
-#elif LL_LINUX
-        //google_breakpad::MinidumpDescriptor desc("/tmp");	//path works in debug fails in production inside breakpad lib so linux gets a little less stack reporting until it is patched.
-        google_breakpad::MinidumpDescriptor desc(mDumpPath);	//path works in debug fails in production inside breakpad lib so linux gets a little less stack reporting until it is patched.
-	mExceptionHandler->set_minidump_descriptor(desc);
-#else
-	mExceptionHandler->set_dump_path(mDumpPath);
-#endif
 }
 
 void LLApp::setDebugFileNames(const std::string &path)
@@ -645,8 +551,7 @@ void LLApp::setDebugFileNames(const std::string &path)
 
 void LLApp::writeMiniDump()
 {
-	if(mExceptionHandler == 0) return;
-	mExceptionHandler->WriteMinidump();
+
 }
 
 // static
@@ -703,13 +608,6 @@ bool LLApp::isExiting()
 
 void LLApp::disableCrashlogger()
 {
-	// Disable Breakpad exception handler.
-	if (mExceptionHandler != 0)
-	{
-		delete mExceptionHandler;
-		mExceptionHandler = 0;
-	}
-
 	sDisableCrashlogger = TRUE;
 }
 
@@ -1012,48 +910,6 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *)
 	}
 }
 
-#if LL_LINUX
-bool unix_minidump_callback(const google_breakpad::MinidumpDescriptor& minidump_desc, void* context, bool succeeded)
-{
-	// Copy minidump file path into fixed buffer in the app instance to avoid
-	// heap allocations in a crash handler.
-	
-	// path format: <dump_dir>/<minidump_id>.dmp
-	
-	//HACK:  *path points to the buffer in getMiniDumpFilename which has already allocated space
-	//to avoid doing allocation during crash.
-	char * path = LLApp::instance()->getMiniDumpFilename();
-	int dir_path_len = strlen(path);
-	
-	// The path must not be truncated.
-	S32 remaining =  LLApp::MAX_MINDUMP_PATH_LENGTH - dir_path_len;
-
-	llassert( (remaining - strlen(minidump_desc.path())) > 5);
-	
-	path += dir_path_len;
-
-	if (dir_path_len > 0 && path[-1] != '/')
-	{
-		*path++ = '/';
-		--remaining;
-	}
-
-	strncpy(path, minidump_desc.path(), remaining);
-	
-	LL_INFOS("CRASHREPORT") << "generated minidump: " << LLApp::instance()->getMiniDumpFilename() << LL_ENDL;
-	LLApp::runErrorHandler();
-	
-#ifndef LL_RELEASE_FOR_DOWNLOAD
-	clear_signals();
-	return false;
-#else
-	return true;
-#endif
-
-}
-#endif
-
-
 bool unix_post_minidump_callback(const char *dump_dir,
 					  const char *minidump_id,
 					  void *context, bool succeeded)
diff --git a/indra/llcommon/llapp.h b/indra/llcommon/llapp.h
index 245c73e3a22..6d013c378ca 100644
--- a/indra/llcommon/llapp.h
+++ b/indra/llcommon/llapp.h
@@ -49,10 +49,6 @@ void clear_signals();
 
 #endif
 
-namespace google_breakpad {
-	class ExceptionHandler; // See exception_handler.h
-}
-
 class LL_COMMON_API LLApp
 {
 	friend class LLErrorThread;
@@ -312,9 +308,6 @@ class LL_COMMON_API LLApp
 private:
 	// the static application instance if it was created.
 	static LLApp* sApplication;
-	
-	google_breakpad::ExceptionHandler * mExceptionHandler;
-
 
 #if !LL_WINDOWS
 	friend void default_unix_signal_handler(int signum, siginfo_t *info, void *);
-- 
GitLab