Skip to content

Commit

Permalink
Fixes for stack overflow detection
Browse files Browse the repository at this point in the history
- Add a stack overflow try-block in Main.
- Add code for pretty OSX stack overflow messages.
  • Loading branch information
sjoelund committed Sep 9, 2015
1 parent ceb1975 commit 260aeb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Compiler/Main/Main.mo
Expand Up @@ -76,6 +76,7 @@ import SimCode;
import SimCodeMain;
import SimCodeFunctionUtil;
import Socket;
import StackOverflow;
import System;
import TplMain;
import Util;
Expand Down Expand Up @@ -818,6 +819,7 @@ protected
list<String> args_1;
GC.ProfStats stats;
algorithm
try
try
args_1 := init(args);
if Flags.isSet(Flags.GC_PROF) then
Expand All @@ -833,6 +835,13 @@ algorithm
if Flags.isSet(Flags.GC_PROF) then
print(GC.profStatsStr(GC.getProfStats(), head="GC stats at end of program:") + "\n");
end if;
else
print("Stack overflow detected and was not caught.\nSend us a bug report at https://trac.openmodelica.org/OpenModelica/newticket\n Include the following trace:\n");
for s in StackOverflow.readableStacktraceMessages() loop
print(s);
print("\n");
end for;
end try annotation(__OpenModelica_stackOverflowCheckpoint=true);
end main;

protected function main2
Expand Down
10 changes: 9 additions & 1 deletion Compiler/Util/StackOverflow.mo
Expand Up @@ -59,12 +59,20 @@ protected
list<String> strs;
String so,fun;
algorithm
// regex for Linux messages
(n,strs) := System.regex(inSymbol, "^([^(]*)[(]([^+]*[^+]*)[+][^)]*[)] *[[]0x[0-9a-fA-F]*[]]$", 3, extended=true);
if n == 3 then
{_,so,fun} := strs;
outSymbol := so + "(" + unmangle(fun) + ")";
else
outSymbol := inSymbol;
// regex for OSX messages
(n,strs) := System.regex(inSymbol, "^[0-9 ]*([A-Za-z0-9.]*) *0x[0-9a-fA-F]* ([A-Za-z0-9_]*) *[+] *[0-9]*$", 3, extended=true);
if n == 3 then
{_,so,fun} := strs;
outSymbol := so + "(" + unmangle(fun) + ")";
else
outSymbol := inSymbol;
end if;
end if;
end stripAddresses;

Expand Down

0 comments on commit 260aeb5

Please sign in to comment.