Bug 856566 - Fixed crashreporter compilation and profiler on mingw. r=ted
authorJacek Caban <jacek@codeweavers.com>
Fri, 05 Apr 2013 11:29:50 +0200
changeset 127772 c99b61f740d717035cd585b40c5f1043997d4fab
parent 127771 305ce1b7307124fad3e12d7ac45def78b66d3297
child 127773 d0a75bdaa01efe52672396c1ea42f39143e38099
push id24512
push userryanvm@gmail.com
push dateFri, 05 Apr 2013 20:13:49 +0000
treeherdermozilla-central@139b6ba547fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs856566
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 856566 - Fixed crashreporter compilation and profiler on mingw. r=ted
configure.in
toolkit/crashreporter/LoadLibraryRemote.cpp
toolkit/crashreporter/client/crashreporter_win.cpp
toolkit/crashreporter/injector/Makefile.in
toolkit/crashreporter/injector/injector.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
tools/profiler/PlatformMacros.h
widget/windows/LSPAnnotator.cpp
--- a/configure.in
+++ b/configure.in
@@ -6015,17 +6015,17 @@ if test -n "$MOZ_CRASHREPORTER"; then
 
   if test "$OS_TARGET" = "Linux" -o "$OS_ARCH" = "SunOS" && \
     test -z "$SKIP_LIBRARY_CHECKS"; then
     PKG_CHECK_MODULES(MOZ_GTHREAD, gthread-2.0)
     AC_SUBST(MOZ_GTHREAD_CFLAGS)
     AC_SUBST(MOZ_GTHREAD_LIBS)
   fi
 
-  if test "$OS_ARCH" != "$HOST_OS_ARCH"; then
+  if test "$OS_ARCH" != "$HOST_OS_ARCH" -a "$OS_ARCH" != "WINNT"; then
     AC_MSG_ERROR([Breakpad tools do not support compiling on $HOST_OS_ARCH while targeting $OS_ARCH.  Use --disable-crashreporter.])
   fi
 
   if test "$OS_ARCH" = "WINNT"; then
     if test -z "$HAVE_64BIT_OS"; then
       MOZ_CRASHREPORTER_INJECTOR=1
       AC_DEFINE(MOZ_CRASHREPORTER_INJECTOR)
     fi
--- a/toolkit/crashreporter/LoadLibraryRemote.cpp
+++ b/toolkit/crashreporter/LoadLibraryRemote.cpp
@@ -17,18 +17,16 @@
 #include <winnt.h>
 #include <stdlib.h>
 #ifdef DEBUG_OUTPUT
 #include <stdio.h>
 #endif
 
 #include "nsWindowsHelpers.h"
 
-namespace {
-
 typedef const unsigned char* FileView;
 
 template<>
 class nsAutoRefTraits<FileView>
 {
 public:
   typedef FileView RawRef;
   static FileView Void()
@@ -38,18 +36,16 @@ public:
 
   static void Release(RawRef aView)
   {
     if (NULL != aView)
       UnmapViewOfFile(aView);
   }
 };
 
-} // anonymous namespace
-
 #ifndef IMAGE_SIZEOF_BASE_RELOCATION
 // Vista SDKs no longer define IMAGE_SIZEOF_BASE_RELOCATION!?
 #define IMAGE_SIZEOF_BASE_RELOCATION (sizeof(IMAGE_BASE_RELOCATION))
 #endif
 
 #include "LoadLibraryRemote.h"
 
 typedef struct {
@@ -431,10 +427,10 @@ static void* MemoryGetProcAddress(PMEMOR
   }
 
   if ((DWORD)idx > exports->NumberOfFunctions) {
     // name <-> ordinal number don't match
     return NULL;
   }
 
   // AddressOfFunctions contains the RVAs to the "real" functions
-  return (FARPROC) (module->remoteCodeBase + (*(DWORD *) (localCodeBase + exports->AddressOfFunctions + (idx*4))));
+  return module->remoteCodeBase + (*(DWORD *) (localCodeBase + exports->AddressOfFunctions + (idx*4)));
 }
--- a/toolkit/crashreporter/client/crashreporter_win.cpp
+++ b/toolkit/crashreporter/client/crashreporter_win.cpp
@@ -2,16 +2,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifdef WIN32_LEAN_AND_MEAN
 #undef WIN32_LEAN_AND_MEAN
 #endif
 
