考虑下面的两个不同程序,
test.nim
和 sdl_test.nim
,使用带有 nim c --out:sdl_test -d:debug --debugger:native sdl_test.nim
的 NativeDebug 扩展在 VSCode 中调试。
在调试
test.nim
程序时,我可以正常评估变量值。但是在调试 sdl_test.nim
程序时,到处都是“当前上下文中没有符号 XXX。(来自数据评估表达式 --thread 1 --frame 0 tex)”。
var win: WindowPtr
-> WindowPtr* = ptr object
),所以没有办法反省它们?SDL 变量(无法检查):
虚拟变量(可检查):
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Nim Project",
"type": "gdb",
"request": "launch",
"target": "test",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText"
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Nim Project",
"type": "shell",
"command": "nim c --out:test -d:debug --debugger:native test.nim",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
type
TestObj = object
num: int
val: float
str: string
proc initTestObj(num: int): TestObj =
TestObj(num: num, val: 3.141, str: "TestObj")
proc foo(x: int): int =
let y = x + 2
return y * 10
proc bar(x: int): int =
if x == 3:
return foo(x)
return x * 100
proc main =
var a = 1
a += 3
let str = "foobar"
var seq1 = @[0, 1, 2, 3, 4]
a = bar(1)
a = bar(2)
a = bar(3)
let tobj = initTestObj(11)
main()
import sdl2
var
win: WindowPtr
ren: RendererPtr
bmp: SurfacePtr
tex: TexturePtr
discard init(INIT_EVERYTHING)
proc main() =
win = createWindow("Hello World!", 100, 100, 620, 387, SDL_WINDOW_SHOWN)
if win == nil:
echo("createWindow Error: ", getError())
quit(1)
ren = createRenderer(win, -1, Renderer_Accelerated or Renderer_PresentVsync)
if ren == nil:
echo("createRenderer Error: ", getError())
quit(1)
bmp = loadBMP("grumpy-cat.bmp")
if bmp == nil:
echo("loadBMP Error: ", getError())
quit(1)
tex = createTextureFromSurface(ren, bmp)
if tex == nil:
echo("createTextureFromSurface Error: ", getError())
quit(1)
freeSurface(bmp)
for i in countup(1, 20):
ren.clear
copy(ren, tex, nil, nil)
ren.present
delay(100)
destroy tex
destroy ren
destroy win
sdl2.quit()
main()