C++ macro to log every line of code

前端 未结 2 1254
小鲜肉
小鲜肉 2021-02-02 15:05

During one of my recent discussions with my manager, he mentioned that one of his former clients used a C++ macro to log info about every line of code. All they had to do was en

2条回答
  •  眼角桃花
    2021-02-02 15:16

    I don't know if every line/variable can be expanded like that, but function calls can be logged. I have logged all function calls using the -finstrument-functions option of gcc. It will call:

      void __cyg_profile_func_enter (void *this_fn, void *call_site);
    

    and

       void __cyg_profile_func_exit  (void *this_fn, void *call_site);
    

    for function enter and exit.

    The docs explain how to use it. I don't know if other compilers offer something similar.

提交回复
热议问题