This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 1/2] [GCC] Improve regexp handling on libc[cp]1::compiler_triplet_regexp::find
- From: Sergio Durigan Junior <sergiodj at redhat dot com>
- To: GDB Patches <gdb-patches at sourceware dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Tom Tromey <tom at tromey dot com>, Keith Seitz <keiths at redhat dot com>, Phil Muldoon <pmuldoon at redhat dot com>, Alexandre Oliva <aoliva at redhat dot com>
- Date: Wed, 23 Aug 2017 00:18:18 -0400
- Subject: [PATCH 1/2] [GCC] Improve regexp handling on libc[cp]1::compiler_triplet_regexp::find
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=sergiodj at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 57C5AC0587DE
- References: <87mv6qhq9u.fsf@redhat.com>
This is the GCC patch.
It adjusts the behaviour of make_regexp in order to not add the "-" at
the end of the triplet regexp. This is now GDB's responsibility.
It also improves the 'find' methods of both
libcc1::compiler_triplet_regexp and libcp1::compiler_triplet_regexp
classes by implementing a detection of a triplet string in the compiler
name. If it finds the triplet there, then the pristine compiler name is
used to match a compiler in the system, without using the initial
triplet regexp provided by GDB. If the compiler name doesn't start with
a triplet, then the old behaviour is maintained and we'll still search
for compilers using the triplet regexp.
With this patch it is possible to include triplets in compiler names
(via the --program-prefix configure option), like Debian does, for
example. I chose not to worry too much about possible suffixes (which
can be specified via --program-suffix) because even with them it is
still possible to find the compiler in the system. It is important to
note that Debian uses suffixes as well.
It is still perfectly possible to find compilers without
prefixes/suffixes, like "gcc" (this is how Fedora names its GCC, by the
way).
OK to apply?
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
libcc1/ChangeLog:
2017-08-23 Sergio Durigan Junior <sergiodj@redhat.com>
* libcc1.cc (make_regexp): Don't add dash after triplet regexp.
Handle case when COMPILER is empty.
(libcc1::compiler_triplet_regexp::find): Detect when
C_COMPILER_NAME already contains a triplet.
* libcp1.cc (make_regexp): Don't add dash after triplet regexp.
Handle case when COMPILER is empty.
(libcp1::compiler_triplet_regexp::find): Detect when
CP_COMPILER_NAME already contains a triplet.
diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc
index 0ef6c112dae..41a6e3cca77 100644
--- a/libcc1/libcc1.cc
+++ b/libcc1/libcc1.cc
@@ -336,31 +336,34 @@ make_regexp (const char *triplet_regexp, const char *compiler)
{
std::stringstream buf;
- buf << "^" << triplet_regexp << "-";
+ buf << "^" << triplet_regexp;
- // Quote the compiler name in case it has something funny in it.
- for (const char *p = compiler; *p; ++p)
+ if (compiler[0] != '\0')
{
- switch (*p)
+ // Quote the compiler name in case it has something funny in it.
+ for (const char *p = compiler; *p; ++p)
{
- case '.':
- case '^':
- case '$':
- case '*':
- case '+':
- case '?':
- case '(':
- case ')':
- case '[':
- case '{':
- case '\\':
- case '|':
- buf << '\\';
- break;
+ switch (*p)
+ {
+ case '.':
+ case '^':
+ case '$':
+ case '*':
+ case '+':
+ case '?':
+ case '(':
+ case ')':
+ case '[':
+ case '{':
+ case '\\':
+ case '|':
+ buf << '\\';
+ break;
+ }
+ buf << *p;
}
- buf << *p;
+ buf << "$";
}
- buf << "$";
return buf.str ();
}
@@ -382,12 +385,30 @@ libcc1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const
char *
libcc1::compiler_triplet_regexp::find (std::string &compiler) const
{
- std::string rx = make_regexp (triplet_regexp_.c_str (), C_COMPILER_NAME);
+ regex_t triplet;
+ bool c_compiler_has_triplet = false;
+
+ // Some distros, like Debian, choose to use a prefix and a suffix
+ // in their C_COMPILER_NAME, so we try to check if that's the case
+ // here and adjust the regexp's accordingly.
+ std::string triplet_rx = make_regexp (triplet_regexp_.c_str (), "");
+ int code = regcomp (&triplet, triplet_rx.c_str (), REG_EXTENDED | REG_NOSUB);
+
+ if (code == 0)
+ {
+ if (regexec (&triplet, C_COMPILER_NAME, 0, NULL, 0) == 0)
+ c_compiler_has_triplet = true;
+
+ regfree (&triplet);
+ }
+
+ std::string rx = make_regexp (c_compiler_has_triplet
+ ? "" : triplet_regexp_.c_str (),
+ C_COMPILER_NAME);
if (self_->verbose)
fprintf (stderr, _("searching for compiler matching regex %s\n"),
rx.c_str());
- regex_t triplet;
- int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
+ code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
if (code != 0)
{
size_t len = regerror (code, &triplet, NULL, 0);
diff --git a/libcc1/libcp1.cc b/libcc1/libcp1.cc
index bbd8488af93..5bac6e4e37c 100644
--- a/libcc1/libcp1.cc
+++ b/libcc1/libcp1.cc
@@ -360,31 +360,34 @@ make_regexp (const char *triplet_regexp, const char *compiler)
{
std::stringstream buf;
- buf << "^" << triplet_regexp << "-";
+ buf << "^" << triplet_regexp;
- // Quote the compiler name in case it has something funny in it.
- for (const char *p = compiler; *p; ++p)
+ if (compiler[0] != '\0')
{
- switch (*p)
+ // Quote the compiler name in case it has something funny in it.
+ for (const char *p = compiler; *p; ++p)
{
- case '.':
- case '^':
- case '$':
- case '*':
- case '+':
- case '?':
- case '(':
- case ')':
- case '[':
- case '{':
- case '\\':
- case '|':
- buf << '\\';
- break;
+ switch (*p)
+ {
+ case '.':
+ case '^':
+ case '$':
+ case '*':
+ case '+':
+ case '?':
+ case '(':
+ case ')':
+ case '[':
+ case '{':
+ case '\\':
+ case '|':
+ buf << '\\';
+ break;
+ }
+ buf << *p;
}
- buf << *p;
+ buf << "$";
}
- buf << "$";
return buf.str ();
}
@@ -406,12 +409,30 @@ libcp1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const
char *
libcp1::compiler_triplet_regexp::find (std::string &compiler) const
{
- std::string rx = make_regexp (triplet_regexp_.c_str (), CP_COMPILER_NAME);
+ regex_t triplet;
+ bool cp_compiler_name_has_triplet = false;
+
+ // Some distros, like Debian, choose to use a prefix and a suffix
+ // in their CP_COMPILER_NAME, so we try to check if that's the case
+ // here and adjust the regexp's accordingly.
+ std::string triplet_rx = make_regexp (triplet_regexp_.c_str (), "");
+ int code = regcomp (&triplet, triplet_rx.c_str (), REG_EXTENDED | REG_NOSUB);
+
+ if (code == 0)
+ {
+ if (regexec (&triplet, CP_COMPILER_NAME, 0, NULL, 0) == 0)
+ cp_compiler_name_has_triplet = true;
+
+ regfree (&triplet);
+ }
+
+ std::string rx = make_regexp (cp_compiler_name_has_triplet
+ ? "" : triplet_regexp_.c_str (),
+ CP_COMPILER_NAME);
if (self_->verbose)
fprintf (stderr, _("searching for compiler matching regex %s\n"),
rx.c_str());
- regex_t triplet;
- int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
+ code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
if (code != 0)
{
size_t len = regerror (code, &triplet, NULL, 0);