Skip to content

Commit

Permalink
Add callstack logging utility
Browse files Browse the repository at this point in the history
  • Loading branch information
tustanivsky committed Sep 23, 2024
1 parent 595bf09 commit 6b72925
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "SentryTransactionContext.h"
#include "SentryUserFeedbackDesktop.h"

#include "Utils/SentryLogUtils.h"
#include "Utils/SentryScreenshotUtils.h"

#include "Infrastructure/SentryConvertorsDesktop.h"
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
27 changes: 27 additions & 0 deletions plugin-dev/Source/Sentry/Private/Utils/SentryLogUtils.cpp
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions plugin-dev/Source/Sentry/Private/Utils/SentryLogUtils.h
Original file line number Diff line number Diff line change
@@ -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);
};

0 comments on commit 6b72925

Please sign in to comment.