]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/
authorJan Kratochvil <jan.kratochvil@redhat.com>
Tue, 17 Apr 2012 15:56:21 +0000 (15:56 +0000)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Tue, 17 Apr 2012 15:56:21 +0000 (15:56 +0000)
New option "set debug auto-load".
* NEWS: New commands "set debug auto-load" and "show debug auto-load".
* auto-load.c (debug_auto_load, show_debug_auto_load: New.
(auto_load_safe_path_vec_update)
(filename_is_in_auto_load_safe_path_vec): Call fprintf_unfiltered
if DEBUG_AUTO_LOAD.
(file_is_auto_load_safe): New parameters debug_fmt and ....
Call fprintf_unfiltered if DEBUG_AUTO_LOAD.
(source_gdb_script_for_objfile): Extend the file_is_auto_load_safe
caller by explanatory string.
(_initialize_auto_load): Register "set debug auto-load".
* auto-load.h (file_is_auto_load_safe): New parameters debug_fmt
and ....
* linux-thread-db.c (try_thread_db_load_from_pdir_1)
(try_thread_db_load_from_dir): Extend the file_is_auto_load_safe caller
by explanatory string.
* main.c (captured_main): Likewise.
* python/py-auto-load.c (gdbpy_load_auto_script_for_objfile)
(source_section_scripts): Likewise.

gdb/doc/
New option "set debug auto-load".
* gdb.texinfo (Auto-loading): New menu item for auto-load verbose mode.
(auto-load verbose mode): New node.

gdb/ChangeLog
gdb/NEWS
gdb/auto-load.c
gdb/auto-load.h
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/linux-thread-db.c
gdb/main.c
gdb/python/py-auto-load.c

index 5ebb391d3881a3cf6e255b9100bc81556af579f6..642b9780c0accaafa0a65fd3cb9aef0fc6a36680 100644 (file)
@@ -1,3 +1,25 @@
+2012-04-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       New option "set debug auto-load".
+       * NEWS: New commands "set debug auto-load" and "show debug auto-load".
+       * auto-load.c (debug_auto_load, show_debug_auto_load: New.
+       (auto_load_safe_path_vec_update)
+       (filename_is_in_auto_load_safe_path_vec): Call fprintf_unfiltered
+       if DEBUG_AUTO_LOAD.
+       (file_is_auto_load_safe): New parameters debug_fmt and ....
+       Call fprintf_unfiltered if DEBUG_AUTO_LOAD.
+       (source_gdb_script_for_objfile): Extend the file_is_auto_load_safe
+       caller by explanatory string.
+       (_initialize_auto_load): Register "set debug auto-load".
+       * auto-load.h (file_is_auto_load_safe): New parameters debug_fmt
+       and ....
+       * linux-thread-db.c (try_thread_db_load_from_pdir_1)
+       (try_thread_db_load_from_dir): Extend the file_is_auto_load_safe caller
+       by explanatory string.
+       * main.c (captured_main): Likewise.
+       * python/py-auto-load.c (gdbpy_load_auto_script_for_objfile)
+       (source_section_scripts): Likewise.
+
 2012-04-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        New option "set auto-load safe-path".
index 28a9a7eff4c9acc579be969c9839fa64f54897a3..72b4d9022d3695428712bd043704b6d03d5ed35d 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -159,6 +159,10 @@ show auto-load safe-path
   Set a list of directories from which it is safe to auto-load files.
   The delimiter (':' above) may differ according to the host platform.
 
+set debug auto-load on|off
+show debug auto-load
+  Control display of debugging info for auto-loading the files above.
+
 * New remote packets
 
 z0/z1 conditional breakpoints extension
index 076e50bd1b2af8bd20d9309ac9ca2582ef034baf..9d19179feb94a23f90cb1408224b3fbd218a59bc 100644 (file)
 static void source_gdb_script_for_objfile (struct objfile *objfile, FILE *file,
                                           const char *filename);
 
+/* Value of the 'set debug auto-load' configuration variable.  */
+static int debug_auto_load = 0;
+
+/* "show" command for the debug_auto_load configuration variable.  */
+
+static void
+show_debug_auto_load (struct ui_file *file, int from_tty,
+                     struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Debugging output for files "
+                           "of 'set auto-load ...' is %s.\n"),
+                   value);
+}
+
 /* User-settable option to enable/disable auto-loading of GDB_AUTO_FILE_NAME
    scripts:
    set auto-load gdb-scripts on|off
@@ -112,6 +126,11 @@ auto_load_safe_path_vec_update (void)
   unsigned len;
   int ix;
 
+  if (debug_auto_load)
+    fprintf_unfiltered (gdb_stdlog,
+                       _("auto-load: Updating directories of \"%s\".\n"),
+                       auto_load_safe_path);
+
   free_char_ptr_vec (auto_load_safe_path_vec);
 
   auto_load_safe_path_vec = dirnames_to_char_ptr_vec (auto_load_safe_path);
@@ -126,14 +145,34 @@ auto_load_safe_path_vec_update (void)
       char *real_path = gdb_realpath (expanded);
 
       /* Ensure the current entry is at least tilde_expand-ed.  */
