Attempt to provide simplified and detailed tracebacks
This commit is contained in:
parent
3a790c9c72
commit
391f877e6c
1 changed files with 32 additions and 14 deletions
|
|
@ -274,25 +274,43 @@ proc shortenEntries(entries: seq[StackTraceEntry]): seq[StackTraceEntry] =
|
||||||
|
|
||||||
# Detect this pattern:
|
# Detect this pattern:
|
||||||
# (procname: a, line: 393, filename: asyncmacro.nim)
|
# (procname: a, line: 393, filename: asyncmacro.nim)
|
||||||
|
# ...
|
||||||
# (procname: a_continue, line: 34, filename: asyncmacro.nim)
|
# (procname: a_continue, line: 34, filename: asyncmacro.nim)
|
||||||
|
# ...
|
||||||
# (procname: aIter, line: 40, filename: tasync_traceback.nim)
|
# (procname: aIter, line: 40, filename: tasync_traceback.nim)
|
||||||
let second = get(entries, i+1)
|
proc searchBackwards(entries: seq[StackTraceEntry],
|
||||||
|
current: StackTraceEntry): (int, StackTraceEntry) =
|
||||||
|
# Search backwards for the beginning of the pattern.
|
||||||
|
result[0] = 0
|
||||||
|
if not ($current.procName).normalize().endsWith("iter"):
|
||||||
|
return
|
||||||
|
|
||||||
let third = get(entries, i+2)
|
# Find (procname: a, line: 393, filename: asyncmacro.nim)
|
||||||
let fitsPattern =
|
let start = entries.len-1
|
||||||
cmpIgnoreStyle($entry.filename, "asyncmacro.nim") == 0 and
|
var counter = start
|
||||||
cmpIgnoreStyle($second.filename, "asyncmacro.nim") == 0 and
|
while counter >= 0:
|
||||||
($second.procName).startsWith($entry.procName) and
|
if cmpIgnoreStyle($entries[counter].procName & "iter",
|
||||||
($second.procName).endsWith("continue") and
|
$current.procName) == 0:
|
||||||
cmpIgnoreStyle($third.procName, $entry.procName & "iter") == 0
|
break
|
||||||
|
counter.dec()
|
||||||
|
|
||||||
if fitsPattern:
|
# Return when no beginning of pattern is found.
|
||||||
entry = StackTraceEntry(
|
if counter < 0:
|
||||||
procName: entry.procName,
|
return
|
||||||
line: third.line,
|
|
||||||
filename: third.filename
|
result[0] = start - counter
|
||||||
|
result[1] = StackTraceEntry(
|
||||||
|
procName: entries[result[0]].procName,
|
||||||
|
line: current.line,
|
||||||
|
filename: current.filename
|
||||||
)
|
)
|
||||||
i.inc(2)
|
|
||||||
|
let (itemsToRemove, newEntry) = searchBackwards(result, entry)
|
||||||
|
|
||||||
|
if itemsToRemove != 0:
|
||||||
|
entry = newEntry
|
||||||
|
# Remove the previous entries.
|
||||||
|
result.setLen(result.len-itemsToRemove)
|
||||||
|
|
||||||
result.add(entry)
|
result.add(entry)
|
||||||
i.inc
|
i.inc
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue