Skip to content

Commit 40d148d

Browse files
Ed LuDanielSnd
Ed Lu
authored andcommitted
Merged PR godotengine#56014 Add Breakpad for crash dump generation
use_breakpad=yes use_lto=yes debug_symbols=yes separate_debug_symbols=no use_static_cpp=yes Fixed compiling on Windows Make crash dump printing work better on Windows Tweaked Breakpad build Fixed Breakpad build for Godot 4 Switched to WINDOWS_ENABLED Removed some non buildable files listed in the files to build Ran clang format Fixed the other formatting issues detected by CI Removed a comment and added clarifying comment on crash dump message as to why it is printed twice on Windows Make an ugly string conversion to make Windows build work Tweaked the build configuration and formatted again removed lss Add lss properly Reinitialize breakpad after mono initialization on Linux otherwise the breakpad signal handlers are not active Disable Windows crash handler on destruction similarly to Linux Renamed breakpad_enabled to use_breakpad Forgot to wrap one piece of code inside ifdef USE_BREAKPAD Updated copyright years in the added files Fix register types for breakpad Fixed dir access Removed musl and elf_reader which was the only thing seemingly depending on it Updated header guards Removed the memdelete call Made copyright header changes that the checks wanted Update the version hash breakpad is said to be used from Try to fix .gitignore matching Breakpad source files Added missing breakpad source file compile for Linux Delete unused files Update breakpad Remove mono re-registration, replace accidentally removed line Fixups
1 parent ca899d2 commit 40d148d

File tree

289 files changed

+75909
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

289 files changed

+75909
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ thirdparty/swappy-frame-pacing/arm64-v8a/abi.json
267267
thirdparty/swappy-frame-pacing/armeabi-v7a/abi.json
268268
thirdparty/swappy-frame-pacing/x86/abi.json
269269
thirdparty/swappy-frame-pacing/x86_64/abi.json
270+
# Do not ignore breakpad source files
271+
!thirdparty/breakpad/src/client/linux/log
270272

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

COPYRIGHT.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ Comment: Basis Universal
188188
Copyright: 2019-2024, Binomial LLC.
189189
License: Apache-2.0
190190

191-
Files: thirdparty/brotli/*
191+
Files: ./thirdparty/breakpad/
192+
Comment: Breakpad is a set of client and server components which implement a crash-reporting system.
193+
Copyright: 2006, Google Inc.
194+
License: BSD-3-clause
195+
196+
Files: ./thirdparty/brotli/
192197
Comment: Brotli
193198
Copyright: 2009, 2010, 2013-2016 by the Brotli Authors.
194199
License: Expat

SConstruct

+4
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loade
191191
opts.Add(BoolVariable("disable_exceptions", "Force disabling exception handling code", True))
192192
opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "")
193193
opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True))
194+
opts.Add(BoolVariable("use_breakpad", "Enable Breakpad crash dump creation.", False))
194195

195196
# Advanced options
196197
opts.Add(
@@ -514,6 +515,9 @@ if not env["deprecated"]:
514515
if env["precision"] == "double":
515516
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
516517

518+
if env["use_breakpad"]:
519+
env.Append(CPPDEFINES=["USE_BREAKPAD"])
520+
517521
# Default num_jobs to local cpu count if not user specified.
518522
# SCons has a peculiarity where user-specified options won't be overridden
519523
# by SetOption, so we can rely on this to know if we should use our default.

main/main.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@
136136
#endif // TOOLS_ENABLED && !GDSCRIPT_NO_LSP
137137
#endif // MODULE_GDSCRIPT_ENABLED
138138

139+
#ifdef USE_BREAKPAD
140+
#include "modules/breakpad/breakpad.h"
141+
#endif
142+
139143
/* Static members */
140144

141145
// Singletons
@@ -1974,6 +1978,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
19741978

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

