Modifying variables during runtime
With GDB it's even possible to modify variables during runtime. This can be very handy for experimentation. Instead of changing the source code and recompiling the program, you can change the variable with GDB and see what happens.
Knowing how to change variables and arrays during runtime can speed up your debugging and experimentation phase.
Getting ready
For this recipe, you'll need the memtest.c
program from the previous recipe. You'll also need the Makefile from the Starting GDB recipe in this chapter, the Make tool, and the GCC compiler.
How to do it…
In this recipe, we'll continue using the program from the previous recipe. Here, we'll replace the null character in the sixth place with another character and the last character with a null character:
- If you haven't yet compiled the
memtest
program from the previous recipe, do so now:$> make memtest gcc -g -Wall -Wextra -pedantic -std...