From 903996e8d4ebc30c42d3c2d041fb7a1c8e530ab8 Mon Sep 17 00:00:00 2001
From: "Graham Madarasz (Graham Linden)" <graham@lindenlab.com>
Date: Thu, 28 Mar 2013 19:25:51 -0700
Subject: Google Breakpad Fix

---
 autobuild.xml                           | 28 ++++++++--------
 indra/cmake/Copy3rdPartyLibs.cmake      |  1 -
 indra/cmake/FreeType.cmake              |  6 ----
 indra/cmake/GoogleBreakpad.cmake        |  3 ++
 indra/linux_crash_logger/CMakeLists.txt |  3 ++
 indra/llcommon/llapp.cpp                | 59 +++++++++++++++++++++++++++++++--
 indra/llcommon/llapp.h                  |  2 +-
 indra/win_crash_logger/CMakeLists.txt   |  1 +
 8 files changed, 78 insertions(+), 25 deletions(-)

diff --git a/autobuild.xml b/autobuild.xml
index 11c2da52dc..37e5964679 100644
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -606,9 +606,9 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>9f8a9dc39fd7c3da0fb3533782d1fddf</string>
+              <string>bd6f84f9fb3c2e68850676d06935373f</string>
               <key>url</key>
-              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-freetype/rev/226814/arch/Linux/installer/freetype-2.3.9-linux-20110418.tar.bz2</string>
+              <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-freetype/rev/271684/arch/Linux/installer/freetype-2.4.4-linux-20130312.tar.bz2</string>
             </map>
             <key>name</key>
             <string>linux</string>
@@ -761,10 +761,10 @@
           <map>
             <key>archive</key>
             <map>
-              <key>hash</key>
-              <string>21babc394dbf8572830f2e85adec7b9f</string>
-              <key>url</key>
-              <string>http://s3.amazonaws.com/viewer-source-downloads/install_pkgs/google_breakpad-0.0.0-rev599-darwin-20110202.tar.bz2</string>
+           <key>hash</key>
+	      <string>79976b2f93ec5716709b752483ffa04a</string>
+          <key>url</key>
+          <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-google-breakpad/rev/273021/arch/Darwin/installer/google_breakpad-0.0.0-rev1099-darwin-20130328.tar.bz2</string>
             </map>
             <key>name</key>
             <string>darwin</string>
@@ -773,10 +773,10 @@
           <map>
             <key>archive</key>
             <map>
-              <key>hash</key>
-              <string>204b02a9480c411232255798839431a2</string>
-              <key>url</key>
-              <string>http://s3.amazonaws.com/viewer-source-downloads/install_pkgs/google_breakpad-0.0.0-rev599-linux-20110311.tar.bz2</string>
+             <key>hash</key>
+	         <string>1df1bb19a43a2d1a684ce9d4da9dc7bc</string>
+             <key>url</key>
+	         <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-google-breakpad/rev/273021/arch/Linux/installer/google_breakpad-0.0.0-rev1099-linux-20130328.tar.bz2</string>
             </map>
             <key>name</key>
             <string>linux</string>
@@ -786,9 +786,9 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>627c51136e14e64c5d39933f3abd3bdf</string>
+	      <string>cfd02d75dbd55327de71db81dc8a3f41</string>
               <key>url</key>
-              <string>http://s3.amazonaws.com/viewer-source-downloads/install_pkgs/google_breakpad-0.0.0-rev599-windows-20110218.tar.bz2</string>
+             <string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-google-breakpad/rev/273021/arch/CYGWIN/installer/google_breakpad-0.0.0-rev1099-windows-20130328.tar.bz2</string>
             </map>
             <key>name</key>
             <string>windows</string>
@@ -834,9 +834,9 @@
             <key>archive</key>
             <map>
               <key>hash</key>
-              <string>212701468920519f3989677cea9ca4f1</string>
+              <string>98994d5b0b4b3d43be22aa6a5c36e6fa</string>
               <key>url</key>
