Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Breakpad for crash dump generation #56014

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions COPYRIGHT.txt
Expand Up @@ -146,6 +146,11 @@ Comment: Basis Universal
Copyright: 2022, Binomial LLC.
License: Apache-2.0

Files: ./thirdparty/breakpad/
Comment: Breakpad is a set of client and server components which implement a crash-reporting system.
Copyright: 2006, Google Inc.
License: BSD-3-clause

Files: ./thirdparty/brotli/
Comment: Brotli
Copyright: 2009, 2010, 2013-2016 by the Brotli Authors.
Expand Down
4 changes: 4 additions & 0 deletions SConstruct
Expand Up @@ -182,6 +182,7 @@ opts.Add(BoolVariable("openxr", "Enable the OpenXR driver", True))
opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "")
opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True))
opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loader dynamically", True))
opts.Add(BoolVariable("use_breakpad", "Enable Breakpad crash dump creation.", False))

# Advanced options
opts.Add(BoolVariable("dev", "If yes, alias for verbose=yes warnings=extra werror=yes", False))
Expand Down Expand Up @@ -413,6 +414,9 @@ if not env_base["deprecated"]:
if env_base["float"] == "64":
env_base.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])

if env_base["use_breakpad"]:
env_base.Append(CPPDEFINES=["USE_BREAKPAD"])

if selected_platform in platform_list:
tmppath = "./platform/" + selected_platform
sys.path.insert(0, tmppath)
Expand Down
8 changes: 8 additions & 0 deletions main/main.cpp
Expand Up @@ -99,6 +99,10 @@

#include "modules/modules_enabled.gen.h" // For mono.

#ifdef USE_BREAKPAD
#include "modules/breakpad/breakpad.h"
#endif

/* Static members */

// Singletons
Expand Down Expand Up @@ -1269,6 +1273,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
initialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
register_core_extensions(); // core extensions must be registered after globals setup and before display

#ifdef USE_BREAKPAD
report_user_data_dir_usable();
#endif

ResourceUID::get_singleton()->load_from_cache(); // load UUIDs from cache.

GLOBAL_DEF("memory/limits/multithreaded_server/rid_pool_prealloc", 60);
Expand Down
186 changes: 186 additions & 0 deletions modules/breakpad/SCsub
@@ -0,0 +1,186 @@
#!/usr/bin/env python

Import("env")
Import("env_modules")

env_breakpad = env_modules.Clone()

# Thirdparty source files

thirdparty_obj = []

thirdparty_dir = "#thirdparty/breakpad/"

# TODO: find out when these are needed (if at all)
dwarf_module = False
stabs_module = False

# Parts of this build script is based on the previous PR trying to implement this
# https://github.com/godotengine/godot/pull/22778/files

env_breakpad.Append(
CPPDEFINES=[
"PUBLIC",
"_HAS_EXCEPTIONS=0",
"_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS",
]
)

breakpad_src = [
"src/common/convert_UTF.cc",
"src/common/md5.cc",
"src/common/string_conversion.cc",
]

if env["platform"] == "linuxbsd":
breakpad_src += [
"src/client/linux/crash_generation/crash_generation_client.cc",
"src/client/linux/crash_generation/crash_generation_server.cc",
"src/client/linux/dump_writer_common/thread_info.cc",
"src/client/linux/dump_writer_common/ucontext_reader.cc",
"src/client/linux/handler/exception_handler.cc",
"src/client/linux/handler/minidump_descriptor.cc",
"src/client/linux/log/log.cc",
"src/client/linux/microdump_writer/microdump_writer.cc",
"src/client/linux/minidump_writer/linux_core_dumper.cc",
"src/client/linux/minidump_writer/linux_dumper.cc",
"src/client/linux/minidump_writer/linux_ptrace_dumper.cc",
"src/client/linux/minidump_writer/minidump_writer.cc",
"src/client/minidump_file_writer.cc",
"src/common/language.cc",
"src/common/linux/breakpad_getcontext.S",
"src/common/linux/crc32.cc",
"src/common/linux/elf_core_dump.cc",
"src/common/linux/elf_symbols_to_module.cc",
"src/common/linux/elfutils.cc",
"src/common/linux/file_id.cc",
"src/common/linux/guid_creator.cc",
"src/common/linux/linux_libc_support.cc",
"src/common/linux/memory_mapped_file.cc",
"src/common/linux/safe_readlink.cc",
"src/common/path_helper.cc",
]

if env["platform"] == "windows":
env_breakpad.Append(
CPPDEFINES=[
"_CRT_SECURE_NO_WARNINGS",
"NOMINMAX",
"WIN32_LEAN_AND_MEAN",
"_UNICODE",
"UNICODE",
]
)

breakpad_src += [
"src/client/windows/crash_generation/client_info.cc",
"src/client/windows/crash_generation/crash_generation_client.cc",
"src/client/windows/crash_generation/crash_generation_server.cc",
"src/client/windows/crash_generation/minidump_generator.cc",
"src/client/windows/handler/exception_handler.cc",
"src/common/windows/guid_string.cc",
"src/common/windows/pe_source_line_writer.cc",
"src/common/windows/string_utils.cc",
]


