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.
g++ -o test bad.cc
Execute it, and observe the segmentation fault.
Looking at the code, try to figure out what causes the segv fault.
Recompile the code: g++ -o test -D_GLIBCXX_DEBUG bad.cc
Excute test and observe a bit helpful message than segmentation fault.
Fix the error that causes the segmentation fault.
Compile and run to see the assert failure.
Recompile the code: g++ -o test -DNDEBUG bad.cc
Observe that the assertion failure disappeared.
Now, let's debug the code with gdb.
Compile the code with debugging option enabled: g++ -o test -ggdb bad.cc
Run the debugger: gdb ./test
Set a breakpoint at the assertion: b 14
Run the program: r
Print the filename: p filename
Find out why the filename contains that valie and fix it.
Be familar with other debugging commands such as next (n), step (s), and continue (c): man gdb
Fix the last bug in the code to print out the following outputs.
ddd ./test
Submit your bad.cc: ~cs253/bin/checkin L3R# bad.cc