From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 69946 invoked by alias); 23 Apr 2015 20:38:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 69827 invoked by uid 89); 23 Apr 2015 20:38:40 -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:38:38 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3NKca9L027136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 23 Apr 2015 16:38:36 -0400 Received: from host1.jankratochvil.net (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3NKcYHO023668; Thu, 23 Apr 2015 16:38:35 -0400 Subject: [PATCH v2 2/4] libcc1: set debug compile: Display GCC driver filename From: Jan Kratochvil To: gcc-patches@gcc.gnu.org Cc: Phil Muldoon Date: Thu, 23 Apr 2015 20:38:00 -0000 Message-ID: <20150423203834.23973.8401.stgit@host1.jankratochvil.net> In-Reply-To: <20150423203827.23973.72954.stgit@host1.jankratochvil.net> References: <20150423203827.23973.72954.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg01448.txt.bz2 Hi, already approved, reposting just to keep it a part of the series: https://gcc.gnu.org/ml/gcc-patches/2015-04/msg01301.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 /usr/bin/ARCH-OS-gcc and chooses one but it does not display which one. It cannot, GCC method set_arguments() does not yet know whether 'set debug compile' is enabled or not. Unfortunately this changes libcc1 API in an incompatible way. There is a possibility of a hack to keep the API the same - one could pass "-v" option explicitly to set_arguments(), set_arguments() could compare the "-v" string and print the GCC filename accordingly. Then the 'verbose' parameter of compile() would lose its meaning. What do you think? GDB counterpart: [PATCH v2 1/2] compile: set debug compile: Display GCC driver filename https://sourceware.org/ml/gdb-patches/2015-04/msg00909.html Message-ID: <20150423203402.23140.92757.stgit@host1.jankratochvil.net> Jan include/ChangeLog 2015-04-23 Jan Kratochvil * gcc-interface.h (enum gcc_base_api_version): Add comment to GCC_FE_VERSION_1. (struct gcc_base_vtable): Rename set_arguments to set_arguments_v0. Update comment for compile. New method set_arguments. libcc1/ChangeLog 2015-04-23 Jan Kratochvil * libcc1.cc: Include intl.h. (struct libcc1): Add field verbose. (libcc1::libcc1): Initialize it. (libcc1_set_arguments): Add parameter verbose, implement it. (libcc1_set_arguments_v0): New function. (libcc1_compile): Set parameter verbose to SELF. (vtable): Use libcc1_set_arguments_v0 and add libcc1_set_arguments. --- include/gcc-interface.h | 45 +++++++++++++++++++++++++++++---------------- libcc1/libcc1.cc | 34 +++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/include/gcc-interface.h b/include/gcc-interface.h index dcfa6ce..21cc403 100644 --- a/include/gcc-interface.h +++ b/include/gcc-interface.h @@ -45,6 +45,8 @@ struct gcc_base_context; enum gcc_base_api_version { GCC_FE_VERSION_0 = 0, + + /* Parameter verbose has been moved from compile to set_arguments. */ GCC_FE_VERSION_1 = 1, }; @@ -65,20 +67,13 @@ 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 + set_arguments method. GCC_FE_VERSION_0 version did not have the + verbose parameter. */ - 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 @@ -95,9 +90,9 @@ struct gcc_base_vtable void *datum); /* Perform the compilation. FILENAME is the name of the resulting - object file. VERBOSE can be set to cause GCC to print some - information as it works. Returns true on success, false on - error. */ + object file. VERBOSE should be the same value as passed + to gcc_base_vtable::set_arguments. Returns true on success, false + on error. */ int /* bool */ (*compile) (struct gcc_base_context *self, const char *filename, @@ -106,6 +101,24 @@ struct gcc_base_vtable /* Destroy this object. */ void (*destroy) (struct gcc_base_context *self); + + /* 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. VERBOSE can be set + to cause GCC to print some information as it works. + + 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, + const char *triplet_regexp, + int argc, char **argv, int /* bool */ verbose); }; /* The GCC object. */ diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc index 99a0fa1..06a91f6 100644 --- a/libcc1/libcc1.cc +++ b/libcc1/libcc1.cc @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "xregex.h" #include "findcomp.hh" #include "compiler-name.h" +#include "intl.h" struct libcc1; @@ -66,6 +67,9 @@ struct libcc1 : public gcc_c_context std::vector args; std::string source_file; + + /* Non-zero as an equivalent to gcc driver option "-v". */ + bool verbose; }; // A local subclass of connection that holds a back-pointer to the @@ -97,7 +101,8 @@ libcc1::libcc1 (const gcc_base_vtable *v, print_function (NULL), print_datum (NULL), args (), - source_file () + source_file (), + verbose (false) { base.ops = v; c_ops = cv; @@ -309,13 +314,19 @@ make_regexp (const char *triplet_regexp, const char *compiler) static char * libcc1_set_arguments (struct gcc_base_context *s, const char *triplet_regexp, - int argc, char **argv) + int argc, char **argv, int verbose) { libcc1 *self = (libcc1 *) s; regex_t triplet; int code; + self->verbose = verbose != 0; + std::string rx = make_regexp (triplet_regexp, COMPILER_NAME); + // Simulate fnotice by fprintf. + if (self->verbose) + fprintf (stderr, _("searching for compiler matching regex %s\n"), + rx.c_str()); code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB); if (code != 0) { @@ -341,6 +352,8 @@ libcc1_set_arguments (struct gcc_base_context *s, (char *) NULL); } regfree (&triplet); + if (self->verbose) + fprintf (stderr, _("found compiler %s\n"), compiler.c_str()); self->args.push_back (compiler); @@ -350,6 +363,14 @@ libcc1_set_arguments (struct gcc_base_context *s, return NULL; } +static char * +libcc1_set_arguments_v0 (struct gcc_base_context *s, + const char *triplet_regexp, + int argc, char **argv) +{ + return libcc1_set_arguments (s, triplet_regexp, argc, argv, false); +} + static void libcc1_set_source_file (struct gcc_base_context *s, const char *file) @@ -439,6 +460,8 @@ libcc1_compile (struct gcc_base_context *s, { libcc1 *self = (libcc1 *) s; + self->verbose = verbose != 0; + int fds[2]; if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) != 0) { @@ -466,7 +489,7 @@ libcc1_compile (struct gcc_base_context *s, self->args.push_back ("-c"); self->args.push_back ("-o"); self->args.push_back (filename); - if (verbose) + if (self->verbose) self->args.push_back ("-v"); self->connection = new libcc1_connection (fds[0], stderr_fds[0], self); @@ -505,11 +528,12 @@ libcc1_destroy (struct gcc_base_context *s) static const struct gcc_base_vtable vtable = { GCC_FE_VERSION_1, - libcc1_set_arguments, + libcc1_set_arguments_v0, libcc1_set_source_file, libcc1_set_print_callback, libcc1_compile, - libcc1_destroy + libcc1_destroy, + libcc1_set_arguments, }; extern "C" gcc_c_fe_context_function gcc_c_fe_context;