if env["platform"] == "osx" or env["platform"] == "iphone":
breakpad_src += [
"src/common/simple_string_dictionary.cc",
]

if env["platform"] == "osx":
breakpad_src += [
"src/client/mac/Framework/Breakpad.mm",
"src/client/mac/Framework/OnDemandServer.mm",
"src/client/mac/crash_generation/ConfigFile.mm",
"src/client/mac/crash_generation/Inspector.mm",
"src/client/mac/crash_generation/InspectorMain.mm",
"src/client/mac/crash_generation/crash_generation_client.cc",
"src/client/mac/crash_generation/crash_generation_server.cc",
"src/client/mac/handler/breakpad_nlist_64.cc",
"src/client/mac/handler/dynamic_images.cc",
"src/client/mac/handler/exception_handler.cc",
"src/client/mac/handler/minidump_generator.cc",
"src/client/mac/handler/protected_memory_allocator.cc",
"src/common/mac/GTMLogger.m",
"src/common/mac/HTTPGetRequest.m",
"src/common/mac/HTTPPutRequest.m",
"src/common/mac/HTTPRequest.m",
"src/common/mac/HTTPSimplePostRequest.m",
"src/common/mac/MachIPC.mm",
"src/common/mac/arch_utilities.cc",
"src/common/mac/bootstrap_compat.cc",
"src/common/mac/encoding_util.m",
"src/common/mac/file_id.cc",
"src/common/mac/launch_reporter.cc",
"src/common/mac/macho_id.cc",
"src/common/mac/macho_reader.cc",
"src/common/mac/macho_utilities.cc",
"src/common/mac/macho_walker.cc",
"src/common/mac/string_utilities.cc",
]

if env["platform"] == "iphone":
breakpad_src += [
"src/client/ios/Breakpad.mm",
"src/client/ios/BreakpadController.mm",
"src/client/ios/exception_handler_no_mach.cc",
"src/client/ios/handler/ios_exception_minidump_generator.mm",
"src/common/long_string_dictionary.cc",
]

# if solaris:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using Godot on Illumos / Solaris? :D Cool!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well there are files for solaris in Breakpad, so I thought it would be at least theoretically useful to keep the list of files for solaris here.

# breakpad_src += [
# "src/client/solaris/handler/Makefile",
# "src/client/solaris/handler/exception_handler.cc",
# "src/client/solaris/handler/minidump_generator.cc",
# "src/client/solaris/handler/solaris_lwp.cc",
# "src/common/solaris/file_id.cc",
# "src/common/solaris/guid_creator.cc",
# ]

if dwarf_module:
breakpad_src += [
"src/common/dwarf/bytereader.cc",
"src/common/dwarf/cfi_assembler.cc",
"src/common/dwarf/dwarf2diehandler.cc",
"src/common/dwarf/dwarf2reader.cc",
"src/common/dwarf/elf_reader.cc",
"src/common/dwarf/functioninfo.cc",
"src/common/dwarf_cfi_to_module.cc",
"src/common/dwarf_cu_to_module.cc",
"src/common/dwarf_line_to_module.cc",
"src/common/dwarf_range_list_handler.cc",
"src/common/module.cc",
]

if stabs_module:
breakpad_src += [
"src/common/stabs_reader.cc",
"src/common/stabs_to_module.cc",
]

breakpad_src = [thirdparty_dir + file for file in breakpad_src]

env_breakpad.Prepend(CPPPATH=[thirdparty_dir + "src"])

env_thirdparty = env_breakpad.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, breakpad_src)
env.modules_sources += thirdparty_obj


# Godot source files

module_obj = []

if env["platform"] == "linuxbsd" or env["platform"] == "windows":
env_breakpad.add_source_files(module_obj, ["breakpad_linuxbsd_windows.cpp"])
else:
raise Exception("Breakpad not implemented for selected platform")

env.modules_sources += module_obj

# Needed to force rebuilding the module files when the thirdparty library is updated.
env.Depends(module_obj, thirdparty_obj)
48 changes: 48 additions & 0 deletions modules/breakpad/breakpad.h
@@ -0,0 +1,48 @@
/*************************************************************************/
/* breakpad.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#ifndef BREAKPAD_H
#define BREAKPAD_H

void initialize_breakpad(bool register_handlers);
void disable_breakpad();
void report_user_data_dir_usable();

// Due to Mono runtime initialization in release mode overriding signal handlers, Breakpad needs re-initialization after loading it
void report_mono_loaded_to_breakpad();

// Linux crash handling goes through this
void breakpad_handle_signal(int sig);

// Windows crash handling goes through this
// TODO: should Windows header be included here to use an actual type?
void breakpad_handle_exception_pointers(void *exinfo);

#endif // BREAKPAD_H