This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Look for system.gdbinit in specified --data-directory
Pedro Alves writes:
> On 11/13/2012 09:30 PM, Doug Evans wrote:
> > On Wed, Nov 7, 2012 at 9:51 AM, <dje@google.com> wrote:
> >> Hi.
> >>
> >> On targets where system.gdbinit lives in data-directory, IWBN if
> >> gdb looked for it in the new place when data-directory is overridden
> >> at startup.
> >>
> >> Ok to check in?
> >>
> >> 2012-11-07 Doug Evans <dje@google.com>
> >>
> >> * main.c (gdb_datadir_provided): New static global.
> >> (get_init_files): If --data-directory is provided,
> >> and SYSTEM_GDBINIT lives in data-directory, look for it there.
> >
> > Hi.
> > I think this is reasonable and it's been soaking awhile (so to speak),
> > so I will check this in in a few days if there are no objections.
>
> I agree this is reasonable, but shouldn't this be documented
> somewhere?
To me it's a straightforward bug fix, so I left it at that.
[I'm not going to require writing docs for bug fixes, it'll bring gdb development to a crawl. :-)]
Eli, doc rfa please.
[And thanks. :-)]
2012-11-14 Doug Evans <dje@google.com>
* main.c (gdb_datadir_provided): New static global.
(get_init_files): If --data-directory is provided,
and SYSTEM_GDBINIT lives in data-directory, look for it there.
* NEWS: Mention it.
doc/
* gdb.texinfo (System-wide configuration): If the system-wide init
file lives in the data-directory, and --data-directory is provided,
look for it there.
Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.548
diff -u -p -r1.548 NEWS
--- NEWS 17 Oct 2012 00:53:21 -0000 1.548
+++ NEWS 14 Nov 2012 18:09:09 -0000
@@ -3,6 +3,10 @@
*** Changes since GDB 7.5
+* If the system-wide init file (specified by --with-system-gdbinit) lives
+ in GDB's data-directory, then GDB will now look for it in the directory
+ specified by the --data-directory command line option.
+
* New command line options:
-nh Disables auto-loading of ~/.gdbinit, but still executes all the
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.114
diff -u -p -r1.114 main.c
--- main.c 15 Oct 2012 21:45:04 -0000 1.114
+++ main.c 14 Nov 2012 18:09:09 -0000
@@ -60,6 +60,11 @@ char *gdb_sysroot = 0;
/* GDB datadir, used to store data files. */
char *gdb_datadir = 0;
+/* Non-zero if GDB_DATADIR was provided on the command line.
+ This doesn't track whether data-directory is set later from the
+ command line, but we don't reread system.gdbinit when that happens. */
+static int gdb_datadir_provided = 0;
+
/* If gdb was configured with --with-python=/path,
the possibly relocated path to python's lib directory. */
char *python_libdir = 0;
@@ -163,13 +168,38 @@ get_init_files (char **system_gdbinit,
if (!initialized)
{
struct stat homebuf, cwdbuf, s;
- char *homedir, *relocated_sysgdbinit;
+ char *homedir;
if (SYSTEM_GDBINIT[0])
{
- relocated_sysgdbinit = relocate_path (gdb_program_name,
- SYSTEM_GDBINIT,
- SYSTEM_GDBINIT_RELOCATABLE);
+ int datadir_len = strlen (GDB_DATADIR);
+ int sys_gdbinit_len = strlen (SYSTEM_GDBINIT);
+ char *relocated_sysgdbinit;
+
+ /* If SYSTEM_GDBINIT lives in data-directory, and data-directory
+ has been provided, search for SYSTEM_GDBINIT there. */
+ if (gdb_datadir_provided
+ && datadir_len < sys_gdbinit_len
+ && strncmp (SYSTEM_GDBINIT, GDB_DATADIR, datadir_len) == 0
+ && strchr (SLASH_STRING, SYSTEM_GDBINIT[datadir_len]) != NULL)
+ {
+ /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
+ to gdb_datadir. */
+ char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
+ char *p;
+
+ for (p = tmp_sys_gdbinit; strchr (SLASH_STRING, *p); ++p)
+ continue;
+ relocated_sysgdbinit = concat (gdb_datadir, SLASH_STRING, p,
+ NULL);
+ xfree (tmp_sys_gdbinit);
+ }
+ else
+ {
+ relocated_sysgdbinit = relocate_path (gdb_program_name,
+ SYSTEM_GDBINIT,
+ SYSTEM_GDBINIT_RELOCATABLE);
+ }
if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0)
sysgdbinit = relocated_sysgdbinit;
else
@@ -591,6 +621,7 @@ captured_main (void *data)
case 'D':
xfree (gdb_datadir);
gdb_datadir = xstrdup (optarg);
+ gdb_datadir_provided = 1;
break;
#ifdef GDBTK
case 'z':
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.1017
diff -u -p -r1.1017 gdb.texinfo
--- doc/gdb.texinfo 5 Nov 2012 19:36:38 -0000 1.1017
+++ doc/gdb.texinfo 14 Nov 2012 18:09:09 -0000
@@ -34544,6 +34544,14 @@ then @value{GDBN} will always look for @
wherever @value{GDBN} is installed.
@end itemize
+If the system-wide init file lives in the @value{GDBN} data-directory
+(@pxref{Data Files}), then @value{GDBN} will look for the file in the
+directory specified by the @option{--data-directory} command line option.
+Note that the system-wide init file is only read once, during @value{GDBN}
+initialization. If the data-directory is changed after @value{GDBN} has
+started with the @code{set data-directory} command, the file will not be
+reread.
+
@node Maintenance Commands
@appendix Maintenance Commands
@cindex maintenance commands