If you know the lines where the variables change that you are interested in, then you can use the breakpoint command to do a simple tracing:
Example:
#include <iostream>
int main(int, char **)
{
for(int i = 0; i < 100; ++i)
{
std::cout << i << std::endl;
}
return 0;
}
When you compile this program like
c++ -g -o t1 t1.cpp
then you can use a breakpoint command like this:
break 7
commands
print i
continue
end
to generate a simple trace. This should also work for watchpoints (breakpoints that get triggered when a variable changes state).
Here's the log of an example gdb session:
$ gdb t1
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/t1...done.
(gdb) break 7
Breakpoint 1 at 0x40087c: file t1.cpp, line 7.
(gdb) commands
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>print i
>continue
>end
(gdb) set pagination off
(gdb) r
Starting program: /tmp/t1
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$1 = 0
0
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$2 = 1
1
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$3 = 2
2
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$4 = 3
3
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$5 = 4
4
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$6 = 5
5
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$7 = 6
6
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$8 = 7
7
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$9 = 8
8
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$10 = 9
9
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$11 = 10
10
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$12 = 11
11
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$13 = 12
12
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$14 = 13
13
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$15 = 14
14
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$16 = 15
15
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$17 = 16
16
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$18 = 17
17
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$19 = 18
18
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$20 = 19
19
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$21 = 20
20
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$22 = 21
21
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$23 = 22
22
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$24 = 23
23
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$25 = 24
24
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$26 = 25
25
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$27 = 26
26
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$28 = 27
27
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$29 = 28
28
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$30 = 29
29
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$31 = 30
30
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$32 = 31
31
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$33 = 32
32
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$34 = 33
33
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$35 = 34
34
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$36 = 35
35
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$37 = 36
36
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$38 = 37
37
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$39 = 38
38
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$40 = 39
39
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$41 = 40
40
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$42 = 41
41
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$43 = 42
42
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$44 = 43
43
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$45 = 44
44
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$46 = 45
45
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$47 = 46
46
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$48 = 47
47
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$49 = 48
48
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$50 = 49
49
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$51 = 50
50
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$52 = 51
51
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$53 = 52
52
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$54 = 53
53
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$55 = 54
54
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$56 = 55
55
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$57 = 56
56
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$58 = 57
57
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$59 = 58
58
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$60 = 59
59
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$61 = 60
60
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$62 = 61
61
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$63 = 62
62
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$64 = 63
63
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$65 = 64
64
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$66 = 65
65
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$67 = 66
66
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$68 = 67
67
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$69 = 68
68
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$70 = 69
69
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$71 = 70
70
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$72 = 71
71
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$73 = 72
72
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$74 = 73
73
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$75 = 74
74
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$76 = 75
75
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$77 = 76
76
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$78 = 77
77
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$79 = 78
78
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$80 = 79
79
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$81 = 80
80
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$82 = 81
81
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$83 = 82
82
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$84 = 83
83
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$85 = 84
84
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$86 = 85
85
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$87 = 86
86
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$88 = 87
87
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$89 = 88
88
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$90 = 89
89
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$91 = 90
90
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$92 = 91
91
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$93 = 92
92
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$94 = 93
93
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$95 = 94
94
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$96 = 95
95
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$97 = 96
96
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$98 = 97
97
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$99 = 98
98
Breakpoint 1, main () at t1.cpp:7
7 std::cout << i << std::endl;
$100 = 99
99
Program exited normally.
(gdb) q