As mentioned earlier, it is usually a good idea to not exit GDB while you recompile your code. This way your breakpoints and various other actions you set up (for example, display
commands, to be discussed in Chapter 3) are retained. If you were to exit GDB, you would have to type these all over again.
However, you may need to exit GDB before you are finished debugging. If you are quitting for a break or for the day, and you cannot stay logged in to the computer, you'll need to exit GDB. In order to not lose them, you can put your commands for breakpoints and other settings in a GDB startup file, and then they will be loaded automatically every time you start up GDB.
GDB's startup files are named .gdbinit by default. You can have one in your home directory for general purposes and another in the directory containing a particular project for purposes specific to that project. For instance, you would put commands to set breakpoints in a startup file in the latter directory. In your .gdbinit file in your home directory, you may wish to store some general-purpose macros you've developed, as discussed in Chapter 2.
GDB reads the startup file in your home directory before it loads an executable. So if you were to have a command in your home directory's .gdbinit file such as
break g
saying to break at the function g()
, then GDB would always complain at startup that it does not know that function. However, the line would be fine in your local project directory's startup file, because the local startup file is read after the executable (and its symbol table) has been loaded. Note that this feature of GDB implies that it is best to not put programming projects in your home directory, as you would not be able to put project-specific information in .gdbinit.
You can specify the startup file at the time you invoke GDB. For example,
$ gdb -command=z x
would say to run GDB on the executable file x, first reading in commands from the file z. Also, because DDD is just a front end for GDB, invoking DDD will invoke GDB's startup files as well.
Finally, you can customize DDD in various ways by selecting Edit | Preferences. For Eclipse, the sequence is Window | Preferences.