COMP 2673 - Lab3 In-lab Assignment Goals: Introduction to ddd - After this lab you should know: how to compile a program so that it can be debugged how to start and quit ddd how to set breakpoints, run, step into, step over, and continue how to examine the values of variables __________________________________________________________________________ What is GDB? GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed. GDB can do four main kinds of things to help you catch bugs in the act: 1. Start your program, specifying anything that might affect its behavior. 2. Make your program stop on specified conditions. 3. Examine what has happened, when your program has stopped. 4. Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. The program being debugged can be written in C, C++, Pascal (and many other languages). Those programs might be executing on the same machine as GDB (native) or on another machine (remote). GDB can run on most popular UNIX and Microsoft Windows variants. In this lab, we would use ddd (Data Display Debugger), which is a GUI version of gdb. __________________________________________________________________________ Steps: 1. Go to your directory IntroToCS3. 2. Copy the file ~sarora/IntroToCS3/linkedlist.tgz to your directory. 3. Extract the assignment 3 files from this file using the command: tar -xvzf linkedlist.tgz 4. The above command will create a directory "linkedlist". 5. Enter this directory. 6. Compile the files by typing "make". This creates an executable file by the name "executable". "executable" is a program that performs addition, deletion and traversal on linked lists, and it has some bugs that we will locate and fix using debugger in today's lab. 7. If you look in the Makefile, the files have been compiled using the "-g" option. This option stores debug information in the "executable", which is essential if you want to use a degugger on this executable. You would want to remove this option once the executable is working correctly as this extra information slows down execution of the program. 8. Open the file in the debugger by typing "ddd executable &". This would open the source file (corresponding to the executable) which contains the function "main()". In this case it will open "llist.cpp" in the ddd window (because "llist.cpp" is the file corresponding to "executable" that contains the function "main()"). 9. Click close on the dialog box "DDD Tip of the day". 10. Set a breakpoint on the first line inside the function main() as follows: - Right click on the beginning of that line. - Select "Set Breakpoint". 11. Start running the program in the debugger by pressing F2 and then in the dialog box which appears click "Run". 12. Press 8 to view the command tool. 13. Execute the program in the debugger, and experiment with the following commands: - Click "Step" in the command tool window to "step inside" the statement. - Click "Next" in the command tool window to run the next statement. - Click "Cont" in the command tool window to continue execution till the the next "termination point", which is either a Breakpoint you have set, a fatal error in the program or the end of program. - Toggle a breakpoint by moving the cursor to a line and using the "stop" button. 14. The execution stops at the line (green arrow becomes a broken red arrow): cout<Data<<" -> "; 15. Press 3 to view the data window. 16. In the data window, right click and select "New Display...". 17. In the dialog box for "New Display" type "temp" and click "Display". 18. The value of variable "temp" shows up in the data window. 19. Right click on this value and select "Display *()". 20. The value of location pointed to by "temp" shows up in the data window. 21. Start running the program again by clicking "Run" in the command tool. 22. In the dialog box which appears click "Yes". 23. Click "Next" in the command tool window. 24. Click "Step" in the command tool window. 25. The variable "temp" becomes visible in the data window. 24. Click "Next" again in the command tool window. 25. The change in the value of the variable "temp" can be seen in the data window. 26. Click "Next" repeatedly in the command tool window until the program crashes (the green arrow becomes a broken red arrow) . 27. Write down on a piece of paper your name and the reason you think the program crashed. Also suggest a way (i.e. give correct code for that part) to fix this bug. Turn-in this paper to TA. 28. (EXTRA CREDIT) Figure out (on your own) how to set a "temporary breakpoint", experiment with "temporary breakpoint" and figure out the difference between a "breakpoint" and a "temporary breakpoint". Write down the difference on on a piece of paper and Turn-in this paper to TA. 29. Quit the debugger by pressing Q.