This commit is contained in:
Kartik K. Agaram 2017-12-05 01:15:10 -08:00
parent 26b4bdc8b3
commit d51abbf123
5 changed files with 15 additions and 28 deletions

View File

@ -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")

View File

@ -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);

View File

@ -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;
}

View File

@ -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)

View File

@ -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;
}