#2090 closed defect (fixed)
Stack overflow detection
Reported by: | Martin Sjölund | Owned by: | Martin Sjölund |
---|---|---|---|
Priority: | high | Milestone: | 1.9.4 |
Component: | MetaModelica | Version: | trunk |
Keywords: | Cc: | Adrian Pop, Peter Fritzson, Adeel Asghar, Per Östlund |
Description
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:
(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
Change History (9)
comment:1 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
comment:4 by , 10 years ago
Milestone: | 1.9.1 → 1.9.2 |
---|
This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).
comment:5 by , 10 years ago
Milestone: | 1.9.2 → 1.9.3 |
---|
Milestone changed to 1.9.3 since 1.9.2 was released.
comment:7 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
This has been fixed by using try-blocks with a special annotation __OpenModelica_stackOverflowCheckpoint=true
.
The omc main function now detects overflows. For later we need some additional code to not crash (right now, the main function prints the error and exits).
I did consider some new syntax to be something like:
An alternative would be something more explicit:
I kinda like the first one. I think it's possible to detect these things and add the required macros in the generated code.