I want to have a log for C++ program that will trace every executed line. How to do that?
Private research annotation
Sign in to add a private research label or note.
Jump to turn (21)
- 1I want to have a log for C++ program that will trace every executed line. How to
- 2are there any tools to do that automatically?
- 3what is difference between gcov and lcov?
- 4how to instrument every if condition similar to what you can get using \\cyg\pro
- 5is it possible using compiler options?
- 6I don't want to instrument functions. I want to instrument is statements without
- 7how libInstrumentIfStatements could look like?
- 8what will be result for int main() { if (1 < 2) std::cout << "true"; else std::c
- 9can you change the library to print also condition and the result of evaluation?
- 10how to make it work with variables in runtime?
- 11continue
- 12continue
- 13what will be the result for the program I provided before?
- 14can you make it print the condition itself?
- 15what will be the result for my program?
- 16also add printing the result of evaluation
- 17what will be the result for my programm?
- 18white the library again
- 19write the example of IfInstrumenterVisitor again
- 20continue
- 21how to compile it?
- User
I want to have a log for C++ program that will trace every executed line. How to do that?
- Assistant
There are several ways to log every executed line in a C++ program. One approach is to use the preprocessor to add logging statements before each line of code. Another approach is to use a debugging tool such as gdb to set breakpoints on each line and print the current line when the breakpoint is hit.
Here is an example of how to use the preprocessor to add logging statements:
code#define LOG(x) std::cout << x << std::endl; int main() { LOG("Starting program"); int a = 5; LOG("a = " << a); return 0; }This will print "Starting program" and "a = 5" to the console when the program runs.
To use gdb to log the executed line, you can use the following command