diff options
author | Mark Wielaard <mjw@redhat.com> | 2015-01-25 11:20:39 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2015-01-29 13:39:01 +0100 |
commit | 38360086aea4f956dcd4ba406318595ea11f7dea (patch) | |
tree | 7cab1d6ca85a5eb23cbc4f22e22a473b025dbb3c /gdb/utils.c | |
parent | 0f81d3f0a799c6e8c2a89d7f519916e3c9c0f65e (diff) | |
download | gdb-38360086aea4f956dcd4ba406318595ea11f7dea.zip gdb-38360086aea4f956dcd4ba406318595ea11f7dea.tar.gz gdb-38360086aea4f956dcd4ba406318595ea11f7dea.tar.bz2 |
Merge GCC producer parsers. Allow digits in identifiers.
Both dwarf2read.c (checkproducer) and utils.c (producer_is_gcc_ge_4)
implemented a GCC producer parser that tried to extract the major and minor
version of GCC. Merge them into one GCC producer parser used by both. Also
allow digits in the identifier after "GNU " such as used by GCC5 like:
"GNU C11 5.0.0 20150123 (experimental) -mtune=generic -march=x86-64 -gdwarf-5"
gdb/ChangeLog:
* dwarf2read.c (checkproducer): Call producer_is_gcc.
* utils.c (producer_is_gcc_ge_4): Likewise.
(producer_is_gcc): New function.
* utils.h (producer_is_gcc): New declaration.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index a9a3082..909476b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3258,36 +3258,8 @@ make_bpstat_clear_actions_cleanup (void) int producer_is_gcc_ge_4 (const char *producer) { - const char *cs; int major, minor; - - if (producer == NULL) - { - /* For unknown compilers expect their behavior is not compliant. For GCC - this case can also happen for -gdwarf-4 type units supported since - gcc-4.5. */ - - return -1; - } - - /* Skip any identifier after "GNU " - such as "C++" or "Java". */ - - if (strncmp (producer, "GNU ", strlen ("GNU ")) != 0) - { - /* For non-GCC compilers expect their behavior is not compliant. */ - - return -1; - } - cs = &producer[strlen ("GNU ")]; - while (*cs && !isdigit (*cs)) - cs++; - if (sscanf (cs, "%d.%d", &major, &minor) != 2) - { - /* Not recognized as GCC. */ - - return -1; - } - + major = producer_is_gcc (producer, &minor); if (major < 4) return -1; if (major > 4) @@ -3295,6 +3267,36 @@ producer_is_gcc_ge_4 (const char *producer) return minor; } +/* Returns the major version number if the given PRODUCER string is GCC and + sets the MINOR version. Returns -1 if the given PRODUCER is NULL or it + isn't GCC. */ +int +producer_is_gcc (const char *producer, int *minor) +{ + const char *cs; + int major; + + if (producer != NULL && strncmp (producer, "GNU ", strlen ("GNU ")) == 0) + { + /* Skip any identifier after "GNU " - such as "C11" "C++" or "Java". + A full producer string might look like: + "GNU C 4.7.2" + "GNU Fortran 4.8.2 20140120 (Red Hat 4.8.2-16) -mtune=generic ..." + "GNU C++14 5.0.0 20150123 (experimental)" + */ + cs = &producer[strlen ("GNU ")]; + while (*cs && !isspace (*cs)) + cs++; + if (*cs && isspace (*cs)) + cs++; + if (sscanf (cs, "%d.%d", &major, minor) == 2) + return major; + } + + /* Not recognized as GCC. */ + return -1; +} + /* Helper for make_cleanup_free_char_ptr_vec. */ static void |