xref: /aosp_15_r20/external/libchrome/base/debug/dump_without_crashing.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2013 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #include "base/debug/dump_without_crashing.h"
6*635a8641SAndroid Build Coastguard Worker 
7*635a8641SAndroid Build Coastguard Worker #include "base/logging.h"
8*635a8641SAndroid Build Coastguard Worker 
9*635a8641SAndroid Build Coastguard Worker namespace {
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker // Pointer to the function that's called by DumpWithoutCrashing() to dump the
12*635a8641SAndroid Build Coastguard Worker // process's memory.
13*635a8641SAndroid Build Coastguard Worker void(CDECL* dump_without_crashing_function_)() = nullptr;
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker }  // namespace
16*635a8641SAndroid Build Coastguard Worker 
17*635a8641SAndroid Build Coastguard Worker namespace base {
18*635a8641SAndroid Build Coastguard Worker 
19*635a8641SAndroid Build Coastguard Worker namespace debug {
20*635a8641SAndroid Build Coastguard Worker 
DumpWithoutCrashing()21*635a8641SAndroid Build Coastguard Worker bool DumpWithoutCrashing() {
22*635a8641SAndroid Build Coastguard Worker   if (dump_without_crashing_function_) {
23*635a8641SAndroid Build Coastguard Worker     (*dump_without_crashing_function_)();
24*635a8641SAndroid Build Coastguard Worker     return true;
25*635a8641SAndroid Build Coastguard Worker   }
26*635a8641SAndroid Build Coastguard Worker   return false;
27*635a8641SAndroid Build Coastguard Worker }
28*635a8641SAndroid Build Coastguard Worker 
SetDumpWithoutCrashingFunction(void (CDECL * function)())29*635a8641SAndroid Build Coastguard Worker void SetDumpWithoutCrashingFunction(void (CDECL *function)()) {
30*635a8641SAndroid Build Coastguard Worker #if !defined(COMPONENT_BUILD)
31*635a8641SAndroid Build Coastguard Worker   // In component builds, the same base is shared between modules
32*635a8641SAndroid Build Coastguard Worker   // so might be initialized several times. However in non-
33*635a8641SAndroid Build Coastguard Worker   // component builds this should never happen.
34*635a8641SAndroid Build Coastguard Worker   DCHECK(!dump_without_crashing_function_);
35*635a8641SAndroid Build Coastguard Worker #endif
36*635a8641SAndroid Build Coastguard Worker   dump_without_crashing_function_ = function;
37*635a8641SAndroid Build Coastguard Worker }
38*635a8641SAndroid Build Coastguard Worker 
39*635a8641SAndroid Build Coastguard Worker }  // namespace debug
40*635a8641SAndroid Build Coastguard Worker 
41*635a8641SAndroid Build Coastguard Worker }  // namespace base
42