From 7ad11e3867f4a7602edb8793c4c90d557d85c7c7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jul 2019 17:02:29 -0400 Subject: core/reporter: Return in error case in SaveToFile() If the path couldn't be created, then we shouldn't be attempting to save the file. --- src/core/reporter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index 774022569..79af28314 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp @@ -31,8 +31,10 @@ std::string GetTimestamp() { using namespace nlohmann; void SaveToFile(const json& json, const std::string& filename) { - if (!FileUtil::CreateFullPath(filename)) + if (!FileUtil::CreateFullPath(filename)) { LOG_ERROR(Core, "Failed to create path for '{}' to save report!", filename); + return; + } std::ofstream file( FileUtil::SanitizePath(filename, FileUtil::DirectorySeparator::PlatformDefault)); -- cgit v1.2.3 From f12eb408344b992ac71ded87903510263dc51836 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jul 2019 17:05:24 -0400 Subject: core/reporter: Make bracing consistent Makes all control statements braced, regardless of their size, making code more uniform. --- src/core/reporter.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/core') diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index 79af28314..be471131f 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp @@ -63,8 +63,11 @@ json GetReportCommonData(u64 title_id, ResultCode result, const std::string& tim {"result_description", fmt::format("{:08X}", result.description.Value())}, {"timestamp", timestamp}, }; - if (user_id.has_value()) + + if (user_id.has_value()) { out["user_id"] = fmt::format("{:016X}{:016X}", (*user_id)[1], (*user_id)[0]); + } + return out; } @@ -189,8 +192,9 @@ void Reporter::SaveCrashReport(u64 title_id, ResultCode result, u64 set_flags, u const std::array& registers, const std::array& backtrace, u32 backtrace_size, const std::string& arch, u32 unk10) const { - if (!IsReportingEnabled()) + if (!IsReportingEnabled()) { return; + } const auto timestamp = GetTimestamp(); json out; @@ -214,8 +218,9 @@ void Reporter::SaveCrashReport(u64 title_id, ResultCode result, u64 set_flags, u void Reporter::SaveSvcBreakReport(u32 type, bool signal_debugger, u64 info1, u64 info2, std::optional> resolved_buffer) const { - if (!IsReportingEnabled()) + if (!IsReportingEnabled()) { return; + } const auto timestamp = GetTimestamp(); const auto title_id = system.CurrentProcess()->GetTitleID(); @@ -240,8 +245,9 @@ void Reporter::SaveSvcBreakReport(u32 type, bool signal_debugger, u64 info1, u64 void Reporter::SaveUnimplementedFunctionReport(Kernel::HLERequestContext& ctx, u32 command_id, const std::string& name, const std::string& service_name) const { - if (!IsReportingEnabled()) + if (!IsReportingEnabled()) { return; + } const auto timestamp = GetTimestamp(); const auto title_id = system.CurrentProcess()->GetTitleID(); @@ -261,8 +267,9 @@ void Reporter::SaveUnimplementedAppletReport( u32 applet_id, u32 common_args_version, u32 library_version, u32 theme_color, bool startup_sound, u64 system_tick, std::vector> normal_channel, std::vector> interactive_channel) const { - if (!IsReportingEnabled()) + if (!IsReportingEnabled()) { return; + } const auto timestamp = GetTimestamp(); const auto title_id = system.CurrentProcess()->GetTitleID(); @@ -295,8 +302,9 @@ void Reporter::SaveUnimplementedAppletReport( void Reporter::SavePlayReport(u64 title_id, u64 process_id, std::vector> data, std::optional user_id) const { - if (!IsReportingEnabled()) + if (!IsReportingEnabled()) { return; + } const auto timestamp = GetTimestamp(); json out; @@ -318,8 +326,9 @@ void Reporter::SavePlayReport(u64 title_id, u64 process_id, std::vector custom_text_main, std::optional custom_text_detail) const { - if (!IsReportingEnabled()) + if (!IsReportingEnabled()) { return; + } const auto timestamp = GetTimestamp(); json out; @@ -338,8 +347,9 @@ void Reporter::SaveErrorReport(u64 title_id, ResultCode result, } void Reporter::SaveUserReport() const { - if (!IsReportingEnabled()) + if (!IsReportingEnabled()) { return; + } const auto timestamp = GetTimestamp(); const auto title_id = system.CurrentProcess()->GetTitleID(); -- cgit v1.2.3 From 6ec48af2223c2470ce342a707f63c67b72c6cee9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jul 2019 17:08:10 -0400 Subject: core/reporter: Remove pessimizing move in GetHLERequestContextData() This can inhibit copy-elision, so we can remove this redundant move. --- src/core/reporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index be471131f..96b71037a 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp @@ -176,7 +176,7 @@ json GetHLERequestContextData(Kernel::HLERequestContext& ctx) { out["buffer_descriptor_c"] = GetHLEBufferDescriptorData(ctx.BufferDescriptorC()); out["buffer_descriptor_x"] = GetHLEBufferDescriptorData(ctx.BufferDescriptorX()); - return std::move(out); + return out; } } // Anonymous namespace -- cgit v1.2.3 From e721c344ae2f7267bdf40508eda08bd6c3c6e491 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jul 2019 17:09:24 -0400 Subject: core/reporter: Remove unnecessary namespace qualifiers The Reporter class is part of the Core namespace, so the System class doesn't need to be qualified. --- src/core/reporter.cpp | 2 +- src/core/reporter.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index 96b71037a..d79a9336d 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp @@ -183,7 +183,7 @@ json GetHLERequestContextData(Kernel::HLERequestContext& ctx) { namespace Core { -Reporter::Reporter(Core::System& system) : system(system) {} +Reporter::Reporter(System& system) : system(system) {} Reporter::~Reporter() = default; diff --git a/src/core/reporter.h b/src/core/reporter.h index 3de19c0f7..9487a11b6 100644 --- a/src/core/reporter.h +++ b/src/core/reporter.h @@ -18,7 +18,7 @@ namespace Core { class Reporter { public: - explicit Reporter(Core::System& system); + explicit Reporter(System& system); ~Reporter(); void SaveCrashReport(u64 title_id, ResultCode result, u64 set_flags, u64 entry_point, u64 sp, @@ -50,7 +50,7 @@ public: private: bool IsReportingEnabled() const; - Core::System& system; + System& system; }; } // namespace Core -- cgit v1.2.3 From 2321656dbe4eba8105b59576ae4ed486ca65918f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jul 2019 17:19:43 -0400 Subject: core/reporter: Add missing includes and forward declarations Adds missing inclusions to prevent potential compilation issues. --- src/core/reporter.cpp | 6 +++++- src/core/reporter.h | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index d79a9336d..dbc350070 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp @@ -2,8 +2,13 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include + +#include +#include #include + #include "common/file_util.h" #include "common/hex_util.h" #include "common/scm_rev.h" @@ -14,7 +19,6 @@ #include "core/hle/result.h" #include "core/reporter.h" #include "core/settings.h" -#include "fmt/time.h" namespace { diff --git a/src/core/reporter.h b/src/core/reporter.h index 9487a11b6..4266ca550 100644 --- a/src/core/reporter.h +++ b/src/core/reporter.h @@ -4,7 +4,9 @@ #pragma once +#include #include +#include #include #include "common/common_types.h" @@ -16,6 +18,8 @@ class HLERequestContext; namespace Core { +class System; + class Reporter { public: explicit Reporter(System& system); -- cgit v1.2.3 From 48807e9a24e7e75344076547799b083f40def8fc Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 5 Jul 2019 17:40:51 -0400 Subject: core/reporter: Allow moves into SaveToFile() Taking the json instance as a constant reference, makes all moves into the parameter non-functional, resulting in copies. Taking it by value allows moves to function. --- src/core/reporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index dbc350070..6ea26fda7 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp @@ -34,7 +34,7 @@ std::string GetTimestamp() { using namespace nlohmann; -void SaveToFile(const json& json, const std::string& filename) { +void SaveToFile(json json, const std::string& filename) { if (!FileUtil::CreateFullPath(filename)) { LOG_ERROR(Core, "Failed to create path for '{}' to save report!", filename); return; -- cgit v1.2.3