[PATCH v2 2/2] [gdb/symtab] Use expand_all_symtabs in maint expand-symtabs

Tom de Vries tdevries@suse.de
Sun Sep 22 10:40:25 GMT 2024


When issuing a command "maint expand-symtabs", maintenance_expand_symtabs is
called with regexp == nullptr, and calls expand_symtabs_matching like so:
...
      objfile->expand_symtabs_matching
       ([&] (const char *filename, bool basenames)
	{
	  /* KISS: Only apply the regexp to the complete file name.  */
	  return (!basenames
		  && (regexp == NULL || re_exec (filename)));
	},
...

To expand all symtabs gdb usually uses expand_all_symtabs (used for -readnow),
but here we try to handle it in the filename_matcher argument.

Make this more similar to how gdb usually works by using expand_all_symtabs.

A previous version of the patch instead used a nullptr filename_matcher for
the regexp == nullptr case.  That approach regressed test-cases
gdb.dwarf2/dwz-unused-pu.exp and gdb.dwarf2/dw2-dummy.exp.

Tested on x86_64-linux.
---
 gdb/symmisc.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 7f8141588b7..caca1e09f64 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -903,18 +903,25 @@ maintenance_expand_symtabs (const char *args, int from_tty)
 	}
     }
 
-  if (regexp)
-    re_comp (regexp);
+  if (regexp == nullptr)
+    {
+      for (struct program_space *pspace : program_spaces)
+	for (objfile *objfile : pspace->objfiles ())
+	  objfile->expand_all_symtabs ();
+
+      return;
+    }
+
+  re_comp (regexp);
 
   for (struct program_space *pspace : program_spaces)
     for (objfile *objfile : pspace->objfiles ())
       objfile->expand_symtabs_matching
 	([&] (const char *filename, bool basenames)
-	 {
-	   /* KISS: Only apply the regexp to the complete file name.  */
-	   return (!basenames
-		   && (regexp == NULL || re_exec (filename)));
-	 },
+	   {
+	     /* KISS: Only apply the regexp to the complete file name.  */
+	     return !basenames && re_exec (filename);
+	   },
 	 NULL,
 	 NULL,
 	 NULL,
-- 
2.35.3



More information about the Gdb-patches mailing list