How to add code at the entry of every function?

前端 未结 6 854
悲哀的现实
悲哀的现实 2020-12-05 15:03

I want to add some code before every function call to do some checking. The only way I know is:

#define SOME_CODE printf(\"doing something...\");

class test         


        
6条回答
  •  抹茶落季
    2020-12-05 15:30

    A fair number of profilers (and similar tools) can/will do things like this. It's actually easier at the binary level than the source code level. At the source code level, it's sufficiently difficult that for most practical purposes you might as well treat it as impossible.

    Depending on the compiler you're using, there's a pretty fair chance that it has a flag to support such insertions -- usually present primarily to support the profilers and such I mentioned above.

提交回复
热议问题