9

This is a seemly trivial question but I can't find a simple way to accomplish this.

I have my .gdbinit file defined in the same directory as where gdb.exe exist -- that is inside my compiler's bin directory. However, when I run gdb I get this:

GNU gdb (GDB) 7.5.50.20120804-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-w64-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
warning: File "g:\Mingw32-4.6.3\bin\.gdbinit" auto-loading has been declined by
your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".

I looked up the manual about auto-loading here but it has nothing about keeping that new safe-path I added saved! Exiting gdb and starting it up again and the safe-paths I added are gone.

My .gdbinit contains settings that I always want loaded upon startup. Loading .gdbinit is probably environment agnostic but what's the simplest way to do this under Windows? There is an addition constraint that .gdbinit cannot reside in my home directory -- it must be in the same path as the gdb.exe executable.

greatwolf
  • 20,287
  • 13
  • 71
  • 105

5 Answers5

9

I have my .gdbinit file defined in the same directory as where gdb.exe exist

Put into your $HOME or into current directory.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • 3
    I added the .gdbinit in the current directory, but still does not work. The echo command I add at the beginning of the file is also not printed. – Sarvavyapi Mar 05 '15 at 18:32
  • 2
    Does Windows even have a `$HOME` directory? And what is the `current directory` (gdb is being launched by an IDE, but putting it in the directory with the IDE's .exe didn't work)? Where should the file be on Windows? – Mawg says reinstate Monica Jul 13 '18 at 11:22
  • 1
    @MawgsaysreinstateMonica Under Windows, just put your .gdbinit under `C:\Users\YourUsername`; this is the home directory – Razakhel Jan 30 '20 at 17:01
  • 1
    I have no clue why this refuses to work for me, using powershell(7) I even see the file if I `cat $home\.gdbinit` but I wrapped with in a powershell profile function for convenience `arm-none-eabi-gdb.exe -iex "set auto-load safe-path $pwd" -ix "$pwd/.gdbinit" -q .\target\thumbv6m-none-eabi\debug\` – Jack Sep 06 '20 at 14:15
7

I use CodeSourcery arm-none-eabi-gdb.exe on Windows 7. Following the above instructions did not work in my case. Below command worked:

arm-none-eabi-gdb.exe -x D:\CodeSourcery\bin\.gdbinit

Sarvavyapi
  • 810
  • 3
  • 23
  • 35
2

I launch xt-gdb that comes with Xtensa tool chain with -iex -ix parameters as follows:

xt-gdb -iex "set auto-load safe-path Path\to\gdbinit\dir" -ix Path\to\gdbinit\dir.gdbinit

AK S
  • 174
  • 1
  • 5
  • `-ix Path\to\gdbinit\dir\.gdbinit` is the only thing working for me (without setting `HOME`). – Zitrax Feb 07 '23 at 09:54
2

None of the above answers worked for me. The problem is that under windows there's no HOME enviroment variable set. So let's set one: Write in command line:

   set HOME=c:\users\user

where the .gdbinit should be, and where You can disable the security protection by setting it content:

set auto-load safe-path /

And from now, Your gdb will load Your local .gdbinit

c:\MinGW\bin\gdb.exe app.exe
  • As per my comment to the accepted answer, the home directory under Windows is already considered being `C:\Users\YourUsername`. Just put your .gdbinit here and this will work fine – Razakhel Jan 30 '20 at 17:04
  • @Razakhel that does not seem to be true in general, putting it there does not work for me at least. I think gdb specifically looks for the `HOME` env variable which does not exist by default on windows. – Zitrax Feb 07 '23 at 09:56
  • This is interesting. I currently don't have any `HOME` environment variable on my Windows (11) and gdb finds my printers without any issue; it was the same with my Windows 8.1 at the time of writing my original comment. For that matter, my user directory is not in any environment variable at all. I have no idea what it's specifically looking for then. – Razakhel Feb 08 '23 at 10:50
1

For other struggling xtensa toolchain users: xt-gdb is not looking for a file named .gdbinit but rather .xt-gdbinit. Otherwise the mechanics are exactly the same as with standard gdb.

pitrz
  • 11
  • 1