Luciano
Luciano

Reputation: 2989

.gdbinit file not found in local directory

The debugger gdb cannot find my local .gdbinit file but instead only the one located in the folder pointed by -cd argument.

When there is no file in the local folder from where it's launched it doesn't show any warning:

/home/mydir/sources $ rm .gdbinit
/home/mydir/sources $ gdb --cd /home/mydir/apprundir
(output omited)

But, if we create a .gdbinit file in the current folder from where it's launched, it detects that it is there but instead of loading it shows "warning: .gdbinit: No such file or directory".

/home/mydir/sources $ > .gdbinit
/home/mydir/sources $ gdb -cd /home/mydir/apprundir
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
warning: .gdbinit: No such file or directory

Is there any other ways to set up a cmd file not by gdb command line arguments? But by any external ways like environment variables or others? I can't pass arguments to gdb because it's being launched by third-party scripts, and I cannot create files inside the app home folder.

PS: My last alternative is the put all commands inside the $HOME/.gdbinit file but I'm avoiding it, because there are others development environments sharing the same $HOME/.dbginit file

Upvotes: 0

Views: 5636

Answers (2)

Daniel Donnelly
Daniel Donnelly

Reputation: 609

I found a solution to all of our problems. It's called the rr debugger:

https://rr-project.org/

First of all, it's a drop-in replacement for gdb, which means it should work with IDE's like Codelite with minimal settings.

Secondly, it's freakin reversible! Reversible computation is a theoretical area, but obviously they're achieving this by storing and replaying all associated code instructions.

You know when you're debugging something and you think, hmm it would be nice to back up to this or that breakpoint, well they've finally made it possible!

Upvotes: 0

Employed Russian
Employed Russian

Reputation: 213375

warning: .gdbinit: No such file or directory

That is almost certainly a bug in GDB -- I would expect it to read .gdbinit from the directory specified via -cd DIR argument. Documentation says:

 5. Processes command line options and operands.
 6. Reads and executes the commands from init file (if any) in the current working directory ...

Logically, current working directory at that point in time should be DIR.

My last alternative is the put all commands inside the $HOME/.gdbinit file but I'm avoiding it, because there are others development environments sharing the same $HOME/.dbginit file

If you have non-ancient GDB with embedded Python, you can put source ~/.gdbinit.py into your ~/.gdbinit. In the ~/.gdbinit.py, you have full power of Python at your disposal. You can examine the environment, arguments (including the binary you are about to debug), and adjust settings appropriately for that particular environment.

Upvotes: 1

Related Questions