Debugging Lab

In this lab, you will learn debugging tools such as assert, gdb, and C++ library debugging flag.

For a basic introduction to GDB, please take a look at this youtube video and man page.

  1. Download bad.cc.
  2. Compile it: g++ -o test bad.cc
  3. Execute it, and observe the segmentation fault.
  4. Looking at the code, try to figure out what causes the segv fault.
  5. Recompile the code: g++ -o test -D_GLIBCXX_DEBUG bad.cc
  6. Excute test and observe a bit helpful message than segmentation fault.
  7. Fix the error that causes the segmentation fault.
  8. Compile and run to see the assert failure.
  9. Recompile the code: g++ -o test -DNDEBUG bad.cc
  10. Observe that the assertion failure disappeared.
  11. Now, let's debug the code with gdb.
  12. Compile the code with debugging option enabled: g++ -o test -ggdb bad.cc
  13. Run the debugger: gdb ./test
  14. Set a breakpoint at the assertion: b 14
  15. Run the program: r
  16. Print the filename: p filename
  17. Find out why the filename contains that valie and fix it.
  18. Be familar with other debugging commands such as next (n), step (s), and continue (c): man gdb
  19. Fix the last bug in the code to print out the following outputs.
    The 3rd character is c
    search cs.colostate.edu colostate.edu
  20. Before submitting your work, try the graphical interface for GDB: ddd ./test
  21. Submit your bad.cc: ~cs253/bin/checkin L3R# bad.cc

Grading:

10 points: All bugs are fixed
9 points: Some bugs are fixed but not complete.
8 points: No bugs are fixed.

Note: Please use the exact name given.