GDB (xrefs)
/tmp/gdb-8.1/gdb/gdb_regex.c
Go to the documentation of this file.
1 /* Copyright (C) 2011-2018 Free Software Foundation, Inc.
2 
3  This file is part of GDB.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #include "defs.h"
19 #include "gdb_regex.h"
20 #include "common/def-vector.h"
21 
22 compiled_regex::compiled_regex (const char *regex, int cflags,
23  const char *message)
24 {
25  gdb_assert (regex != NULL);
26  gdb_assert (message != NULL);
27 
28  int code = regcomp (&m_pattern, regex, cflags);
29  if (code != 0)
30  {
31  size_t length = regerror (code, &m_pattern, NULL, 0);
32  gdb::def_vector<char> err (length);
33 
34  regerror (code, &m_pattern, err.data (), length);
35  error (("%s: %s"), message, err.data ());
36  }
37 }
38 
40 {
41  regfree (&m_pattern);
42 }
43 
44 int
45 compiled_regex::exec (const char *string, size_t nmatch,
46  regmatch_t pmatch[], int eflags) const
47 {
48  return regexec (&m_pattern, string, nmatch, pmatch, eflags);
49 }
50 
51 int
52 compiled_regex::search (const char *string,
53  int length, int start, int range,
54  struct re_registers *regs)
55 {
56  return re_search (&m_pattern, string, length, start, range, regs);
57 }
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition: gnu-nat.c:1822
std::vector< T, gdb::default_init_allocator< T > > def_vector
Definition: def-vector.h:32
compiled_regex(const char *regex, int cflags, const char *message) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4)
Definition: gdb_regex.c:22
int search(const char *string, int size, int startpos, int range, struct re_registers *regs)
Definition: gdb_regex.c:52
regex_t m_pattern
Definition: gdb_regex.h:60
Definition: value.c:62
#define gdb_assert(expr)
Definition: gdb_assert.h:32
int code
Definition: ser-unix.c:239
void error(const char *fmt,...)
Definition: errors.c:38
int exec(const char *string, size_t nmatch, regmatch_t pmatch[], int eflags) const
Definition: gdb_regex.c:45