blob: ef4a5c7326eb149bd752edcd65feec172679f37e [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2013 The Chromium Authors
[email protected]5a8d4ce2013-12-18 17:42:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_DEBUG_DUMP_WITHOUT_CRASHING_H_
6#define BASE_DEBUG_DUMP_WITHOUT_CRASHING_H_
7
8#include "base/base_export.h"
9#include "base/compiler_specific.h"
Aditya Kushwah5a286b72022-02-10 04:54:4310#include "base/location.h"
11#include "base/time/time.h"
[email protected]5a8d4ce2013-12-18 17:42:2712#include "build/build_config.h"
13
Aditya Kushwah5a286b72022-02-10 04:54:4314// These values are persisted to logs. Entries should not be renumbered and
15// numeric values should never be reused.
16enum class DumpWithoutCrashingStatus {
17 kThrottled,
18 kUploaded,
19 kMaxValue = kUploaded
20};
21
[email protected]5a8d4ce2013-12-18 17:42:2722namespace base {
23
24namespace debug {
25
26// Handler to silently dump the current process without crashing.
[email protected]f0e90cf92014-07-21 17:13:5827// Before calling this function, call SetDumpWithoutCrashingFunction to pass a
wfh93846272017-06-28 11:50:4728// function pointer.
29// Windows:
30// This must be done for each instance of base (i.e. module) and is normally
31// chrome_elf!DumpProcessWithoutCrash. See example code in chrome_main.cc that
32// does this for chrome.dll and chrome_child.dll. Note: Crashpad sets this up
33// for main chrome.exe as part of calling crash_reporter::InitializeCrashpad.
34// Mac/Linux:
35// Crashpad does this as part of crash_reporter::InitializeCrashpad.
wezb8279212017-01-17 22:50:5636// Returns false if called before SetDumpWithoutCrashingFunction.
Bruce Dawsonfe207532020-05-05 18:16:4337//
Olivier Li19d89252020-05-13 17:57:5538// This function must not be called with a tail call because that would cause
Bruce Dawsonfe207532020-05-05 18:16:4339// the caller to be omitted from the call stack in the crash dump, and that is
40// confusing and omits what is likely the most important context.
Aditya Kushwah5a286b72022-02-10 04:54:4341
42// Handler to silently dump the current process without crashing, that keeps
43// track of call location so some throttling can be applied to avoid very
44// frequent dump captures, which can have side-effects.
45// `location` Location of the file from where the function is called.
46// `time_between_dumps` Time until the next dump should be captured.
Peter Kastingf541f7782023-03-10 23:44:4647NOT_TAIL_CALLED BASE_EXPORT bool DumpWithoutCrashing(
48 const base::Location& location = base::Location::Current(),
Peter Boström6b0de942023-06-27 14:54:2449 base::TimeDelta time_between_dumps = base::Days(1));
Aditya Kushwah5a286b72022-02-10 04:54:4350
[email protected]5a8d4ce2013-12-18 17:42:2751// Sets a function that'll be invoked to dump the current process when
Aditya Kushwah5a286b72022-02-10 04:54:4352// DumpWithoutCrashing* is called. May be called with null to remove a
Ken Rockot408a56a82020-08-21 17:24:0153// previously set function.
Peter Kastinga91ca8e2024-08-22 06:29:3154BASE_EXPORT void SetDumpWithoutCrashingFunction(void (*function)());
[email protected]5a8d4ce2013-12-18 17:42:2755
Peter Boström5460a952025-02-10 05:07:5956// Reset DumpWithoutCrashing throttling for testing.
57BASE_EXPORT void ResetDumpWithoutCrashingThrottlingForTesting();
Justin Cohen4cdff782023-03-23 01:58:3558
[email protected]5a8d4ce2013-12-18 17:42:2759} // namespace debug
[email protected]5a8d4ce2013-12-18 17:42:2760} // namespace base
61
62#endif // BASE_DEBUG_DUMP_WITHOUT_CRASHING_H_