+#define NOMINMAX
+
 #include "crashreporter.h"
 
 #include <windows.h>
 #include <commctrl.h>
 #include <richedit.h>
 #include <shellapi.h>
 #include <shlobj.h>
 #include <shlwapi.h>
@@ -888,17 +890,17 @@ static BOOL CALLBACK CrashReporterDialog
     RECT rect;
     HWND hwnd = GetDlgItem(hwndDlg, IDC_VIEWREPORTBUTTON);
     GetRelativeRect(hwnd, hwndDlg, &rect);
     ResizeControl(hwnd, rect, Str(ST_VIEWREPORT), false, 0);
     SetDlgItemText(hwndDlg, IDC_VIEWREPORTBUTTON, Str(ST_VIEWREPORT).c_str());
 
     hwnd = GetDlgItem(hwndDlg, IDC_SUBMITREPORTCHECK);
     GetRelativeRect(hwnd, hwndDlg, &rect);
-    int maxdiff = ResizeControl(hwnd, rect, Str(ST_CHECKSUBMIT), false,
+    long maxdiff = ResizeControl(hwnd, rect, Str(ST_CHECKSUBMIT), false,
                                 gCheckboxPadding);
     SetDlgItemText(hwndDlg, IDC_SUBMITREPORTCHECK,
                    Str(ST_CHECKSUBMIT).c_str());
 
     if (!CheckBoolKey(gCrashReporterKey.c_str(),
                       SUBMIT_REPORT_VALUE, &enabled))
       enabled = ShouldEnableSending();
 
@@ -915,34 +917,34 @@ static BOOL CALLBACK CrashReporterDialog
     SetWindowLongPtr(hwndComment, GWLP_USERDATA, (LONG_PTR)OldWndProc);
     wstring commentGrayText = Str(ST_COMMENTGRAYTEXT);
     wchar_t* hMem = (wchar_t*)GlobalAlloc(GPTR, (commentGrayText.length() + 1)*sizeof(wchar_t));
     wcscpy(hMem, commentGrayText.c_str());
     SetProp(hwndComment, L"PROP_GRAYTEXT", hMem);
 
     hwnd = GetDlgItem(hwndDlg, IDC_INCLUDEURLCHECK);
     GetRelativeRect(hwnd, hwndDlg, &rect);
-    int diff = ResizeControl(hwnd, rect, Str(ST_CHECKURL), false,
+    long diff = ResizeControl(hwnd, rect, Str(ST_CHECKURL), false,
                              gCheckboxPadding);
-    maxdiff = max(diff, maxdiff);
+    maxdiff = std::max(diff, maxdiff);
     SetDlgItemText(hwndDlg, IDC_INCLUDEURLCHECK, Str(ST_CHECKURL).c_str());
 
     // want this on by default
     if (CheckBoolKey(gCrashReporterKey.c_str(), INCLUDE_URL_VALUE, &enabled) &&
         !enabled) {
       CheckDlgButton(hwndDlg, IDC_INCLUDEURLCHECK, BST_UNCHECKED);
     } else {
       CheckDlgButton(hwndDlg, IDC_INCLUDEURLCHECK, BST_CHECKED);
     }
 
     hwnd = GetDlgItem(hwndDlg, IDC_EMAILMECHECK);
     GetRelativeRect(hwnd, hwndDlg, &rect);
     diff = ResizeControl(hwnd, rect, Str(ST_CHECKEMAIL), false,
                          gCheckboxPadding);
-    maxdiff = max(diff, maxdiff);
+    maxdiff = std::max(diff, maxdiff);
     SetDlgItemText(hwndDlg, IDC_EMAILMECHECK, Str(ST_CHECKEMAIL).c_str());
 
     if (CheckBoolKey(gCrashReporterKey.c_str(), EMAIL_ME_VALUE, &enabled) &&
         enabled) {
       CheckDlgButton(hwndDlg, IDC_EMAILMECHECK, BST_CHECKED);
     } else {
       CheckDlgButton(hwndDlg, IDC_EMAILMECHECK, BST_UNCHECKED);
     }
@@ -990,17 +992,17 @@ static BOOL CALLBACK CrashReporterDialog
       SetDlgItemVisible(hwndDlg, IDC_RESTARTBUTTON, false);
     }
     // See if we need to widen the window
     // Leave 6 pixels on either side + 6 pixels between the buttons
     int neededSize = closeRect.right - closeRect.left +
       restartRect.right - restartRect.left + 6 * 3;
     GetClientRect(hwndDlg, &r);
     // We may already have resized one of the checkboxes above
-    maxdiff = max(maxdiff, neededSize - (r.right - r.left));
+    maxdiff = std::max(maxdiff, neededSize - (r.right - r.left));
 
     if (maxdiff > 0) {
       // widen window
       GetWindowRect(hwndDlg, &r);
       r.right += maxdiff;
       MoveWindow(hwndDlg, r.left, r.top,
                  r.right - r.left, r.bottom - r.top, TRUE);
       // shift both buttons right
@@ -1217,43 +1219,48 @@ static wstring UTF8ToWide(const string& 
   delete [] buffer;
 
   if (success)
     *success = true;
 
   return str;
 }
 
-string WideToUTF8(const wstring& wide, bool* success)
+static string WideToMBCP(const wstring& wide, unsigned int cp, bool* success = nullptr)
 {
   char* buffer = NULL;
-  int buffer_size = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(),
+  int buffer_size = WideCharToMultiByte(cp, 0, wide.c_str(),
                                         -1, NULL, 0, NULL, NULL);
   if(buffer_size == 0) {
     if (success)
       *success = false;
     return "";
   }
 
   buffer = new char[buffer_size];
   if(buffer == NULL) {
     if (success)
       *success = false;
     return "";
   }
 
-  WideCharToMultiByte(CP_UTF8, 0, wide.c_str(),
+  WideCharToMultiByte(cp, 0, wide.c_str(),
                       -1, buffer, buffer_size, NULL, NULL);
-  string utf8 = buffer;
+  string mb = buffer;
   delete [] buffer;
 
   if (success)
     *success = true;
 
-  return utf8;
+  return mb;
+}
+
+string WideToUTF8(const wstring& wide, bool* success)
+{
+  return WideToMBCP(wide, CP_UTF8, success);
 }
 
 /* === Crashreporter UI Functions === */
 
 bool UIInit()
 {
   for (int i = 0; i < sizeof(kDefaultAttachedBottom) / sizeof(UINT); i++) {
     gAttachedBottom.insert(kDefaultAttachedBottom[i]);
@@ -1419,18 +1426,21 @@ ifstream* UIOpenRead(const string& filen
 
   // The "open" method on pre-MSVC8 ifstream implementations doesn't accept a
   // wchar_t* filename, so use _wfopen directly in that case.  For VC8 and
   // later, _wfopen has been deprecated in favor of _wfopen_s, which does
   // not exist in earlier versions, so let the ifstream open the file itself.
 #if _MSC_VER >= 1400  // MSVC 2005/8
   ifstream* file = new ifstream();
   file->open(UTF8ToWide(filename).c_str(), ios::in);
-#else  // _MSC_VER >= 1400
+#elif defined(_MSC_VER)
   ifstream* file = new ifstream(_wfopen(UTF8ToWide(filename).c_str(), L"r"));
+#else   // GCC
+  ifstream* file = new ifstream(WideToMBCP(UTF8ToWide(filename), CP_ACP).c_str(),
+                                ios::in);
 #endif  // _MSC_VER >= 1400
 
   return file;
 }
 
 ofstream* UIOpenWrite(const string& filename, bool append) // append=false
 {
   // adapted from breakpad's src/common/windows/http_upload.cc
@@ -1438,19 +1448,22 @@ ofstream* UIOpenWrite(const string& file
   // The "open" method on pre-MSVC8 ifstream implementations doesn't accept a
   // wchar_t* filename, so use _wfopen directly in that case.  For VC8 and
   // later, _wfopen has been deprecated in favor of _wfopen_s, which does
   // not exist in earlier versions, so let the ifstream open the file itself.
 #if _MSC_VER >= 1400  // MSVC 2005/8
   ofstream* file = new ofstream();
   file->open(UTF8ToWide(filename).c_str(), append ? ios::out | ios::app
                                                   : ios::out);
-#else  // _MSC_VER >= 1400
+#elif defined(_MSC_VER)
   ofstream* file = new ofstream(_wfopen(UTF8ToWide(filename).c_str(),
                                         append ? L"a" : L"w"));
+#else   // GCC
+  ofstream* file = new ofstream(WideToMBCP(UTF8ToWide(filename), CP_ACP).c_str(),
+                                append ? ios::out | ios::app : ios::out);
 #endif  // _MSC_VER >= 1400
 
   return file;
 }
 
 struct FileData
 {
   FILETIME timestamp;
--- a/toolkit/crashreporter/injector/Makefile.in
+++ b/toolkit/crashreporter/injector/Makefile.in
@@ -19,9 +19,13 @@ CPPSRCS = injector.cpp
 
 SHARED_LIBRARY_LIBS += ../breakpad-windows-standalone/$(LIB_PREFIX)google_breakpad_standalone_s.$(LIB_SUFFIX)
 
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/crashreporter/google-breakpad/src
-LDFLAGS += -ENTRY:DummyEntryPoint
+ifndef GNU_CC
+LDFLAGS += -ENTRY:DummyEntryPoint
+else
+LDFLAGS += -Wl,-e,_DummyEntryPoint@12
+endif
--- a/toolkit/crashreporter/injector/injector.cpp
+++ b/toolkit/crashreporter/injector/injector.cpp
@@ -4,19 +4,19 @@
 
 #include <windows.h>
 
 #include "client/windows/handler/exception_handler.h"
 
 using google_breakpad::ExceptionHandler;
 using std::wstring;
 
-BOOL WINAPI DummyEntryPoint(HINSTANCE instance,
-                            DWORD reason,
-                            void* reserved)
+extern "C" BOOL WINAPI DummyEntryPoint(HINSTANCE instance,
+                                       DWORD reason,
+                                       void* reserved)
 {
   __debugbreak();
 
   return FALSE; // We're being loaded remotely, this shouldn't happen!
 }
 
 // support.microsoft.com/kb/94248
 extern "C" BOOL WINAPI _CRT_INIT(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved); 
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -17,17 +17,17 @@
 #ifdef WIN32_LEAN_AND_MEAN
 #undef WIN32_LEAN_AND_MEAN
 #endif
 
 #include "nsIWindowsRegKey.h"
 #include "client/windows/crash_generation/client_info.h"
 #include "client/windows/crash_generation/crash_generation_server.h"
 #include "client/windows/handler/exception_handler.h"
-#include <DbgHelp.h>
+#include <dbghelp.h>
 #include <string.h>
 #include "nsDirectoryServiceUtils.h"
 
 #include "nsWindowsDllInterceptor.h"
 #elif defined(XP_MACOSX)
 #include "client/mac/crash_generation/client_info.h"
 #include "client/mac/crash_generation/crash_generation_server.h"
 #include "client/mac/handler/exception_handler.h"
--- a/tools/profiler/PlatformMacros.h
+++ b/tools/profiler/PlatformMacros.h
@@ -54,22 +54,22 @@
 #  define SPS_ARCH_amd64 1
 #  define SPS_OS_darwin 1
 
 #elif defined(__APPLE__) && defined(__i386__)
 #  define SPS_PLAT_x86_darwin 1
 #  define SPS_ARCH_x86 1
 #  define SPS_OS_darwin 1
 
-#elif defined(_MSC_VER) && defined(_M_IX86)
+#elif (defined(_MSC_VER) || defined(__MINGW32__)) && (defined(_M_IX86) || defined(__i386__))
 #  define SPS_PLAT_x86_windows 1
 #  define SPS_ARCH_x86 1
 #  define SPS_OS_windows 1
 
-#elif defined(_MSC_VER) && defined(_M_X64)
+#elif (defined(_MSC_VER) || defined(__MINGW32__)) && (defined(_M_X64) || defined(__x86_64__))
 #  define SPS_PLAT_amd64_windows 1
 #  define SPS_ARCH_amd64 1
 #  define SPS_OS_windows 1
 
 #else
 #  error "Unsupported platform"
 #endif
 
--- a/widget/windows/LSPAnnotator.cpp
+++ b/widget/windows/LSPAnnotator.cpp
@@ -11,17 +11,17 @@
  * on machines with several LSPs.
  */
 
 #include "nsICrashReporter.h"
 #include "nsISupportsImpl.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include <windows.h>
-#include <Ws2spi.h>
+#include <ws2spi.h>
 
 namespace mozilla {
 namespace crashreporter {
 
 class LSPAnnotationGatherer : public nsRunnable
 {
 public:
   NS_DECL_ISUPPORTS