-              <string>http://s3.amazonaws.com/viewer-source-downloads/install_pkgs/gmock-1.5.0-windows-20110224.tar.bz2</string>
+		<string>http://automated-builds-secondlife-com.s3.amazonaws.com/hg/repo/3p-google-mock-graham/rev/272961/arch/CYGWIN/installer/gmock-1.6.0-windows-20130327.tar.bz2</string>
             </map>
             <key>name</key>
             <string>windows</string>
diff --git a/indra/cmake/Copy3rdPartyLibs.cmake b/indra/cmake/Copy3rdPartyLibs.cmake
index c32e357da3..2a73900c71 100644
--- a/indra/cmake/Copy3rdPartyLibs.cmake
+++ b/indra/cmake/Copy3rdPartyLibs.cmake
@@ -260,7 +260,6 @@ elseif(LINUX)
         libboost_filesystem-mt.so.${BOOST_VERSION}.0
         libboost_signals-mt.so.${BOOST_VERSION}.0
         libboost_system-mt.so.${BOOST_VERSION}.0
-        libbreakpad_client.so.0
         libcollada14dom.so
         libcrypto.so.1.0.0
         libdb-5.1.so
diff --git a/indra/cmake/FreeType.cmake b/indra/cmake/FreeType.cmake
index 43a9d282d0..baa61d73c8 100644
--- a/indra/cmake/FreeType.cmake
+++ b/indra/cmake/FreeType.cmake
@@ -7,13 +7,7 @@ if (STANDALONE)
   pkg_check_modules(FREETYPE REQUIRED freetype2)
 else (STANDALONE)
   use_prebuilt_binary(freetype)
-  if (LINUX)
-    set(FREETYPE_INCLUDE_DIRS
-        ${LIBS_PREBUILT_DIR}/include)
-  else (LINUX)
     set(FREETYPE_INCLUDE_DIRS ${LIBS_PREBUILT_DIR}/include)
-  endif (LINUX)
-
   set(FREETYPE_LIBRARIES freetype)
 endif (STANDALONE)
 
diff --git a/indra/cmake/GoogleBreakpad.cmake b/indra/cmake/GoogleBreakpad.cmake
index 7498674042..96e22791ec 100644
--- a/indra/cmake/GoogleBreakpad.cmake
+++ b/indra/cmake/GoogleBreakpad.cmake
@@ -15,5 +15,8 @@ else (STANDALONE)
   if (WINDOWS)
     set(BREAKPAD_EXCEPTION_HANDLER_LIBRARIES exception_handler crash_generation_client common)
   endif (WINDOWS)
+  # yes, this does look dumb, no, it's not incorrect
+  #
+  set(BREAKPAD_INCLUDE_DIRECTORIES "${LIBS_PREBUILT_DIR}/include/google_breakpad" "${LIBS_PREBUILT_DIR}/include/google_breakpad/google_breakpad")
 endif (STANDALONE)
 
diff --git a/indra/linux_crash_logger/CMakeLists.txt b/indra/linux_crash_logger/CMakeLists.txt
index 98ebdc7487..a1f334ffad 100644
--- a/indra/linux_crash_logger/CMakeLists.txt
+++ b/indra/linux_crash_logger/CMakeLists.txt
@@ -12,6 +12,7 @@ include(LLVFS)
 include(LLXML)
 include(Linking)
 include(UI)
