added another system.getStackTrace

This commit is contained in:
Araq 2012-05-20 18:42:50 +02:00
commit 29b63be980
2 changed files with 14 additions and 0 deletions

View file

@ -190,6 +190,7 @@ type
msg* {.exportc: "message".}: string ## the exception's message. Not msg* {.exportc: "message".}: string ## the exception's message. Not
## providing an exception message ## providing an exception message
## is bad style. ## is bad style.
trace: string
EAsynch* = object of E_Base ## Abstract exception class for EAsynch* = object of E_Base ## Abstract exception class for
## *asynchronous exceptions* (interrupts). ## *asynchronous exceptions* (interrupts).
@ -1901,6 +1902,10 @@ when not defined(EcmaScript) and not defined(NimrodVM):
proc getStackTrace*(): string proc getStackTrace*(): string
## gets the current stack trace. This is only works for debug builds. ## gets the current stack trace. This is only works for debug builds.
proc getStackTrace*(e: ref E_Base): string
## gets the stack trace associated with `e`, which is the stack that
## lead to the ``raise`` statement. This is only works for debug builds.
{.push stack_trace: off.} {.push stack_trace: off.}
when hostOS == "standalone": when hostOS == "standalone":
include "system/embedded" include "system/embedded"

View file

@ -194,6 +194,9 @@ proc quitOrDebug() {.inline.} =
proc raiseException(e: ref E_Base, ename: CString) {.compilerRtl.} = proc raiseException(e: ref E_Base, ename: CString) {.compilerRtl.} =
e.name = ename e.name = ename
when hasSomeStackTrace:
e.trace = ""
rawWriteStackTrace(e.trace)
if localRaiseHook != nil: if localRaiseHook != nil:
if not localRaiseHook(e): return if not localRaiseHook(e): return
if globalRaiseHook != nil: if globalRaiseHook != nil:
@ -253,6 +256,12 @@ proc getStackTrace(): string =
else: else:
result = "No stack traceback available\n" result = "No stack traceback available\n"
proc getStackTrace(e: ref E_Base): string =
if not isNil(e) and not isNil(e.trace):
result = e.trace
else:
result = ""
when defined(endb): when defined(endb):
var var
dbgAborting: bool # whether the debugger wants to abort dbgAborting: bool # whether the debugger wants to abort