-      xfree (dir);
       VEC_replace (char_ptr, auto_load_safe_path_vec, ix, expanded);
 
+      if (debug_auto_load)
+       {
+         if (strcmp (expanded, dir) == 0)
+           fprintf_unfiltered (gdb_stdlog,
+                               _("auto-load: Using directory \"%s\".\n"),
+                               expanded);
+         else
+           fprintf_unfiltered (gdb_stdlog,
+                               _("auto-load: Resolved directory \"%s\" "
+                                 "as \"%s\".\n"),
+                               dir, expanded);
+       }
+      xfree (dir);
+
       /* If gdb_realpath returns a different content, append it.  */
       if (strcmp (real_path, expanded) == 0)
        xfree (real_path);
       else
-       VEC_safe_push (char_ptr, auto_load_safe_path_vec, real_path);
+       {
+         VEC_safe_push (char_ptr, auto_load_safe_path_vec, real_path);
+
+         if (debug_auto_load)
+           fprintf_unfiltered (gdb_stdlog,
+                               _("auto-load: And canonicalized as \"%s\".\n"),
+                               real_path);
+       }
     }
 }
 
@@ -217,16 +256,30 @@ filename_is_in_auto_load_safe_path_vec (const char *filename,
   if (dir == NULL)
     {
       if (*filename_realp == NULL)
-       *filename_realp = gdb_realpath (filename);
+       {
+         *filename_realp = gdb_realpath (filename);
+         if (debug_auto_load && strcmp (*filename_realp, filename) != 0)
+           fprintf_unfiltered (gdb_stdlog,
+                               _("auto-load: Resolved "
+                                 "file \"%s\" as \"%s\".\n"),
+                               filename, *filename_realp);
+       }
 
-      for (ix = 0; VEC_iterate (char_ptr, auto_load_safe_path_vec, ix, dir);
-          ++ix)
-       if (filename_is_in_dir (*filename_realp, dir))
-         break;
+      if (strcmp (*filename_realp, filename) != 0)
+       for (ix = 0; VEC_iterate (char_ptr, auto_load_safe_path_vec, ix, dir);
+            ++ix)
+         if (filename_is_in_dir (*filename_realp, dir))
+           break;
     }
 
   if (dir != NULL)
-    return 1;
+    {
+      if (debug_auto_load)
+       fprintf_unfiltered (gdb_stdlog, _("auto-load: File \"%s\" matches "
+                                         "directory \"%s\".\n"),
+                           filename, dir);
+      return 1;
+    }
 
   return 0;
 }
