summary refs log tree commit diff stats
path: root/compiler/cgen.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2016-12-18 00:08:11 +0100
committerAraq <rumpf_a@web.de>2016-12-18 00:08:11 +0100
commit31bc063f2d66cf0463d700b041f250ab920c8217 (patch)
treef8a8903b14736c87947eadf965fde15616e05f35 /compiler/cgen.nim
parenta88a965c6d3f54086f2682dc98ee9e5930c2fa66 (diff)
downloadNim-31bc063f2d66cf0463d700b041f250ab920c8217.tar.gz
significantly better stack traces when templates are involved
Diffstat (limited to 'compiler/cgen.nim')
-rw-r--r--compiler/cgen.nim20
1 files changed, 12 insertions, 8 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 3217b86e4..0cb1de142 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -191,21 +191,25 @@ proc freshLineInfo(p: BProc; info: TLineInfo): bool =
     result = true
 
 proc genLineDir(p: BProc, t: PNode) =
-  var line = t.info.safeLineNm
+  var tt = t
+  while tt.kind in {nkStmtListExpr}+nkCallKinds:
+    tt = tt.lastSon
+  let line = tt.info.safeLineNm
+
   if optEmbedOrigSrc in gGlobalOptions:
-    add(p.s(cpsStmts), ~"//" & t.info.sourceLine & rnl)
-  genCLineDir(p.s(cpsStmts), t.info.toFullPath, line)
+    add(p.s(cpsStmts), ~"//" & tt.info.sourceLine & rnl)
+  genCLineDir(p.s(cpsStmts), tt.info.toFullPath, line)
   if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and
       (p.prc == nil or sfPure notin p.prc.flags):
-    if freshLineInfo(p, t.info):
+    if freshLineInfo(p, tt.info):
       linefmt(p, cpsStmts, "#endb($1, $2);$n",
-              line.rope, makeCString(toFilename(t.info)))
+              line.rope, makeCString(toFilename(tt.info)))
   elif ({optLineTrace, optStackTrace} * p.options ==
       {optLineTrace, optStackTrace}) and
-      (p.prc == nil or sfPure notin p.prc.flags) and t.info.fileIndex >= 0:
-    if freshLineInfo(p, t.info):
+      (p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex >= 0:
+    if freshLineInfo(p, tt.info):
       linefmt(p, cpsStmts, "nimln($1, $2);$n",
-              line.rope, t.info.quotedFilename)
+              line.rope, tt.info.quotedFilename)
 
 proc postStmtActions(p: BProc) {.inline.} =
   add(p.s(cpsStmts), p.module.injectStmt)