This is the mail archive of the mailing list for the Archer project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python] add another auto-load search directory

We would like a new auto-load directory to be available.

Using $ is not always nice for a distro -- it makes
ldconfig barf.

Using /usr/lib/debug is also not always nice, because it means, e.g.,
that libstdc++ would ship with files in this directory, breaking the
historical practice of only putting debuginfo there.

So, this patch makes gdb search a new subdirectory of gdb_datadir.  It
still looks for the full path, so you want to install files as, e.g.,


diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index fef4680..388b724 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18356,6 +18356,12 @@ If this file does not exist, and if the parameter
 @code{debug-file-directory} is set, then @value{GDBN} will append the
 object file's real name to the value of this parameter, and try again.
+Finally, if this file does not exist, then @value{GDBN} will look in
+subdirectory of @code{gdb_datadir} (whose value is available from
+@code{maint show gdb_datadir}).  Specifically, @value{GDBN} will take
+the value of @code{gdb_datadir}, append @samp{python/auto-load}, and
+then append the object file's real name.
 Also, if a separate debug file is used, @value{GDBN} will look for the
 @samp{} file both in the directory associated with the
 application and the directory associated with the separate debug file.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index b95016a..b3c3123 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -966,10 +966,11 @@ static void
 gdbpy_new_objfile (struct objfile *objfile)
   char *realname;
-  char *filename;
+  char *filename, *debugfile;
   int len;
   FILE *input;
   PyGILState_STATE state;
+  struct cleanup *cleanups;
   if (!gdbpy_auto_load || !objfile || !objfile->name)
@@ -985,35 +986,49 @@ gdbpy_new_objfile (struct objfile *objfile)
   strcpy (filename + len, GDBPY_AUTO_FILENAME);
   input = fopen (filename, "r");
+  debugfile = filename;
+  cleanups = make_cleanup (xfree, filename);
+  make_cleanup (xfree, realname);
   if (!input && debug_file_directory)
       /* Also try the same file in the separate debug info directory.  */
-      char *debugfile;
       debugfile = xmalloc (strlen (filename)
 			   + strlen (debug_file_directory) + 1);
       strcpy (debugfile, debug_file_directory);
       /* FILENAME is absolute, so we don't need a "/" here.  */
       strcat (debugfile, filename);
-      xfree (filename);
-      filename = debugfile;
+      make_cleanup (xfree, debugfile);
+      input = fopen (debugfile, "r");
+    }
-      input = fopen (filename, "r");
+  if (!input)
+    {
+      /* Also try the same file in a subdirectory of gdb's data
+	 directory.  */
+      debugfile = xmalloc (strlen (gdb_datadir) + strlen (filename)
+			   + strlen ("/auto-load") + 1);
+      strcpy (debugfile, gdb_datadir);
+      strcat (debugfile, "/auto-load");
+      /* FILENAME is absolute, so we don't need a "/" here.  */
+      strcat (debugfile, filename);
+      make_cleanup (xfree, debugfile);
+      input = fopen (debugfile, "r");
   if (input)
       /* We don't want to throw an exception here -- but the user
 	 would like to know that something went wrong.  */
-      if (PyRun_SimpleFile (input, filename))
+      if (PyRun_SimpleFile (input, debugfile))
 	gdbpy_print_stack ();
       fclose (input);
-  xfree (realname);
-  xfree (filename);
+  do_cleanups (cleanups);
   gdbpy_current_objfile = NULL;
   PyGILState_Release (state);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]