From patchwork Thu Apr 23 20:34:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 6408 Received: (qmail 65429 invoked by alias); 23 Apr 2015 20:34:20 -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 65420 invoked by uid 89); 23 Apr 2015 20:34:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 23 Apr 2015 20:34:18 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3NKYFga031707 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 23 Apr 2015 16:34:16 -0400 Received: from host1.jankratochvil.net (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3NKYD1l000606; Thu, 23 Apr 2015 16:34:14 -0400 Subject: [PATCH v2 2/2] compile: Add 'set compile-gcc' From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Phil Muldoon Date: Thu, 23 Apr 2015 22:34:13 +0200 Message-ID: <20150423203413.23140.35224.stgit@host1.jankratochvil.net> In-Reply-To: <20150423203402.23140.92757.stgit@host1.jankratochvil.net> References: <20150423203402.23140.92757.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes Hi, as discussed in How to use compile & execute function in GDB https://sourceware.org/ml/gdb/2015-04/msg00026.html GDB currently searches for /usr/bin/ARCH-OS-gcc and chooses one but one cannot override which one. This patch does not change the libcc1 API as it overloads the triplet_regexp parameter of GCC's set_arguments. GCC decides on the meaning of the triplet_regexp parameter according to the success of: + if (access (triplet_regexp, X_OK) == 0) Jan gdb/ChangeLog 2015-04-21 Jan Kratochvil * 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 2015-04-21 Jan Kratochvil * doc/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 2015-04-21 Jan Kratochvil * gcc-interface.h (enum gcc_base_api_version): Add comment to GCC_FE_VERSION_1. (struct gcc_base_vtable): Describe triplet_regexp parameter overload for set_arguments. --- gdb/compile/compile.c | 40 +++++++++++++++++++++++++++++++++------- gdb/doc/gdb.texinfo | 33 ++++++++++++++++++++++++++++----- include/gcc-interface.h | 7 +++++-- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 7f4c11d..c5267ba 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -299,6 +299,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. @@ -430,8 +443,6 @@ compile_to_object (struct command_line *cmd, 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; @@ -481,12 +492,17 @@ compile_to_object (struct command_line *cmd, char *cmd_string, if (compile_debug) fprintf_unfiltered (gdb_stdout, "debug output:\n\n%s", code); - os_rx = osabi_triplet_regexp (gdbarch_osabi (gdbarch)); - arch_rx = gdbarch_gnu_triplet_regexp (gdbarch); + if (compile_gcc[0] != 0) + triplet_rx = 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); + /* Allow triplets with or without vendor set. */ + triplet_rx = concat (arch_rx, "(-[^-]*)?-", os_rx, (char *) NULL); + make_cleanup (xfree, triplet_rx); + } /* Set compiler command-line arguments. */ get_args (compiler, gdbarch, &argc, &argv); @@ -688,4 +704,14 @@ String quoting is parsed like in shell, for example:\n\ " -fno-stack-protector" ); set_compile_args (compile_args, 0, NULL); + + add_setshow_string_cmd ("compile-gcc", class_support, + &compile_gcc, + _("Set compile command GCC driver filename"), + _("Show compile command GCC driver filename"), + _("\ +It should be absolute pathname to 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/gdb.texinfo b/gdb/doc/gdb.texinfo index 0410702..8f3777d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -17437,11 +17437,13 @@ will print to the console. @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} host is searched for @value{NGCC} binary matching the -target architecture and operating system. +@value{GDBN} is running. By default the 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} host is searched for +@value{NGCC} binary matching the target architecture and operating +system. This search can be overriden by @code{set compile-gcc} @value{GDBN} +command below. Specifically @code{PATH} is searched for binaries matching regular expression @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being @@ -17451,6 +17453,27 @@ 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)?}. +Besides the compiler driver @value{GDBN} needs also shared library +@file{libcc1.so}. 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 @code{gcc}, found usually for example +under name @code{x86_64-linux-gnu-gcc}. +@end table + @node GDB Files @chapter @value{GDBN} Files diff --git a/include/gcc-interface.h b/include/gcc-interface.h index c11b7a1..81925b1 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, - /* Parameter verbose has been moved from compile to set_arguments. */ + /* Parameter verbose has been moved from compile to set_arguments. + Parameter triplet_regexp of set_arguments can be also gcc driver + executable. */ GCC_FE_VERSION_1 = 1, }; @@ -104,7 +106,8 @@ struct gcc_base_vtable /* 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. + configury triplet prefix to the compiler; TRIPLET_REGEXP can be + also absolute filename to the computer. 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