Tangible Code


/*
  From the Omniscient Debugger:
  http://www.lambdacs.com/debugger/debugger.html
*/

import java.io.*; 
import java.util.*; 
 
/* 
  Demo quick sort program with a bug. 
  QuickSortNonThreaded 10             works correctly 
  QuickSortNonThreaded 11             doesn't! 
*/ 
 
public class QuickSortNonThreaded { 
    static int   MAX; 
    int[]             array; 
 
     
public static void main(String[] argv) { int n = 11; if (argv.length > 0) n = Integer.parseInt(argv[0]); long start = System.currentTimeMillis(); sortNElements(n); long end = System.currentTimeMillis(); long total = end-start; System.out.println(""+ total + "ms"); }
public static void main(String[] argv<String[0]>) { int n11=11; if (argv.length0 > 0) n = Integer.parseInt(argv[0]); long start1117345=System.currentTimeMillis(); sortNElements(n11); long end1117395=System.currentTimeMillis(); long total50=end1117395-start1117345; System.out.println(""+ total50 + "ms"); }
public static void sortNElements(int nElements) { MAX = nElements; System.out.println("-------------- QuickSortNonThreaded Program ----------------"); QuickSortNonThreaded q = new QuickSortNonThreaded(); q.array = new int[MAX]; q.array[0] = 1; // More-or-less random for (int i=1; i < MAX; i++) q.array[i] = ((i-1)*1233)%1974; q.sortAll(); q.checkOrder(); q.printAll(); }
^ public static void sortNElements(int nElements11) {
MAX11=nElements11; System.out.println("-------------- QuickSortNonThreaded Program ----------------"); QuickSortNonThreaded q<QuickSortNonThreaded>=new QuickSortNonThreaded(); q.array<int[11]>=new int[MAX11]; q.array[0]1=1; // More-or-less random
for (int i1=1; i1 < MAX11; i++) q.array[i1]0 = ((i1-1)*1233)%1974;
for (int i=1; i2 < MAX11; i1++) q.array[i2]1233 = ((i2-1)*1233)%1974;
for (int i=1; i3 < MAX11; i2++) q.array[i3]492 = ((i3-1)*1233)%1974;
for (int i=1; i4 < MAX11; i3++) q.array[i4]1725 = ((i4-1)*1233)%1974;
for (int i=1; i5 < MAX11; i4++) q.array[i5]984 = ((i5-1)*1233)%1974;
for (int i=1; i6 < MAX11; i5++) q.array[i6]243 = ((i6-1)*1233)%1974;
for (int i=1; i7 < MAX11; i6++) q.array[i7]1476 = ((i7-1)*1233)%1974;
for (int i=1; i8 < MAX11; i7++) q.array[i8]735 = ((i8-1)*1233)%1974;
for (int i=1; i9 < MAX11; i8++) q.array[i9]1968 = ((i9-1)*1233)%1974;
for (int i=1; i10 < MAX11; i9++) q.array[i10]1227 = ((i10-1)*1233)%1974;
q.sortAll(); q.checkOrder(); q.printAll(); }
public void sortAll() { sort(0, MAX-1); }
^ public void sortAll() {
sort(0, MAX11-1); }
public void checkOrder() { for (int i=1; i < MAX; i++) { if (array[i-1] > array[i]) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); } }
^ public void checkOrder() {
for (int i1=1; i1 < MAX11; i++) { if (array[i1-1]0 > array[i1]1) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i2 < MAX11; i1++) { if (array[i2-1]1 > array[i2]243) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i3 < MAX11; i2++) { if (array[i3-1]243 > array[i3]492) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i4 < MAX11; i3++) { if (array[i4-1]492 > array[i4]735) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i5 < MAX11; i4++) { if (array[i5-1]735 > array[i5]984) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i6 < MAX11; i5++) { if (array[i6-1]984 > array[i6]1227) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i7 < MAX11; i6++) { if (array[i7-1]1227 > array[i7]1233) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i8 < MAX11; i7++) { if (array[i8-1]1233 > array[i8]1476) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i9 < MAX11; i8++) { if (array[i9-1]1476 > array[i9]1968) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
for (int i=1; i10 < MAX11; i9++) { if (array[i10-1]1968 > array[i10]1725) System.out.println("Out of order: array[" + (i10-1) + "]="+array[i10-1]1968 +" > array["+i10+"]="+array[i10]1725); }
for (int i=1; i11 < MAX11; i10++) { if (array[i-1] > array[i]) System.out.println("Out of order: array[" + (i-1) + "]="+array[i-1] +" > array["+i+"]="+array[i]); }
}
public void printAll() { int top = MAX; if (MAX > 100) top=100; for (int i=0; i < top; i++) { System.out.println(i + " "+ array[i]); } }
^ public void printAll() {
int top11 = MAX11; if (MAX11 > 100) top=100;
for (int i0=0; i0 < top11; i++) { System.out.println(i0 + " "+ array[i0]0); }
for (int i=0; i1 < top11; i0++) { System.out.println(i1 + " "+ array[i1]1); }
for (int i=0; i2 < top11; i1++) { System.out.println(i2 + " "+ array[i2]243); }
for (int i=0; i3 < top11; i2++) { System.out.println(i3 + " "+ array[i3]492); }
for (int i=0; i4 < top11; i3++) { System.out.println(i4 + " "+ array[i4]735); }
for (int i=0; i5 < top11; i4++) { System.out.println(i5 + " "+ array[i5]984); }
for (int i=0; i6 < top11; i5++) { System.out.println(i6 + " "+ array[i6]1227); }
for (int i=0; i7 < top11; i6++) { System.out.println(i7 + " "+ array[i7]1233); }
for (int i=0; i8 < top11; i7++) { System.out.println(i8 + " "+ array[i8]1476); }
for (int i=0; i9 < top11; i8++) { System.out.println(i9 + " "+ array[i9]1968); }
for (int i=0; i10 < top11; i9++) { System.out.println(i10 + " "+ array[i10]1725); }
for (int i=0; i11 < top11; i10++) { System.out.println(i + " "+ array[i]); }
}
// **** This will be called both recursively and from different threads. ****
public void sort(int start, int end) { int i, j, tmp, average, middle; if ((end - start) < 1) return; // One element, done! if ((end - start) == 1) { // Two elements, sort directly if (array[end] > array[start]) return; tmp = array[start]; array[start] = array[end]; array[end] = tmp; return; } average = average(start, end); middle = end; // This will become the pivot point L: for (i = start; i < middle; i++) { // Start the pivot: if (array[i] > average) { // Move all values > average up, for (j = middle; j > i; j--) { if (array[j] <= average) { // all values <= average down. tmp = array[i]; array[i] = array[j]; array[j] = tmp; middle = j; // The pivot point remains in the middle continue L; } } } } sort(start, middle-1); // Do the bottom half here. sort(middle, end); // Do the top half here. return; }
^ public void sort(int start0, int end10) {
int i, j, tmp, average, middle; if ((end10 - start0) < 1) return; // One element, done! if ((end10 - start0) == 1) { // Two elements, sort directly if (array[end] > array[start]) return; tmp = array[start]; array[start] = array[end]; array[end] = tmp; return; } average885 = average(start0, end10); middle10 = end10; // This will become the pivot point L: for (i = start0; i < middle; i++) { // Start the pivot: if (array[i] > average) { // Move all values > average up, for (j = middle; j > i; j--) { if (array[j] <= average) { // all values <= average down. tmp = array[i]; array[i] = array[j]; array[j] = tmp; middle = j; // The pivot point remains in the middle continue L; } } } } sort(start0, middle6-1); // Do the bottom half here. sort(middle6, end10); // Do the top half here. return; }
public int average(int start, int end) { int sum = 0; for (int i = start; i < end; i++) { sum += array[i]; } return (sum/(end-start)); }
^ public int average(int start0, int end10)
885
{
int sum0 = 0;
for (int i0=start0; i0 < end10; i++) { sum1 += array[i0]1; }
for (int i=start; i1 < end10; i0++) { sum1 += array[i1]0; }
for (int i=start; i2 < end10; i1++) { sum1234 += array[i2]1233; }
for (int i=start; i3 < end10; i2++) { sum1726 += array[i3]492; }
for (int i=start; i4 < end10; i3++) { sum3451 += array[i4]1725; }
for (int i=start; i5 < end10; i4++) { sum4435 += array[i5]984; }
for (int i=start; i6 < end10; i5++) { sum4678 += array[i6]243; }
for (int i=start; i7 < end10; i6++) { sum6154 += array[i7]1476; }
for (int i=start; i8 < end10; i7++) { sum6889 += array[i8]735; }
for (int i=start; i9 < end10; i8++) { sum8857 += array[i9]1968; }
for (int i=start; i10 < end10; i9++) { sum += array[i]; }
return sum8857/(end10-start0)); }
}
 main
   sortNElements
     sortAll
       sort(0, 10)
           average(0, 10)
          sort(0, 5)9
          sort(6, 10)6
      checkOrder
      printAll

 

This is a prototype of a tracing debugger. First, an instrumented version of the program yields a detailed log of the execution. Then, after the program terminates, this interface provides a structured view of that log.

On the right is the hierarchical trace of function calls. To the right of each collapsed line is the number of function called from that function (e.g. sort(0, 6) has 9 calls nested beneath it). Clicking a line in the trace highlights in the code that particular call to that particular function: the "live function".

Within the live function, the values of each variable are shown next to it. Function calls are underlined, and clicking one jumps to it, making it the live function. Clicking the up arrow button next to the function name jumps back to the calling function. The buttons next to a loop cycle through its iterations. Unreached code is grayed out.

Within the live function, the values of each variable are shown next to it. Function calls are underlined, and clicking one jumps to it, making it the live function. Clicking the up arrow button next to the function name jumps back to the calling function. The buttons next to a loop cycle through its iterations. Unreached code is grayed out.

For more information see: the project overview, design principles, interface specification, and the thesis report [pdf].

 

What do you think?

Would you prefer this type of tool to a traditional debugger? Why?

What would you change about/add to the interface?

Your email address (optional):