﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2090	Stack overflow detection	Martin Sjölund	Martin Sjölund	"Because OMEdit requires omc to never crash, we need a way to recover from stack overflow.
As far as I can tell there are ways to get the maximum stack size in boehm's GC (since they inspect the stack). If we get the threshold at program start, we can check this in every called function (with rather low overhead).

We would need one thing in the runtime: Another point to longjmp to when we overflow the stack. Same as far matchcontinue; just another stack to add.

In the MetaModelica language, we would need another builtin function (external C would not be enough since it creates a new stack frame even if a macro is called). You call the new builtin operator something like:
{{{#!mo
(stackOverflow,message) := checkStackOverflow();
if not stackOverflow then
  // stuff that can cause stack overflow
  popStackOverflowBuffer(); // ugly, but I think needed
else
  // error-handling
  // popStackOverflowBuffer() might not be needed
  // it depends how you implement checkStackOverflow()
  // it might be nicer to have the clean-up always called
end if;
}}}

It would look nicer if we added special syntax for it, but I think it's fine to simply add an operator. Or maybe even `external ""C-macro""` ;)

As for getting the backtrace so we can add the messages, there are some ways given here:
http://stackoverflow.com/questions/3151779/how-its-better-to-invoke-gdb-from-program-to-print-its-stacktrace"	defect	closed	high	1.9.4	MetaModelica	trunk	fixed		Adrian Pop Peter Fritzson Adeel Asghar Per Östlund
