See the this pointer for C++ objects

BAS_METHOD is an alternative tracing macro to use for method on C++ objects. It gives is a unique pointer for the “this” pointer of the object we are tracing calls into the methods of. This is what a trace might look like for a APPfoo object with this code:

#include <BAS/BASstring.h> #include <BAS/BAStrace.h> BAS_TRACE_INIT; class BASstring; class APPfoo{ public: APPfoo(); ~APPfoo(); void run(const BASstring& Value, int Count); }; APPfoo::APPfoo(){ BAS_METHOD(APPfoo::APPfoo); } APPfoo::~APPfoo(){ BAS_METHOD(APPfoo::~APPfoo); } void APPfoo::run(const BASstring& Value, int Count){ BAS_METHOD(APPfoo::run); BAS_VAR2(Value, Count); BASstring Out; for (int i=0; i < Count; i++){ BAS_VAR(i); Out += Value + "\n"; } BAS_HEX("Dump", Out.data(), Out.size()); BASout << Out; }

Here’s the potential trace:

17:58:05.844701 0x1107d25c0 APPfoo . >APPfoo::APPfoo Line:10 this=0x7ffee9b9d7d0 17:58:05.844756 0x1107d25c0 APPfoo . <APPfoo::APPfoo 17:58:05.844798 0x1107d25c0 main . About to call run on Foo 17:58:05.844832 0x1107d25c0 APPfoo . >APPfoo::run Line:17 this=0x7ffee9b9d7d0 17:58:05.844889 0x1107d25c0 APPfoo . . Value = Rabbit, Count = 5 17:58:05.844924 0x1107d25c0 APPfoo . . i = 0 17:58:05.844960 0x1107d25c0 APPfoo . . i = 1 17:58:05.844995 0x1107d25c0 APPfoo . . i = 2 17:58:05.845029 0x1107d25c0 APPfoo . . i = 3 17:58:05.845064 0x1107d25c0 APPfoo . . i = 4 17:58:05.845104 0x1107d25c0 APPfoo . . Dump= (size=35) 52 61 62 62 69 74 0A 52 Rabb it.R 61 62 62 69 74 0A 52 61 abbi t.Ra 62 62 69 74 0A 52 61 62 bbit .Rab 62 69 74 0A 52 61 62 62 bit. Rabb 69 74 0A it. 17:58:05.845140 0x1107d25c0 APPfoo . <APPfoo::run 17:58:05.845182 0x1107d25c0 main . All done! 17:58:05.845217 0x1107d25c0 APPfoo . >APPfoo::~APPfoo Line:13 this=0x7ffee9b9d7d0 17:58:05.845271 0x1107d25c0 APPfoo . <APPfoo::~APPfoo 17:58:05.845326 0x1107d25c0 main <main

This is super helpful when debugging for the lifetime of C++ objects in an application.