Bug 1286802 - Part 2: Refactor google_breakpad::ExceptionHandler for including heap regions. r?ted draft
authorCervantes Yu <cyu@mozilla.com>
Tue, 14 Mar 2017 19:34:59 +0800
changeset 580335 fafe58b23541df4d76494cfea60a168ac4fc4d3a
parent 580334 38ec1ae34e195f6e814ee13a34fd3d42cc44090b
child 580336 c21afd250116ccdd8bcd486475a07837b556bf31
push id59519
push usercyu@mozilla.com
push dateThu, 18 May 2017 11:09:20 +0000
reviewersted
bugs1286802
milestone55.0a1
Bug 1286802 - Part 2: Refactor google_breakpad::ExceptionHandler for including heap regions. r?ted This moves type definitions and minidump callback to minidump_callback.{h|cpp}, which will be used by google_breakpad::ExceptionHandler for in-process crash generation, and by googld_breakpad::CrashGenerationServer for out-of-process crash generation. MozReview-Commit-ID: AMsQHSUTYNx
toolkit/crashreporter/breakpad-client/windows/common/minidump_callback.cc
toolkit/crashreporter/breakpad-client/windows/common/minidump_callback.h
toolkit/crashreporter/breakpad-client/windows/handler/exception_handler.cc
toolkit/crashreporter/breakpad-client/windows/handler/exception_handler.h
--- a/toolkit/crashreporter/breakpad-client/windows/common/minidump_callback.cc
+++ b/toolkit/crashreporter/breakpad-client/windows/common/minidump_callback.cc
@@ -1,8 +1,54 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #include "minidump_callback.h"
 
+#include <algorithm>
+#include <cassert>
+
+namespace google_breakpad {
+
+BOOL CALLBACK MinidumpWriteDumpCallback(
+    PVOID context,
+    const PMINIDUMP_CALLBACK_INPUT callback_input,
+    PMINIDUMP_CALLBACK_OUTPUT callback_output) {
+  switch (callback_input->CallbackType) {
+  case MemoryCallback: {
+    MinidumpCallbackContext* callback_context =
+        reinterpret_cast<MinidumpCallbackContext*>(context);
+
+    if (callback_context->iter == callback_context->end)
+      return FALSE;
+
+    // Include the specified memory region.
+    callback_output->MemoryBase = callback_context->iter->ptr;
+    callback_output->MemorySize = callback_context->iter->length;
+    callback_context->iter++;
+    return TRUE;
+  }
+
+    // Include all modules.
+  case IncludeModuleCallback:
+  case ModuleCallback:
+    return TRUE;
+
+    // Include all threads.
+  case IncludeThreadCallback:
+  case ThreadCallback:
+    return TRUE;
+
+    // Stop receiving cancel callbacks.
+  case CancelCallback:
+    callback_output->CheckCancel = FALSE;
+    callback_output->Cancel = FALSE;
+    return TRUE;
+  }
+  // Ignore other callback types.
+  return FALSE;
+}
+
+}  // namespace google_breakpad
+
--- a/toolkit/crashreporter/breakpad-client/windows/common/minidump_callback.h
+++ b/toolkit/crashreporter/breakpad-client/windows/common/minidump_callback.h
@@ -1,9 +1,49 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #ifndef MINIDUMP_CALLBACK_H__
 #define MINIDUMP_CALLBACK_H__
+
+#include <windows.h>
+#include <dbghelp.h>
+
+#include <list>
+
+namespace google_breakpad {
+
+// These entries store a list of memory regions that the client wants included
+// in the minidump.
+struct AppMemory {
+  ULONG64 ptr;
+  ULONG length;
+
+  bool operator==(const struct AppMemory& other) const {
+    return ptr == other.ptr;
+  }
+
+  bool operator==(const void* other) const {
+    return ptr == reinterpret_cast<ULONG64>(other);
+  }
+};
+typedef std::list<AppMemory> AppMemoryList;
+
+// This is passed as the context to the MinidumpWriteDump callback.
+typedef struct {
+  AppMemoryList::const_iterator iter;
+  AppMemoryList::const_iterator end;
+} MinidumpCallbackContext;
+
+// This function is used as a callback when calling MinidumpWriteDump,
+// in order to add additional memory regions to the dump.
+BOOL CALLBACK MinidumpWriteDumpCallback(
+    PVOID context,
+    const PMINIDUMP_CALLBACK_INPUT callback_input,
+    PMINIDUMP_CALLBACK_OUTPUT callback_output);
+
+}  // namespace google_breakpad
+
 #endif
