Three things:
1) That parser/decorator would probably be a nightmare to write, and even then would likely miss many special cases. I only say this because I have written many arbitrary parsers myself, and when you have no control over the content you are parsing, the complexity increases dramatically.
You may be correct. I don't know. However, unless the scripts have very strict syntax rules (which I don't think they do), adding a line of code to execute before and after the main body of the script should be straightforward and quite doable.
2) Even if you could write a "good" parser, there are other issues. What about the rights to alter other modders' code? Can you get permission from them all? Probably not.
Since you are not proposing to distribute the "altered" code, rights do not come into play. We currently clean other modders' mods without their permission. This would be a very similar process.
3) I don't know if the Oblivion modding framework would even be able to do this. I am no expert, but I can't think of any mods that alter other mods' scripts. There are plugins that replace scripts, but I don't know of any that re-write them.
Since we have direct access to the script, we can treat it as data and do whatever we want to it. The question as I see it more along the lines of can the debug line be dumped to a file before a crash happens (hence the question about the viability of critical sections).
I don't know... I maybe just don't understand what is available, but this approach seems very problematic to me.
Sorry, it's the best one I can come up with to address what I see as a glaring lack in the Oblivion extension implementation.
I don't know about altering scripts, but what about an anologue of the ShowQuestVariables console function, which will print the values of any quest script variables. AFAIK quest scripts are the only sort that run all the time, and so are the only ones that would not be simple to track down normally (ie. if you cast a spell and the game crashes, it's obvious the spell is bugged, but a quest script can bug at any time).
Actually casting a spell could tweak a problem in a running script and cause the game to crash as a side effect rather than a direct effect of the spell. The goal for me is to get a better of idea of what the game was doing when the crash happened. I've used automated decoration of code in the past to address similar problems. I don't know if it will work here.
I know jack and squat about programming, so apologies if this is dumb:
Instead of trying to alter every script with additional code, would it be possible to create a log showing each script that executes so you could look at the log and see something like:
...6/02/10 20:30:15 OOOHelmetOfRudeness.scr6/02/10 20:30:16 AllNaturalRainOnYourParade.scr6/02/10 20:30:18 BobsUnstableMod.scrend of file
That way you could find the culprit.
Of course it would be nice if this log was only a few lines long and not a record of every script that executes ever. Maybe it could rewrite itself so it's not a million lines long.
This was the only way I could come up with to create that log. I don't see anything currently in Oblivion that would support generating the log entries unless we add something like this.
In my professional capacity I have constructed similar instrumentation systems embedded within Visual Studio to instrument C# code in the past, as a method of post-hoc crash anolysis. There are however a number of challenges associated with it. While the actual task of auto-instrumenting scripts is not challenging (though hardly trivial), the massive overhead of including this amount of IO would create a severe performance issue. I'd be very wary about attempting this - a large number of OB scripts do nothing for most of the time, only kicking in at relevant moments. A system like this would cause every one of those "empty" scripts to have to run and dump data. That may end up causing unanticipated issues and actually crash the game giving false positives.
Note that I'm not saying it's a bad idea, but perhaps you'd need to limit it to instrumenting a subset of the scripts at any given time.
Point taken. I think some experimentation will let us know how bad this would make things. It's certainly a good idea to be able to limit the scripts being checked anyway so as to lessen the size of the logfile. Somewhere I had some stats on the cost of disk writes but I haven't looked at it in years. And clearly you'd only want to run something like this when you are trying to diagnose a problem.
Thank you all for all the feedback so far. Hopefully, together, we'll be able to design something that will work.