Skip to content

Instantly share code, notes, and snippets.

@solodon4
Created June 24, 2019 02:04
Show Gist options
  • Save solodon4/84527abdf4255dc5b582b1c482d93323 to your computer and use it in GitHub Desktop.
Save solodon4/84527abdf4255dc5b582b1c482d93323 to your computer and use it in GitHub Desktop.
func_tracer
#if defined(DEBUG)
#include <stdio.h>
#include <string.h>
#include <typeinfo>
struct func_tracer
{
__declspec(non_user_code)
func_tracer(const char* fn, const char* tp = nullptr, const void* thisptr = nullptr) : func_name(fn), this_type(tp), this_ptr(thisptr)
{
if (this_ptr)
printf("%*c %p->%s::%s\n", indent++*2, '>', this_ptr, this_type, func_name);
else
printf("%*c %s\n" , indent++*2, '>', func_name);
}
__declspec(non_user_code)
~func_tracer()
{
if (this_ptr)
printf("%*c %p->%s::%s\n", --indent*2, '<', this_ptr, this_type, func_name);
else
printf("%*c %s\n" , --indent*2, '<', func_name);
}
const char* func_name;
const char* this_type;
const void* this_ptr;
static unsigned int indent;
};
unsigned int func_tracer::indent = 0;
#define TR func_tracer fntr(__func__, strchr(typeid(*this).name(),' ')+1, this)
#define PR(format, ...) printf("%*c " format, func_tracer::indent*2, ':', __VA_ARGS__);
#define RT func_tracer fntr(__func__)
#else
#define TR
#define PR(format, ...)
#define RT
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment