Base Framework
Public Types | Public Member Functions | Static Public Member Functions | List of all members
StackFrame Class Reference

#include <base/StackFrame.h>

Public Types

enum  {
  FLAG_SHOW_ADDRESS = 1 << 0, FLAG_SHOW_MODULE = 1 << 1, FLAG_INDENT = 1 << 2, FLAG_COMPACT = 1 << 3,
  FLAG_FULL_PATH = 1 << 4, FLAG_USE_COLORS = 1 << 5, FLAG_USE_COLORS_IF_ANSI_TERMINAL = 1 << 6, FLAG_STRIP_NAMESPACE = 1 << 7,
  FLAG_TRIM_SYSTEM = 1 << 8, FLAG_DEFAULT = FLAG_COMPACT | FLAG_SHOW_ADDRESS | FLAG_SHOW_MODULE | FLAG_INDENT | FLAG_TRIM_SYSTEM | FLAG_USE_COLORS_IF_ANSI_TERMINAL
}
 

Public Member Functions

 StackFrame (const ConstSpan< const void * > &stackTrace)
 
StackFrameoperator= (const ConstSpan< const void * > &assign)
 
unsigned long getHash () const noexcept
 
ConstSpan< const void * > getTrace () const noexcept
 
MemorySize getSize () const noexcept
 
bool isEmpty () const noexcept
 
const void * getFrame (MemorySize index) const noexcept
 
MemoryDiff find (const void *address) const noexcept
 
MemoryDiff findLast (const void *address) const noexcept
 
void stripUntil (MemorySize index) noexcept
 
MemorySize stripUntil (const void *ip) noexcept
 
bool operator== (const StackFrame &compare) const noexcept
 
bool operator!= (const StackFrame &compare) const noexcept
 
bool operator== (const ConstSpan< const void * > &compare) const noexcept
 
bool operator!= (const ConstSpan< const void * > &compare) const noexcept
 
 operator bool () const noexcept
 

Static Public Member Functions

static constexpr bool doesSupportStackTrace () noexcept
 
static bool getUseStandardOut () noexcept
 
static void setUseStandardOut (bool useStandardOut) noexcept
 
static FormatOutputStreamgetErrorStream () noexcept
 
static unsigned long getHash (const ConstSpan< const void * > &stackTrace) noexcept
 
static void * getStackFrame () noexcept
 
static void * getCaller () noexcept
 
static unsigned int getStack (const void **dest, unsigned int size, unsigned int skip=1, bool trim=true)
 
static StackFrame getStack (unsigned int skip=1, unsigned int levels=32, bool trim=true)
 
static void dump (unsigned int skip=1, unsigned int levels=32)
 
static FormatOutputStreamtoStream (FormatOutputStream &stream, const ConstSpan< const void * > &stackTrace, unsigned int flags=FLAG_DEFAULT)
 

Detailed Description

Stack frame.

Member Function Documentation

◆ doesSupportStackTrace()

static constexpr bool StackFrame::doesSupportStackTrace ( )
inlinestaticconstexprnoexcept

Returns true if stack trace is supported.

◆ dump()

static void StackFrame::dump ( unsigned int  skip = 1,
unsigned int  levels = 32 
)
static

Dump stack.

Parameters
levelsThe maximum number of levels to dump.

◆ find()

MemoryDiff StackFrame::find ( const void *  address) const
noexcept

Returns the index of the symbol address if found.

Returns
Returns -1 if not found.

◆ findLast()

MemoryDiff StackFrame::findLast ( const void *  address) const
noexcept

Returns the index of the last occurrence symbol address if found.

Returns
Returns -1 if not found.

◆ getCaller()

static void* StackFrame::getCaller ( )
staticnoexcept

Returns the caller. Not available for all platforms.

◆ getErrorStream()

static FormatOutputStream& StackFrame::getErrorStream ( )
staticnoexcept

Returns the preferred output stream.

◆ getFrame()

const void* StackFrame::getFrame ( MemorySize  index) const
inlinenoexcept

Returns the stack frame.

◆ getHash() [1/2]

unsigned long StackFrame::getHash ( ) const
inlinenoexcept

Returns hash for stack trace.

◆ getHash() [2/2]

static unsigned long StackFrame::getHash ( const ConstSpan< const void * > &  stackTrace)
staticnoexcept

Returns hash for stack trace.

◆ getSize()

MemorySize StackFrame::getSize ( ) const
inlinenoexcept

Returns the number of stack frames.

◆ getStack() [1/2]

static unsigned int StackFrame::getStack ( const void **  dest,
unsigned int  size,
unsigned int  skip = 1,
bool  trim = true 
)
static

Returns the stack trace.

◆ getStack() [2/2]

static StackFrame StackFrame::getStack ( unsigned int  skip = 1,
unsigned int  levels = 32,
bool  trim = true 
)
static

Returns the stack.

Parameters
skipSkip the first frames.
levelsThe maximum number of levels to dump.
trimTrim to base address.

◆ getStackFrame()

static void* StackFrame::getStackFrame ( )
staticnoexcept

Returns the stack frame. Not available for all platforms.

◆ getTrace()

ConstSpan<const void*> StackFrame::getTrace ( ) const
inlinenoexcept

Returns the stack frames.

◆ getUseStandardOut()

static bool StackFrame::getUseStandardOut ( )
staticnoexcept

Print stack trace to standard out instead of standard error.

◆ isEmpty()

bool StackFrame::isEmpty ( ) const
inlinenoexcept

Returns the number of stack frames.

◆ operator bool()

StackFrame::operator bool ( ) const
inlinenoexcept

Returns true if stack trace is empty.

◆ operator!=() [1/2]

bool StackFrame::operator!= ( const ConstSpan< const void * > &  compare) const
inlinenoexcept

Returns true if stack traces are non-equal.

◆ operator!=() [2/2]

bool StackFrame::operator!= ( const StackFrame compare) const
inlinenoexcept

Returns true if stack traces are non-equal.

◆ operator==() [1/2]

bool StackFrame::operator== ( const ConstSpan< const void * > &  compare) const
inlinenoexcept

Returns true if stack traces are equal.

◆ operator==() [2/2]

bool StackFrame::operator== ( const StackFrame compare) const
inlinenoexcept

Returns true if stack traces are equal.

◆ setUseStandardOut()

static void StackFrame::setUseStandardOut ( bool  useStandardOut)
staticnoexcept

Print stack trace to standard out instead of standard error.

◆ stripUntil() [1/2]

MemorySize StackFrame::stripUntil ( const void *  ip)
noexcept

Strips any frames before the first occurrence of the given address if present on the stack.

Returns
The number of frames skipped.

◆ stripUntil() [2/2]

void StackFrame::stripUntil ( MemorySize  index)
noexcept

Strips any frames before the given index.

◆ toStream()

static FormatOutputStream& StackFrame::toStream ( FormatOutputStream stream,
const ConstSpan< const void * > &  stackTrace,
unsigned int  flags = FLAG_DEFAULT 
)
static

Format stack trace to stream.