是否有一个编译器功能,注入自定义函数入口和出口code? [英] Is there a compiler feature to inject custom function entry and exit code?

查看:99
本文介绍了是否有一个编译器功能,注入自定义函数入口和出口code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前的编码在Windows上使用VS2005(但也不会介意知道是否有其他的编译器和平台的选择,我最感兴趣的OSX作为替代平台)。我有一个C(无C ++)计划,我倒是喜欢做以下...

Currently coding on Windows with VS2005 (but wouldn't mind knowing if there are options for other compilers and platforms. I'm most interested in OSX as an alternative platform.) I have a C (no C++) program and I'd like to do the following...

给出一个函数,比如...

Given a function, say...

int MyFunction(int myparam)
{
   // Entry point.
   ...
   // Exit point.
   return 1;
}

我喜欢把code的片段在入口点和出口点。但是,我宁愿没有修改100的那都已经在那里等功能。有没有一种方法来定义函数入口和出口code编译器将注入我的所有功能,而无需修改它们呢?

I'd like to put a snippet of code at the entry point and at the exit point. BUT, I'd rather not have to modify the 100's of functions that are already out there. Is there a way to define function entry and exit code that the compiler will inject for all my functions without having to modify them all?

我发现或试图将需要我编辑的每一个功能,这是一个大量的工作大多数解决方案。我想有人一定已经打这样的事情,并解决它。我不能在这个要求我怀疑是独一无二的。

Most solutions I've found or tried will require me to edit every single function, which is a lot of work. I figure someone else must have hit something like this already and solved it. I can't be unique in this request I suspect.

推荐答案

这是微软特有的,但你可以挂接到的 _penter _pexit 功能进入和退出函数时做一些事情 - 你有一些特殊的标志来编译您的项目

It's Microsoft-specific, but you can hook into the _penter and _pexit functions to do something when entering and exiting a function -- you'll have to compile your project with some special flags.

教程一点点这里有,你可以找到如何使用他们在谷歌多了一些成果。此外,这个博客帖子进入上你需要做的,以避免搞乱入境堆叠装配的一些细节并退出。

There's a little bit of a tutorial here, and you can find a few more results on how to use them on Google. Also, this blog post goes into some detail on the assembly that you need to do to avoid messing up the stack on entry and exit.

这篇关于是否有一个编译器功能,注入自定义函数入口和出口code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