1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.*; 22 import gov.nasa.jpf.Path; 23 import gov.nasa.jpf.util.*; 24 import gov.nasa.jpf.util.Printable; 25 26 import java.io.PrintWriter ; 27 28 33 public class TrailInfo implements Transition, Printable { 35 private int thread; 36 private int random; 37 private Step first, last; 38 int nSteps; 39 40 private Object annotation; 41 String output; 42 43 static boolean showSteps; 45 static boolean init (Config config) { 46 showSteps = config.getBoolean("vm.report.show_steps"); 47 return true; 48 } 49 50 public TrailInfo (int t, int r) { 51 thread = t; 52 random = r; 53 } 54 55 public String getLabel () { 56 if (last != null) { 57 return last.getLineString(); 58 } else { 59 return "?"; 60 } 61 } 62 63 public void setOutput (String s) { 64 output = s; 65 } 66 67 public void setAnnotation (Object o) { 68 annotation = o; 69 } 70 71 public Object getAnnotation () { 72 return annotation; 73 } 74 75 public String getOutput () { 76 return output; 77 } 78 79 public void setRandom (int r) { 80 random = r; 81 } 82 83 public int getRandom () { 84 return this.random; 85 } 86 87 public Step getStep (int index) { 88 Step s; 89 int i; 90 for (i=0, s=first; (s!= null) && (i<index); i++, s=s.next); 91 return s; 92 } 93 94 public Step getLastStep () { 95 return last; 96 } 97 98 public int getStepCount () { 99 return nSteps; 100 } 101 102 public int getThread () { 103 return this.thread; 104 } 105 106 109 public TransitionStep getTransitionStep (int index) { 110 return getStep(index); 111 } 112 113 116 public TransitionStep getLastTransitionStep () { 117 return last; 118 } 119 120 121 void addStep (Step step) { 122 if (first == null) { 123 first = step; 124 last = step; 125 } else { 126 last.next = step; 127 last = step; 128 } 129 nSteps++; 130 } 131 132 public void printOn (PrintWriter pw) { 133 SourceRef sr = new SourceRef(); 134 135 pw.print("Thread #"); 136 pw.print(thread); 137 138 if (random != -1) { 139 pw.print(" Random #"); 140 pw.print(random); 141 } 142 pw.println(); 143 144 if (showSteps) { 145 for (Step s=first; s != null; s = s.next) { 146 s.printStepOn(pw, sr, null); 147 } 148 } 149 } 150 151 public void toXML (PrintWriter pw) { 152 if (random == -1) { 153 pw.println("\t<Step Thread=\"" + getThread() + "\">"); 154 } else { 155 pw.println("\t<Step Thread=\"" + getThread() + "\" Random=\"" + 156 getRandom() + "\">"); 157 } 158 159 for (Step s=first; s!= null; s=s.next) { 160 s.toXML(pw); 161 } 162 163 pw.println("\t</Step>"); 164 } 165 166 public static void toXML (PrintWriter s, Path path) { 167 s.println("<?xml version=\"1.0\"?>"); 168 s.println("<!DOCTYPE Trace ["); 169 170 s.println("\t<!ELEMENT Trace (Step+)>"); 171 s.println("\t<!ATTLIST Trace"); 172 s.println("\t\tHandler CDATA #REQUIRED"); 173 s.println("\t\tApplication CDATA #REQUIRED"); 174 s.println("\t\tMessage CDATA #IMPLIED>"); 175 176 s.println("\t<!ELEMENT Step (Instruction+,Comment*)>"); 177 s.println("\t<!ATTLIST Step"); 178 s.println("\t\tThread CDATA #REQUIRED "); 179 s.println("\t\tRandom CDATA \"-1\">"); 180 181 s.println("\t<!ELEMENT Instruction (EMPTY)>"); 182 s.println("\t<!ATTLIST Instruction"); 183 s.println("\t\tFile CDATA #REQUIRED"); 184 s.println("\t\tLine CDATA #REQUIRED>"); 185 186 s.println("\t<!ELEMENT Comment (#PCDATA)>"); 187 s.println("]>"); 188 s.println(); 189 190 s.print("<Trace "); 191 s.print(" Handler=\"gov.nasa.jpf.jvm.JVMXMLTraceHandler\""); 192 s.print(" Application=\""); 193 s.print(JVM.getVM().getMainClassName()); 194 s.println("\">"); 195 196 for (int i = 0; i < path.length(); i++) { 197 TrailInfo ti = (TrailInfo) path.get(i); 198 ti.toXML(s); 199 } 200 201 s.println("</Trace>"); 202 } 203 } 204 | Popular Tags |