CSE 221 Closed Lab 5 Instructions


Table of Contents


1. Objectives

To debug two buggy implementations of Swap_Substring.


2. Set Up

Two students should work together at ONE workstation.

  1. Login.


  2. In an xterm window, create a new directory (folder) for this closed lab by typing the "make directory" command:
         mkdir closed-lab05
  3. Change or move to the new directory (folder) for this closed lab by typing the "change directory" command:
         cd closed-lab05
  4. Copy the catalog for this closed lab by typing the "copy" command:
        cp -R /class/sce/now/221/closed-labs/catalogs/closed-lab05/*  . 
    NOTE: The period . is part of the command. It denotes the current directory (folder).

  5. To see what happened, type the "list" command with the "long" option:
         ls -l
    You should see something like the following:
      total 8
      drwx--S---   2 long     cisfact      512 May  5 16:40 buggy-1
      drwx--S---   2 long     cisfact      512 May  5 16:40 buggy-2
  6. The two directories buggy_1 and buggy_2 each contain buggy implementations of Swap_Substring, called Buggy_1.cpp and Buggy_2.cpp, respectively. In addition, they each contain the file test-script.

    There is a single bug in each of Buggy_1.cpp and Buggy_2.cpp. Your job is to locate and correct the bug in each. The tester-provided test cases from the warm-up exercise are your starting clues. You should first debug Buggy_1.cpp and then Buggy_2.cpp.




3. Perform Debugging

  1. Use the "change directory" command, cd, to move to directory buggy_1 and open Buggy_1.cpp in emacs. Take a look at Buggy_1.cpp and determine how you would like to proceed based on the tester's test case. Consider using some of the strategies discussed in the unit on debugging. This could include things like use of debug statements, tracing, and running your own test cases, either interactively or not.

  2. When you think that you have corrected the bug in Buggy_1.cpp, then do a Build Project to compile Buggy_1.cpp. Following this, test the corrected version. Do this by typing
        Buggy_1 < test-script
    in an xterm window. This will run Buggy_1, taking input from test-script and writing output to the monitor.


  3. Just as in closed lab 5, there are three possible outcomes to the test:
    1. You get a violated assertion error: In this case, there is still at least one bug in Buggy_1.cpp, so you will need to try one more time to debug it.

    2.  
    3. Your test script does not detect any bugs: As you look at the output on the monitor, it will NOT END with a message that looks like:
      ERROR DETECTED:
          expected // some value appears here
          observed // a different value appears here
      EXECUTION TERMINATING
      
      Process shell finished
      In this case you have successfully debugged Buggy_1.cpp. Congratulations!

    4.  
    5. Your test script detects a bug: The last test case executed will result in a message that looks like this one:
      -------------------------------------------------
                             |  t1  = "Swap_It_Out"
                             |  pos = 5
                             |  len = 0
                             |  t2  = ""
      -------------------------------------------------
      Swap_Substring (t1, pos, len, t2);  |
      -------------------------------------------------
                             |  t1  = "Swap_?It_Out"
                             |  pos = 5
                             |  len = 0
                             |  t2  = ""
      -------------------------------------------------
      
      ERROR DETECTED:
          expected t1 = Swap_It_Out
          observed t1 = Swap_?It_Out
      EXECUTION TERMINATING
      
      Process shell finished
      In this case, there is still at least one bug in Buggy_1.cpp, so you will need to try one more time to debug it.


    6. Once Buggy_1.cpp has been debugged, repeat the same process on Buggy_2.cpp.



    4. Proctor Check-off

    Let the proctor know when you have successfully debugged both Buggy_1.cpp and Buggy_2.cpp. The proctor will check that your work is correct.