aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-01-01 11:31:47 -0700
committerTom Tromey <tom@tromey.com>2022-01-18 10:14:43 -0700
commitd322d6d69df61a1af481de7e50359c3d92c0de14 (patch)
treed62d224c341e948e5712623d79648ea77ea23f0f /gdbsupport
parent0589ca4e7ba9b8d60599706b57be22c007c1f4fa (diff)
downloadgdb-d322d6d69df61a1af481de7e50359c3d92c0de14.zip
gdb-d322d6d69df61a1af481de7e50359c3d92c0de14.tar.gz
gdb-d322d6d69df61a1af481de7e50359c3d92c0de14.tar.bz2
Move gdb_regex to gdbsupport
This moves the gdb_regex convenience class to gdbsupport.
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/Makefile.am1
-rw-r--r--gdbsupport/Makefile.in19
-rw-r--r--gdbsupport/gdb_regex.cc57
-rw-r--r--gdbsupport/gdb_regex.h57
4 files changed, 126 insertions, 8 deletions
diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am
index 9e43348..6049fac 100644
--- a/gdbsupport/Makefile.am
+++ b/gdbsupport/Makefile.am
@@ -54,6 +54,7 @@ libgdbsupport_a_SOURCES = \
gdb-dlfcn.cc \
gdb-hashtab.cc \
gdb_obstack.cc \
+ gdb_regex.cc \
gdb_tilde_expand.cc \
gdb_wait.cc \
gdb_vecs.cc \
diff --git a/gdbsupport/Makefile.in b/gdbsupport/Makefile.in
index 59e1dfe..852e98c 100644
--- a/gdbsupport/Makefile.in
+++ b/gdbsupport/Makefile.in
@@ -152,14 +152,15 @@ am_libgdbsupport_a_OBJECTS = agent.$(OBJEXT) btrace-common.$(OBJEXT) \
environ.$(OBJEXT) errors.$(OBJEXT) event-loop.$(OBJEXT) \
fileio.$(OBJEXT) filestuff.$(OBJEXT) format.$(OBJEXT) \
gdb-dlfcn.$(OBJEXT) gdb-hashtab.$(OBJEXT) \
- gdb_obstack.$(OBJEXT) gdb_tilde_expand.$(OBJEXT) \
- gdb_wait.$(OBJEXT) gdb_vecs.$(OBJEXT) job-control.$(OBJEXT) \
- netstuff.$(OBJEXT) new-op.$(OBJEXT) pathstuff.$(OBJEXT) \
- print-utils.$(OBJEXT) ptid.$(OBJEXT) rsp-low.$(OBJEXT) \
- run-time-clock.$(OBJEXT) safe-strerror.$(OBJEXT) \
- scoped_mmap.$(OBJEXT) search.$(OBJEXT) signals.$(OBJEXT) \
- signals-state-save-restore.$(OBJEXT) tdesc.$(OBJEXT) \
- thread-pool.$(OBJEXT) xml-utils.$(OBJEXT) $(am__objects_1)
+ gdb_obstack.$(OBJEXT) gdb_regex.$(OBJEXT) \
+ gdb_tilde_expand.$(OBJEXT) gdb_wait.$(OBJEXT) \
+ gdb_vecs.$(OBJEXT) job-control.$(OBJEXT) netstuff.$(OBJEXT) \
+ new-op.$(OBJEXT) pathstuff.$(OBJEXT) print-utils.$(OBJEXT) \
+ ptid.$(OBJEXT) rsp-low.$(OBJEXT) run-time-clock.$(OBJEXT) \
+ safe-strerror.$(OBJEXT) scoped_mmap.$(OBJEXT) search.$(OBJEXT) \
+ signals.$(OBJEXT) signals-state-save-restore.$(OBJEXT) \
+ tdesc.$(OBJEXT) thread-pool.$(OBJEXT) xml-utils.$(OBJEXT) \
+ $(am__objects_1)
libgdbsupport_a_OBJECTS = $(am_libgdbsupport_a_OBJECTS)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -379,6 +380,7 @@ libgdbsupport_a_SOURCES = \
gdb-dlfcn.cc \
gdb-hashtab.cc \
gdb_obstack.cc \
+ gdb_regex.cc \
gdb_tilde_expand.cc \
gdb_wait.cc \
gdb_vecs.cc \
@@ -486,6 +488,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb-dlfcn.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb-hashtab.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_obstack.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_regex.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_tilde_expand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_vecs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_wait.Po@am__quote@
diff --git a/gdbsupport/gdb_regex.cc b/gdbsupport/gdb_regex.cc
new file mode 100644
index 0000000..f4d23cf
--- /dev/null
+++ b/gdbsupport/gdb_regex.cc
@@ -0,0 +1,57 @@
+/* Copyright (C) 2011-2022 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 "gdb_regex.h"
+#include "gdbsupport/def-vector.h"
+
+compiled_regex::compiled_regex (const char *regex, int cflags,
+ const char *message)
+{
+ gdb_assert (regex != NULL);
+ gdb_assert (message != NULL);
+
+ int code = regcomp (&m_pattern, regex, cflags);
+ if (code != 0)
+ {
+ size_t length = regerror (code, &m_pattern, NULL, 0);
+ gdb::def_vector<char> err (length);
+
+ regerror (code, &m_pattern, err.data (), length);
+ error (("%s: %s"), message, err.data ());
+ }
+}
+
+compiled_regex::~compiled_regex ()
+{
+ regfree (&m_pattern);
+}
+
+int
+compiled_regex::exec (const char *string, size_t nmatch,
+ regmatch_t pmatch[], int eflags) const
+{
+ return regexec (&m_pattern, string, nmatch, pmatch, eflags);
+}
+
+int
+compiled_regex::search (const char *string,
+ int length, int start, int range,
+ struct re_registers *regs)
+{
+ return re_search (&m_pattern, string, length, start, range, regs);
+}
diff --git a/gdbsupport/gdb_regex.h b/gdbsupport/gdb_regex.h
new file mode 100644
index 0000000..1b31f5b
--- /dev/null
+++ b/gdbsupport/gdb_regex.h
@@ -0,0 +1,57 @@
+/* Portable <regex.h>.
+ Copyright (C) 2000-2022 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/>. */
+
+#ifndef GDB_REGEX_H
+#define GDB_REGEX_H 1
+
+# include "xregex.h"
+
+/* A compiled regex. This is mainly a wrapper around regex_t. The
+ the constructor throws on regcomp error and the destructor is
+ responsible for calling regfree. The former means that it's not
+ possible to create an instance of compiled_regex that isn't
+ compiled, hence the name. */
+class compiled_regex
+{
+public:
+ /* Compile a regexp and throw an exception on error, including
+ MESSAGE. REGEX and MESSAGE must not be NULL. */
+ compiled_regex (const char *regex, int cflags,
+ const char *message)
+ ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (4);
+
+ ~compiled_regex ();
+
+ DISABLE_COPY_AND_ASSIGN (compiled_regex);
+
+ /* Wrapper around ::regexec. */
+ int exec (const char *string,
+ size_t nmatch, regmatch_t pmatch[],
+ int eflags) const;
+
+ /* Wrapper around ::re_search. (Not const because re_search's
+ regex_t parameter isn't either.) */
+ int search (const char *string, int size, int startpos,
+ int range, struct re_registers *regs);
+
+private:
+ /* The compiled pattern. */
+ regex_t m_pattern;
+};
+
+#endif /* not GDB_REGEX_H */