@@ -240,11 +293,20 @@ filename_is_in_auto_load_safe_path_vec (const char *filename,
    directory.  */
 
 int
-file_is_auto_load_safe (const char *filename)
+file_is_auto_load_safe (const char *filename, const char *debug_fmt, ...)
 {
   char *filename_real = NULL;
   struct cleanup *back_to;
 
+  if (debug_auto_load)
+    {
+      va_list debug_args;
+
+      va_start (debug_args, debug_fmt);
+      vfprintf_unfiltered (gdb_stdlog, debug_fmt, debug_args);
+      va_end (debug_args);
+    }
+
   back_to = make_cleanup (free_current_contents, &filename_real);
 
   if (filename_is_in_auto_load_safe_path_vec (filename, &filename_real))
@@ -281,7 +343,10 @@ source_gdb_script_for_objfile (struct objfile *objfile, FILE *file,
   struct auto_load_pspace_info *pspace_info;
   volatile struct gdb_exception e;
 
-  is_safe = file_is_auto_load_safe (filename);
+  is_safe = file_is_auto_load_safe (filename, _("auto-load: Loading canned "
+                                               "sequences of commands script "
+                                               "\"%s\" for objfile \"%s\".\n"),
+                                   filename, objfile->name);
 
   /* Add this script to the hash table too so "info auto-load gdb-scripts"
      can print it.  */
@@ -975,4 +1040,13 @@ See the commands 'set auto-load safe-path' and 'show auto-load safe-path' to\n\
 access the current full list setting."),
                 &cmdlist);
   set_cmd_completer (cmd, filename_completer);
+
+  add_setshow_boolean_cmd ("auto-load", class_maintenance,
+                          &debug_auto_load, _("\
+Set auto-load verifications debugging."), _("\
+Show auto-load verifications debugging."), _("\
+When non-zero, debugging output for files of 'set auto-load ...'\n\
+is displayed."),
+                           NULL, show_debug_auto_load,
+                           &setdebuglist, &showdebuglist);
 }
index 6b2fe759c58344e5b86d31ac86930880a9cef2b9..16cad982dbd6c8a7d32009ff8575443babbeb17b 100644 (file)
@@ -55,6 +55,7 @@ extern struct cmd_list_element **auto_load_set_cmdlist_get (void);
 extern struct cmd_list_element **auto_load_show_cmdlist_get (void);
 extern struct cmd_list_element **auto_load_info_cmdlist_get (void);
 
-extern int file_is_auto_load_safe (const char *filename);
+extern int file_is_auto_load_safe (const char *filename,
+                                  const char *debug_fmt, ...);
 
 #endif /* AUTO_LOAD_H */
index b4f18dcc8cfca347c4de3606e1119da842a32a5b..a5d66f026f9905fbd479d6f290c5bd67569f08e0 100644 (file)
@@ -1,3 +1,9 @@
+2012-04-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       New option "set debug auto-load".
+       * gdb.texinfo (Auto-loading): New menu item for auto-load verbose mode.
+       (auto-load verbose mode): New node.
+
 2012-04-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        New option "set auto-load safe-path".
index ce90f60767c4ca86d333ea94811ef983ddb845b8..14b4fda5feca17c61be426ec686d5b50eef6a489 100644 (file)
@@ -20978,6 +20978,7 @@ These are @value{GDBN} control commands for the auto-loading:
 * libthread_db.so.1 file::             @samp{set/show/info auto-load libthread-db}
 * objfile-gdb.gdb file::               @samp{set/show/info auto-load gdb-script}
 * Auto-loading safe path::             @samp{set/show/info auto-load safe-path}
+* Auto-loading verbose mode::          @samp{set/show debug auto-load}
 @xref{Python Auto-loading}.
 @end menu
 
@@ -21176,6 +21177,45 @@ entries again.  @value{GDBN} already canonicalizes most of the filenames on its
 own before starting the comparison so a canonical form of directories is
 recommended to be entered.
 
+@node Auto-loading verbose mode
+@subsection Displaying files tried for auto-load
+@cindex auto-loading verbose mode
+
+For better visibility of all the file locations where you can place scripts to
+be auto-loaded with inferior --- or to protect yourself against accidental
+execution of untrusted scripts --- @value{GDBN} provides a feature for printing
+all the files attempted to be loaded.  Both existing and non-existing files may
+be printed.
+
+For example the list of directories from which it is safe to auto-load files
+(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
+may not be too obvious while setting it up.
+
+@smallexample
+(gdb) set debug auto-load ues
+(gdb) file ~/src/t/true
+auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
+           for objfile "/tmp/true".
+auto-load: Updating directories of "/usr:/opt".
+auto-load: Using directory "/usr".
+auto-load: Using directory "/opt".
+warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
+         by your `auto-load safe-path' set to "/usr:/opt".
+@end smallexample
+
+@table @code
+@anchor{set debug auto-load}
+@kindex set debug auto-load
+@item set debug auto-load [on|off]
+Set whether to print the filenames attempted to be auto-loaded.
+
+@anchor{show debug auto-load}
+@kindex show debug auto-load
+@item show debug auto-load
+Show whether printing of the filenames attempted to be auto-loaded is turned
+on or off.
+@end table
+
 @node Messages/Warnings
 @section Optional Warnings and Messages
 
index 1f6042d3db7fd67cf2aef99033296ae4710c02c7..f78f662d4359cae58229290fa4aa8b9af8912087 100644 (file)
@@ -870,7 +870,9 @@ try_thread_db_load_from_pdir_1 (struct objfile *obj)
   gdb_assert (cp != NULL);
   strcpy (cp + 1, LIBTHREAD_DB_SO);
 
-  if (!file_is_auto_load_safe (path))
+  if (!file_is_auto_load_safe (path, _("auto-load: Loading libthread-db "
+                                      "library \"%s\" from $pdir.\n"),
+                              path))
     result = 0;
   else
     result = try_thread_db_load (path);
@@ -940,7 +942,10 @@ try_thread_db_load_from_dir (const char *dir, size_t dir_len)
   path[dir_len] = '/';
   strcpy (path + dir_len + 1, LIBTHREAD_DB_SO);
 
-  if (!file_is_auto_load_safe (path))
+  if (!file_is_auto_load_safe (path, _("auto-load: Loading libthread-db "
+                                      "library \"%s\" from explicit "
+                                      "directory.\n"),
+                              path))
     result = 0;
   else
     result = try_thread_db_load (path);
index 48e522eb6183682742a69b5a9c72795884dd727c..fe41551d947df052f29743b38f6478c2102eb364 100644 (file)
@@ -945,7 +945,10 @@ captured_main (void *data)
       auto_load_local_gdbinit_pathname = gdb_realpath (local_gdbinit);
 
       if (!inhibit_gdbinit && auto_load_local_gdbinit
-         && file_is_auto_load_safe (local_gdbinit))
+         && file_is_auto_load_safe (local_gdbinit,
+                                    _("auto-load: Loading .gdbinit "
+                                      "file \"%s\".\n"),
+                                    local_gdbinit))
        {
          auto_load_local_gdbinit_loaded = 1;
 
index c54194d02ee55aaaf91b2acf1be8a67f20a6d81f..8512129c707b8c83040a34f8c4785d6b4f12cea0 100644 (file)
@@ -75,7 +75,10 @@ gdbpy_load_auto_script_for_objfile (struct objfile *objfile, FILE *file,
   int is_safe;
   struct auto_load_pspace_info *pspace_info;
 
-  is_safe = file_is_auto_load_safe (filename);
+  is_safe = file_is_auto_load_safe (filename,
+                                   _("auto-load: Loading Python script \"%s\" "
+                                     "by extension for objfile \"%s\".\n"),
+                                   filename, objfile->name);
 
   /* Add this script to the hash table too so "info auto-load python-scripts"
      can print it.  */
@@ -153,7 +156,12 @@ source_section_scripts (struct objfile *objfile, const char *source_name,
          make_cleanup_fclose (stream);
          make_cleanup (xfree, full_path);
 
-         if (!file_is_auto_load_safe (full_path))
+         if (!file_is_auto_load_safe (full_path,
+                                      _("auto-load: Loading Python script "
+                                        "\"%s\" from section \"%s\" of "
+                                        "objfile \"%s\".\n"),
+                                      full_path, GDBPY_AUTO_SECTION_NAME,
+                                      objfile->name))
            opened = 0;
        }
       else