summaryrefslogtreecommitdiff
path: root/gdb/compile
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2017-02-21 13:32:56 -0800
committerSergio Durigan Junior <sergiodj@redhat.com>2017-08-23 11:16:35 -0400
commit6e41ddec97d402c6c150701da0f70d40bd6ed5ca (patch)
tree584df3b69d7feba5ac880046ec7385b02ae2c416 /gdb/compile
parente68c32d53e44ac0fe9f48637c0113da42b62644a (diff)
compile: Add 'set compile-gcc'
As discussed in How to use compile & execute function in GDB https://sourceware.org/ml/gdb/2015-04/msg00026.html GDB currently searches for compilers on /usr/bin/ARCH-OS-gcc and chooses a match from there. However, it is not currently possible for the user to override which compiler to use. This is what this patch implements. It is also a sync between GCC's and GDB's interfaces. gdb/ChangeLog 2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com> * NEWS (Changes since GDB 7.9): Add set compile-gcc and show compile-gcc. * compile/compile.c (compile_gcc, show_compile_gcc): New. (compile_to_object): Implement compile_gcc. (_initialize_compile): Install "set compile-gcc". Initialize compile_gcc. gdb/doc/ChangeLog 2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.texinfo (Compiling and Injecting Code): Add to subsection "Compiler search for the compile command" descriptions of set compile-gcc and show compile-gcc. include/ChangeLog 2017-08-23 Jan Kratochvil <jan.kratochvil@redhat.com> * gcc-interface.h (enum gcc_base_api_version): Update comment for GCC_FE_VERSION_1. (struct gcc_base_vtable): Rename set_arguments to set_arguments_v0. Add set_arguments, set_triplet_regexp and set_driver_filename.
Diffstat (limited to 'gdb/compile')
-rw-r--r--gdb/compile/compile.c63
1 files changed, 52 insertions, 11 deletions
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 36baab3ede..bbb31f11c0 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -335,6 +335,19 @@ append_args (int *argcp, char ***argvp, int argc, char **argv)
(*argvp)[(*argcp)] = NULL;
}
+/* String for 'set compile-gcc' and 'show compile-gcc'. */
+static char *compile_gcc;
+
+/* Implement 'show compile-gcc'. */
+
+static void
+show_compile_gcc (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Compile command GCC driver filename is \"%s\".\n"),
+ value);
+}
+
/* Return DW_AT_producer parsed for get_selected_frame () (if any).
Return NULL otherwise.
@@ -452,8 +465,6 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
int ok;
FILE *src;
struct gdbarch *gdbarch = get_current_arch ();
- const char *os_rx;
- const char *arch_rx;
char *triplet_rx;
char *error_message;
@@ -505,22 +516,39 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
if (compile_debug)
fprintf_unfiltered (gdb_stdlog, "debug output:\n\n%s", code.c_str ());
- os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch));
- arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
+ if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
+ compiler->fe->ops->set_verbose (compiler->fe, compile_debug);
- /* Allow triplets with or without vendor set. */
- triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL);
- make_cleanup (xfree, triplet_rx);
+ if (compile_gcc[0] != 0)
+ {
+ if (compiler->fe->ops->version < GCC_FE_VERSION_1)
+ error (_("Command 'set compile-gcc' requires GCC version 6 or higher "
+ "(libcc1 interface version 1 or higher)"));
+
+ compiler->fe->ops->set_driver_filename (compiler->fe, compile_gcc);
+ }
+ else
+ {
+ const char *os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch));
+ const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
+
+ /* Allow triplets with or without vendor set. */
+ triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL);
+ make_cleanup (xfree, triplet_rx);
+
+ if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
+ compiler->fe->ops->set_triplet_regexp (compiler->fe, triplet_rx);
+ }
/* Set compiler command-line arguments. */
get_args (compiler, gdbarch, &argc, &argv);
gdb_argv argv_holder (argv);
if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
- compiler->fe->ops->set_verbose (compiler->fe, compile_debug);
-
- error_message = compiler->fe->ops->set_arguments (compiler->fe, triplet_rx,
- argc, argv);
+ error_message = compiler->fe->ops->set_arguments (compiler->fe, argc, argv);
+ else
+ error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe, triplet_rx,
+ argc, argv);
if (error_message != NULL)
{
make_cleanup (xfree, error_message);
@@ -742,4 +770,17 @@ String quoting is parsed like in shell, for example:\n\
" -fno-stack-protector"
);
set_compile_args (compile_args, 0, NULL);
+
+ add_setshow_optional_filename_cmd ("compile-gcc", class_support,
+ &compile_gcc,
+ _("Set compile command "
+ "GCC driver filename"),
+ _("Show compile command "
+ "GCC driver filename"),
+ _("\
+It should be absolute filename of the gcc executable.\n\
+If empty the default target triplet will be searched in $PATH."),
+ NULL, show_compile_gcc, &setlist,
+ &showlist);
+ compile_gcc = xstrdup ("");
}