Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "build/build_config.h"
      6 
      7 #include "chrome/common/dump_without_crashing.h"
      8 
      9 #include "base/logging.h"
     10 #include "chrome/common/chrome_constants.h"
     11 
     12 #if defined(OS_WIN)
     13 #include <windows.h>
     14 #endif
     15 
     16 namespace {
     17 
     18 #if defined(OS_POSIX)
     19 // Pointer to the function that's called by DumpWithoutCrashing() to dump the
     20 // process's memory.
     21 void (*dump_without_crashing_function_)() = NULL;
     22 #endif
     23 
     24 }  // namespace
     25 
     26 namespace logging {
     27 
     28 void DumpWithoutCrashing() {
     29 #if defined(OS_WIN)
     30   // Get the breakpad pointer from chrome.exe
     31   typedef void (__cdecl *DumpProcessFunction)();
     32   DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>(
     33       ::GetProcAddress(::GetModuleHandle(chrome::kBrowserProcessExecutableName),
     34                        "DumpProcessWithoutCrash"));
     35   if (DumpProcess)
     36     DumpProcess();
     37 #elif defined(OS_POSIX)
     38   if (dump_without_crashing_function_)
     39     (*dump_without_crashing_function_)();
     40 #else
     41   NOTIMPLEMENTED();
     42 #endif
     43 }
     44 
     45 #if defined(OS_POSIX)
     46 void SetDumpWithoutCrashingFunction(void (*function)()) {
     47   dump_without_crashing_function_ = function;
     48 }
     49 #endif
     50 
     51 }  // namespace logging
     52