Skip to content

Commit a9ece11

Browse files
Calinoubruvzg
authored andcommitted
Merged PR godotengine#56014 Add Breakpad for crash dump generation and show GUI Alert when crashing on desktop
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 Show a GUI alert when crashing on desktop platforms This makes it possible to know that Godot has crashed without looking at the console (which may not be visible to the user). - Change the window title while dumping the backtrace, as this can take a while to finish. - If file logging is enabled, print path to log file to standard error and the GUI alert. Clicking OK will open the log file in the default program associated with `.log` files. Notepad has native associations for `.log` on Windows, so this works on Windows too. Co-Authored-By: bruvzg <[email protected]>
1 parent 455ae14 commit a9ece11

File tree

290 files changed

+76004
-5
lines changed

Some content is hidden

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

290 files changed

+76004
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ thirdparty/swappy-frame-pacing/arm64-v8a/abi.json
271271
thirdparty/swappy-frame-pacing/armeabi-v7a/abi.json
272272
thirdparty/swappy-frame-pacing/x86/abi.json
273273
thirdparty/swappy-frame-pacing/x86_64/abi.json
274+
# Do not ignore breakpad source files
275+
!thirdparty/breakpad/src/client/linux/log
274276

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

COPYRIGHT.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ Comment: Basis Universal
217217
Copyright: 2019-2024, Binomial LLC.
218218
License: Apache-2.0
219219

220-
Files: thirdparty/brotli/*
220+
Files: ./thirdparty/breakpad/
221+
Comment: Breakpad is a set of client and server components which implement a crash-reporting system.
222+
Copyright: 2006, Google Inc.
223+
License: BSD-3-clause
224+
225+
Files: ./thirdparty/brotli/
221226
Comment: Brotli
222227
Copyright: 2009, 2010, 2013-2016 by the Brotli Authors.
223228
License: Expat

SConstruct

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ opts.Add(BoolVariable("use_volk", "Use the volk library to load the Vulkan loade
202202
opts.Add(BoolVariable("accesskit", "Use AccessKit C SDK", True))
203203
opts.Add(("accesskit_sdk_path", "Path to the AccessKit C SDK", ""))
204204
opts.Add(BoolVariable("sdl", "Enable the SDL3 input driver", True))
205-
205+
opts.Add(BoolVariable("use_breakpad", "Enable Breakpad crash dump creation.", False))
206206
# Advanced options
207207
opts.Add(
208208
BoolVariable(
@@ -556,6 +556,9 @@ if not env["deprecated"]:
556556
if env["precision"] == "double":
557557
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
558558

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

main/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
#endif // TOOLS_ENABLED && !GDSCRIPT_NO_LSP
148148
#endif // MODULE_GDSCRIPT_ENABLED
149149

150+
#ifdef USE_BREAKPAD
151+
#include "modules/breakpad/breakpad.h"
152+
#endif
153+
150154
/* Static members */
151155

152156
// Singletons
@@ -2093,6 +2097,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
20932097

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

2100+
#ifdef USE_BREAKPAD
2101+
report_user_data_dir_usable();
2102+
#endif
2103+
20962104
if (ProjectSettings::get_singleton()->has_custom_feature("dedicated_server")) {
20972105
audio_driver = NULL_AUDIO_DRIVER;
20982106
display_driver = NULL_DISPLAY_DRIVER;

modules/breakpad/SCsub

Lines changed: 187 additions & 0 deletions
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

Lines changed: 48 additions & 0 deletions
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)