]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
skip -gfile: call fnmatch without FNM_FILE_NAME
authorFangrui Song <maskray@sourceware.org>
Sun, 29 Dec 2024 22:57:44 +0000 (14:57 -0800)
committerFangrui Song <maskray@sourceware.org>
Sat, 4 Jan 2025 05:15:32 +0000 (21:15 -0800)
fnmatch is called with the FNM_FILE_NAME flag so that `skip -gfi /usr/*`
doesn't match /usr/include/*.  This makes the file matching feature not
useful for STL headers that reside in multiple directories.  In
addition, the user cannot use a single `*` to match multiple leading
path components.

Let's drop the FNM_FILE_NAME flag and remove the assertion from
gdb_filename_fnmatch (originally for the auto-load feature).

gdb/doc/gdb.texinfo
gdb/skip.c
gdb/symtab.c
gdb/utils.c

index b985399cf34039dbb416fd862d19198bf3954123..c77ac7f30c27ce422fa25f053f01af4f7754eff0 100644 (file)
@@ -6737,7 +6737,9 @@ Functions in @var{file} will be skipped over when stepping.
 @itemx -gfi @var{file-glob-pattern}
 @cindex skipping over files via glob-style patterns
 Functions in files matching @var{file-glob-pattern} will be skipped
-over when stepping.
+over when stepping.  The directory separator character @file{/} is treated as a
+regular character, so it can be matched by wildcard characters @file{*} and
+@file{?}.
 
 @smallexample
 (@value{GDBP}) skip -gfi utils/*.c
index 3791c29b1e014c43e95583db831dd2234603d9de..aaa0785962591ea93e1d000766680b1a0ee336e9 100644 (file)
@@ -531,7 +531,7 @@ skiplist_entry::do_skip_gfile_p (const symtab_and_line &function_sal) const
   /* Check first sole SYMTAB->FILENAME.  It may not be a substring of
      symtab_to_fullname as it may contain "./" etc.  */
   if (gdb_filename_fnmatch (m_file.c_str (), function_sal.symtab->filename,
-                           FNM_FILE_NAME | FNM_NOESCAPE) == 0)
+                           FNM_NOESCAPE) == 0)
     result = true;
 
   /* Before we invoke symtab_to_fullname, which is expensive, do a quick
@@ -542,14 +542,14 @@ skiplist_entry::do_skip_gfile_p (const symtab_and_line &function_sal) const
   else if (!basenames_may_differ
       && gdb_filename_fnmatch (lbasename (m_file.c_str ()),
                               lbasename (function_sal.symtab->filename),
-                              FNM_FILE_NAME | FNM_NOESCAPE) != 0)
+                              FNM_NOESCAPE) != 0)
     result = false;
   else
     {
       /* Note: symtab_to_fullname caches its result, thus we don't have to.  */
       const char *fullname = symtab_to_fullname (function_sal.symtab);
 
-      result = compare_glob_filenames_for_search (fullname, m_file.c_str ());
+      result = gdb_filename_fnmatch (m_file.c_str (), fullname, FNM_NOESCAPE);
     }
 
   if (debug_skip)
index 106e540ca48f28fb279e9caf8e4f135fcff77378..ba421267b9a8ad30887d72adde2a1cfffa4b94e9 100644 (file)
@@ -588,40 +588,6 @@ compare_filenames_for_search (const char *filename, const char *search_name)
              && STRIP_DRIVE_SPEC (filename) == &filename[len - search_len]));
 }
 
-/* Same as compare_filenames_for_search, but for glob-style patterns.
-   Heads up on the order of the arguments.  They match the order of
-   compare_filenames_for_search, but it's the opposite of the order of
-   arguments to gdb_filename_fnmatch.  */
-
-bool
-compare_glob_filenames_for_search (const char *filename,
-                                  const char *search_name)
-{
-  /* We rely on the property of glob-style patterns with FNM_FILE_NAME that
-     all /s have to be explicitly specified.  */
-  int file_path_elements = count_path_elements (filename);
-  int search_path_elements = count_path_elements (search_name);
-
-  if (search_path_elements > file_path_elements)
-    return false;
-
-  if (IS_ABSOLUTE_PATH (search_name))
-    {
-      return (search_path_elements == file_path_elements
-             && gdb_filename_fnmatch (search_name, filename,
-                                      FNM_FILE_NAME | FNM_NOESCAPE) == 0);
-    }
-
-  {
-    const char *file_to_compare
-      = strip_leading_path_elements (filename,
-                                    file_path_elements - search_path_elements);
-
-    return gdb_filename_fnmatch (search_name, file_to_compare,
-                                FNM_FILE_NAME | FNM_NOESCAPE) == 0;
-  }
-}
-
 /* Check for a symtab of a specific name by searching some symtabs.
    This is a helper function for callbacks of iterate_over_symtabs.
 
index 6f2055e299d363a9504259cfbeb2c12ddde73bdf..4027d4f26c38449d593cfd871c994738cf78d493 100644 (file)
@@ -3491,8 +3491,8 @@ wait_to_die_with_timeout (pid_t pid, int *status, int timeout)
 
 #endif /* HAVE_WAITPID */
 
-/* Provide fnmatch compatible function for FNM_FILE_NAME matching of host files.
-   Both FNM_FILE_NAME and FNM_NOESCAPE must be set in FLAGS.
+/* Provide fnmatch compatible function for matching of host files.
+   FNM_NOESCAPE must be set in FLAGS.
 
    It handles correctly HAVE_DOS_BASED_FILE_SYSTEM and
    HAVE_CASE_INSENSITIVE_FILE_SYSTEM.  */
@@ -3500,8 +3500,6 @@ wait_to_die_with_timeout (pid_t pid, int *status, int timeout)
 int
 gdb_filename_fnmatch (const char *pattern, const char *string, int flags)
 {
-  gdb_assert ((flags & FNM_FILE_NAME) != 0);
-
   /* It is unclear how '\' escaping vs. directory separator should coexist.  */
   gdb_assert ((flags & FNM_NOESCAPE) != 0);