*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / auto-load.c
index 076e50bd1b2af8bd20d9309ac9ca2582ef034baf..9d4d0bcb9cccf33779029b9392501a70672a5ffc 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);
+       }
     }
 }
 
@@ -142,6 +181,12 @@ auto_load_safe_path_vec_update (void)
 static void
 set_auto_load_safe_path (char *args, int from_tty, struct cmd_list_element *c)
 {
+  if (auto_load_safe_path[0] == '\0')
+    {
+      xfree (auto_load_safe_path);
+      auto_load_safe_path = xstrdup (DEFAULT_AUTO_LOAD_SAFE_PATH);
+    }
+
   auto_load_safe_path_vec_update ();
 }
 
@@ -151,7 +196,7 @@ static void
 show_auto_load_safe_path (struct ui_file *file, int from_tty,
                          struct cmd_list_element *c, const char *value)
 {
-  if (*value == 0)
+  if (strcmp (value, "/") == 0)
     fprintf_filtered (file, _("Auto-load files are safe to load from any "
                              "directory.\n"));
   else
@@ -170,8 +215,9 @@ add_auto_load_safe_path (char *args, int from_tty)
 
   if (args == NULL || *args == 0)
     error (_("\
-Adding empty directory element disables the auto-load safe-path security.  \
-Use 'set auto-load safe-path' instead if you mean that."));
+Directory argument required.\n\
+Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
+"));
 
   s = xstrprintf ("%s%c%s", auto_load_safe_path, DIRNAME_SEPARATOR, args);
   xfree (auto_load_safe_path);
@@ -192,6 +238,12 @@ filename_is_in_dir (const char *filename, const char *dir)
   while (dir_len && IS_DIR_SEPARATOR (dir[dir_len - 1]))
     dir_len--;
 
+  /* Ensure auto_load_safe_path "/" matches any FILENAME.  On MS-Windows
+     platform FILENAME even after gdb_realpath does not have to start with
+     IS_DIR_SEPARATOR character, such as the 'C:\x.exe' filename.  */
+  if (dir_len == 0)
+    return 1;
+
   return (filename_ncmp (dir, filename, dir_len) == 0
          && (IS_DIR_SEPARATOR (filename[dir_len])
              || filename[dir_len] == '\0'));
@@ -217,16 +269,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 +306,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 +356,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.  */
@@ -958,8 +1036,10 @@ Set the list of directories from which it is safe to auto-load files."), _("\
 Show the list of directories from which it is safe to auto-load files."), _("\
 Various files loaded automatically for the 'set auto-load ...' options must\n\
 be located in one of the directories listed by this option.  Warning will be\n\
-printed and file will not be used otherwise.  Use empty string (or even\n\
-empty directory entry) to allow any file for the 'set auto-load ...' options.\n\
+printed and file will not be used otherwise.\n\
+Setting this parameter to an empty list resets it to its default value.\n\
+Setting this parameter to '/' (without the quotes) allows any file\n\
+for the 'set auto-load ...' options.\n\
 This option is ignored for the kinds of files having 'set auto-load ... off'.\n\
 This options has security implications for untrusted inferiors."),
                                     set_auto_load_safe_path,
@@ -975,4 +1055,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);
 }
This page took 0.025843 seconds and 4 git commands to generate.