[patch] Don't call symtabs_from_filename if we don't have to.

Doug Evans dje@google.com
Sat Jan 14 22:32:00 GMT 2012


Hi.

This patch can greatly reduce the time to do "gdb a.out ; b main ; run"
for large programs.
[e.g. ~32 seconds to ~8 seconds, and that's with .gdb_index]

I will check this in in a few days if there are no objections.

2012-01-14  Doug Evans  <dje@google.com>

	* linespec.c (decode_line_internal): Don't call symtabs_from_filename
	if we know we don't have a file name to look for.

Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.142
diff -u -p -r1.142 linespec.c
--- linespec.c	4 Jan 2012 14:24:57 -0000	1.142
+++ linespec.c	14 Jan 2012 21:00:40 -0000
@@ -894,32 +894,44 @@ decode_line_internal (struct linespec_st
   first_half = p = locate_first_half (argptr, &is_quote_enclosed);
 
   /* First things first: if ARGPTR starts with a filename, get its
-     symtab and strip the filename from ARGPTR.  */
-  TRY_CATCH (file_exception, RETURN_MASK_ERROR)
+     symtab and strip the filename from ARGPTR.
+     Avoid calling symtab_from_filename if we know can,
+     it can be expensive.  */
+
+  if (*p != '\0')
     {
-      self->file_symtabs = symtabs_from_filename (argptr, p, is_quote_enclosed,
-						  &self->user_filename);
-    }
+      TRY_CATCH (file_exception, RETURN_MASK_ERROR)
+	{
+	  self->file_symtabs = symtabs_from_filename (argptr, p,
+						      is_quote_enclosed,
+						      &self->user_filename);
+	}
 
-  if (VEC_empty (symtab_p, self->file_symtabs))
+      if (file_exception.reason >= 0)
+	{
+	  /* Check for single quotes on the non-filename part.  */
+	  is_quoted = (**argptr
+		       && strchr (get_gdb_completer_quote_characters (),
+				  **argptr) != NULL);
+	  if (is_quoted)
+	    end_quote = skip_quoted (*argptr);
+
+	  /* Locate the next "half" of the linespec.  */
+	  first_half = p = locate_first_half (argptr, &is_quote_enclosed);
+	}
+
+      if (VEC_empty (symtab_p, self->file_symtabs))
+	{
+	  /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
+	  VEC_safe_push (symtab_p, self->file_symtabs, NULL);
+	}
+    }
+  else
     {
       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
       VEC_safe_push (symtab_p, self->file_symtabs, NULL);
     }
 
-  if (file_exception.reason >= 0)
-    {
-      /* Check for single quotes on the non-filename part.  */
-      is_quoted = (**argptr
-		   && strchr (get_gdb_completer_quote_characters (),
-			      **argptr) != NULL);
-      if (is_quoted)
-	end_quote = skip_quoted (*argptr);
-
-      /* Locate the next "half" of the linespec.  */
-      first_half = p = locate_first_half (argptr, &is_quote_enclosed);
-    }
-
   /* Check if this is an Objective-C method (anything that starts with
      a '+' or '-' and a '[').  */
   if (is_objc_method_format (p))



More information about the Gdb-patches mailing list