diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/system.nim | 4 | ||||
-rwxr-xr-x | lib/system/alloc.nim | 6 | ||||
-rwxr-xr-x | lib/system/assign.nim | 34 | ||||
-rwxr-xr-x | lib/system/debugger.nim | 16 | ||||
-rwxr-xr-x | lib/system/excpt.nim | 21 |
5 files changed, 60 insertions, 21 deletions
diff --git a/lib/system.nim b/lib/system.nim index e35d2914f..4a1bde56a 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -1961,11 +1961,11 @@ when not defined(EcmaScript) and not defined(NimrodVM): ## for debug builds. when hostOS != "standalone": proc getStackTrace*(): string - ## gets the current stack trace. This is only works for debug builds. + ## gets the current stack trace. This 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. + ## lead to the ``raise`` statement. This only works for debug builds. {.push stack_trace: off, profiler:off.} when hostOS == "standalone": diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index bcc70b853..127df755e 100755 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -553,7 +553,7 @@ proc rawAlloc(a: var TMemRegion, requestedSize: int): pointer = sysAssert(allocInv(a), "rawAlloc: before listRemove test") ListRemove(a.freeSmallChunks[s], c) sysAssert(allocInv(a), "rawAlloc: end listRemove test") - sysAssert(((cast[TAddress](result) and PageMask) -% smallChunkOverhead()) %% + sysAssert(((cast[TAddress](result) and PageMask) - smallChunkOverhead()) %% size == 0, "rawAlloc 21") sysAssert(allocInv(a), "rawAlloc: end small size") else: @@ -582,7 +582,7 @@ proc rawDealloc(a: var TMemRegion, p: pointer) = # `p` is within a small chunk: var c = cast[PSmallChunk](c) var s = c.size - sysAssert(((cast[TAddress](p) and PageMask) -% smallChunkOverhead()) %% + sysAssert(((cast[TAddress](p) and PageMask) - smallChunkOverhead()) %% s == 0, "rawDealloc 3") var f = cast[ptr TFreeCell](p) #echo("setting to nil: ", $cast[TAddress](addr(f.zeroField))) @@ -605,7 +605,7 @@ proc rawDealloc(a: var TMemRegion, p: pointer) = ListRemove(a.freeSmallChunks[s div memAlign], c) c.size = SmallChunkSize freeBigChunk(a, cast[PBigChunk](c)) - sysAssert(((cast[TAddress](p) and PageMask) -% smallChunkOverhead()) %% + sysAssert(((cast[TAddress](p) and PageMask) - smallChunkOverhead()) %% s == 0, "rawDealloc 2") else: # set to 0xff to check for usage after free bugs: diff --git a/lib/system/assign.nim b/lib/system/assign.nim index cd4a34f6c..4b8d2033d 100755 --- a/lib/system/assign.nim +++ b/lib/system/assign.nim @@ -60,7 +60,7 @@ proc genericAssignAux(dest, src: Pointer, mt: PNimType, shallow: bool) = unsureAsgnRef(x, s2) return sysAssert(dest != nil, "genericAssignAux 3") - unsureAsgnRef(x, newObj(mt, seq.len * mt.base.size + GenericSeqSize)) + unsureAsgnRef(x, newSeq(mt, seq.len)) var dst = cast[taddress](cast[ppointer](dest)[]) for i in 0..seq.len-1: genericAssignAux( @@ -68,9 +68,6 @@ proc genericAssignAux(dest, src: Pointer, mt: PNimType, shallow: bool) = cast[pointer](cast[taddress](s2) +% i *% mt.base.size +% GenericSeqSize), mt.Base, shallow) - var dstseq = cast[PGenericSeq](dst) - dstseq.len = seq.len - dstseq.reserved = seq.len of tyObject: # we need to copy m_type field for tyObject, as it could be empty for # sequence reallocations: @@ -98,6 +95,35 @@ proc genericShallowAssign(dest, src: Pointer, mt: PNimType) {.compilerProc.} = genericAssignAux(dest, src, mt, true) GC_enable() +when false: + proc debugNimType(t: PNimType) = + if t.isNil: + cprintf("nil!") + return + var k: cstring + case t.kind + of tyBool: k = "bool" + of tyChar: k = "char" + of tyEnum: k = "enum" + of tyArray: k = "array" + of tyObject: k = "object" + of tyTuple: k = "tuple" + of tyRange: k = "range" + of tyPtr: k = "ptr" + of tyRef: k = "ref" + of tyVar: k = "var" + of tySequence: k = "seq" + of tyProc: k = "proc" + of tyPointer: k = "range" + of tyOpenArray: k = "openarray" + of tyString: k = "string" + of tyCString: k = "cstring" + of tyInt: k = "int" + of tyInt32: k = "int32" + else: k = "other" + cprintf("%s %ld\n", k, t.size) + debugNimType(t.base) + proc genericSeqAssign(dest, src: Pointer, mt: PNimType) {.compilerProc.} = var src = src # ugly, but I like to stress the parser sometimes :-) genericAssign(dest, addr(src), mt) diff --git a/lib/system/debugger.nim b/lib/system/debugger.nim index 37995d919..2add37740 100755 --- a/lib/system/debugger.nim +++ b/lib/system/debugger.nim @@ -664,6 +664,9 @@ proc dbgRegisterWatchpoint(address: pointer, name: cstring, Watchpoints[L].oldValue = genericHash(address, typ) inc WatchpointsLen +proc dbgUnregisterWatchpoints*() = + WatchpointsLen = 0 + proc dbgWriteStackTrace(f: PFrame) = const firstCalls = 32 @@ -706,15 +709,22 @@ proc dbgWriteStackTrace(f: PFrame) = write(stdout, tempFrames[j].procname) write(stdout, "\n") +proc strstr(s1, s2: cstring): cstring {.importc, header: "<string.h>".} + +proc interestingFilename(filename: cstring): bool = + #result = strstr(filename, "/rst.nim") == nil + result = true + proc checkWatchpoints = let L = WatchpointsLen for i in 0.. <L: let newHash = genericHash(Watchpoints[i].address, Watchpoints[i].typ) if newHash != Watchpoints[i].oldValue: - dbgWriteStackTrace(framePtr) - debugOut(Watchpoints[i].name) + if interestingFilename(framePtr.filename): + dbgWriteStackTrace(framePtr) + debugOut(Watchpoints[i].name) Watchpoints[i].oldValue = newHash - + proc endb(line: int) {.compilerproc.} = # This proc is called before every Nimrod code line! # Thus, it must have as few parameters as possible to keep the diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 204fba376..aedb0ef4b 100755 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -192,11 +192,7 @@ proc quitOrDebug() {.inline.} = else: endbStep() # call the debugger -proc raiseException(e: ref E_Base, ename: CString) {.compilerRtl.} = - e.name = ename - when hasSomeStackTrace: - e.trace = "" - rawWriteStackTrace(e.trace) +proc raiseExceptionAux(e: ref E_Base) = if localRaiseHook != nil: if not localRaiseHook(e): return if globalRaiseHook != nil: @@ -205,7 +201,7 @@ proc raiseException(e: ref E_Base, ename: CString) {.compilerRtl.} = pushCurrentException(e) c_longjmp(excHandler.context, 1) elif e[] of EOutOfMemory: - writeToStdErr(ename) + writeToStdErr(e.name) quitOrDebug() else: when hasSomeStackTrace: @@ -214,7 +210,7 @@ proc raiseException(e: ref E_Base, ename: CString) {.compilerRtl.} = add(buf, "Error: unhandled exception: ") if not isNil(e.msg): add(buf, e.msg) add(buf, " [") - add(buf, $ename) + add(buf, $e.name) add(buf, "]\n") writeToStdErr(buf) else: @@ -230,16 +226,23 @@ proc raiseException(e: ref E_Base, ename: CString) {.compilerRtl.} = add(buf, "Error: unhandled exception: ") if not isNil(e.msg): add(buf, e.msg) add(buf, " [") - xadd(buf, ename, c_strlen(ename)) + xadd(buf, e.name, c_strlen(e.name)) add(buf, "]\n") writeToStdErr(buf) quitOrDebug() +proc raiseException(e: ref E_Base, ename: CString) {.compilerRtl.} = + e.name = ename + when hasSomeStackTrace: + e.trace = "" + rawWriteStackTrace(e.trace) + raiseExceptionAux(e) + proc reraiseException() {.compilerRtl.} = if currException == nil: raise newException(ENoExceptionToReraise, "no exception to reraise") else: - raiseException(currException, currException.name) + raiseExceptionAux(currException) proc WriteStackTrace() = when hasSomeStackTrace: |