1 #ifndef CALLSTACK_TRACKER_CLASS
2 #define CALLSTACK_TRACKER_CLASS
25 #ifdef ENABLE_CALLSTACK_TRACKING
28 class callstack_records;
29 class callstack_tracker;
56 bool push_frame(
const char *class_name,
const char *func,
const char *file,
81 int depth()
const {
return _depth; }
90 double highest()
const {
return _highest; }
97 callstack_records *_bt;
113 #define GET_AND_TEST_STACK_TRACE(header, failure_return) { \
114 int trace_size = thread_wide_stack_trace().full_trace_size(); \
115 char *stack_trace = thread_wide_stack_trace().full_trace(); \
116 ASSERT_TRUE(trace_size >= strlen(stack_trace) + 1, "insufficient estimated stack trace size"); \
117 if (trace_size < strlen(stack_trace) + 1) { \
119 LOG(a_sprintf("failure in stack trace return: estimated size (%d) was less than actual (%d)", \
120 trace_size, strlen(stack_trace))); \
123 return failure_return; \
125 ASSERT_TRUE(strlen(stack_trace) > 1, "empty stack trace"); \
126 if (strlen(stack_trace) < 2) { \
127 LOG("failure in stack trace return: the trace output string was empty!"); \
128 return failure_return; \
130 LOG(astring("\n\n################\n\n") + header + "\n" + stack_trace); \
154 const char *file =
"",
int line = 0,
bool add_frame =
false);
168 void assign(
const char *class_name,
const char *func,
const char *file,
186 inline void no_op() { }
187 #define frame_tracking_instance
188 #define GET_AND_TEST_STACK_TRACE(header, failure_return) no_op();
189 #define __trail_of_function(p1, p2, p3, p4, p5) no_op();
Contains definitions that control how libraries and programs are built.
This object can provide a backtrace at runtime of the invoking methods.
double frames_out() const
reports the number of call stack frames that were removed, total.
bool push_frame(const char *class_name, const char *func, const char *file, int line)
adds a new stack from for the "class_name" in "function" at the "line".
double frames_in() const
reports the number of call stack frames that were added, total.
bool pop_frame()
removes the last callstack frame off from our tracking.
virtual ~callstack_tracker()
char * full_trace() const
provides the current stack trace in a newly malloc'd string.
int depth() const
the current number of frames we know of.
double highest() const
reports the maximum stack depth seen during the runtime so far.
bool update_line(int line)
sets the line number within the current stack frame.
static basis::mutex & __callstack_tracker_synchronizer()
protects concurrent access.
int full_trace_size() const
this returns an estimated number of bytes needed for the full_trace().
a small object that represents a stack trace in progress.
frame_tracking_instance(const char *class_name="", const char *func="", const char *file="", int line=0, bool add_frame=false)
as an automatic variable, this can hang onto frame information.
~frame_tracking_instance()
releases the information and this stack frame in the tracker.
void clean()
throws out our accumulated memory and pops frame if applicable.
char * _file
newly allocated copies.
bool _frame_involved
has this object been added to the tracker?
void assign(const char *class_name, const char *func, const char *file, int line)
similar to assignment operator but doesn't require an object.
frame_tracking_instance & operator=(const frame_tracking_instance &to_copy)
Constants and objects used throughout HOOPLE.
Implements an application lock to ensure only one is running at once.
callstack_tracker & thread_wide_stack_trace()
the single instance of callstack_tracker.
void update_current_stack_frame_line_number(int line)
sets the line number for the current frame in the global stack trace.