summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar lat9nq2022-07-10 11:29:10 -0400
committerGravatar lat9nq2022-09-04 21:36:04 -0400
commitf958cbc737542332ed4de9cf503fa4a8d1106564 (patch)
tree70f7b4ddbdeb1bb0aa68f95ad4494a6b5a8de1a4
parentMerge pull request #8855 from german77/pls (diff)
downloadyuzu-f958cbc737542332ed4de9cf503fa4a8d1106564.tar.gz
yuzu-f958cbc737542332ed4de9cf503fa4a8d1106564.tar.xz
yuzu-f958cbc737542332ed4de9cf503fa4a8d1106564.zip
yuzu: Use a debugger to generate minidumps
yuzu: Move mini_dump out of core startup_checks: Better exception handling
-rw-r--r--src/common/settings.h1
-rw-r--r--src/yuzu/CMakeLists.txt10
-rw-r--r--src/yuzu/applets/qt_controller.cpp2
-rw-r--r--src/yuzu/configuration/config.cpp6
-rw-r--r--src/yuzu/configuration/config.h4
-rw-r--r--src/yuzu/configuration/configure_debug.cpp21
-rw-r--r--src/yuzu/configuration/configure_debug.h2
-rw-r--r--src/yuzu/configuration/configure_debug.ui122
-rw-r--r--src/yuzu/configuration/configure_input.cpp2
-rw-r--r--src/yuzu/configuration/configure_per_game.cpp3
-rw-r--r--src/yuzu/configuration/input_profiles.cpp9
-rw-r--r--src/yuzu/configuration/input_profiles.h4
-rw-r--r--src/yuzu/main.cpp32
-rw-r--r--src/yuzu/main.h2
-rw-r--r--src/yuzu/mini_dump.cpp185
-rw-r--r--src/yuzu/mini_dump.h12
-rw-r--r--src/yuzu/startup_checks.cpp29
-rw-r--r--src/yuzu/startup_checks.h5
18 files changed, 360 insertions, 91 deletions
diff --git a/src/common/settings.h b/src/common/settings.h
index 14ed9b237..8354fdba7 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -529,6 +529,7 @@ struct Values {
529 Setting<bool> use_debug_asserts{false, "use_debug_asserts"}; 529 Setting<bool> use_debug_asserts{false, "use_debug_asserts"};
530 Setting<bool> use_auto_stub{false, "use_auto_stub"}; 530 Setting<bool> use_auto_stub{false, "use_auto_stub"};
531 Setting<bool> enable_all_controllers{false, "enable_all_controllers"}; 531 Setting<bool> enable_all_controllers{false, "enable_all_controllers"};
532 Setting<bool> create_crash_dumps{false, "create_crash_dumps"};
532 533
533 // Miscellaneous 534 // Miscellaneous
534 Setting<std::string> log_filter{"*:Info", "log_filter"}; 535 Setting<std::string> log_filter{"*:Info", "log_filter"};
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt
index 50007338f..3d9906ade 100644
--- a/src/yuzu/CMakeLists.txt
+++ b/src/yuzu/CMakeLists.txt
@@ -208,6 +208,16 @@ add_executable(yuzu
208 yuzu.rc 208 yuzu.rc
209) 209)
210 210
211if (WIN32 AND NOT ("${DBGHELP_LIBRARY}" STREQUAL "DBGHELP_LIBRARY-NOTFOUND"))
212 target_sources(yuzu PRIVATE
213 mini_dump.cpp
214 mini_dump.h
215 )
216
217 target_link_libraries(yuzu PUBLIC ${DBGHELP_LIBRARY})
218 target_compile_definitions(yuzu PRIVATE -DYUZU_DBGHELP)
219endif()
220
211file(GLOB COMPAT_LIST 221file(GLOB COMPAT_LIST
212 ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.qrc 222 ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.qrc
213 ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json) 223 ${PROJECT_BINARY_DIR}/dist/compatibility_list/compatibility_list.json)
diff --git a/src/yuzu/applets/qt_controller.cpp b/src/yuzu/applets/qt_controller.cpp
index 8be311fcb..1d8072243 100644
--- a/src/yuzu/applets/qt_controller.cpp
+++ b/src/yuzu/applets/qt_controller.cpp
@@ -63,7 +63,7 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
63 InputCommon::InputSubsystem* input_subsystem_, Core::System& system_) 63 InputCommon::InputSubsystem* input_subsystem_, Core::System& system_)
64 : QDialog(parent), ui(std::make_unique<Ui::QtControllerSelectorDialog>()), 64 : QDialog(parent), ui(std::make_unique<Ui::QtControllerSelectorDialog>()),
65 parameters(std::move(parameters_)), input_subsystem{input_subsystem_}, 65 parameters(std::move(parameters_)), input_subsystem{input_subsystem_},
66 input_profiles(std::make_unique<InputProfiles>(system_)), system{system_} { 66 input_profiles(std::make_unique<InputProfiles>()), system{system_} {
67 ui->setupUi(this); 67 ui->setupUi(this);
68 68
69 player_widgets = { 69 player_widgets = {
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index da6e5aa88..e44759856 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -15,8 +15,7 @@
15 15
16namespace FS = Common::FS; 16namespace FS = Common::FS;
17 17
18Config::Config(Core::System& system_, const std::string& config_name, ConfigType config_type) 18Config::Config(const std::string& config_name, ConfigType config_type) : type(config_type) {
19 : type(config_type), system{system_} {
20 global = config_type == ConfigType::GlobalConfig; 19 global = config_type == ConfigType::GlobalConfig;
21 20
22 Initialize(config_name); 21 Initialize(config_name);
@@ -546,6 +545,7 @@ void Config::ReadDebuggingValues() {
546 ReadBasicSetting(Settings::values.use_debug_asserts); 545 ReadBasicSetting(Settings::values.use_debug_asserts);
547 ReadBasicSetting(Settings::values.use_auto_stub); 546 ReadBasicSetting(Settings::values.use_auto_stub);
548 ReadBasicSetting(Settings::values.enable_all_controllers); 547 ReadBasicSetting(Settings::values.enable_all_controllers);
548 ReadBasicSetting(Settings::values.create_crash_dumps);
549 549
550 qt_config->endGroup(); 550 qt_config->endGroup();
551} 551}
@@ -1160,6 +1160,7 @@ void Config::SaveDebuggingValues() {
1160 WriteBasicSetting(Settings::values.use_debug_asserts); 1160 WriteBasicSetting(Settings::values.use_debug_asserts);
1161 WriteBasicSetting(Settings::values.disable_macro_jit); 1161 WriteBasicSetting(Settings::values.disable_macro_jit);
1162 WriteBasicSetting(Settings::values.enable_all_controllers); 1162 WriteBasicSetting(Settings::values.enable_all_controllers);
1163 WriteBasicSetting(Settings::values.create_crash_dumps);
1163 1164
1164 qt_config->endGroup(); 1165 qt_config->endGroup();
1165} 1166}
@@ -1545,7 +1546,6 @@ void Config::Reload() {
1545 ReadValues(); 1546 ReadValues();
1546 // To apply default value changes 1547 // To apply default value changes
1547 SaveValues(); 1548 SaveValues();
1548 system.ApplySettings();
1549} 1549}
1550 1550
1551void Config::Save() { 1551void Config::Save() {
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h
index 486ceea94..06fa7d2d0 100644
--- a/src/yuzu/configuration/config.h
+++ b/src/yuzu/configuration/config.h
@@ -25,7 +25,7 @@ public:
25 InputProfile, 25 InputProfile,
26 }; 26 };
27 27
28 explicit Config(Core::System& system_, const std::string& config_name = "qt-config", 28 explicit Config(const std::string& config_name = "qt-config",
29 ConfigType config_type = ConfigType::GlobalConfig); 29 ConfigType config_type = ConfigType::GlobalConfig);
30 ~Config(); 30 ~Config();
31 31
@@ -194,8 +194,6 @@ private:
194 std::unique_ptr<QSettings> qt_config; 194 std::unique_ptr<QSettings> qt_config;
195 std::string qt_config_loc; 195 std::string qt_config_loc;
196 bool global; 196 bool global;
197
198 Core::System& system;
199}; 197};
200 198
201// These metatype declarations cannot be in common/settings.h because core is devoid of QT 199// These metatype declarations cannot be in common/settings.h because core is devoid of QT
diff --git a/src/yuzu/configuration/configure_debug.cpp b/src/yuzu/configuration/configure_debug.cpp
index 04d397750..622808e94 100644
--- a/src/yuzu/configuration/configure_debug.cpp
+++ b/src/yuzu/configuration/configure_debug.cpp
@@ -2,6 +2,7 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include <QDesktopServices> 4#include <QDesktopServices>
5#include <QMessageBox>
5#include <QUrl> 6#include <QUrl>
6#include "common/fs/path_util.h" 7#include "common/fs/path_util.h"
7#include "common/logging/backend.h" 8#include "common/logging/backend.h"
@@ -26,6 +27,16 @@ ConfigureDebug::ConfigureDebug(const Core::System& system_, QWidget* parent)
26 27
27 connect(ui->toggle_gdbstub, &QCheckBox::toggled, 28 connect(ui->toggle_gdbstub, &QCheckBox::toggled,
28 [&]() { ui->gdbport_spinbox->setEnabled(ui->toggle_gdbstub->isChecked()); }); 29 [&]() { ui->gdbport_spinbox->setEnabled(ui->toggle_gdbstub->isChecked()); });
30
31 connect(ui->create_crash_dumps, &QCheckBox::stateChanged, [&](int) {
32 if (crash_dump_warning_shown) {
33 return;
34 }
35 QMessageBox::warning(this, tr("Restart Required"),
36 tr("yuzu is required to restart in order to apply this setting."),
37 QMessageBox::Ok, QMessageBox::Ok);
38 crash_dump_warning_shown = true;
39 });
29} 40}
30 41
31ConfigureDebug::~ConfigureDebug() = default; 42ConfigureDebug::~ConfigureDebug() = default;
@@ -71,7 +82,14 @@ void ConfigureDebug::SetConfiguration() {
71 ui->disable_web_applet->setChecked(UISettings::values.disable_web_applet.GetValue()); 82 ui->disable_web_applet->setChecked(UISettings::values.disable_web_applet.GetValue());
72#else 83#else
73 ui->disable_web_applet->setEnabled(false); 84 ui->disable_web_applet->setEnabled(false);
74 ui->disable_web_applet->setText(QString::fromUtf8("Web applet not compiled")); 85 ui->disable_web_applet->setText(tr("Web applet not compiled"));
86#endif
87
88#ifdef YUZU_DBGHELP
89 ui->create_crash_dumps->setChecked(Settings::values.create_crash_dumps.GetValue());
90#else
91 ui->create_crash_dumps->setEnabled(false);
92 ui->create_crash_dumps->setText(tr("MiniDump creation not compiled"));
75#endif 93#endif
76} 94}
77 95
@@ -84,6 +102,7 @@ void ConfigureDebug::ApplyConfiguration() {
84 Settings::values.enable_fs_access_log = ui->fs_access_log->isChecked(); 102 Settings::values.enable_fs_access_log = ui->fs_access_log->isChecked();
85 Settings::values.reporting_services = ui->reporting_services->isChecked(); 103 Settings::values.reporting_services = ui->reporting_services->isChecked();
86 Settings::values.dump_audio_commands = ui->dump_audio_commands->isChecked(); 104 Settings::values.dump_audio_commands = ui->dump_audio_commands->isChecked();
105 Settings::values.create_crash_dumps = ui->create_crash_dumps->isChecked();
87 Settings::values.quest_flag = ui->quest_flag->isChecked(); 106 Settings::values.quest_flag = ui->quest_flag->isChecked();
88 Settings::values.use_debug_asserts = ui->use_debug_asserts->isChecked(); 107 Settings::values.use_debug_asserts = ui->use_debug_asserts->isChecked();
89 Settings::values.use_auto_stub = ui->use_auto_stub->isChecked(); 108 Settings::values.use_auto_stub = ui->use_auto_stub->isChecked();
diff --git a/src/yuzu/configuration/configure_debug.h b/src/yuzu/configuration/configure_debug.h
index 42d30f170..030a0b7f7 100644
--- a/src/yuzu/configuration/configure_debug.h
+++ b/src/yuzu/configuration/configure_debug.h
@@ -32,4 +32,6 @@ private:
32 std::unique_ptr<Ui::ConfigureDebug> ui; 32 std::unique_ptr<Ui::ConfigureDebug> ui;
33 33
34 const Core::System& system; 34 const Core::System& system;
35
36 bool crash_dump_warning_shown{false};
35}; 37};
diff --git a/src/yuzu/configuration/configure_debug.ui b/src/yuzu/configuration/configure_debug.ui
index 47b8b80f1..314d47af5 100644
--- a/src/yuzu/configuration/configure_debug.ui
+++ b/src/yuzu/configuration/configure_debug.ui
@@ -7,60 +7,60 @@
7 </property> 7 </property>
8 <widget class="QWidget"> 8 <widget class="QWidget">
9 <layout class="QVBoxLayout" name="verticalLayout_1"> 9 <layout class="QVBoxLayout" name="verticalLayout_1">
10 <item> 10 <item>
11 <layout class="QVBoxLayout" name="verticalLayout_2"> 11 <layout class="QVBoxLayout" name="verticalLayout_2">
12 <item> 12 <item>
13 <widget class="QGroupBox" name="groupBox"> 13 <widget class="QGroupBox" name="groupBox">
14 <property name="title"> 14 <property name="title">
15 <string>Debugger</string> 15 <string>Debugger</string>
16 </property> 16 </property>
17 <layout class="QVBoxLayout" name="verticalLayout_3"> 17 <layout class="QVBoxLayout" name="verticalLayout_3">
18 <item>
19 <layout class="QHBoxLayout" name="horizontalLayout_11">
20 <item>
21 <widget class="QCheckBox" name="toggle_gdbstub">
22 <property name="text">
23 <string>Enable GDB Stub</string>
24 </property>
25 </widget>
26 </item>
27 <item>
28 <spacer name="horizontalSpacer">
29 <property name="orientation">
30 <enum>Qt::Horizontal</enum>
31 </property>
32 <property name="sizeHint" stdset="0">
33 <size>
34 <width>40</width>
35 <height>20</height>
36 </size>
37 </property>
38 </spacer>
39 </item>
40 <item>
41 <widget class="QLabel" name="label_11">
42 <property name="text">
43 <string>Port:</string>
44 </property>
45 </widget>
46 </item>
18 <item> 47 <item>
19 <layout class="QHBoxLayout" name="horizontalLayout_11"> 48 <widget class="QSpinBox" name="gdbport_spinbox">
20 <item> 49 <property name="minimum">
21 <widget class="QCheckBox" name="toggle_gdbstub"> 50 <number>1024</number>
22 <property name="text"> 51 </property>
23 <string>Enable GDB Stub</string> 52 <property name="maximum">
24 </property> 53 <number>65535</number>
25 </widget> 54 </property>
26 </item> 55 </widget>
27 <item>
28 <spacer name="horizontalSpacer">
29 <property name="orientation">
30 <enum>Qt::Horizontal</enum>
31 </property>
32 <property name="sizeHint" stdset="0">
33 <size>
34 <width>40</width>
35 <height>20</height>
36 </size>
37 </property>
38 </spacer>
39 </item>
40 <item>
41 <widget class="QLabel" name="label_11">
42 <property name="text">
43 <string>Port:</string>
44 </property>
45 </widget>
46 </item>
47 <item>
48 <widget class="QSpinBox" name="gdbport_spinbox">
49 <property name="minimum">
50 <number>1024</number>
51 </property>
52 <property name="maximum">
53 <number>65535</number>
54 </property>
55 </widget>
56 </item>
57 </layout>
58 </item> 56 </item>
59 </layout> 57 </layout>
60 </widget> 58 </item>
61 </item> 59 </layout>
62 </layout> 60 </widget>
63 </item> 61 </item>
62 </layout>
63 </item>
64 <item> 64 <item>
65 <widget class="QGroupBox" name="groupBox_2"> 65 <widget class="QGroupBox" name="groupBox_2">
66 <property name="title"> 66 <property name="title">
@@ -231,6 +231,13 @@
231 <string>Debugging</string> 231 <string>Debugging</string>
232 </property> 232 </property>
233 <layout class="QGridLayout" name="gridLayout_3"> 233 <layout class="QGridLayout" name="gridLayout_3">
234 <item row="2" column="0">
235 <widget class="QCheckBox" name="reporting_services">
236 <property name="text">
237 <string>Enable Verbose Reporting Services**</string>
238 </property>
239 </widget>
240 </item>
234 <item row="0" column="0"> 241 <item row="0" column="0">
235 <widget class="QCheckBox" name="fs_access_log"> 242 <widget class="QCheckBox" name="fs_access_log">
236 <property name="text"> 243 <property name="text">
@@ -238,20 +245,20 @@
238 </property> 245 </property>
239 </widget> 246 </widget>
240 </item> 247 </item>
241 <item row="1" column="0"> 248 <item row="0" column="1">
242 <widget class="QCheckBox" name="dump_audio_commands"> 249 <widget class="QCheckBox" name="dump_audio_commands">
243 <property name="text">
244 <string>Dump Audio Commands To Console**</string>
245 </property>
246 <property name="toolTip"> 250 <property name="toolTip">
247 <string>Enable this to output the latest generated audio command list to the console. Only affects games using the audio renderer.</string> 251 <string>Enable this to output the latest generated audio command list to the console. Only affects games using the audio renderer.</string>
248 </property> 252 </property>
253 <property name="text">
254 <string>Dump Audio Commands To Console**</string>
255 </property>
249 </widget> 256 </widget>
250 </item> 257 </item>
251 <item row="2" column="0"> 258 <item row="2" column="1">
252 <widget class="QCheckBox" name="reporting_services"> 259 <widget class="QCheckBox" name="create_crash_dumps">
253 <property name="text"> 260 <property name="text">
254 <string>Enable Verbose Reporting Services**</string> 261 <string>Create Minidump After Crash</string>
255 </property> 262 </property>
256 </widget> 263 </widget>
257 </item> 264 </item>
@@ -340,7 +347,6 @@
340 <tabstop>disable_loop_safety_checks</tabstop> 347 <tabstop>disable_loop_safety_checks</tabstop>
341 <tabstop>fs_access_log</tabstop> 348 <tabstop>fs_access_log</tabstop>
342 <tabstop>reporting_services</tabstop> 349 <tabstop>reporting_services</tabstop>
343 <tabstop>dump_audio_commands</tabstop>
344 <tabstop>quest_flag</tabstop> 350 <tabstop>quest_flag</tabstop>
345 <tabstop>enable_cpu_debugging</tabstop> 351 <tabstop>enable_cpu_debugging</tabstop>
346 <tabstop>use_debug_asserts</tabstop> 352 <tabstop>use_debug_asserts</tabstop>
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp
index 16fba3deb..cb55472c9 100644
--- a/src/yuzu/configuration/configure_input.cpp
+++ b/src/yuzu/configuration/configure_input.cpp
@@ -65,7 +65,7 @@ void OnDockedModeChanged(bool last_state, bool new_state, Core::System& system)
65 65
66ConfigureInput::ConfigureInput(Core::System& system_, QWidget* parent) 66ConfigureInput::ConfigureInput(Core::System& system_, QWidget* parent)
67 : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()), 67 : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()),
68 profiles(std::make_unique<InputProfiles>(system_)), system{system_} { 68 profiles(std::make_unique<InputProfiles>()), system{system_} {
69 ui->setupUi(this); 69 ui->setupUi(this);
70} 70}
71 71
diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp
index af8343b2e..c3cb8f61d 100644
--- a/src/yuzu/configuration/configure_per_game.cpp
+++ b/src/yuzu/configuration/configure_per_game.cpp
@@ -42,8 +42,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st
42 const auto file_path = std::filesystem::path(Common::FS::ToU8String(file_name)); 42 const auto file_path = std::filesystem::path(Common::FS::ToU8String(file_name));
43 const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename()) 43 const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename())
44 : fmt::format("{:016X}", title_id); 44 : fmt::format("{:016X}", title_id);
45 game_config = 45 game_config = std::make_unique<Config>(config_file_name, Config::ConfigType::PerGameConfig);
46 std::make_unique<Config>(system, config_file_name, Config::ConfigType::PerGameConfig);
47 46
48 addons_tab = std::make_unique<ConfigurePerGameAddons>(system_, this); 47 addons_tab = std::make_unique<ConfigurePerGameAddons>(system_, this);
49 audio_tab = std::make_unique<ConfigureAudio>(system_, this); 48 audio_tab = std::make_unique<ConfigureAudio>(system_, this);
diff --git a/src/yuzu/configuration/input_profiles.cpp b/src/yuzu/configuration/input_profiles.cpp
index 20b22e7de..807afbeb2 100644
--- a/src/yuzu/configuration/input_profiles.cpp
+++ b/src/yuzu/configuration/input_profiles.cpp
@@ -27,7 +27,7 @@ std::filesystem::path GetNameWithoutExtension(std::filesystem::path filename) {
27 27
28} // namespace 28} // namespace
29 29
30InputProfiles::InputProfiles(Core::System& system_) : system{system_} { 30InputProfiles::InputProfiles() {
31 const auto input_profile_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "input"; 31 const auto input_profile_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "input";
32 32
33 if (!FS::IsDir(input_profile_loc)) { 33 if (!FS::IsDir(input_profile_loc)) {
@@ -43,8 +43,8 @@ InputProfiles::InputProfiles(Core::System& system_) : system{system_} {
43 43
44 if (IsINI(filename) && IsProfileNameValid(name_without_ext)) { 44 if (IsINI(filename) && IsProfileNameValid(name_without_ext)) {
45 map_profiles.insert_or_assign( 45 map_profiles.insert_or_assign(
46 name_without_ext, std::make_unique<Config>(system, name_without_ext, 46 name_without_ext,
47 Config::ConfigType::InputProfile)); 47 std::make_unique<Config>(name_without_ext, Config::ConfigType::InputProfile));
48 } 48 }
49 49
50 return true; 50 return true;
@@ -80,8 +80,7 @@ bool InputProfiles::CreateProfile(const std::string& profile_name, std::size_t p
80 } 80 }
81 81
82 map_profiles.insert_or_assign( 82 map_profiles.insert_or_assign(
83 profile_name, 83 profile_name, std::make_unique<Config>(profile_name, Config::ConfigType::InputProfile));
84 std::make_unique<Config>(system, profile_name, Config::ConfigType::InputProfile));
85 84
86 return SaveProfile(profile_name, player_index); 85 return SaveProfile(profile_name, player_index);
87} 86}
diff --git a/src/yuzu/configuration/input_profiles.h b/src/yuzu/configuration/input_profiles.h
index 65fc9e62c..2bf3e4250 100644
--- a/src/yuzu/configuration/input_profiles.h
+++ b/src/yuzu/configuration/input_profiles.h
@@ -15,7 +15,7 @@ class Config;
15class InputProfiles { 15class InputProfiles {
16 16
17public: 17public:
18 explicit InputProfiles(Core::System& system_); 18 explicit InputProfiles();
19 virtual ~InputProfiles(); 19 virtual ~InputProfiles();
20 20
21 std::vector<std::string> GetInputProfileNames(); 21 std::vector<std::string> GetInputProfileNames();
@@ -31,6 +31,4 @@ private:
31 bool ProfileExistsInMap(const std::string& profile_name) const; 31 bool ProfileExistsInMap(const std::string& profile_name) const;
32 32
33 std::unordered_map<std::string, std::unique_ptr<Config>> map_profiles; 33 std::unordered_map<std::string, std::unique_ptr<Config>> map_profiles;
34
35 Core::System& system;
36}; 34};
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index a85adc072..ca3f4da70 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -138,6 +138,10 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
138#include "yuzu/uisettings.h" 138#include "yuzu/uisettings.h"
139#include "yuzu/util/clickable_label.h" 139#include "yuzu/util/clickable_label.h"
140 140
141#ifdef YUZU_DBGHELP
142#include "yuzu/mini_dump.h"
143#endif
144
141using namespace Common::Literals; 145using namespace Common::Literals;
142 146
143#ifdef USE_DISCORD_PRESENCE 147#ifdef USE_DISCORD_PRESENCE
@@ -269,10 +273,9 @@ bool GMainWindow::CheckDarkMode() {
269#endif // __linux__ 273#endif // __linux__
270} 274}
271 275
272GMainWindow::GMainWindow(bool has_broken_vulkan) 276GMainWindow::GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan)
273 : ui{std::make_unique<Ui::MainWindow>()}, system{std::make_unique<Core::System>()}, 277 : ui{std::make_unique<Ui::MainWindow>()}, system{std::make_unique<Core::System>()},
274 input_subsystem{std::make_shared<InputCommon::InputSubsystem>()}, 278 input_subsystem{std::make_shared<InputCommon::InputSubsystem>()}, config{std::move(config_)},
275 config{std::make_unique<Config>(*system)},
276 vfs{std::make_shared<FileSys::RealVfsFilesystem>()}, 279 vfs{std::make_shared<FileSys::RealVfsFilesystem>()},
277 provider{std::make_unique<FileSys::ManualContentProvider>()} { 280 provider{std::make_unique<FileSys::ManualContentProvider>()} {
278#ifdef __linux__ 281#ifdef __linux__
@@ -1637,7 +1640,8 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
1637 const auto config_file_name = title_id == 0 1640 const auto config_file_name = title_id == 0
1638 ? Common::FS::PathToUTF8String(file_path.filename()) 1641 ? Common::FS::PathToUTF8String(file_path.filename())
1639 : fmt::format("{:016X}", title_id); 1642 : fmt::format("{:016X}", title_id);
1640 Config per_game_config(*system, config_file_name, Config::ConfigType::PerGameConfig); 1643 Config per_game_config(config_file_name, Config::ConfigType::PerGameConfig);
1644 system->ApplySettings();
1641 } 1645 }
1642 1646
1643 // Save configurations 1647 // Save configurations
@@ -2981,7 +2985,7 @@ void GMainWindow::OnConfigure() {
2981 2985
2982 Settings::values.disabled_addons.clear(); 2986 Settings::values.disabled_addons.clear();
2983 2987
2984 config = std::make_unique<Config>(*system); 2988 config = std::make_unique<Config>();
2985 UISettings::values.reset_to_defaults = false; 2989 UISettings::values.reset_to_defaults = false;
2986 2990
2987 UISettings::values.game_dirs = std::move(old_game_dirs); 2991 UISettings::values.game_dirs = std::move(old_game_dirs);
@@ -3042,6 +3046,7 @@ void GMainWindow::OnConfigure() {
3042 3046
3043 UpdateStatusButtons(); 3047 UpdateStatusButtons();
3044 controller_dialog->refreshConfiguration(); 3048 controller_dialog->refreshConfiguration();
3049 system->ApplySettings();
3045} 3050}
3046 3051
3047void GMainWindow::OnConfigureTas() { 3052void GMainWindow::OnConfigureTas() {
@@ -4082,7 +4087,22 @@ void GMainWindow::changeEvent(QEvent* event) {
4082#endif 4087#endif
4083 4088
4084int main(int argc, char* argv[]) { 4089int main(int argc, char* argv[]) {
4090 std::unique_ptr<Config> config = std::make_unique<Config>();
4085 bool has_broken_vulkan = false; 4091 bool has_broken_vulkan = false;
4092 bool is_child = false;
4093 if (CheckEnvVars(&is_child)) {
4094 return 0;
4095 }
4096
4097#ifdef YUZU_DBGHELP
4098 PROCESS_INFORMATION pi;
4099 if (!is_child && Settings::values.create_crash_dumps.GetValue() && SpawnDebuggee(argv[0], pi)) {
4100 config.reset(nullptr);
4101 DebugDebuggee(pi);
4102 return 0;
4103 }
4104#endif
4105
4086 if (StartupChecks(argv[0], &has_broken_vulkan)) { 4106 if (StartupChecks(argv[0], &has_broken_vulkan)) {
4087 return 0; 4107 return 0;
4088 } 4108 }
@@ -4135,7 +4155,7 @@ int main(int argc, char* argv[]) {
4135 // generating shaders 4155 // generating shaders
4136 setlocale(LC_ALL, "C"); 4156 setlocale(LC_ALL, "C");
4137 4157
4138 GMainWindow main_window{has_broken_vulkan}; 4158 GMainWindow main_window{std::move(config), has_broken_vulkan};
4139 // After settings have been loaded by GMainWindow, apply the filter 4159 // After settings have been loaded by GMainWindow, apply the filter
4140 main_window.show(); 4160 main_window.show();
4141 4161
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 1ae2b93d9..716aef063 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -120,7 +120,7 @@ class GMainWindow : public QMainWindow {
120public: 120public:
121 void filterBarSetChecked(bool state); 121 void filterBarSetChecked(bool state);
122 void UpdateUITheme(); 122 void UpdateUITheme();
123 explicit GMainWindow(bool has_broken_vulkan); 123 explicit GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan);
124 ~GMainWindow() override; 124 ~GMainWindow() override;
125 125
126 bool DropAction(QDropEvent* event); 126 bool DropAction(QDropEvent* event);
diff --git a/src/yuzu/mini_dump.cpp b/src/yuzu/mini_dump.cpp
new file mode 100644
index 000000000..ad8a4f607
--- /dev/null
+++ b/src/yuzu/mini_dump.cpp
@@ -0,0 +1,185 @@
1#include <cstdio>
2#include <ctime>
3#include <filesystem>
4#include <windows.h>
5#include "common/logging/log.h"
6#include "yuzu/mini_dump.h"
7#include "yuzu/startup_checks.h"
8
9// dbghelp.h must be included after windows.h
10#include <dbghelp.h>
11
12void CreateMiniDump(HANDLE process_handle, DWORD process_id, MINIDUMP_EXCEPTION_INFORMATION* info,
13 EXCEPTION_POINTERS* pep) {
14 LOG_INFO(Core, "called");
15
16 char file_name[255];
17 const std::time_t the_time = std::time(nullptr);
18 std::strftime(file_name, 255, "yuzu-crash-%Y%m%d%H%M%S.dmp", std::localtime(&the_time));
19
20 // Open the file
21 HANDLE file_handle = CreateFile(file_name, GENERIC_READ | GENERIC_WRITE, 0, nullptr,
22 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
23
24 if ((file_handle != nullptr) && (file_handle != INVALID_HANDLE_VALUE)) {
25 // Create the minidump
26 const MINIDUMP_TYPE dump_type = MiniDumpNormal;
27
28 const bool write_dump_status = MiniDumpWriteDump(process_handle, process_id, file_handle,
29 dump_type, (pep != 0) ? info : 0, 0, 0);
30
31 if (!write_dump_status) {
32 LOG_ERROR(Core, "MiniDumpWriteDump failed. Error: {}", GetLastError());
33 } else {
34 LOG_INFO(Core, "Minidump created.");
35 }
36
37 // Close the file
38 CloseHandle(file_handle);
39
40 } else {
41 LOG_ERROR(Core, "CreateFile failed. Error: {}", GetLastError());
42 }
43}
44
45bool SpawnDebuggee(const char* arg0, PROCESS_INFORMATION& pi) {
46 std::memset(&pi, 0, sizeof(pi));
47
48 if (!SpawnChild(arg0, &pi, 0)) {
49 std::fprintf(stderr, "warning: continuing without crash dumps\n");
50 return false;
51 }
52
53 // Don't debug if we are already being debugged
54 if (IsDebuggerPresent()) {
55 return false;
56 }
57
58 const bool can_debug = DebugActiveProcess(pi.dwProcessId);
59 if (!can_debug) {
60 std::fprintf(stderr,
61 "warning: DebugActiveProcess failed (%d), continuing without crash dumps\n",
62 GetLastError());
63 return false;
64 }
65
66 return true;
67}
68
69void DebugDebuggee(PROCESS_INFORMATION& pi) {
70 DEBUG_EVENT deb_ev;
71
72 while (deb_ev.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT) {
73 const bool wait_success = WaitForDebugEvent(&deb_ev, INFINITE);
74 if (!wait_success) {
75 std::fprintf(stderr, "error: WaitForDebugEvent failed (%d)\n", GetLastError());
76 return;
77 }
78
79 switch (deb_ev.dwDebugEventCode) {
80 case OUTPUT_DEBUG_STRING_EVENT:
81 case CREATE_PROCESS_DEBUG_EVENT:
82 case CREATE_THREAD_DEBUG_EVENT:
83 case EXIT_PROCESS_DEBUG_EVENT:
84 case EXIT_THREAD_DEBUG_EVENT:
85 case LOAD_DLL_DEBUG_EVENT:
86 case RIP_EVENT:
87 case UNLOAD_DLL_DEBUG_EVENT:
88 ContinueDebugEvent(deb_ev.dwProcessId, deb_ev.dwThreadId, DBG_CONTINUE);
89 break;
90 case EXCEPTION_DEBUG_EVENT:
91 EXCEPTION_RECORD& record = deb_ev.u.Exception.ExceptionRecord;
92
93 std::fprintf(stderr, "ExceptionCode: 0x%08x %s\n", record.ExceptionCode,
94 ExceptionName(record.ExceptionCode));
95 if (!deb_ev.u.Exception.dwFirstChance) {
96 HANDLE thread_handle = OpenThread(THREAD_ALL_ACCESS, false, deb_ev.dwThreadId);
97 if (thread_handle == nullptr) {
98 std::fprintf(stderr, "OpenThread failed (%d)\n", GetLastError());
99 }
100 if (SuspendThread(thread_handle) == (DWORD)-1) {
101 std::fprintf(stderr, "SuspendThread failed (%d)\n", GetLastError());
102 }
103
104 CONTEXT context;
105 std::memset(&context, 0, sizeof(context));
106 context.ContextFlags = CONTEXT_ALL;
107 if (!GetThreadContext(thread_handle, &context)) {
108 std::fprintf(stderr, "GetThreadContext failed (%d)\n", GetLastError());
109 break;
110 }
111
112 EXCEPTION_POINTERS ep;
113 ep.ExceptionRecord = &record;
114 ep.ContextRecord = &context;
115
116 MINIDUMP_EXCEPTION_INFORMATION info;
117 info.ThreadId = deb_ev.dwThreadId;
118 info.ExceptionPointers = &ep;
119 info.ClientPointers = false;
120
121 CreateMiniDump(pi.hProcess, pi.dwProcessId, &info, &ep);
122
123 std::fprintf(stderr, "previous thread suspend count: %d\n",
124 ResumeThread(thread_handle));
125 if (CloseHandle(thread_handle) == 0) {
126 std::fprintf(stderr, "error: CloseHandle(thread_handle) failed (%d)\n",
127 GetLastError());
128 }
129 }
130 ContinueDebugEvent(deb_ev.dwProcessId, deb_ev.dwThreadId, DBG_EXCEPTION_NOT_HANDLED);
131 break;
132 }
133 }
134}
135
136const char* ExceptionName(DWORD exception) {
137 switch (exception) {
138 case EXCEPTION_ACCESS_VIOLATION:
139 return "EXCEPTION_ACCESS_VIOLATION";
140 case EXCEPTION_DATATYPE_MISALIGNMENT:
141 return "EXCEPTION_DATATYPE_MISALIGNMENT";
142 case EXCEPTION_BREAKPOINT:
143 return "EXCEPTION_BREAKPOINT";
144 case EXCEPTION_SINGLE_STEP:
145 return "EXCEPTION_SINGLE_STEP";
146 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
147 return "EXCEPTION_ARRAY_BOUNDS_EXCEEDED";
148 case EXCEPTION_FLT_DENORMAL_OPERAND:
149 return "EXCEPTION_FLT_DENORMAL_OPERAND";
150 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
151 return "EXCEPTION_FLT_DIVIDE_BY_ZERO";
152 case EXCEPTION_FLT_INEXACT_RESULT:
153 return "EXCEPTION_FLT_INEXACT_RESULT";
154 case EXCEPTION_FLT_INVALID_OPERATION:
155 return "EXCEPTION_FLT_INVALID_OPERATION";
156 case EXCEPTION_FLT_OVERFLOW:
157 return "EXCEPTION_FLT_OVERFLOW";
158 case EXCEPTION_FLT_STACK_CHECK:
159 return "EXCEPTION_FLT_STACK_CHECK";
160 case EXCEPTION_FLT_UNDERFLOW:
161 return "EXCEPTION_FLT_UNDERFLOW";
162 case EXCEPTION_INT_DIVIDE_BY_ZERO:
163 return "EXCEPTION_INT_DIVIDE_BY_ZERO";
164 case EXCEPTION_INT_OVERFLOW:
165 return "EXCEPTION_INT_OVERFLOW";
166 case EXCEPTION_PRIV_INSTRUCTION:
167 return "EXCEPTION_PRIV_INSTRUCTION";
168 case EXCEPTION_IN_PAGE_ERROR:
169 return "EXCEPTION_IN_PAGE_ERROR";
170 case EXCEPTION_ILLEGAL_INSTRUCTION:
171 return "EXCEPTION_ILLEGAL_INSTRUCTION";
172 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
173 return "EXCEPTION_NONCONTINUABLE_EXCEPTION";
174 case EXCEPTION_STACK_OVERFLOW:
175 return "EXCEPTION_STACK_OVERFLOW";
176 case EXCEPTION_INVALID_DISPOSITION:
177 return "EXCEPTION_INVALID_DISPOSITION";
178 case EXCEPTION_GUARD_PAGE:
179 return "EXCEPTION_GUARD_PAGE";
180 case EXCEPTION_INVALID_HANDLE:
181 return "EXCEPTION_INVALID_HANDLE";
182 default:
183 return nullptr;
184 }
185}
diff --git a/src/yuzu/mini_dump.h b/src/yuzu/mini_dump.h
new file mode 100644
index 000000000..59ba615e4
--- /dev/null
+++ b/src/yuzu/mini_dump.h
@@ -0,0 +1,12 @@
1#pragma once
2
3#include <windows.h>
4
5#include <dbghelp.h>
6
7void CreateMiniDump(HANDLE process_handle, DWORD process_id, MINIDUMP_EXCEPTION_INFORMATION* info,
8 EXCEPTION_POINTERS* pep);
9
10bool SpawnDebuggee(const char* arg0, PROCESS_INFORMATION& pi);
11void DebugDebuggee(PROCESS_INFORMATION& pi);
12const char* ExceptionName(DWORD exception);
diff --git a/src/yuzu/startup_checks.cpp b/src/yuzu/startup_checks.cpp
index 8421280bf..29b87da05 100644
--- a/src/yuzu/startup_checks.cpp
+++ b/src/yuzu/startup_checks.cpp
@@ -31,19 +31,36 @@ void CheckVulkan() {
31 } 31 }
32} 32}
33 33
34bool StartupChecks(const char* arg0, bool* has_broken_vulkan) { 34bool CheckEnvVars(bool* is_child) {
35#ifdef _WIN32 35#ifdef _WIN32
36 // Check environment variable to see if we are the child 36 // Check environment variable to see if we are the child
37 char variable_contents[8]; 37 char variable_contents[8];
38 const DWORD startup_check_var = 38 const DWORD startup_check_var =
39 GetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, variable_contents, 8); 39 GetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, variable_contents, 8);
40 if (startup_check_var > 0 && std::strncmp(variable_contents, "ON", 8) == 0) { 40 if (startup_check_var > 0 && std::strncmp(variable_contents, ENV_VAR_ENABLED_TEXT, 8) == 0) {
41 CheckVulkan(); 41 CheckVulkan();
42 return true; 42 return true;
43 } 43 }
44 44
45 // Don't perform startup checks if we are a child process
46 char is_child_s[8];
47 const DWORD is_child_len = GetEnvironmentVariableA(IS_CHILD_ENV_VAR, is_child_s, 8);
48 if (is_child_len > 0 && std::strncmp(is_child_s, ENV_VAR_ENABLED_TEXT, 8) == 0) {
49 *is_child = true;
50 return false;
51 } else if (!SetEnvironmentVariableA(IS_CHILD_ENV_VAR, ENV_VAR_ENABLED_TEXT)) {
52 std::fprintf(stderr, "SetEnvironmentVariableA failed to set %s with error %d\n",
53 IS_CHILD_ENV_VAR, GetLastError());
54 return true;
55 }
56#endif
57 return false;
58}
59
60bool StartupChecks(const char* arg0, bool* has_broken_vulkan) {
61#ifdef _WIN32
45 // Set the startup variable for child processes 62 // Set the startup variable for child processes
46 const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, "ON"); 63 const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, ENV_VAR_ENABLED_TEXT);
47 if (!env_var_set) { 64 if (!env_var_set) {
48 std::fprintf(stderr, "SetEnvironmentVariableA failed to set %s with error %d\n", 65 std::fprintf(stderr, "SetEnvironmentVariableA failed to set %s with error %d\n",
49 STARTUP_CHECK_ENV_VAR, GetLastError()); 66 STARTUP_CHECK_ENV_VAR, GetLastError());
@@ -53,7 +70,7 @@ bool StartupChecks(const char* arg0, bool* has_broken_vulkan) {
53 PROCESS_INFORMATION process_info; 70 PROCESS_INFORMATION process_info;
54 std::memset(&process_info, '\0', sizeof(process_info)); 71 std::memset(&process_info, '\0', sizeof(process_info));
55 72
56 if (!SpawnChild(arg0, &process_info)) { 73 if (!SpawnChild(arg0, &process_info, 0)) {
57 return false; 74 return false;
58 } 75 }
59 76
@@ -106,7 +123,7 @@ bool StartupChecks(const char* arg0, bool* has_broken_vulkan) {
106} 123}
107 124
108#ifdef _WIN32 125#ifdef _WIN32
109bool SpawnChild(const char* arg0, PROCESS_INFORMATION* pi) { 126bool SpawnChild(const char* arg0, PROCESS_INFORMATION* pi, int flags) {
110 STARTUPINFOA startup_info; 127 STARTUPINFOA startup_info;
111 128
112 std::memset(&startup_info, '\0', sizeof(startup_info)); 129 std::memset(&startup_info, '\0', sizeof(startup_info));
@@ -120,7 +137,7 @@ bool SpawnChild(const char* arg0, PROCESS_INFORMATION* pi) {
120 nullptr, // lpProcessAttributes 137 nullptr, // lpProcessAttributes
121 nullptr, // lpThreadAttributes 138 nullptr, // lpThreadAttributes
122 false, // bInheritHandles 139 false, // bInheritHandles
123 0, // dwCreationFlags 140 flags, // dwCreationFlags
124 nullptr, // lpEnvironment 141 nullptr, // lpEnvironment
125 nullptr, // lpCurrentDirectory 142 nullptr, // lpCurrentDirectory
126 &startup_info, // lpStartupInfo 143 &startup_info, // lpStartupInfo
diff --git a/src/yuzu/startup_checks.h b/src/yuzu/startup_checks.h
index 096dd54a8..f2fc2d9d4 100644
--- a/src/yuzu/startup_checks.h
+++ b/src/yuzu/startup_checks.h
@@ -7,11 +7,14 @@
7#include <windows.h> 7#include <windows.h>
8#endif 8#endif
9 9
10constexpr char IS_CHILD_ENV_VAR[] = "YUZU_IS_CHILD";
10constexpr char STARTUP_CHECK_ENV_VAR[] = "YUZU_DO_STARTUP_CHECKS"; 11constexpr char STARTUP_CHECK_ENV_VAR[] = "YUZU_DO_STARTUP_CHECKS";
12constexpr char ENV_VAR_ENABLED_TEXT[] = "ON";
11 13
12void CheckVulkan(); 14void CheckVulkan();
15bool CheckEnvVars(bool* is_child);
13bool StartupChecks(const char* arg0, bool* has_broken_vulkan); 16bool StartupChecks(const char* arg0, bool* has_broken_vulkan);
14 17
15#ifdef _WIN32 18#ifdef _WIN32
16bool SpawnChild(const char* arg0, PROCESS_INFORMATION* pi); 19bool SpawnChild(const char* arg0, PROCESS_INFORMATION* pi, int flags);
17#endif 20#endif