about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--003trace.cc12
-rw-r--r--020run.cc12
-rw-r--r--029tools.cc6
-rw-r--r--036refcount.cc7
-rw-r--r--050scenario.cc6
5 files changed, 15 insertions, 28 deletions
diff --git a/003trace.cc b/003trace.cc
index 7a062b63..7c9801e8 100644
--- a/003trace.cc
+++ b/003trace.cc
@@ -117,6 +117,12 @@ struct trace_stream {
     return *curr_stream;
   }
 
+  void dump() {
+    ofstream fout("last_run");
+    fout << readable_contents("");
+    fout.close();
+  }
+
   // be sure to call this before messing with curr_stream or curr_label
   void newline();
   // useful for debugging
@@ -214,11 +220,7 @@ struct lease_tracer {
 lease_tracer::lease_tracer() { Trace_stream = new trace_stream; }
 lease_tracer::~lease_tracer() {
   if (!Trace_stream) return;  // in case tests close Trace_stream
-  if (Save_trace) {
-    ofstream fout("last_run");
-    fout << Trace_stream->readable_contents("");
-    fout.close();
-  }
+  if (Save_trace) Trace_stream->dump();
   delete Trace_stream, Trace_stream = NULL;
 }
 :(before "End Includes")
diff --git a/020run.cc b/020run.cc
index b94d274a..4d151b93 100644
--- a/020run.cc
+++ b/020run.cc
@@ -233,13 +233,11 @@ else if (is_equal(*arg, "--trace")) {
 
 :(code)
 void cleanup_main() {
-  if (Save_trace && Trace_stream) {
-    cerr << "writing trace to 'last_run'\n";
-    ofstream fout("last_run");
-    fout << Trace_stream->readable_contents("");
-    fout.close();
-  }
-  if (Trace_stream) delete Trace_stream, Trace_stream = NULL;
+  if (!Trace_stream) return;
+  if (Save_trace);
+    Trace_stream->dump();
+  delete Trace_stream;
+  Trace_stream = NULL;
 }
 :(before "End One-time Setup")
 atexit(cleanup_main);
diff --git a/029tools.cc b/029tools.cc
index ca86b397..244b72b2 100644
--- a/029tools.cc
+++ b/029tools.cc
@@ -179,11 +179,7 @@ case _SAVE_TRACE: {
 }
 :(before "End Primitive Recipe Implementations")
 case _SAVE_TRACE: {
-  if (Save_trace) {
-    ofstream fout("last_run");
-    fout << Trace_stream->readable_contents("");
-    fout.close();
-  }
+  if (Save_trace) Trace_stream->dump();
   break;
 }
 
diff --git a/036refcount.cc b/036refcount.cc
index 69c00d05..075060ba 100644
--- a/036refcount.cc
+++ b/036refcount.cc
@@ -75,12 +75,7 @@ void decrement_refcount(int old_address, const type_tree* payload_type, int payl
   put(Memory, old_address, old_refcount);
   if (old_refcount < 0) {
     cerr << "Negative refcount!!! " << old_address << ' ' << old_refcount << '\n';
-    if (Trace_stream) {
-      cerr << "Saving trace to last_run.\n";
-      ofstream fout("last_run");
-      fout << Trace_stream->readable_contents("");
-      fout.close();
-    }
+    if (Trace_stream) Trace_stream->dump();
     exit(1);
   }
   // End Decrement Refcount(old_address, payload_type, payload_size)
diff --git a/050scenario.cc b/050scenario.cc
index b7d5b58b..e84a18e9 100644
--- a/050scenario.cc
+++ b/050scenario.cc
@@ -229,11 +229,7 @@ void run_mu_scenario(const scenario& s) {
   if (!Hide_errors && trace_contains_errors() && !Scenario_testing_scenario)
     Passed = false;
   if (not_already_inside_test && Trace_stream) {
-    if (Save_trace) {
-      ofstream fout("last_run");
-      fout << Trace_stream->readable_contents("");
-      fout.close();
-    }
+    if (Save_trace) Trace_stream->dump();
     delete Trace_stream;
     Trace_stream = NULL;
   }