This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto][patch] Add a debug option to the plugin
- From: Rafael Espindola <espindola at google dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Cc: Diego Novillo <dnovillo at google dot com>
- Date: Mon, 8 Dec 2008 13:21:35 +0000
- Subject: [lto][patch] Add a debug option to the plugin
This patch adds a debug option to the linker plugin. This is similar
to the collect2 one. For now it just prints the call to lto-wrapper.
To use it, one should pass -Wl,-plugin-opt=-debug to gcc.
2008-12-08 Rafael Avila de Espindola <espindola@google.com>
* lto-plugin.c (debug): New.
(exec_lto_wrapper): Print argv if debug is true.
(process_option): Process the -debug command line option.
Cheers,
--
Rafael Avila de Espindola
Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index bb91002..16171a0 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -93,6 +93,8 @@ static unsigned int num_output_files = 0;
static char **lto_wrapper_argv;
static int lto_wrapper_num_args;
+static int debug;
+
/* Parse an entry of the IL symbol table. The data to be parsed is pointed
by P and the result is written in ENTRY. The slot number is stored in SLOT.
Returns the address of the next entry. */
@@ -347,7 +349,17 @@ exec_lto_wrapper (char *const argv[])
int pid;
int pipe_read;
int pipe_write;
- int t = pipe (pipefd);
+ int t;
+
+ if (debug)
+ {
+ int i;
+ for (i = 0; argv[i]; i++)
+ fprintf (stderr, "%s ", argv[i]);
+ fprintf (stderr, "\n");
+
+ }
+ t = pipe (pipefd);
assert (t == 0);
pipe_read = pipefd[0];
pipe_write = pipefd[1];
@@ -539,15 +551,21 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
return LDPS_OK;
}
-/* Parse the lto=... OPTION. */
+/* Parse the plugin options. */
static void
process_option (const char *option)
{
- lto_wrapper_num_args += 1;
- lto_wrapper_argv = (char **) realloc (lto_wrapper_argv,
- lto_wrapper_num_args * sizeof (char *));
- lto_wrapper_argv[lto_wrapper_num_args - 1] = strdup(option);
+ if (strcmp (option, "-debug") == 0)
+ debug = 1;
+ else
+ {
+ int size;
+ lto_wrapper_num_args += 1;
+ size = lto_wrapper_num_args * sizeof (char *);
+ lto_wrapper_argv = (char **) realloc (lto_wrapper_argv, size);
+ lto_wrapper_argv[lto_wrapper_num_args - 1] = strdup(option);
+ }
}
/* Called by gold after loading the plugin. TV is the transfer vector. */