From 21850aa73ea90c6846f2b47903d5ac1b6b916b05 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Thu, 23 Dec 2021 15:09:29 -0800 Subject: [PATCH] chore: replace stack trace logic with StackRecorder Signed-off-by: Michael Pollind --- .../UnixLike/AzCore/Debug/Trace_UnixLike.cpp | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/Debug/Trace_UnixLike.cpp b/Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/Debug/Trace_UnixLike.cpp index b0ee4ea1e3..67de4a3219 100644 --- a/Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/Debug/Trace_UnixLike.cpp +++ b/Code/Framework/AzCore/Platform/Common/UnixLike/AzCore/Debug/Trace_UnixLike.cpp @@ -9,11 +9,9 @@ #include #include #include +#include -#include -#include #include -#include namespace AZ::Debug { @@ -114,19 +112,15 @@ namespace AZ::Debug azsnprintf(message, MaxMessageLength, "Error: signal %s: \n", strsignal(signal)); Debug::Trace::Instance().Output(nullptr, message); - void* buffers[MaxStackLines]; - int numberBacktraceStrings = backtrace(buffers, MaxStackLines); - char** backtraceResults = backtrace_symbols(buffers, numberBacktraceStrings); - if (backtraceResults == nullptr) - { - Debug::Trace::Instance().Output(nullptr, "==================================================================\n"); - return; + StackFrame frames[MaxStackLines]; + SymbolStorage::StackLine stackLines[MaxStackLines]; + SymbolStorage decoder; + const unsigned int numberOfFrames = StackRecorder::Record(frames, MaxStackLines); + decoder.DecodeFrames(frames, numberOfFrames, stackLines); + for(int i = 0; i < numberOfFrames; ++i) { + azsnprintf(message, MaxMessageLength, "%s \n", stackLines[i]); + Debug::Trace::Instance().Output(nullptr, message); } - for (int j = 0; j < numberBacktraceStrings; j++) - { - Debug::Trace::Instance().Output(nullptr, backtraceResults[j]); - } - Debug::Trace::Instance().Output(nullptr, "==================================================================\n"); } #endif