feisty meow concerns codebase  2.140
callstack_tracker.h File Reference
Include dependency graph for callstack_tracker.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  application::callstack_tracker
 This object can provide a backtrace at runtime of the invoking methods. More...
 
class  application::frame_tracking_instance
 a small object that represents a stack trace in progress. More...
 

Namespaces

 application
 Implements an application lock to ensure only one is running at once.
 

Macros

#define GET_AND_TEST_STACK_TRACE(header, failure_return)
 

Functions

callstack_tracker & application::thread_wide_stack_trace ()
 the single instance of callstack_tracker. More...
 
void application::update_current_stack_frame_line_number (int line)
 sets the line number for the current frame in the global stack trace. More...
 

Macro Definition Documentation

◆ GET_AND_TEST_STACK_TRACE

#define GET_AND_TEST_STACK_TRACE (   header,
  failure_return 
)
Value:
{ \
int trace_size = thread_wide_stack_trace().full_trace_size(); \
char *stack_trace = thread_wide_stack_trace().full_trace(); \
ASSERT_TRUE(trace_size >= strlen(stack_trace) + 1, "insufficient estimated stack trace size"); \
if (trace_size < strlen(stack_trace) + 1) { \
/* error condition here; we are supposed to get the actual size we would need to allocate! */ \
LOG(a_sprintf("failure in stack trace return: estimated size (%d) was less than actual (%d)", \
trace_size, strlen(stack_trace))); \
/* mandatory free step for newly allocated string. */ \
free(stack_trace); \
return failure_return; \
} \
ASSERT_TRUE(strlen(stack_trace) > 1, "empty stack trace"); \
if (strlen(stack_trace) < 2) { \
LOG("failure in stack trace return: the trace output string was empty!"); \
return failure_return; \
} \
LOG(astring("\n\n################\n\n") + header + "\n" + stack_trace); \
/* mandatory free step for newly allocated string. */ \
free(stack_trace); \
}
char * full_trace() const
provides the current stack trace in a newly malloc'd string.
int full_trace_size() const
this returns an estimated number of bytes needed for the full_trace().
callstack_tracker & thread_wide_stack_trace()
the single instance of callstack_tracker.

super helpful macro that shows the current stack trace and checks it for validity. this shouldn't impact the trace, since all the code is embedded inline from the macro. this does require that LOG() is defined, and that a failure return value is expected from the embedding function.

Definition at line 113 of file callstack_tracker.h.