Expose DumpWithoutCrashing (fixes #3588)

This commit is contained in:
Nik Pavlov 2024-07-02 18:08:16 +00:00 committed by Marshall Greenblatt
parent a461a89728
commit 231701d98b
13 changed files with 225 additions and 6 deletions

View File

@ -16,6 +16,7 @@
'include/base/cef_callback_list.h',
'include/base/cef_cancelable_callback.h',
'include/base/cef_compiler_specific.h',
'include/base/cef_dump_without_crashing.h',
'include/base/cef_lock.h',
'include/base/cef_logging.h',
'include/base/cef_macros.h',
@ -43,6 +44,7 @@
'include/internal/cef_types_wrappers.h',
],
'includes_common_capi': [
'include/internal/cef_dump_without_crashing_internal.h',
'include/internal/cef_logging_internal.h',
'include/internal/cef_string.h',
'include/internal/cef_string_list.h',
@ -123,6 +125,7 @@
'libcef_dll/base/cef_atomic_flag.cc',
'libcef_dll/base/cef_callback_helpers.cc',
'libcef_dll/base/cef_callback_internal.cc',
'libcef_dll/base/cef_dump_without_crashing.cc',
'libcef_dll/base/cef_lock.cc',
'libcef_dll/base/cef_lock_impl.cc',
'libcef_dll/base/cef_logging.cc',

View File

@ -0,0 +1,76 @@
// Copyright (c) 2024 Marshall A. Greenblatt. Portions copyright (c) 2012
// Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
///
/// \file
/// Provides functions for generating crash dumps.
///
/// NOTE: The contents of this file are only available to applications that link
/// against the libcef_dll_wrapper target.
///
/// NOTE: Ensure crash reporting is configured before use. See
/// https://bitbucket.org/chromiumembedded/cef/wiki/CrashReporting.md for more
/// information
///
/// WARNING: Crash reporting should not be used in the main/browser process
/// before calling CefInitialize or in sub-processes before CefExecuteProcess.
///
#ifndef CEF_INCLUDE_BASE_CEF_DUMP_WITHOUT_CRASHING_H_
#define CEF_INCLUDE_BASE_CEF_DUMP_WITHOUT_CRASHING_H_
#pragma once
constexpr long long kOneDayInMilliseconds = 86400000;
///
/// CefDumpWithoutCrashing allows for generating crash dumps with a throttling
/// mechanism, preventing frequent dumps from being generated in a short period
/// of time from the same location. The |function_name|, |file_name|, and
/// |line_number| determine the location of the dump. The
/// |mseconds_between_dumps| is an interval between consecutive dumps in
/// milliseconds from the same location.
///
/// Returns true if the dump was successfully generated, false otherwise.
///
bool CefDumpWithoutCrashing(
long long mseconds_between_dumps = kOneDayInMilliseconds,
const char* function_name = __builtin_FUNCTION(),
const char* file_name = __builtin_FILE(),
int line_number = __builtin_LINE());
///
/// CefDumpWithoutCrashingUnthrottled allows for immediate crash dumping without
/// any throttling constraints.
///
/// Returns true if the dump was successfully generated, false otherwise.
///
bool CefDumpWithoutCrashingUnthrottled();
#endif // CEF_INCLUDE_BASE_CEF_DUMP_WITHOUT_CRASHING_H_

View File

@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "9c6ab9977da5debe35d54d14d1ef27e880e702f1"
#define CEF_API_HASH_UNIVERSAL "ea36c0aa57b37523b5677f107729dbf4d0b23933"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "d380724b425dd0a26253d93fbff6d98cde701835"
#define CEF_API_HASH_PLATFORM "42cdaa02d9babfd5409c5d7cb4abf77ea9f0b8d4"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "84b1cbbab962186b04157f7584203008a3d52c97"
#define CEF_API_HASH_PLATFORM "832e89ccb2ee279fb7b6fe9a30c83863ffa42fa1"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "a5e140f4266d52538620cb2a82ec49c0ae84a025"
#define CEF_API_HASH_PLATFORM "7b768d2e27822636321fb437be8d17cb0c3b7809"
#endif
#ifdef __cplusplus

View File

@ -0,0 +1,68 @@
// Copyright (c) 2024 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef CEF_INCLUDE_INTERNAL_CEF_DUMP_WITHOUT_CRASHING_INTERNAL_H_
#define CEF_INCLUDE_INTERNAL_CEF_DUMP_WITHOUT_CRASHING_INTERNAL_H_
#pragma once
#include <stddef.h>
#include "include/internal/cef_export.h"
#ifdef __cplusplus
extern "C" {
#endif
// See include/base/cef_dump_without_crashing.h for intended usage.
///
/// cef_dump_without_crashing allows for capturing crash dumps in a throttled
/// manner. This function should only be called after CefInitialize has been
/// successfully called. For detailed behavior, usage instructions, and
/// considerations, refer to the documentation of DumpWithoutCrashing in
/// base/debug/dump_without_crashing.h.
///
CEF_EXPORT int cef_dump_without_crashing(long long mseconds_between_dumps,
const char* function_name,
const char* file_name,
int line_number);
///
/// cef_dump_without_crashing_unthrottled allows for capturing crash dumps
/// without any throttling constraints. This function should also only be called
/// after CefInitialize has been successfully called. For detailed behavior,
/// usage instructions, and considerations, refer to the documentation of
/// DumpWithoutCrashingUnthrottled in base/debug/dump_without_crashing.h.
///
CEF_EXPORT int cef_dump_without_crashing_unthrottled();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // CEF_INCLUDE_INTERNAL_CEF_DUMP_WITHOUT_CRASHING_INTERNAL_H_

View File

@ -2,10 +2,12 @@
// 2011 the Chromium Authors. All rights reserved. Use of this source code is
// governed by a BSD-style license that can be found in the LICENSE file.
#include "base/debug/dump_without_crashing.h"
#include "base/logging.h"
#include "base/threading/platform_thread.h"
#include "base/trace_event/trace_event.h"
#include "cef/include/base/cef_build.h"
#include "cef/include/internal/cef_dump_without_crashing_internal.h"
#include "cef/include/internal/cef_logging_internal.h"
#include "cef/include/internal/cef_thread_internal.h"
#include "cef/include/internal/cef_trace_event_internal.h"
@ -227,3 +229,16 @@ cef_get_current_platform_thread_handle() {
return base::PlatformThread::CurrentHandle().platform_handle();
#endif
}
CEF_EXPORT int cef_dump_without_crashing(long long mseconds_between_dumps,
const char* function_name,
const char* file_name,
int line_number) {
return base::debug::DumpWithoutCrashing(
base::Location::Current(function_name, file_name, line_number),
base::Milliseconds(mseconds_between_dumps));
}
CEF_EXPORT int cef_dump_without_crashing_unthrottled() {
return base::debug::DumpWithoutCrashingUnthrottled();
}

View File

@ -0,0 +1,20 @@
// Copyright (c) 2024 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/base/cef_dump_without_crashing.h"
#include "include/internal/cef_dump_without_crashing_internal.h"
bool CefDumpWithoutCrashing(long long mseconds_between_dumps,
const char* function_name,
const char* file_name,
int line_number) {
return cef_dump_without_crashing(mseconds_between_dumps, function_name,
file_name, line_number);
}
bool CefDumpWithoutCrashingUnthrottled() {
return cef_dump_without_crashing_unthrottled();
}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=641096b7a6d43e8f7fbb4aad3c5ee870717b7f32$
// $hash=fd47567e105e5fc15bee190670216f0f007c6d27$
//
#include <dlfcn.h>
@ -65,6 +65,7 @@
#include "include/capi/views/cef_window_capi.h"
#include "include/cef_api_hash.h"
#include "include/cef_version.h"
#include "include/internal/cef_dump_without_crashing_internal.h"
#include "include/internal/cef_logging_internal.h"
#include "include/internal/cef_string_list.h"
#include "include/internal/cef_string_map.h"
@ -253,6 +254,9 @@ struct libcef_pointers {
decltype(&cef_window_create_top_level) cef_window_create_top_level;
decltype(&cef_api_hash) cef_api_hash;
decltype(&cef_version_info) cef_version_info;
decltype(&cef_dump_without_crashing) cef_dump_without_crashing;
decltype(&cef_dump_without_crashing_unthrottled)
cef_dump_without_crashing_unthrottled;
decltype(&cef_get_min_log_level) cef_get_min_log_level;
decltype(&cef_get_vlog_level) cef_get_vlog_level;
decltype(&cef_log) cef_log;
@ -469,6 +473,8 @@ int libcef_init_pointers(const char* path) {
INIT_ENTRY(cef_window_create_top_level);
INIT_ENTRY(cef_api_hash);
INIT_ENTRY(cef_version_info);
INIT_ENTRY(cef_dump_without_crashing);
INIT_ENTRY(cef_dump_without_crashing_unthrottled);
INIT_ENTRY(cef_get_min_log_level);
INIT_ENTRY(cef_get_vlog_level);
INIT_ENTRY(cef_log);
@ -1363,6 +1369,19 @@ NO_SANITIZE("cfi-icall") int cef_version_info(int entry) {
return g_libcef_pointers.cef_version_info(entry);
}
NO_SANITIZE("cfi-icall")
int cef_dump_without_crashing(long long mseconds_between_dumps,
const char* function_name,
const char* file_name,
int line_number) {
return g_libcef_pointers.cef_dump_without_crashing(
mseconds_between_dumps, function_name, file_name, line_number);
}
NO_SANITIZE("cfi-icall") int cef_dump_without_crashing_unthrottled() {
return g_libcef_pointers.cef_dump_without_crashing_unthrottled();
}
NO_SANITIZE("cfi-icall") int cef_get_min_log_level() {
return g_libcef_pointers.cef_get_min_log_level();
}

View File

@ -40,7 +40,8 @@
#define ID_TESTS_PRINT_TO_PDF 32715
#define ID_TESTS_MUTE_AUDIO 32716
#define ID_TESTS_UNMUTE_AUDIO 32717
#define ID_TESTS_LAST 32717
#define ID_TESTS_DUMP_WITHOUT_CRASHING 32718
#define ID_TESTS_LAST 32718
#define IDC_STATIC -1
#define IDS_BINARY_TRANSFER_HTML 1000
#define IDS_BINDING_HTML 1001

View File

@ -11,6 +11,7 @@
#include <string>
#include "include/base/cef_callback.h"
#include "include/base/cef_dump_without_crashing.h"
#include "include/cef_parser.h"
#include "include/cef_task.h"
#include "include/cef_trace.h"
@ -594,6 +595,9 @@ void RunTest(CefRefPtr<CefBrowser> browser, int id) {
case ID_TESTS_OTHER_TESTS:
RunOtherTests(browser);
break;
case ID_TESTS_DUMP_WITHOUT_CRASHING:
CefDumpWithoutCrashing();
break;
}
}

View File

@ -95,6 +95,7 @@ void AddTestMenuItems(CefRefPtr<CefMenuModel> test_menu) {
test_menu->AddItem(ID_TESTS_MUTE_AUDIO, "Mute Audio");
test_menu->AddItem(ID_TESTS_UNMUTE_AUDIO, "Unmute Audio");
test_menu->AddItem(ID_TESTS_OTHER_TESTS, "Other Tests");
test_menu->AddItem(ID_TESTS_DUMP_WITHOUT_CRASHING, "Dump without crashing");
}
void AddFileMenuItems(CefRefPtr<CefMenuModel> file_menu) {

View File

@ -78,6 +78,7 @@ void RemoveMenuItem(NSMenu* menu, SEL action_selector) {
- (IBAction)menuTestsMuteAudio:(id)sender;
- (IBAction)menuTestsUnmuteAudio:(id)sender;
- (IBAction)menuTestsOtherTests:(id)sender;
- (IBAction)menuTestsDumpWithoutCrashing:(id)sender;
- (void)enableAccessibility:(bool)bEnable;
@end
@ -322,6 +323,10 @@ void RemoveMenuItem(NSMenu* menu, SEL action_selector) {
[self testsItemSelected:ID_TESTS_OTHER_TESTS];
}
- (IBAction)menuTestsDumpWithoutCrashing:(id)sender {
[self testsItemSelected:ID_TESTS_DUMP_WITHOUT_CRASHING];
}
- (scoped_refptr<client::RootWindow>)getActiveRootWindow {
return client::MainContext::Get()
->GetRootWindowManager()

View File

@ -434,6 +434,12 @@
<action selector="menuTestsOtherTests:" target="-2" id="HbC-QY-Pwf"/>
</connections>
</menuItem>
<menuItem title="Dump without crashing" id="Xsl-IU-4Kk">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="menuTestsDumpWithoutCrashing:" target="-2" id="cSU-rq-oMD"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>

View File

@ -11,6 +11,7 @@ import os
OTHER_HEADERS = [
'cef_api_hash.h',
'cef_version.h',
'internal/cef_dump_without_crashing_internal.h',
'internal/cef_logging_internal.h',
'internal/cef_string_list.h',
'internal/cef_string_map.h',