用于 penter 和 pexit 的 Visual Studio 宏 [英] Visual Studio macro for penter and pexit
问题描述
我正在一个项目中制作一个分析器,我想让它很容易集成到我的项目中.我将 penter 和 pexit 与/GH/Gh 编译器标志一起使用,因此每次调用或返回函数时都会调用这些函数.现在,基本上我在我的项目中要做的就是在全局范围内的任何地方复制 penter 和 pexit 函数,这有效,但我想制作一个宏,所以它基本上只是插入函数.我定义了宏我的 Profiler.h 文件并将其包含在我的其他项目中.我得到的错误是
I'm making a profiler in a project, and I want to make it easy to integrate into my projects. I'm using penter and pexit with the /GH /Gh compiler flags so those functions are called every time a function is called or returned from. Right now, basically all I have to do in my projects is copy over the penter and pexit function anywhere in the global scope and that works, but I want to make a macro so it just basically inserts the function in. I defined the macro in my Profiler.h file and included that in my other project. the errors i'm getting are
error C2598: linkage specification must be at global scope
error C2601: '_pexit' : local function definitions are illegal
error C1075: end of file found before the left brace '{' at 'path/main.cpp' was matched
请注意,path/main.cpp"是我的项目(非分析器项目)的长路径,而 main 是我调用"宏的地方
note that 'path/main.cpp' is a long path to my project (non-profiler project) and main is where i'm 'calling' the macros
这是我的宏,我一定是理解错了.我想它只是在它被调用"的地方插入函数
here are my macros, I must be understanding these wrong. I figured it'd just insert the function where it was '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; \
} \
感谢您的帮助!
推荐答案
你可以试试 micro-profiler 来完成任务.或者从这里获取它的收集源:hooks.asm它的好处是它也适用于 x64(您不能在 x64 cpp 中注入汇编指令).
You can try micro-profiler to do the task. Or take it's source for collection from here: hooks.asm The good thing about it is that it works for x64 as well (you cannot inject assembly instructions in x64 cpp).
这篇关于用于 penter 和 pexit 的 Visual Studio 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!