diff --git a/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp b/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp index 24f921be..f47f5625 100644 --- a/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp +++ b/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp @@ -21,6 +21,7 @@ #include "SentryTransactionContext.h" #include "SentryUserFeedbackDesktop.h" +#include "Utils/SentryLogUtils.h" #include "Utils/SentryScreenshotUtils.h" #include "Infrastructure/SentryConvertorsDesktop.h" @@ -395,7 +396,11 @@ USentryId* SentrySubsystemDesktop::CaptureException(const FString& type, const F USentryId* SentrySubsystemDesktop::CaptureAssertion(const FString& type, const FString& message) { - return CaptureException(type, message, 7); + int32 framesToSkip = 7; + + SentryLogUtils::LogStackTrace(*message, ELogVerbosity::Error, framesToSkip); + + return CaptureException(type, message, framesToSkip); } USentryId* SentrySubsystemDesktop::CaptureEnsure(const FString& type, const FString& message) diff --git a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp index 42af22f6..3a7aaabd 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp @@ -20,6 +20,7 @@ #include "Misc/EngineVersion.h" #include "Misc/CoreDelegates.h" #include "Misc/App.h" +#include "Misc/AssertionMacros.h" #include "GenericPlatform/GenericPlatformDriver.h" #include "GenericPlatform/GenericPlatformMisc.h" diff --git a/plugin-dev/Source/Sentry/Private/Utils/SentryLogUtils.cpp b/plugin-dev/Source/Sentry/Private/Utils/SentryLogUtils.cpp new file mode 100644 index 00000000..7ca0231d --- /dev/null +++ b/plugin-dev/Source/Sentry/Private/Utils/SentryLogUtils.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2024 Sentry. All Rights Reserved. + +#include "SentryLogUtils.h" + +#include "CoreGlobals.h" +#include "GenericPlatform/GenericPlatformStackWalk.h" +#include "HAL/UnrealMemory.h" +#include "Misc/OutputDeviceRedirector.h" + +void SentryLogUtils::LogStackTrace(const TCHAR* Heading, const ELogVerbosity::Type LogVerbosity, int FramesToSkip) +{ +#if !NO_LOGGING + const SIZE_T StackTraceSize = 65535; + ANSICHAR* StackTrace = (ANSICHAR*)FMemory::SystemMalloc(StackTraceSize); + + { + StackTrace[0] = 0; + FGenericPlatformStackWalk::StackWalkAndDumpEx(StackTrace, StackTraceSize, FramesToSkip + 1, FGenericPlatformStackWalk::EStackWalkFlags::FlagsUsedWhenHandlingEnsure); + } + + FDebug::LogFormattedMessageWithCallstack(LogOutputDevice.GetCategoryName(), __FILE__, __LINE__, Heading, ANSI_TO_TCHAR(StackTrace), LogVerbosity); + + GLog->Flush(); + + FMemory::SystemFree(StackTrace); +#endif +} diff --git a/plugin-dev/Source/Sentry/Private/Utils/SentryLogUtils.h b/plugin-dev/Source/Sentry/Private/Utils/SentryLogUtils.h new file mode 100644 index 00000000..1a6011b9 --- /dev/null +++ b/plugin-dev/Source/Sentry/Private/Utils/SentryLogUtils.h @@ -0,0 +1,12 @@ +// Copyright (c) 2024 Sentry. All Rights Reserved. + +#pragma once + +#include "CoreTypes.h" +#include "Logging/LogVerbosity.h" + +class SentryLogUtils +{ +public: + static void LogStackTrace(const TCHAR* Heading, const ELogVerbosity::Type LogVerbosity, int FramesToSkip); +};