+
--- a/toolkit/crashreporter/breakpad-client/windows/handler/exception_handler.cc
+++ b/toolkit/crashreporter/breakpad-client/windows/handler/exception_handler.cc
@@ -36,22 +36,16 @@
 #include "common/windows/string_utils-inl.h"
 
 #include "windows/common/ipc_protocol.h"
 #include "windows/handler/exception_handler.h"
 #include "common/windows/guid_string.h"
 
 namespace google_breakpad {
 
-// This is passed as the context to the MinidumpWriteDump callback.
-typedef struct {
-  AppMemoryList::const_iterator iter;
-  AppMemoryList::const_iterator end;
-} MinidumpCallbackContext;
-
 vector<ExceptionHandler*>* ExceptionHandler::handler_stack_ = NULL;
 LONG ExceptionHandler::handler_stack_index_ = 0;
 CRITICAL_SECTION ExceptionHandler::handler_stack_critical_section_;
 volatile LONG ExceptionHandler::instance_count_ = 0;
 
 ExceptionHandler::ExceptionHandler(const wstring& dump_path,
                                    FilterCallback filter,
                                    MinidumpCallback callback,
@@ -859,54 +853,16 @@ bool ExceptionHandler::WriteMinidumpWith
     success = callback_(dump_path_c_, next_minidump_id_c_, callback_context_,
                         exinfo, assertion, success);
   }
 
   return success;
 }
 
 // static
-BOOL CALLBACK ExceptionHandler::MinidumpWriteDumpCallback(
-    PVOID context,
-    const PMINIDUMP_CALLBACK_INPUT callback_input,
-    PMINIDUMP_CALLBACK_OUTPUT callback_output) {
-  switch (callback_input->CallbackType) {
-  case MemoryCallback: {
-    MinidumpCallbackContext* callback_context =
-        reinterpret_cast<MinidumpCallbackContext*>(context);
-    if (callback_context->iter == callback_context->end)
-      return FALSE;
-
-    // Include the specified memory region.
-    callback_output->MemoryBase = callback_context->iter->ptr;
-    callback_output->MemorySize = callback_context->iter->length;
-    callback_context->iter++;
-    return TRUE;
-  }
-
-    // Include all modules.
-  case IncludeModuleCallback:
-  case ModuleCallback:
-    return TRUE;
-
-    // Include all threads.
-  case IncludeThreadCallback:
-  case ThreadCallback:
-    return TRUE;
-
-    // Stop receiving cancel callbacks.
-  case CancelCallback:
-    callback_output->CheckCancel = FALSE;
-    callback_output->Cancel = FALSE;
-    return TRUE;
-  }
-  // Ignore other callback types.
-  return FALSE;
-}
-
 bool ExceptionHandler::WriteMinidumpWithExceptionForProcess(
     DWORD requesting_thread_id,
     EXCEPTION_POINTERS* exinfo,
     MDRawAssertionInfo* assertion,
     HANDLE process,
     bool write_requester_stream) {
   bool success = false;
   if (minidump_write_dump_) {
--- a/toolkit/crashreporter/breakpad-client/windows/handler/exception_handler.h
+++ b/toolkit/crashreporter/breakpad-client/windows/handler/exception_handler.h
@@ -64,42 +64,27 @@
 #pragma warning(push)
 // Disable exception handler warnings.
 #pragma warning(disable:4530)
 
 #include <list>
 #include <string>
 #include <vector>
 
+#include "windows/common/minidump_callback.h"
 #include "windows/common/ipc_protocol.h"
 #include "windows/crash_generation/crash_generation_client.h"
 #include "common/scoped_ptr.h"
 #include "google_breakpad/common/minidump_format.h"
 
 namespace google_breakpad {
 
 using std::vector;
 using std::wstring;
 
-// These entries store a list of memory regions that the client wants included
-// in the minidump.
-struct AppMemory {
-  ULONG64 ptr;
-  ULONG length;
-
-  bool operator==(const struct AppMemory& other) const {
-    return ptr == other.ptr;
-  }
-
-  bool operator==(const void* other) const {
-    return ptr == reinterpret_cast<ULONG64>(other);
-  }
-};
-typedef std::list<AppMemory> AppMemoryList;
-
 class ExceptionHandler {
  public:
   // A callback function to run before Breakpad performs any substantial
   // processing of an exception.  A FilterCallback is called before writing
   // a minidump.  context is the parameter supplied by the user as
   // callback_context when the handler was created.  exinfo points to the
   // exception record, if any; assertion points to assertion information,
   // if any.
@@ -352,23 +337,16 @@ class ExceptionHandler {
   // current process.  requesting_thread_id is the ID of the thread
   // that requested the dump.  If the dump is requested as a result of
   // an exception, exinfo contains exception information, otherwise,
   // it is NULL.
   bool WriteMinidumpWithException(DWORD requesting_thread_id,
                                   EXCEPTION_POINTERS* exinfo,
                                   MDRawAssertionInfo* assertion);
 
-  // This function is used as a callback when calling MinidumpWriteDump,
-  // in order to add additional memory regions to the dump.
-  static BOOL CALLBACK MinidumpWriteDumpCallback(
-      PVOID context,
-      const PMINIDUMP_CALLBACK_INPUT callback_input,
-      PMINIDUMP_CALLBACK_OUTPUT callback_output);
-
   // This function does the actual writing of a minidump.  It is
   // called on the handler thread.  requesting_thread_id is the ID of
   // the thread that requested the dump, if that information is
   // meaningful.  If the dump is requested as a result of an
   // exception, exinfo contains exception information, otherwise, it
   // is NULL.  process is the one that will be dumped.  If
   // requesting_thread_id is meaningful and should be added to the
   // minidump, write_requester_stream is |true|.