From patchwork Wed Aug 23 15:20:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 22331 Received: (qmail 72189 invoked by alias); 23 Aug 2017 15:20:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 72172 invoked by uid 89); 23 Aug 2017 15:20:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Aug 2017 15:20:22 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99269883BC for ; Wed, 23 Aug 2017 15:20:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 99269883BC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=sergiodj@redhat.com Received: from psique.yyz.redhat.com (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F685183C1; Wed, 23 Aug 2017 15:20:21 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Sergio Durigan Junior , Jan Kratochvil Subject: [PUSHED 2/2] compile: Add 'set compile-gcc' Date: Wed, 23 Aug 2017 11:20:07 -0400 Message-Id: <20170823152007.5553-2-sergiodj@redhat.com> In-Reply-To: <20170823152007.5553-1-sergiodj@redhat.com> References: <20170823152007.5553-1-sergiodj@redhat.com> X-IsSubscribed: yes From: Jan Kratochvil Pushed as per: https://sourceware.org/ml/gdb-patches/2015-05/msg00710.html 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 * 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 * 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 * 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. --- gdb/ChangeLog | 9 +++++++ gdb/NEWS | 4 ++++ gdb/compile/compile.c | 63 ++++++++++++++++++++++++++++++++++++++++--------- gdb/doc/ChangeLog | 6 +++++ gdb/doc/gdb.texinfo | 36 +++++++++++++++++++++++----- include/ChangeLog | 7 ++++++ include/gcc-interface.h | 61 ++++++++++++++++++++++++++++++++++++----------- 7 files changed, 155 insertions(+), 31 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d7466d0578..7eeab62ae1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2017-08-23 Jan Kratochvil + * NEWS (Changes since GDB 8.0): 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. + +2017-08-23 Jan Kratochvil + * compile/compile.c (compile_to_object): Conditionally call set_verbose. Conditionally call compile or compile_v0. diff --git a/gdb/NEWS b/gdb/NEWS index 4b0a95600f..735415495e 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -27,6 +27,10 @@ QStartupWithShell * New commands +set|show compile-gcc + Set and show compilation command used for compiling and injecting code + with the 'compile' commands. + set debug separate-debug-file show debug separate-debug-file Control the display of debug output about separate debug file search. 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 (""); } diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 40b0e4093f..bf82730830 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,9 @@ +2017-08-23 Jan Kratochvil + + * gdb.texinfo (Compiling and Injecting Code): Add to subsection + "Compiler search for the compile command" descriptions of set + compile-gcc and show compile-gcc. + 2017-08-07 Weimin Pan * gdb.texinfo (Architectures): Add new Sparc64 section to document diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index d0d5d968cb..d977b234d0 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18154,13 +18154,15 @@ will print to the console. @subsection Compiler search for the @code{compile} command -@value{GDBN} needs to find @value{NGCC} for the inferior being debugged which -may not be obvious for remote targets of different architecture than where -@value{GDBN} is running. Environment variable @code{PATH} (@code{PATH} from -shell that executed @value{GDBN}, not the one set by @value{GDBN} -command @code{set environment}). @xref{Environment}. @code{PATH} on +@value{GDBN} needs to find @value{NGCC} for the inferior being debugged +which may not be obvious for remote targets of different architecture +than where @value{GDBN} is running. Environment variable @code{PATH} on @value{GDBN} host is searched for @value{NGCC} binary matching the -target architecture and operating system. +target architecture and operating system. This search can be overriden +by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is +taken from shell that executed @value{GDBN}, it is not the value set by +@value{GDBN} command @code{set environment}). @xref{Environment}. + Specifically @code{PATH} is searched for binaries matching regular expression @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being @@ -18170,6 +18172,28 @@ example both @code{i386} and @code{x86_64} targets look for pattern for pattern @code{s390x?}. @var{os} is currently supported only for pattern @code{linux(-gnu)?}. +On Posix hosts the compiler driver @value{GDBN} needs to find also +shared library @file{libcc1.so} from the compiler. It is searched in +default shared library search path (overridable with usual environment +variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set +compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found +according to the installation of the found compiler --- as possibly +specified by the @code{set compile-gcc} command. + +@table @code +@item set compile-gcc +@cindex compile command driver filename override +Set compilation command used for compiling and injecting code with the +@code{compile} commands. If this option is not set (it is set to +an empty string), the search described above will occur --- that is the +default. + +@item show compile-gcc +Displays the current compile command @value{NGCC} driver filename. +If set, it is the main command @command{gcc}, found usually for example +under name @file{x86_64-linux-gnu-gcc}. +@end table + @node GDB Files @chapter @value{GDBN} Files diff --git a/include/ChangeLog b/include/ChangeLog index 02ee554b90..3b89deb7ed 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,5 +1,12 @@ 2017-08-23 Jan Kratochvil + * 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. + +2017-08-23 Jan Kratochvil + * gcc-interface.h (enum gcc_base_api_version): Add GCC_FE_VERSION_1. (struct gcc_base_vtable): Rename compile to compile_v0. Update diff --git a/include/gcc-interface.h b/include/gcc-interface.h index c98f078454..e3ffd18a75 100644 --- a/include/gcc-interface.h +++ b/include/gcc-interface.h @@ -46,7 +46,9 @@ enum gcc_base_api_version { GCC_FE_VERSION_0 = 0, - /* Deprecated method compile_v0. Added method set_verbose and compile. */ + /* Deprecated methods set_arguments_v0 and compile_v0. Added methods + set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and + compile. */ GCC_FE_VERSION_1 = 1, }; @@ -67,20 +69,12 @@ struct gcc_base_vtable unsigned int version; - /* Set the compiler's command-line options for the next compilation. - TRIPLET_REGEXP is a regular expression that is used to match the - configury triplet prefix to the compiler. - The arguments are copied by GCC. ARGV need not be - NULL-terminated. The arguments must be set separately for each - compilation; that is, after a compile is requested, the - previously-set arguments cannot be reused. - - This returns NULL on success. On failure, returns a malloc()d - error message. The caller is responsible for freeing it. */ + /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 + methods set_triplet_regexp and set_arguments. */ - char *(*set_arguments) (struct gcc_base_context *self, - const char *triplet_regexp, - int argc, char **argv); + char *(*set_arguments_v0) (struct gcc_base_context *self, + const char *triplet_regexp, + int argc, char **argv); /* Set the file name of the program to compile. The string is copied by the method implementation, but the caller must @@ -125,6 +119,45 @@ struct gcc_base_vtable int /* bool */ (*compile) (struct gcc_base_context *self, const char *filename); + + /* Set the compiler's command-line options for the next compilation. + The arguments are copied by GCC. ARGV need not be + NULL-terminated. The arguments must be set separately for each + compilation; that is, after a compile is requested, the + previously-set arguments cannot be reused. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_arguments) (struct gcc_base_context *self, + int argc, char **argv); + + /* Set TRIPLET_REGEXP as a regular expression that is used to match + the configury triplet prefix to the compiler. Calling this method + overrides possible previous call of itself or set_driver_filename. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_triplet_regexp) (struct gcc_base_context *self, + const char *triplet_regexp); + + /* DRIVER_FILENAME should be filename of the gcc compiler driver + program. It will be searched in PATH components like + TRIPLET_REGEXP. Calling this method overrides possible previous + call of itself or set_triplet_regexp. + + This returns NULL on success. On failure, returns a malloc()d + error message. The caller is responsible for freeing it. + + This method is only available since GCC_FE_VERSION_1. */ + + char *(*set_driver_filename) (struct gcc_base_context *self, + const char *driver_filename); }; /* The GCC object. */