libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
CrashHandler.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <memory>
6
7#if (__linux__)
8#include <csignal>
9#include <cstdio>
10#include <cxxabi.h> // for __cxa_demangle
11#include <dlfcn.h> // for dladdr
12#include <execinfo.h>
13#include <unistd.h>
14#include <SDL.h>
15#endif
16
17#if _WIN32
18#include <windows.h>
19#endif
20
21namespace Ship {
22
30typedef void (*CrashHandlerCallback)(char*, size_t*);
31
47class CrashHandler : public Component {
48 public:
57
67 void AppendLine(const char* str);
72 void AppendStr(const char* str);
78
79#ifdef __linux__
84 void PrintRegisters(ucontext_t* ctx);
85#elif _WIN32
90 void PrintRegisters(CONTEXT* ctx);
95 void PrintStack(CONTEXT* ctx);
96#endif
97
98 private:
99 void OnAdded(bool forced) override;
100
101 CrashHandlerCallback mCallback = nullptr;
102 std::unique_ptr<char[]> mOutBuffer;
103 static constexpr size_t gMaxBufferSize = 32768;
104 size_t mOutBuffersize = 0;
105
107 void AppendStrTrunc(const char* str);
108
110 bool CheckStrLen(const char* str);
111};
112} // namespace Ship
A named Part with a parent/child hierarchy and optional thread safety.
Definition Component.h:34
Installs platform-specific signal / exception handlers to capture crash information.
Definition CrashHandler.h:47
CrashHandler(CrashHandlerCallback callback)
Installs the platform crash handlers and immediately registers callback.
void PrintCommon()
Writes platform-agnostic crash header information (OS, build info, etc.) to the report buffer.
void PrintRegisters(ucontext_t *ctx)
Appends the values of the CPU registers from ctx to the crash report.
CrashHandler()
Installs the platform crash handlers with no application callback.
void AppendStr(const char *str)
Appends str (without a trailing newline) to the crash report buffer.
void AppendLine(const char *str)
Appends str followed by a newline to the crash report buffer.
void RegisterCallback(CrashHandlerCallback callback)
Registers (or replaces) the application callback.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
void(* CrashHandlerCallback)(char *, size_t *)
Callback type invoked by CrashHandler when a crash is detected.
Definition CrashHandler.h:30