flatten 20260225
This commit is contained in:
43
tjp/core/debug/glib/Stack.cpp
Executable file
43
tjp/core/debug/glib/Stack.cpp
Executable file
@@ -0,0 +1,43 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#ifdef TJP_CORE_HEADER_ONLY
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "../../header_only/compile.h"
|
||||
|
||||
#include "../Stack.h"
|
||||
#include "../../system/System.h"
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace tjp {
|
||||
namespace core {
|
||||
|
||||
TJP_CORE_HEADER_ONLY_INLINE
|
||||
std::string getStackString(int maxStackDepth)
|
||||
{
|
||||
void* trace[64];
|
||||
if (maxStackDepth > 64) maxStackDepth = 64;
|
||||
|
||||
char** messages = NULL;
|
||||
int trace_size = 0;
|
||||
|
||||
std::ostringstream out;
|
||||
|
||||
trace_size = backtrace( trace, maxStackDepth );
|
||||
messages = backtrace_symbols( trace, trace_size );
|
||||
for( int i = 2; i < trace_size; ++i ) {
|
||||
out << "\t" << messages[i] << std::endl;
|
||||
}
|
||||
|
||||
free (messages);
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user