summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2018-10-28 12:40:42 +0000
committerAndreas Rumpf <rumpf_a@web.de>2018-10-28 13:40:42 +0100
commitdfb8730f51a022ff02bdd973e6c5946cfdcdc3c6 (patch)
tree41ee6f51c072825cd35e19805ffd62d2f502afde /lib
parentf670c55daa3fdad32c02b9c1f0ec0d9031adee62 (diff)
downloadNim-dfb8730f51a022ff02bdd973e6c5946cfdcdc3c6.tar.gz
Implements #9434. Minimal Stacktrace for Exceptions in release mode (#9480)
* Fixes #9434
Diffstat (limited to 'lib')
-rw-r--r--lib/system/excpt.nim10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 7d5f5af7f..20ca143ca 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -381,6 +381,8 @@ proc raiseExceptionAux(e: ref Exception) =
           xadd(buf, s, s.len)
         var buf: array[0..2000, char]
         var L = 0
+        if e.trace.len != 0:
+          add(buf, $e.trace) # gc allocation      
         add(buf, "Error: unhandled exception: ")
         add(buf, e.msg)
         add(buf, " [")
@@ -394,7 +396,7 @@ proc raiseExceptionAux(e: ref Exception) =
           showErrorMessage(tbuf())
           quitOrDebug()
 
-proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} =
+proc raiseExceptionEx(e: ref Exception, ename, procname, filename: cstring, line: int) {.compilerRtl.} =
   if e.name.isNil: e.name = ename
   when hasSomeStackTrace:
     if e.trace.len == 0:
@@ -403,8 +405,14 @@ proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} =
       e.trace.add reraisedFrom(reraisedFromBegin)
       auxWriteStackTrace(framePtr, e.trace)
       e.trace.add reraisedFrom(reraisedFromEnd)
+  else:
+    if procname != nil and filename != nil:
+      e.trace.add StackTraceEntry(procname: procname, filename: filename, line: line)
   raiseExceptionAux(e)
 
+proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} =
+  raiseExceptionEx(e, ename, nil, nil, 0)
+
 proc reraiseException() {.compilerRtl.} =
   if currException == nil:
     sysFatal(ReraiseError, "no exception to reraise")