How to add code at the entry of every function?

前端 未结 6 861
悲哀的现实
悲哀的现实 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:48

    What you are looking for is called "code instrumentation" and I gave a talk at GDC 2012 on manual and compiler-automated instrumentation (click here for code samples).

    There are a number of ways to do what you want. Wrapper functions, Detours and Trampolines, or CAI (compiler-automated instrumentation) which is _penter() / __cyg_profile_func_enter() methods mentioned in other answers.

    All of these as well as some other instrumentation methods are detailed in the PDF's linked above.

提交回复
热议问题