commit a464b717cc87ba64456ef52d7829c478e6e58e91
Author: David Malcolm <dmalcolm@redhat.com>
Date: Fri Feb 27 15:52:40 2015 -0500
Prototype of embedding dumpfiles within .s/.o
@@ -302,6 +302,15 @@ get_dump_file_name (struct dump_file_info *dfi) const
return concat (dump_base_name, dump_id, dfi->suffix, NULL);
}
+void
+gcc::dump_manager::for_each_dumpfile (void (*cb) (struct dump_file_info *,
+ void *user_data),
+ void *user_data)
+{
+ for (unsigned i = 0; i < m_extra_dump_files_in_use; i++)
+ (*cb) (&m_extra_dump_files[i], user_data);
+}
+
/* For a given DFI, open an alternate dump filename (which could also
be a standard stream such as stdout/stderr). If the alternate dump
file cannot be opened, return NULL. */
@@ -220,6 +220,11 @@ public:
const char *
dump_flag_name (int phase) const;
+ void
+ for_each_dumpfile (void (*cb) (struct dump_file_info *,
+ void *user_data),
+ void *user_data);
+
private:
int
@@ -114,6 +114,7 @@ along with GCC; see the file COPYING3. If not see
#include "optabs.h"
#include "tree-chkp.h"
#include "omp-low.h"
+#include "dumpfile.h"
#if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
#include "dbxout.h"
@@ -580,6 +581,84 @@ emit_debug_global_declarations (tree *vec, int len)
timevar_pop (TV_SYMOUT);
}
+/* FIXME: this is just a copy of jit-playback.c's
+ playback::context::read_dump_file with the error-handling
+ hacked out. */
+
+static char *
+read_dump_file (const char *path)
+{
+ char *result = NULL;
+ size_t total_sz = 0;
+ char buf[4096];
+ size_t sz;
+ FILE *f_in;
+
+ f_in = fopen (path, "r");
+ if (!f_in)
+ return NULL;
+
+ while ( (sz = fread (buf, 1, sizeof (buf), f_in)) )
+ {
+ size_t old_total_sz = total_sz;
+ total_sz += sz;
+ result = reinterpret_cast <char *> (xrealloc (result, total_sz + 1));
+ memcpy (result + old_total_sz, buf, sz);
+ }
+
+ if (!feof (f_in))
+ {
+ free (result);
+ fclose (f_in);
+ return NULL;
+ }
+
+ fclose (f_in);
+
+ if (result)
+ {
+ result[total_sz] = '\0';
+ return result;
+ }
+ else
+ return xstrdup ("");
+}
+
+/* FIXME: should have a leading comment. */
+
+static void
+embed_dumpfiles_within_asm ()
+{
+ class callback
+ {
+ public:
+ static void fn (struct dump_file_info *dfi,
+ void */*user_data*/)
+ {
+ char *filename;
+ char *content;
+
+ filename = g->get_dumps ()->get_dump_file_name (dfi);
+ content = read_dump_file (filename);
+
+ /* FIXME: what about error handling? */
+ if (content)
+ {
+ unsigned int flags = SECTION_DEBUG;
+ /* FIXME: name of section? */
+ char *section_name = concat (".note.GNU-dump.", dfi->swtch, NULL);
+ switch_to_section (get_section (section_name, flags, NULL));
+ assemble_string (content, strlen (content));
+ free (section_name);
+ }
+ free (filename);
+ free (content);
+ }
+ };
+
+ g->get_dumps ()->for_each_dumpfile (callback::fn, NULL);
+}
+
/* Compile an entire translation unit. Write a file of assembly
output and various debugging dumps. */
@@ -711,6 +790,9 @@ compile_file (void)
targetm.asm_out.output_ident (ident_str);
}
+ /* FIXME: should only be enabled if an option has been set. */
+ embed_dumpfiles_within_asm ();
+
/* Auto profile finalization. */
if (flag_auto_profile)
end_auto_profile ();