Skip to content

Commit 9793a7d

Browse files
authored
Merge pull request #174 from cortex-command-community/nonwin-backtrace
Linux and MacOS backtrace
2 parents 26c5601 + 5df27ac commit 9793a7d

File tree

13 files changed

+4524
-2358
lines changed

13 files changed

+4524
-2358
lines changed

RTEA.vcxproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@
794794
<ClInclude Include="Source\System\AllegroTools.h" />
795795
<ClInclude Include="Source\System\Atom.h" />
796796
<ClInclude Include="Source\System\Base64\base64.h" />
797+
<ClInclude Include="Source\System\backward\backward.hpp" />
797798
<ClInclude Include="Source\System\Constants.h" />
798799
<ClInclude Include="Source\System\Controller.h" />
799800
<ClInclude Include="Source\System\Entity.h" />
@@ -810,8 +811,6 @@
810811
<ClInclude Include="Source\System\Semver200\semver200.h" />
811812
<ClInclude Include="Source\System\Semver200\version.h" />
812813
<ClInclude Include="Source\System\SpatialPartitionGrid.h" />
813-
<ClInclude Include="Source\System\RTEStackTrace.h" />
814-
<ClInclude Include="Source\System\StackWalker\StackWalker.h" />
815814
<ClInclude Include="Source\System\StandardIncludes.h" />
816815
<ClInclude Include="Source\System\Box.h" />
817816
<ClInclude Include="Source\System\Color.h" />
@@ -1330,8 +1329,6 @@
13301329
<ClCompile Include="Source\System\Semver200\Semver200_parser.cpp" />
13311330
<ClCompile Include="Source\System\Serializable.cpp" />
13321331
<ClCompile Include="Source\System\SpatialPartitionGrid.cpp" />
1333-
<ClCompile Include="Source\System\RTEStackTrace.cpp" />
1334-
<ClCompile Include="Source\System\StackWalker\StackWalker.cpp" />
13351332
<ClCompile Include="Source\System\StandardIncludes.cpp">
13361333
<PrecompiledHeader>Create</PrecompiledHeader>
13371334
<PrecompiledHeaderFile>StandardIncludes.h</PrecompiledHeaderFile>

RTEA.vcxproj.filters

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<Filter Include="GUI\Wrappers">
3535
<UniqueIdentifier>{14ff3fdb-4366-4bed-8b6e-ddcf72987b81}</UniqueIdentifier>
3636
</Filter>
37-
<Filter Include="System\StackWalker">
37+
<Filter Include="System\backward">
3838
<UniqueIdentifier>{a8668dc1-51c5-418d-91bf-7ee92f008cb1}</UniqueIdentifier>
3939
</Filter>
4040
<Filter Include="external">
@@ -612,11 +612,8 @@
612612
<ClInclude Include="Source\System\GameVersion.h">
613613
<Filter>System</Filter>
614614
</ClInclude>
615-
<ClInclude Include="Source\System\StackWalker\StackWalker.h">
616-
<Filter>System\StackWalker</Filter>
617-
</ClInclude>
618-
<ClInclude Include="Source\System\RTEStackTrace.h">
619-
<Filter>System</Filter>
615+
<ClInclude Include="Source\System\backward\backward.hpp">
616+
<Filter>System\backward</Filter>
620617
</ClInclude>
621618
<ClInclude Include="Source\Entities\AEJetpack.h">
622619
<Filter>Entities</Filter>
@@ -1199,12 +1196,6 @@
11991196
<ClCompile Include="Source\System\Semver200\Semver200_parser.cpp">
12001197
<Filter>System\Semver200</Filter>
12011198
</ClCompile>
1202-
<ClCompile Include="Source\System\StackWalker\StackWalker.cpp">
1203-
<Filter>System\StackWalker</Filter>
1204-
</ClCompile>
1205-
<ClCompile Include="Source\System\RTEStackTrace.cpp">
1206-
<Filter>System</Filter>
1207-
</ClCompile>
12081199
<ClCompile Include="Source\Renderer\glad\gl.c">
12091200
<Filter>Renderer\glad</Filter>
12101201
</ClCompile>

Source/System/RTEError.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#ifdef _WIN32
1212
#include "Windows.h"
13-
#include "DbgHelp.h"
14-
#include "RTEStackTrace.h"
1513
#endif
1614

1715
#include <array>
@@ -34,13 +32,19 @@
3432
#include <sys/sysctl.h>
3533
#endif
3634

35+
#include "backward/backward.hpp"
36+
37+
3738
using namespace RTE;
3839

3940
bool RTEError::s_CurrentlyAborting = false;
4041
bool RTEError::s_IgnoreAllAsserts = false;
4142
std::string RTEError::s_LastIgnoredAssertDescription = "";
4243
std::source_location RTEError::s_LastIgnoredAssertLocation = {};
4344

45+
#if (defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)))
46+
backward::SignalHandling sh;
47+
#endif
4448
#ifdef _WIN32
4549
/// <summary>
4650
/// Custom exception handler for Windows SEH.
@@ -157,9 +161,13 @@ static LONG WINAPI RTEWindowsExceptionHandler([[maybe_unused]] EXCEPTION_POINTER
157161
exceptionDescription << getExceptionDescriptionFromCode(exceptionCode) << " at address 0x" << std::uppercase << std::hex << exceptionAddress << ".\n\n"
158162
<< symbolNameAtAddress << std::endl;
159163

160-
RTEStackTrace stackTrace;
164+
backward::StackTrace st;
165+
st.load_here(32, exceptPtr->ContextRecord);
166+
backward::Printer printer;
167+
std::ostringstream stack;
168+
printer.print(st, stack);
161169

162-
RTEError::UnhandledExceptionFunc(exceptionDescription.str(), stackTrace.GetCallStackAsString(processHandle, exceptPtr->ContextRecord));
170+
RTEError::UnhandledExceptionFunc(exceptionDescription.str(), stack.str());
163171
return EXCEPTION_EXECUTE_HANDLER;
164172
#endif
165173
}
@@ -344,10 +352,12 @@ void RTEError::AbortFunc(const std::string& description, const std::source_locat
344352

345353
std::string callstack = "";
346354

347-
#ifdef _WIN32
348-
RTEStackTrace stackTrace;
349-
callstack += ("\n\n" + stackTrace.GetCallStackAsString());
350-
#endif
355+
backward::StackTrace st;
356+
st.load_here();
357+
backward::Printer printer;
358+
std::ostringstream stack;
359+
printer.print(st, stack);
360+
callstack = stack.str();
351361

352362
std::string consoleSaveMsg;
353363
if (!callstack.empty()) {

Source/System/RTEStackTrace.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

Source/System/RTEStackTrace.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

Source/System/StackWalker/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

Source/System/StackWalker/LICENSE

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)