This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] flag to create dump files in same directory as object files


Here's a patch which adds a new flag (-fdump-in-output-dir) to create
dump files in the same directory as the output (object) files rather
than the current working directory. This is useful in build
environments where gcc is invoked from a single directory to build the
same source files in multiple ways or if multiple source files have
the same name. Enabling this flag prevents these dump files from
being written on top of one another by creating dump files alongside
the .o files.

Bootstrapped on x86-64-linux.

OK?

Mark

2009-05-04  Mark Heffernan  <meheff@google.com>

        * common.opt: Add -fdump-in-output-dir.
        * opts.c (decode_options): Change directory of dump_base_name if
        flag_dump_in_output_dir is set.

Index: gcc/opts.c
===================================================================
--- gcc/opts.c  (revision 147106)
+++ gcc/opts.c  (working copy)
@@ -961,6 +961,34 @@ decode_options (unsigned int argc, const

   handle_options (argc, argv, lang_mask);

+  if (flag_dump_in_output_dir && dump_base_name && aux_base_name)
+    {
+      /* Create dump files in same directory as output file.  New
+        DUMP_BASE_NAME is the directory of AUX_BASE_NAME (same as the
+        output file) plus the basename of the existing
+        DUMP_BASE_NAME.  */
+      const char *dump_base, *aux_base;
+
+      base_of_path (dump_base_name, &dump_base);
+      base_of_path (aux_base_name, &aux_base);
+
+      /* DUMP_BASE_NAME is changed only if existing DUMP_BASE_NAME or
+        AUX_BASE_NAME include a directory component.  */
+      if (dump_base != dump_base_name || aux_base != aux_base_name)
+       {
+         int dir_len = aux_base - aux_base_name;
+         char *new_dump_base_name =
+           XNEWVEC (char, strlen(dump_base) + dir_len + 1);
+
+         /* Copy in directory and separator, if any.  */
+         if (dir_len)
+           memcpy (new_dump_base_name, aux_base_name, dir_len);
+         /* Append basename of dump file.  */
+         strcpy (new_dump_base_name + dir_len, dump_base);
+         dump_base_name = new_dump_base_name;
+       }
+    }
+
   /* Handle related options for unit-at-a-time, toplevel-reorder, and
      section-anchors.  */
   if (!flag_unit_at_a_time)
Index: gcc/common.opt
===================================================================
--- gcc/common.opt      (revision 147106)
+++ gcc/common.opt      (working copy)
@@ -458,6 +458,10 @@ fdump-unnumbered
 Common Report Var(flag_dump_unnumbered) VarExists
 Suppress output of instruction numbers, line number notes and
addresses in debugging dumps

+fdump-in-output-dir
+Common Report Var(flag_dump_in_output_dir)
+Create dump files in same directory as output file.
+
 fdwarf2-cfi-asm
 Common Report Var(flag_dwarf2_cfi_asm) Init(HAVE_GAS_CFI_DIRECTIVE)
 Enable CFI tables via GAS assembler directives.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]