Automatically adding Enter/Exit Function Logs to a Project

后端 未结 5 908
攒了一身酷
攒了一身酷 2020-11-29 04:42

I have a 3rd party source code that I have to investigate. I want to see in what order the functions are called but I don\'t want to waste my time typing:

pr         


        
5条回答
  •  温柔的废话
    2020-11-29 05:03

    Besides the usual debugger and aspect-oriented programming techniques, you can also inject your own instrumentation functions using gcc's -finstrument-functions command line options. You'll have to implement your own __cyg_profile_func_enter() and __cyg_profile_func_exit() functions (declare these as extern "C" in C++).

    They provide a means to track what function was called from where. However, the interface is a bit difficult to use since the address of the function being called and its call site are passed instead of a function name, for example. You could log the addresses, and then pull the corresponding names from the symbol table using something like objdump --syms or nm, assuming of course the symbols haven't been stripped from the binaries in question.

    It may just be easier to use gdb. YMMV. :)

提交回复
热议问题