diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-10-19 15:07:54 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-10-19 15:45:55 -0700 |
commit | 77cdc6d03f7b5660f6df6e57a6e50b015e41e3ea (patch) | |
tree | 1cf49f61c1fb1056b7fda6a84f4f2f95bd95fbae /003trace.cc | |
parent | f8aa4b17efed4f56b0c023cf40eb6d6000be1748 (diff) | |
download | mu-77cdc6d03f7b5660f6df6e57a6e50b015e41e3ea.tar.gz |
2271 - bugfix: traces cross-contaminating errors
There were several places where we push a call on to a routine without incrementing call-stack depth, which was used to compute the depth at which to trace an instruction. So sometimes you ended up one depth lower than you started a call with. Do this enough times and instructions that should be traced at level 100 end up at level 0 and pop up as errors. Solution: since call-stack depth is only used for tracing, include it in the trace stream and make sure we reset it along with the trace stream. Then catch all places where we forget to increment call-stack depth and make sure we catch such places in the future. When I first ran into this with Caleb I thought there must be some way that we're writing some output into the warnings result. I didn't recognize that the spurious output as part of the trace, just at the wrong level.
Diffstat (limited to '003trace.cc')
-rw-r--r-- | 003trace.cc | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/003trace.cc b/003trace.cc index 0193fa4f..2eab9017 100644 --- a/003trace.cc +++ b/003trace.cc @@ -108,9 +108,10 @@ struct trace_stream { ostringstream* curr_stream; string curr_label; int curr_depth; + int callstack_depth; int collect_depth; ofstream null_stream; // never opens a file, so writes silently fail - trace_stream() :curr_stream(NULL), curr_depth(0), collect_depth(Max_depth) {} + trace_stream() :curr_stream(NULL), curr_depth(Max_depth), callstack_depth(0), collect_depth(Max_depth) {} ~trace_stream() { if (curr_stream) delete curr_stream; } ostream& stream(string label) { @@ -147,9 +148,7 @@ struct trace_stream { label = trim(label); for (vector<trace_line>::iterator p = past_lines.begin(); p != past_lines.end(); ++p) if (label.empty() || label == p->label) { - if (p->depth) - output << std::setw(4) << p->depth << ' '; - output << p->label << ": " << p->contents << '\n'; + output << std::setw(4) << p->depth << ' ' << p->label << ": " << p->contents << '\n'; } return output.str(); } @@ -359,15 +358,12 @@ using std::ofstream; :(before "End Globals") //: In future layers we'll use the depth field as follows: //: -//: Mu 'applications' will be able to use depths 1-100 as they like. +//: Errors will be depth 0. +//: Warnings will be depth 1. +//: Mu 'applications' will be able to use depths 2-100 as they like. //: Primitive statements will occupy 101-9998 const int Initial_callstack_depth = 101; const int Max_callstack_depth = 9998; -//: (ignore this until the call layer) -:(before "End Globals") -int Callstack_depth = 0; -:(before "End Setup") -Callstack_depth = 0; //: Finally, details of primitive mu statements will occupy depth 9999 (more on that later as well) :(before "End Globals") const int Primitive_recipe_depth = 9999; |