'log file that contains the execution flow of a C or C++ program

I need to generate a log file that contains the execution flow of a C or C++ program. This log file should contain each line of the program (with line number specified) in the order that is executed. What can be use for that? I tried with GDB but I couldn't do it.



Solution 1:[1]

GDB can't do that automatically, but with simple script you should be able to step a program, until it ends and log everything. This will execute very slowly, as CPU will handle a breakpoint every few instructions. Also try looking into GDB's process reply feature.

There are other tools available for this purpose, as explained in this thread.

Hardware tools exist that can capture program execution "trace" while program is running at full speed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community