aboutsummaryrefslogtreecommitdiff
path: root/gdb/producer.c
diff options
context:
space:
mode:
authorWalfred Tedeschi <walfred.tedeschi@intel.com>2017-09-26 18:26:41 +0100
committerPedro Alves <palves@redhat.com>2017-09-26 18:26:41 +0100
commitb32b108aba2c0119d0e231d203d3284539da2379 (patch)
tree9c24604cc4997fcfe86628fb8a701bc8103f9a0f /gdb/producer.c
parent75352e283fb2b265d14c750859156943f6eb2693 (diff)
downloadgdb-b32b108aba2c0119d0e231d203d3284539da2379.zip
gdb-b32b108aba2c0119d0e231d203d3284539da2379.tar.gz
gdb-b32b108aba2c0119d0e231d203d3284539da2379.tar.bz2
Move GDB producer parsing routines to a separate file
gdb/ChangeLog: 2017-09-26 Walfred Tedeschi <walfred.tedeschi@intel.com> * Makefile.in (SFILES): Add producer.c. (COMMON_OBS): Add producer.o * amd64-tdep.c (producer.h): Add new include. * dwarf2read.c (producer.h): Add new include. * producer.c: New file. * producer.h: New file. * utils.c (producer_is_gcc, producer_is_gcc_ge_4): Move to producer.c. * utils.h (producer_is_gcc, producer_is_gcc_ge_4): Move to producer.h.
Diffstat (limited to 'gdb/producer.c')
-rw-r--r--gdb/producer.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/gdb/producer.c b/gdb/producer.c
new file mode 100644
index 0000000..3f9297a
--- /dev/null
+++ b/gdb/producer.c
@@ -0,0 +1,73 @@
+/* Producer string parsers for GDB.
+
+ Copyright (C) 2012-2017 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "defs.h"
+#include "producer.h"
+
+/* See producer.h. */
+
+int
+producer_is_gcc_ge_4 (const char *producer)
+{
+ int major, minor;
+
+ if (! producer_is_gcc (producer, &major, &minor))
+ return -1;
+ if (major < 4)
+ return -1;
+ if (major > 4)
+ return INT_MAX;
+ return minor;
+}
+
+/* See producer.h. */
+
+int
+producer_is_gcc (const char *producer, int *major, int *minor)
+{
+ const char *cs;
+
+ if (producer != NULL && startswith (producer, "GNU "))
+ {
+ int maj, min;
+
+ if (major == NULL)
+ major = &maj;
+ if (minor == NULL)
+ minor = &min;
+
+ /* 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 1;
+ }
+
+ /* Not recognized as GCC. */
+ return 0;
+}
+