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 9 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ bld/
!thirdparty/**/arm/
!thirdparty/**/arm64/

# Do not ignore breakpad source files
!thirdparty/breakpad/src/client/linux/log

# Visual Studio 2015/2017 cache/options directory
.vs/

Expand Down
5 changes: 5 additions & 0 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,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
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loade
opts.Add(BoolVariable("disable_exceptions", "Force disabling exception handling code", 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_breakpad", "Enable Breakpad crash dump creation.", False))

# Advanced options
opts.Add(BoolVariable("dev_mode", "Alias for dev options: verbose=yes warnings=extra werror=yes tests=yes", False))
Expand Down Expand Up @@ -522,6 +523,9 @@ if not env["deprecated"]:
if env["precision"] == "double":
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])

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

tmppath = "./platform/" + env["platform"]
sys.path.insert(0, tmppath)
import detect
Expand Down
8 changes: 8 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
#endif // TOOLS_ENABLED && !GDSCRIPT_NO_LSP
#endif // MODULE_GDSCRIPT_ENABLED

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

/* Static members */

// Singletons
Expand Down Expand Up @@ -1823,6 +1827,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph

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

#ifdef USE_BREAKPAD
report_user_data_dir_usable();
#endif

if (ProjectSettings::get_singleton()->has_custom_feature("dedicated_server")) {
audio_driver = NULL_AUDIO_DRIVER;
display_driver = NULL_DISPLAY_DRIVER;
Expand Down
187 changes: 187 additions & 0 deletions modules/breakpad/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#!/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
Comment on lines +14 to +16
Copy link
Member

Choose a reason for hiding this comment

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

Did anyone find that these were needed in the end? If not, I'd remove the relevant code (and perhaps keep a second branch on your fork with this code present).

Copy link
Author

Choose a reason for hiding this comment

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

If I remember right, no one has tried this out on mac yet. So there is a chance that these would be required on mac.

If it is determined necessary to get this PR merged, I now have a mac I can use for development so I can check things there to make sure the mac version compiles and can create crash dumps.


# 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/pe_file.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:
hhyyrylainen marked this conversation as resolved.
Show resolved Hide resolved
# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**************************************************************************/
/* breakpad.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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();
Copy link
Author

Choose a reason for hiding this comment

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

Looks like there are some leftover mono bits of the code. I can remove these bits when someone would be able to do a PR review / there's a chance that this PR could be betting any closer to being merged.


// 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
Loading
Loading