- Without being able to examine variables contents during program execution, the whole idea of using a debugger is quite lost. You can print the contents of a variable with a command like this:
(gdb) print i
And then you'll get a message like:
$1 = 0
which means that "i" contains the number "0".
- Note that this requires "i" to be in scope, or you'll get a message such as:
No symbol "i" in current context.
- For example, if you break inside the "print_string" function and try to print the value of "i", you'll get this message. You may also try to print more complex expressions, like "i*2", or "argv[3]", or "argv[argc]", and so on.
- In fact, you may also use type casts, call functions found in the program. Again, this is a good time to try this out.
Cem Ozdogan
2011-02-14