dump files tweek

Greg McGary gkm@eng.ascend.com
Sun Oct 31 23:33:00 GMT 1999


Richard Henderson <rth@cygnus.com> writes:

> Sometimes I find it annoying to grep for the first occurrence of
> an insn in the set of dump files, since the files are not sorted
> in any way.
> 
> This patch adds a pass number to the dump file name (eg foo.c.02.cse)
> so that "grep 'insn[^0-9]* 179 foo.c.*" will do the Right Thing.

Sorry I didn't read this before now...

I did something similar a few months ago, but made sequencing
automatic rather than manual.  With automatic sequence#s, you needn't
worry about updating the code every time a new optimization is added
or removed.  I see you changed invoke.texi to document the seq#s.
With automatic seq#s, we'd want to remove that since seq#s wouldn't be
fixed.

The drawback is that the seq#s for a given pass can change between
runs depending on optimization options, and consequently if old debug
files already exist, some will fall through the cracks and not be
rewritten if their seq#s changed.  It seems like overkill to make gcc
automatically remove "<dumpbase>.*.<suffix>" prior to writing a new
debug file, but it would prevent surprises.

Included is a patch against the April 8 1998 EGCS snapshot so you can
see what I did.  The fixed length suffix vector should change to
something growable such as a varray.

Let me know what you think.

Index: toplev.c
===================================================================
RCS file: /3/cvsroot-mirror/tools/gcc/toplev.c,v
retrieving revision 1.8.2.3
diff -u -p -r1.8.2.3 toplev.c
--- toplev.c	1999/01/05 08:47:50	1.8.2.3
+++ toplev.c	1999/06/02 07:47:08
@@ -2177,25 +2177,57 @@ output_lang_identify (asm_out_file)
   ASM_OUTPUT_LABEL (asm_out_file, s);
 }
 
+int
+dump_index (suffix)
+     char *suffix;
+{
+  static char **suffixes_0;
+  char **suffixes;
+
+  if (!suffixes_0)
+    {
+      suffixes_0 = (char **) xmalloc (32 * sizeof (char *));
+      *suffixes_0 = 0;
+    }
+  
+  suffixes = suffixes_0;
+  while (*suffixes)
+    {
+      if (strcmp (suffix, *suffixes) == 0)
+	return suffixes - suffixes_0;
+      suffixes++;
+    }
+  *suffixes = suffix;
+  suffixes[1] = 0;
+  return suffixes - suffixes_0;
+}
+
+char *
+make_dump_name (suffix)
+     char *suffix;
+{
+  char *dumpname = (char *) xmalloc (strlen (dump_base_name) + 3 + strlen (suffix) + 1);
+
+  sprintf (dumpname, "%s-%02d%s", dump_base_name, dump_index (suffix), suffix);
+
+  return dumpname;
+}
+
+
 /* Routine to open a dump file.  */
 static void
 open_dump_file (suffix, function_name)
      char *suffix;
      char *function_name;
 {
-  char *dumpname;
-
   TIMEVAR
     (dump_time,
      {
-       dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
+       char *dumpname = make_dump_name (suffix);
 
        if (rtl_dump_file != NULL)
 	 fclose (rtl_dump_file);
   
-       strcpy (dumpname, dump_base_name);
-       strcat (dumpname, suffix);
-       
        rtl_dump_file = fopen (dumpname, "a");
        
        if (rtl_dump_file == NULL)
@@ -2248,12 +2280,7 @@ static void
 clean_dump_file (suffix)
      char * suffix;
 {
-  char * dumpname;
-
-  dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
-
-  strcpy (dumpname, dump_base_name);
-  strcat (dumpname, suffix);
+  char *dumpname = make_dump_name (suffix);
        
   rtl_dump_file = fopen (dumpname, "w");
 



More information about the Gcc-patches mailing list