Now start gdb again but before you start, run script gdb_example.txt to record your interaction. (You'll submit this interaction.) This time make sure you watch the array after. It is pretty slow to step through every line of your code, so use list to find the line number of the for loop where we start to assign values to the array. Set a breakpoint on that line number and also set a breakpoint somewhere before that line. Start your program using run and it should run up to the first breakpoint. Then use continue to jump to the second breakpoint you set which should be the for loop. At any point, you can use continue to execute up to the next breakpoint. If you tried it again now, it should jump to the second pass through the loop.

Instead, use next to step through one line at a time. Watch the value of after[0] carefully. When it changes, print its address. (Yes, you can do "print &(after[0])" inside gdb.) Then, print the address of a[4]. Does that help you understand what happened? Exit gdb. (Say 'y' when it asks if you want to Quit anyway.) Then exit your script by typing exit. Make sure the script file you generated is named gdb_example.txt and add it to your repository.

The last step is to try to make your program crash. (I had to set OVERFLOW to something like 5000 to get it to crash with a Segmentation fault.) Once you've found a value for OVERFLOW that produces a Segmentation fault, run the program in gdb without setting a breakpoint so that it runs automatically until the crash. Then use the backtrace command and the print command to investigate the value for i. Try backtrace full for even more helpful information. You don't need to record what you're doing on this step. We just want you to see the backtrace command.