first version of the new memory tracking feature
This commit is contained in:
parent
fa101a722f
commit
02a2180a6a
11 changed files with 167 additions and 4 deletions
|
|
@ -355,6 +355,14 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
|||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
||||
else: internalError("genAssignment: " & $ty.kind)
|
||||
|
||||
if optMemTracker in p.options and dest.s in {OnHeap, OnUnknown}:
|
||||
#writeStackTrace()
|
||||
#echo p.currLineInfo, " requesting"
|
||||
linefmt(p, cpsStmts, "#memTrackerWrite((void*)$1, $2, $3, $4);$n",
|
||||
addrLoc(dest), rope getSize(dest.t),
|
||||
makeCString(p.currLineInfo.toFullPath),
|
||||
rope p.currLineInfo.safeLineNm)
|
||||
|
||||
proc genDeepCopy(p: BProc; dest, src: TLoc) =
|
||||
var ty = skipTypes(dest.t, abstractVarRange)
|
||||
case ty.kind
|
||||
|
|
@ -1946,6 +1954,7 @@ proc exprComplexConst(p: BProc, n: PNode, d: var TLoc) =
|
|||
d.s = OnStatic
|
||||
|
||||
proc expr(p: BProc, n: PNode, d: var TLoc) =
|
||||
p.currLineInfo = n.info
|
||||
case n.kind
|
||||
of nkSym:
|
||||
var sym = n.sym
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ type
|
|||
beforeRetNeeded*: bool # true iff 'BeforeRet' label for proc is needed
|
||||
threadVarAccessed*: bool # true if the proc already accessed some threadvar
|
||||
lastLineInfo*: TLineInfo # to avoid generating excessive 'nimln' statements
|
||||
currLineInfo*: TLineInfo # AST codegen will make this superfluous
|
||||
nestedTryStmts*: seq[PNode] # in how many nested try statements we are
|
||||
# (the vars must be volatile then)
|
||||
inExceptBlock*: int # are we currently inside an except block?
|
||||
|
|
|
|||
|
|
@ -242,6 +242,7 @@ proc testCompileOption*(switch: string, info: TLineInfo): bool =
|
|||
of "linetrace": result = contains(gOptions, optLineTrace)
|
||||
of "debugger": result = contains(gOptions, optEndb)
|
||||
of "profiler": result = contains(gOptions, optProfiler)
|
||||
of "memtracker": result = contains(gOptions, optMemTracker)
|
||||
of "checks", "x": result = gOptions * ChecksOptions == ChecksOptions
|
||||
of "floatchecks":
|
||||
result = gOptions * {optNaNCheck, optInfCheck} == {optNaNCheck, optInfCheck}
|
||||
|
|
@ -446,6 +447,10 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
|
|||
processOnOffSwitch({optProfiler}, arg, pass, info)
|
||||
if optProfiler in gOptions: defineSymbol("profiler")
|
||||
else: undefSymbol("profiler")
|
||||
of "memtracker":
|
||||
processOnOffSwitch({optMemTracker}, arg, pass, info)
|
||||
if optMemTracker in gOptions: defineSymbol("memtracker")
|
||||
else: undefSymbol("memtracker")
|
||||
of "checks", "x": processOnOffSwitch(ChecksOptions, arg, pass, info)
|
||||
of "floatchecks":
|
||||
processOnOffSwitch({optNaNCheck, optInfCheck}, arg, pass, info)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ type # please make sure we have under 32 options
|
|||
optProfiler, # profiler turned on
|
||||
optImplicitStatic, # optimization: implicit at compile time
|
||||
# evaluation
|
||||
optPatterns # en/disable pattern matching
|
||||
optPatterns, # en/disable pattern matching
|
||||
optMemTracker
|
||||
|
||||
TOptions* = set[TOption]
|
||||
TGlobalOption* = enum # **keep binary compatible**
|
||||
|
|
|
|||
|
|
@ -323,7 +323,8 @@ proc processOption(c: PContext, n: PNode): bool =
|
|||
of wStacktrace: onOff(c, n, {optStackTrace})
|
||||
of wLinetrace: onOff(c, n, {optLineTrace})
|
||||
of wDebugger: onOff(c, n, {optEndb})
|
||||
of wProfiler: onOff(c, n, {optProfiler})
|
||||
of wProfiler: onOff(c, n, {optProfiler, optMemTracker})
|
||||
of wMemTracker: onOff(c, n, {optMemTracker})
|
||||
of wByRef: onOff(c, n, {optByRef})
|
||||
of wDynlib: processDynLib(c, n, nil)
|
||||
of wOptimization:
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ type
|
|||
|
||||
wColon, wColonColon, wEquals, wDot, wDotDot,
|
||||
wStar, wMinus,
|
||||
wMagic, wThread, wFinal, wProfiler, wObjChecks,
|
||||
wMagic, wThread, wFinal, wProfiler, wMemTracker, wObjChecks,
|
||||
wIntDefine, wStrDefine,
|
||||
|
||||
wDestroy,
|
||||
|
|
@ -121,7 +121,7 @@ const
|
|||
|
||||
":", "::", "=", ".", "..",
|
||||
"*", "-",
|
||||
"magic", "thread", "final", "profiler", "objchecks", "intdefine", "strdefine",
|
||||
"magic", "thread", "final", "profiler", "memtracker", "objchecks", "intdefine", "strdefine",
|
||||
|
||||
"destroy",
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue