I have some legacy C++ code that hasn’t been maintained in years. I’m trying to learn how it functions at the moment. It takes .xml input and should spit out an output text file. Two different .xml input files take vastly different amounts of time to process, and one of them behaves properly, the other doesn’t. They begin the same though. I’d like to output log files of the function calls made when I execute the code with the two different inputs and diff these logs against one another to see where they begin to diverge. I can’t just interrupt the code right at the first line of main() and step my way through the control flow in gdb. It’s taking way too long. Ideally, I’d like to find a way to do something like
gdb --args old_exec inp1.xml -step >log1.txt
gdb --args old_exec inp2.xml -step >log2.txt
diff log1.txt log2.txt
The “-step” flag isn’t real, of course, but maybe some way to tell it to log all the steps does exist. Any thoughts? Thanks!
The GCC compiler has a flag,
-finstrument-functions, which causes your functions to call specific functions on entry and exit; you can use this to track your code flow. With this flag in use, you will need to provide the following functions:and keep in mind that when you compile those functions, they must not be compiled with the intrumentation flag!
You can use addr2line to convert pointers to file/function/line numbers. It would generally be better to record the raw pointers at run-time, and perform post mortem address conversion.
See http://balau82.wordpress.com/2010/10/06/trace-and-profile-function-calls-with-gcc/ for more details.