mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Simplify the Beast fatal error reporting framework:
* Reduce interface to a single function which reports error details * Remove unused functions
This commit is contained in:
@@ -21,6 +21,10 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
// Some basic tests, to keep an eye on things and make sure these types work ok
|
||||
// on all platforms.
|
||||
|
||||
@@ -48,20 +52,22 @@ SystemStats::getBeastVersion()
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
std::string
|
||||
std::vector <std::string>
|
||||
SystemStats::getStackBacktrace()
|
||||
{
|
||||
std::string result;
|
||||
std::vector <std::string> result;
|
||||
|
||||
#if BEAST_ANDROID || BEAST_MINGW || BEAST_BSD
|
||||
#if BEAST_ANDROID || BEAST_MINGW || BEAST_BSD
|
||||
bassertfalse; // sorry, not implemented yet!
|
||||
|
||||
#elif BEAST_WINDOWS
|
||||
#elif BEAST_WINDOWS
|
||||
HANDLE process = GetCurrentProcess();
|
||||
SymInitialize (process, nullptr, TRUE);
|
||||
|
||||
void* stack[128];
|
||||
int frames = (int) CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr);
|
||||
int frames = (int) CaptureStackBackTrace (0,
|
||||
std::distance(std::begin(stack), std::end(stack)),
|
||||
stack, nullptr);
|
||||
|
||||
HeapBlock<SYMBOL_INFO> symbol;
|
||||
symbol.calloc (sizeof (SYMBOL_INFO) + 256, 1);
|
||||
@@ -74,7 +80,9 @@ SystemStats::getStackBacktrace()
|
||||
|
||||
if (SymFromAddr (process, (DWORD64) stack[i], &displacement, symbol))
|
||||
{
|
||||
result.append (std::to_string (i) + ": ");
|
||||
std::string frame;
|
||||
|
||||
frame.append (std::to_string (i) + ": ");
|
||||
|
||||
IMAGEHLP_MODULE64 moduleInfo;
|
||||
zerostruct (moduleInfo);
|
||||
@@ -82,35 +90,33 @@ SystemStats::getStackBacktrace()
|
||||
|
||||
if (::SymGetModuleInfo64 (process, symbol->ModBase, &moduleInfo))
|
||||
{
|
||||
result.append (moduleInfo.ModuleName);
|
||||
result.append (": ");
|
||||
frame.append (moduleInfo.ModuleName);
|
||||
frame.append (": ");
|
||||
}
|
||||
|
||||
result.append (symbol->Name);
|
||||
frame.append (symbol->Name);
|
||||
|
||||
if (displacement)
|
||||
{
|
||||
result.append ("+");
|
||||
result.append (std::to_string (displacement));
|
||||
frame.append ("+");
|
||||
frame.append (std::to_string (displacement));
|
||||
}
|
||||
|
||||
result.append ("\r\n");
|
||||
result.push_back (frame);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
void* stack[128];
|
||||
int frames = backtrace (stack, numElementsInArray (stack));
|
||||
char** frameStrings = backtrace_symbols (stack, frames);
|
||||
int frames = backtrace (stack,
|
||||
std::distance(std::begin(stack), std::end(stack)));
|
||||
|
||||
std::unique_ptr<char*[], void(*)(void*)> frame (
|
||||
backtrace_symbols (stack, frames), std::free);
|
||||
|
||||
for (int i = 0; i < frames; ++i)
|
||||
{
|
||||
result.append (frameStrings[i]);
|
||||
result.append ("\n");
|
||||
}
|
||||
|
||||
::free (frameStrings);
|
||||
#endif
|
||||
result.push_back (frame[i]);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user