c++ - Visual Studio macro for penter and pexit -
i'm making profiler in project, , want make easy integrate projects. i'm using penter , pexit /gh /gh compiler flags functions called every time function called or returned from. right now, have in projects copy on penter , pexit function anywhere in global scope , works, want make macro inserts function in. defined macro in profiler.h file , included in other project. errors i'm getting
error c2598: linkage specification must @ global scope error c2601: '_pexit' : local function definitions illegal error c1075: end of file found before left brace '{' @ 'path/main.cpp' matched
note 'path/main.cpp' long path project (non-profiler project) , main i'm 'calling' macros
here macros, must understanding these wrong. figured it'd insert function 'called'
#define penter \ extern "c" void __declspec(naked) _cdecl _penter(void) \ { \ _asm push ebp; \ _asm mov ebp, esp; \ _asm pushad; \ profiler::getinstance().enter(); \ _asm popad; \ _asm mov esp, ebp; \ _asm pop ebp; \ _asm ret; \ } \ #define pexit \ extern "c" void __declspec(naked) _cdecl _pexit(void) \ { \ _asm push ebp; \ _asm mov ebp, esp; \ _asm pushad; \ profiler::getinstance().exit(); \ _asm popad; \ _asm mov esp, ebp; \ _asm pop ebp; \ _asm ret; \ } \
thanks help!
you missing } @ place before profiler.h.
i use inline
function instead of multiline macro.
extern "c" inline void __declspec(naked) _cdecl _pexit(void) {
_asm pushad; profiler::getinstance().exit(); _asm popad; _asm ret; }
(that way, it's possible step function when debugging - @ least in debug mode when it's not inlined).
i removed unnecessary esp
/ebp
saving , restoring - pushad save registers (even esp) [and technically, need save/restore scratch registers, eax, ecx , edx, other registers must saved function(s) call.
Comments
Post a Comment