+include(FreeType)
 
 include_directories(
     ${LLCOMMON_INCLUDE_DIRS}
@@ -19,6 +20,7 @@ include_directories(
     ${LLMATH_INCLUDE_DIRS}
     ${LLVFS_INCLUDE_DIRS}
     ${LLXML_INCLUDE_DIRS}
+    ${FREETYPE_INCLUDE_DIRS}
     )
 
 set(linux_crash_logger_SOURCE_FILES
@@ -53,6 +55,7 @@ target_link_libraries(linux-crash-logger
     ${LLCOMMON_LIBRARIES}
     ${UI_LIBRARIES}
     ${DB_LIBRARIES}
+    ${FREETYPE_LIBRARIES}
     )
 
 add_custom_target(linux-crash-logger-target ALL
diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index ca258900c7..c6da205815 100644
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -69,10 +69,16 @@ 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"
+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;
@@ -313,7 +319,7 @@ void LLApp::setupErrorHandling()
 	
 	// Add google breakpad exception handler configured for Darwin/Linux.
 	bool installHandler = true;
-#ifdef LL_DARWIN
+#if LL_DARWIN
 	// 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
@@ -346,14 +352,21 @@ void LLApp::setupErrorHandling()
 		installHandler = true;
 	}
 	#endif
-#endif
+
 	if(installHandler && (mExceptionHandler == 0))
 	{
 		std::string dumpPath = "/tmp/";
-		mExceptionHandler = new google_breakpad::ExceptionHandler(dumpPath, 0, &unix_post_minidump_callback, 0, true);
+		mExceptionHandler = new google_breakpad::ExceptionHandler(dumpPath, 0, &unix_post_minidump_callback, 0, true, 0);
+	}
+#elif LL_LINUX
+	if(installHandler && (mExceptionHandler == 0))
+	{
+		google_breakpad::MinidumpDescriptor desc("/tmp");
+	        new google_breakpad::ExceptionHandler(desc, 0, &unix_minidump_callback, 0, true, 0);
 	}
 #endif
 
+#endif
 	startErrorThread();
 }
 
@@ -410,6 +423,9 @@ void LLApp::setMiniDumpDir(const std::string &path)
 	wchar_t buffer[MAX_MINDUMP_PATH_LENGTH];
 	mbstowcs(buffer, path.c_str(), MAX_MINDUMP_PATH_LENGTH);
 	mExceptionHandler->set_dump_path(std::wstring(buffer));
+#elif LL_LINUX
+        google_breakpad::MinidumpDescriptor desc(path);
+	mExceptionHandler->set_minidump_descriptor(desc);
 #else
 	mExceptionHandler->set_dump_path(path);
 #endif
@@ -857,6 +873,43 @@ 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
+	int dirPathLength = strlen(minidump_desc.path());
+	
+	// The path must not be truncated.
+	llassert((dirPathLength + 5) <= LLApp::MAX_MINDUMP_PATH_LENGTH);
+	
+	char * path = LLApp::instance()->getMiniDumpFilename();
+	S32 remaining = LLApp::MAX_MINDUMP_PATH_LENGTH;
+	strncpy(path, minidump_desc.path(), remaining);
+	remaining -= dirPathLength;
+	path += dirPathLength;
+	if (remaining > 0 && dirPathLength > 0 && path[-1] != '/')
+	{
+		*path++ = '/';
+		--remaining;
+	}
+	
+	llinfos << "generated minidump: " << LLApp::instance()->getMiniDumpFilename() << llendl;
+	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 a536a06ea5..afa06df23e 100644
--- a/indra/llcommon/llapp.h
+++ b/indra/llcommon/llapp.h
@@ -38,7 +38,7 @@ typedef LLAtomic32<U32> LLAtomicU32;
 class LLErrorThread;
 class LLLiveFile;
 #if LL_LINUX
-typedef struct siginfo siginfo_t;
+#include <signal.h>
 #endif
 
 typedef void (*LLAppErrorHandler)();
diff --git a/indra/win_crash_logger/CMakeLists.txt b/indra/win_crash_logger/CMakeLists.txt
index 5329c89554..50633599ab 100644
--- a/indra/win_crash_logger/CMakeLists.txt
+++ b/indra/win_crash_logger/CMakeLists.txt
@@ -78,6 +78,7 @@ target_link_libraries(windows-crash-logger
     gdi32
     ole32
     oleaut32
+    wininet
     Wldap32
     )
     
-- 
cgit v1.2.3