Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal errors during VM now produce a user code stacktrace #11642

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/msgs.nim
Expand Up @@ -431,6 +431,9 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
KindColor, `%`(KindFormat, kind))
else:
styledMsgWriteln(color, title, resetStyle, s)

if conf.errorDiagnosticCallback != nil: conf.errorDiagnosticCallback()

handleError(conf, msg, doAbort, s)

proc rawMessage*(conf: ConfigRef; msg: TMsgKind, arg: string) =
Expand Down
1 change: 1 addition & 0 deletions compiler/options.nim
Expand Up @@ -253,6 +253,7 @@ type
suggestMaxResults*: int
lastLineInfo*: TLineInfo
writelnHook*: proc (output: string) {.closure.} # cannot make this gcsafe yet because of Nimble
errorDiagnosticCallback*: proc() {.closure.}
structuredErrorHook*: proc (config: ConfigRef; info: TLineInfo; msg: string;
severity: Severity) {.closure, gcsafe.}
cppCustomNamespace*: string
Expand Down
5 changes: 5 additions & 0 deletions compiler/vm.nim
Expand Up @@ -493,6 +493,11 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
var regs: seq[TFullReg] # alias to tos.slots for performance
move(regs, tos.slots)
#echo "NEW RUN ------------------------"
let errorDiagnosticCallbackOld = c.config.errorDiagnosticCallback
c.config.errorDiagnosticCallback = proc() =
echo "stacktrace for rawExecute:"
stackTraceAux(c, tos, pc)
defer: c.config.errorDiagnosticCallback = errorDiagnosticCallbackOld
while true:
#{.computedGoto.}
let instr = c.code[pc]
Expand Down