nim-gdb 1.1 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. # Exit if anything fails
  3. set -e
  4. which nim > /dev/null || (echo "nim not in PATH"; exit 1)
  5. which gdb > /dev/null || (echo "gdb not in PATH"; exit 1)
  6. which readlink > /dev/null || which greadlink > /dev/null || (echo "readlink not in PATH. Please install coreutils from brew if on Mac."; exit 1)
  7. nreadlink () {
  8. (which greadlink > /dev/null && greadlink "$@") || (which readlink > /dev/null && readlink "$@") || echo "Readlink could not be found"
  9. }
  10. # Find out where the pretty printer Python module is
  11. NIM_SYSROOT=$(dirname $(dirname $(nreadlink -e $(which nim))))
  12. GDB_PYTHON_MODULE_PATH="$NIM_SYSROOT/tools/nim-gdb.py"
  13. # Run GDB with the additional arguments that load the pretty printers
  14. # Set the environment variable `NIM_GDB` to overwrite the call to a
  15. # different/specific command (defaults to `gdb`).
  16. NIM_GDB="${NIM_GDB:-gdb}"
  17. # This is needed for some reason. I can't get -eval-command to work ever
  18. echo "source $GDB_PYTHON_MODULE_PATH" > gdbcommands.txt
  19. # exec replaces the new process of bash with gdb. It is always good to
  20. # have fewer processes.
  21. exec ${NIM_GDB} --command="gdbcommands.txt" "$@"
  22. rm gdbcommands.txt