Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 2 | // 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 Kushwah | 5a286b7 | 2022-02-10 04:54:43 | [diff] [blame] | 10 | #include "base/location.h" |
| 11 | #include "base/time/time.h" |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 12 | #include "build/build_config.h" |
| 13 | |
Aditya Kushwah | 5a286b7 | 2022-02-10 04:54:43 | [diff] [blame] | 14 | // These values are persisted to logs. Entries should not be renumbered and |
| 15 | // numeric values should never be reused. |
| 16 | enum class DumpWithoutCrashingStatus { |
| 17 | kThrottled, |
| 18 | kUploaded, |
| 19 | kMaxValue = kUploaded |
| 20 | }; |
| 21 | |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 22 | namespace base { |
| 23 | |
| 24 | namespace debug { |
| 25 | |
| 26 | // Handler to silently dump the current process without crashing. |
[email protected] | f0e90cf9 | 2014-07-21 17:13:58 | [diff] [blame] | 27 | // Before calling this function, call SetDumpWithoutCrashingFunction to pass a |
wfh | 9384627 | 2017-06-28 11:50:47 | [diff] [blame] | 28 | // 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. |
wez | b827921 | 2017-01-17 22:50:56 | [diff] [blame] | 36 | // Returns false if called before SetDumpWithoutCrashingFunction. |
Bruce Dawson | fe20753 | 2020-05-05 18:16:43 | [diff] [blame] | 37 | // |
Olivier Li | 19d8925 | 2020-05-13 17:57:55 | [diff] [blame] | 38 | // This function must not be called with a tail call because that would cause |
Bruce Dawson | fe20753 | 2020-05-05 18:16:43 | [diff] [blame] | 39 | // 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 Kushwah | 5a286b7 | 2022-02-10 04:54:43 | [diff] [blame] | 41 | |
| 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 Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 47 | NOT_TAIL_CALLED BASE_EXPORT bool DumpWithoutCrashing( |
| 48 | const base::Location& location = base::Location::Current(), |
Peter Boström | 6b0de94 | 2023-06-27 14:54:24 | [diff] [blame] | 49 | base::TimeDelta time_between_dumps = base::Days(1)); |
Aditya Kushwah | 5a286b7 | 2022-02-10 04:54:43 | [diff] [blame] | 50 | |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 51 | // Sets a function that'll be invoked to dump the current process when |
Aditya Kushwah | 5a286b7 | 2022-02-10 04:54:43 | [diff] [blame] | 52 | // DumpWithoutCrashing* is called. May be called with null to remove a |
Ken Rockot | 408a56a8 | 2020-08-21 17:24:01 | [diff] [blame] | 53 | // previously set function. |
Peter Kasting | a91ca8e | 2024-08-22 06:29:31 | [diff] [blame] | 54 | BASE_EXPORT void SetDumpWithoutCrashingFunction(void (*function)()); |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 55 | |
Peter Boström | 5460a95 | 2025-02-10 05:07:59 | [diff] [blame] | 56 | // Reset DumpWithoutCrashing throttling for testing. |
| 57 | BASE_EXPORT void ResetDumpWithoutCrashingThrottlingForTesting(); |
Justin Cohen | 4cdff78 | 2023-03-23 01:58:35 | [diff] [blame] | 58 | |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 59 | } // namespace debug |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 60 | } // namespace base |
| 61 | |
| 62 | #endif // BASE_DEBUG_DUMP_WITHOUT_CRASHING_H_ |