From 740a0c46f45d02c2cd0bb93377591c9622b8ea74 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 12 Jan 2020 01:26:54 -0700 Subject: [PATCH] Add gdb debugging capability --- .vscode/launch.json | 18 ++++++++++++++++ gdbcommands.txt | 1 - nanovg.nimble | 50 ++++++++++++++++++++++++++------------------- nim-gdb | 3 ++- nim-gdb.bat | 14 +++++++++++++ 5 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 .vscode/launch.json delete mode 100644 gdbcommands.txt create mode 100644 nim-gdb.bat diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3ae2400 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Nim Debug", + "type": "gdb", + "request": "launch", + "target": "${workspaceFolder}\\build\\demo\\demo_glfw_debug.exe", + "cwd": "${workspaceRoot}", + "gdbpath": "${workspaceFolder}\\nim-gdb.bat", + "valuesFormatting": "parseText" + } + ] +} \ No newline at end of file diff --git a/gdbcommands.txt b/gdbcommands.txt deleted file mode 100644 index e1e2828..0000000 --- a/gdbcommands.txt +++ /dev/null @@ -1 +0,0 @@ -source C:/Users/jyapa/.choosenim/toolchains/nim-#devel/tools/nim-gdb.py \ No newline at end of file diff --git a/nanovg.nimble b/nanovg.nimble index 0f87384..4d59287 100644 --- a/nanovg.nimble +++ b/nanovg.nimble @@ -17,11 +17,10 @@ requires "nim >= 1.0.0", import os -task buildSDL2Example, "Build SDL2 example": - let buildDir = "build/demosdl2" +proc setupBuildDir(buildDir: string, prefixes: openArray[string]) = + var arch = "" if system.existsDir(buildDir): rmDir buildDir - var arch = "" if defined(amd64): arch = "64bit" else: @@ -30,24 +29,33 @@ task buildSDL2Example, "Build SDL2 example": var files = listFiles "lib/" & arch & "/" for fpath in files: let fname = fpath.extractFileName() - if fname.startsWith("lib") or fname.startsWith("SDL2") or fname.startsWith("glew"): - cpFile fpath, buildDir & "/" & fname + for prefix in prefixes: + if fname.startsWith(prefix): + cpFile fpath, buildDir & "/" & fname + +proc setupGLFW(): string = + switch("define", "useGlfw") + let buildDir = "build/demo" + setupBuildDir(buildDir, ["gl"]) + return buildDir + +proc setupSDL2(): string = + let buildDir = "build/demosdl2" + setupBuildDir(buildDir, ["lib", "SDL2", "glew"]) + return buildDir + +task buildSDL2Example, "Build SDL2 example": + let buildDir = setupSDL2() exec "nim c --app:gui -d:release -d:danger -o:" & buildDir & "/" & "demo_sdl2".toExe & " -r examples/demo_sdl2.nim" +task buildSDL2ExampleDebug, "Build SDL2 example debug": + let buildDir = setupSDL2() + exec "nim c --app:gui --debugger:native -o:" & buildDir & "/" & "demo_sdl2_debug".toExe & " -r examples/demo_sdl2.nim" + task buildGLFWExample, "Build GLFW example": - switch("define", "useGlfw") - var arch = "" - let buildDir = "build/demo" - if system.existsDir(buildDir): - rmDir buildDir - if defined(amd64): - arch = "64bit" - else: - arch = "32bit" - mkDir buildDir - var files = listFiles "lib/" & arch & "/" - for fpath in files: - let fname = fpath.extractFileName() - if fname.startsWith("gl"): - cpFile fpath, buildDir & "/" & fname - exec "nim c --app:gui -d:release -d:danger -o:" & buildDir & "/" & "demo_glfw".toExe & " -r examples/demo.nim" \ No newline at end of file + let buildDir = setupGLFW() + exec "nim c --app:gui -d:release -d:danger -o:" & buildDir & "/" & "demo_glfw".toExe & " -r examples/demo.nim" + +task buildGLFWExampleDebug, "Build GLFW example debug": + let buildDir = setupGLFW() + exec "nim c --app:gui --debugger:native -o:" & buildDir & "/" & "demo_glfw_debug".toExe & " -r examples/demo.nim" \ No newline at end of file diff --git a/nim-gdb b/nim-gdb index f064868..7d77479 100644 --- a/nim-gdb +++ b/nim-gdb @@ -13,7 +13,8 @@ GDB_PYTHON_MODULE_PATH="$NIM_SYSROOT/tools/nim-gdb.py" # Run GDB with the additional arguments that load the pretty printers # Set the environment variable `NIM_GDB` to overwrite the call to a # different/specific command (defaults to `gdb`). -NIM_GDB="${NIM_GDB:-gdb.exe}" +NIM_GDB="${NIM_GDB:-gdb}" +echo "source $GDB_PYTHON_MODULE_PATH" > gdbcommands.txt # exec replaces the new process of bash with gdb. It is always good to # have fewer processes. exec ${NIM_GDB} --command="gdbcommands.txt" "$@" \ No newline at end of file diff --git a/nim-gdb.bat b/nim-gdb.bat new file mode 100644 index 0000000..04968f2 --- /dev/null +++ b/nim-gdb.bat @@ -0,0 +1,14 @@ +@echo off +for %%i in (nim.exe) do (set NIM_BIN=%%~dp$PATH:i) + +for %%i in ("%NIM_BIN%\..\") do (set NIM_ROOT=%%~fi) + +set @GDB_PYTHON_MODULE_PATH=%NIM_ROOT%\tools\nim-gdb.py +set @NIM_GDB=gdb.exe + +@echo source %@GDB_PYTHON_MODULE_PATH%> wingdbcommand.txt + +%@NIM_GDB% --command="wingdbcommand.txt" %* + +EXIT /B %ERRORLEVEL% +@echo on \ No newline at end of file