1981+
#ifdef USE_BREAKPAD
1982+
report_user_data_dir_usable();
1983+
#endif
1984+
19771985
if (ProjectSettings::get_singleton()->has_custom_feature("dedicated_server")) {
19781986
audio_driver = NULL_AUDIO_DRIVER;
19791987
display_driver = NULL_DISPLAY_DRIVER;

modules/breakpad/SCsub

+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#!/usr/bin/env python
2+
3+
Import("env")
4+
Import("env_modules")
5+
6+
env_breakpad = env_modules.Clone()
7+
8+
# Thirdparty source files
9+
10+
thirdparty_obj = []
11+
12+
thirdparty_dir = "#thirdparty/breakpad/"
13+
14+
# TODO: find out when these are needed (if at all)
15+
dwarf_module = False
16+
stabs_module = False
17+
18+
# Parts of this build script is based on the previous PR trying to implement this
19+
# https://github.com/godotengine/godot/pull/22778/files
20+
21+
env_breakpad.Append(
22+
CPPDEFINES=[
23+
"PUBLIC",
24+
"_HAS_EXCEPTIONS=0",
25+
"_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS",
26+
]
27+
)
28+
29+
breakpad_src = [
30+
"src/common/convert_UTF.cc",
31+
"src/common/md5.cc",
32+
"src/common/string_conversion.cc",
33+
]
34+
35+
if env["platform"] == "linuxbsd":
36+
breakpad_src += [
37+
"src/client/linux/crash_generation/crash_generation_client.cc",
38+
"src/client/linux/crash_generation/crash_generation_server.cc",
39+
"src/client/linux/dump_writer_common/thread_info.cc",
40+
"src/client/linux/dump_writer_common/ucontext_reader.cc",
41+
"src/client/linux/handler/exception_handler.cc",
42+
"src/client/linux/handler/minidump_descriptor.cc",
43+
"src/client/linux/log/log.cc",
44+
"src/client/linux/microdump_writer/microdump_writer.cc",
45+
"src/client/linux/minidump_writer/pe_file.cc",
46+
"src/client/linux/minidump_writer/linux_core_dumper.cc",
47+
"src/client/linux/minidump_writer/linux_dumper.cc",
48+
"src/client/linux/minidump_writer/linux_ptrace_dumper.cc",
49+
"src/client/linux/minidump_writer/minidump_writer.cc",
50+
"src/client/minidump_file_writer.cc",
51+
"src/common/language.cc",
52+
"src/common/linux/breakpad_getcontext.S",
53+
"src/common/linux/crc32.cc",
54+
"src/common/linux/elf_core_dump.cc",
55+
"src/common/linux/elf_symbols_to_module.cc",
56+
"src/common/linux/elfutils.cc",
57+
"src/common/linux/file_id.cc",
58+
"src/common/linux/guid_creator.cc",
59+
"src/common/linux/linux_libc_support.cc",
60+
"src/common/linux/memory_mapped_file.cc",
61+
"src/common/linux/safe_readlink.cc",
62+
"src/common/path_helper.cc",
63+
]
64+
65+
if env["platform"] == "windows":
66+
env_breakpad.Append(
67+
CPPDEFINES=[
68+
"_CRT_SECURE_NO_WARNINGS",
69+
"NOMINMAX",
70+
"WIN32_LEAN_AND_MEAN",
71+
"_UNICODE",
72+
"UNICODE",
73+
]
74+
)
75+
76+
breakpad_src += [
77+
"src/client/windows/crash_generation/client_info.cc",
78+
"src/client/windows/crash_generation/crash_generation_client.cc",
79+
"src/client/windows/crash_generation/crash_generation_server.cc",
80+
"src/client/windows/crash_generation/minidump_generator.cc",
81+
"src/client/windows/handler/exception_handler.cc",
82+
"src/common/windows/guid_string.cc",
83+
"src/common/windows/pe_source_line_writer.cc",
84+
"src/common/windows/string_utils.cc",
85+
]
86+
87+
88+
if env["platform"] == "osx" or env["platform"] == "iphone":
89+
breakpad_src += [
90+
"src/common/simple_string_dictionary.cc",
91+
]
92+
93+
if env["platform"] == "osx":
94+
breakpad_src += [
95+
"src/client/mac/Framework/Breakpad.mm",
96+
"src/client/mac/Framework/OnDemandServer.mm",
97+
"src/client/mac/crash_generation/ConfigFile.mm",
98+
"src/client/mac/crash_generation/Inspector.mm",
99+
"src/client/mac/crash_generation/InspectorMain.mm",
100+
"src/client/mac/crash_generation/crash_generation_client.cc",
101+
"src/client/mac/crash_generation/crash_generation_server.cc",
102+
"src/client/mac/handler/breakpad_nlist_64.cc",
103+
"src/client/mac/handler/dynamic_images.cc",
104+
"src/client/mac/handler/exception_handler.cc",
105+
"src/client/mac/handler/minidump_generator.cc",
106+
"src/client/mac/handler/protected_memory_allocator.cc",
107+
"src/common/mac/GTMLogger.m",
108+
"src/common/mac/HTTPGetRequest.m",
109+
"src/common/mac/HTTPPutRequest.m",
110+
"src/common/mac/HTTPRequest.m",
111+
"src/common/mac/HTTPSimplePostRequest.m",
112+
"src/common/mac/MachIPC.mm",
113+
"src/common/mac/arch_utilities.cc",
114+
"src/common/mac/bootstrap_compat.cc",
115+
"src/common/mac/encoding_util.m",
116+
"src/common/mac/file_id.cc",
117+
"src/common/mac/launch_reporter.cc",
118+
"src/common/mac/macho_id.cc",
119+
"src/common/mac/macho_reader.cc",
120+
"src/common/mac/macho_utilities.cc",
121+
"src/common/mac/macho_walker.cc",
122+
"src/common/mac/string_utilities.cc",
123+
]
124+
125+
if env["platform"] == "iphone":
126+
breakpad_src += [
127+
"src/client/ios/Breakpad.mm",
128+
"src/client/ios/BreakpadController.mm",
129+
"src/client/ios/exception_handler_no_mach.cc",
130+
"src/client/ios/handler/ios_exception_minidump_generator.mm",
131+
"src/common/long_string_dictionary.cc",
132+
]
133+
134+
# if solaris:
135+
# breakpad_src += [
136+
# "src/client/solaris/handler/Makefile",
137+
# "src/client/solaris/handler/exception_handler.cc",
138+
# "src/client/solaris/handler/minidump_generator.cc",
139+
# "src/client/solaris/handler/solaris_lwp.cc",
140+
# "src/common/solaris/file_id.cc",
141+
# "src/common/solaris/guid_creator.cc",
142+
# ]
143+
144+
if dwarf_module:
145+
breakpad_src += [
146+
"src/common/dwarf/bytereader.cc",
147+
"src/common/dwarf/cfi_assembler.cc",
148+
"src/common/dwarf/dwarf2diehandler.cc",
149+
"src/common/dwarf/dwarf2reader.cc",
150+
"src/common/dwarf/elf_reader.cc",
151+
"src/common/dwarf/functioninfo.cc",
152+
"src/common/dwarf_cfi_to_module.cc",
153+
"src/common/dwarf_cu_to_module.cc",
154+
"src/common/dwarf_line_to_module.cc",
155+
"src/common/dwarf_range_list_handler.cc",
156+
"src/common/module.cc",
157+
]
158+
159+
if stabs_module:
160+
breakpad_src += [
161+
"src/common/stabs_reader.cc",
162+
"src/common/stabs_to_module.cc",
163+
]
164+
165+
breakpad_src = [thirdparty_dir + file for file in breakpad_src]
166+
167+
env_breakpad.Prepend(CPPPATH=[thirdparty_dir + "src"])
168+
169+
env_thirdparty = env_breakpad.Clone()
170+
env_thirdparty.disable_warnings()
171+
env_thirdparty.add_source_files(thirdparty_obj, breakpad_src)
172+
env.modules_sources += thirdparty_obj
173+
174+
175+
# Godot source files
176+
177+
module_obj = []
178+
179+
if env["platform"] == "linuxbsd" or env["platform"] == "windows":
180+
env_breakpad.add_source_files(module_obj, ["breakpad_linuxbsd_windows.cpp"])
181+
else:
182+
raise Exception("Breakpad not implemented for selected platform")
183+
184+
env.modules_sources += module_obj
185+
186+
# Needed to force rebuilding the module files when the thirdparty library is updated.
187+
env.Depends(module_obj, thirdparty_obj)

modules/breakpad/breakpad.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**************************************************************************/
2+
/* breakpad.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#ifndef BREAKPAD_H
32+
#define BREAKPAD_H
33+
34+
void initialize_breakpad(bool register_handlers);
35+
void disable_breakpad();
36+
void report_user_data_dir_usable();
37+
38+
// Due to Mono runtime initialization in release mode overriding signal handlers, Breakpad needs re-initialization after loading it
39+
void report_mono_loaded_to_breakpad();
40+
41+
// Linux crash handling goes through this
42+
void breakpad_handle_signal(int sig);
43+
44+
// Windows crash handling goes through this
45+
// TODO: should Windows header be included here to use an actual type?
46+
void breakpad_handle_exception_pointers(void *exinfo);
47+
48+
#endif // BREAKPAD_H

0 commit comments

Comments
 (0)