How to print callstack into log?

Hey guys,

How can i print call stack into log ? In blueprint there is Stack Trace node but I can not call that directly in c++ because of linker errors.

What is the best way to print callstack in code ?

2 Likes

Yes, I know but I can’t belive there is not some simple function for that. But yeah, I am looking for CPU call stack, same stack which crash reporter shows.

Then look up source code how this node do it, it seems oyu need to get FFrame and from there call GetStackTrace()

https://github.com/EpicGames/UnrealEngine/blob/ab237f46dc0eee40263acbacbe938312eb0dffbb/Engine/Source/Runtime/Engine/Private/KismetSystemLibrary.cpp#L30
https://github.com/EpicGames/UnrealEngine/blob/ab237f46dc0eee40263acbacbe938312eb0dffbb/Engine/Source/Runtime/CoreUObject/Private/UObject/ScriptCore.cpp#L414

There also seem to be more global version which is static function:

https://github.com/EpicGames/UnrealEngine/blob/ab237f46dc0eee40263acbacbe938312eb0dffbb/Engine/Source/Runtime/CoreUObject/Private/UObject/ScriptCore.cpp#L318

Note that this only give you VM that powers blueprints call stack not native CPU call stack

Supposing the PDBs are loaded, you could look at / trace FWindwsPlatformStackWalk::StackWalkAndDump – for other platforms there are other classes, each implements StackWalkAndDump.

That’s what the crash reporter uses for the call stack.

I found an easy way by actually causing a CallStack to happen by referencing a null pointer when the suspicious activity is believed to be happening. This, mixed with print logs helped me out. I used to do this when working with build scripts.

I know it’s 2 years late, but FDebug::DumpStackTraceToLog() will do exactly this.

9 Likes

Even later, but to see Stack Trace in the log file, add this to the DefaultEngine.ini

[Kismet]
ScriptStackOnWarnings=true
2 Likes