The "record goto" command scans its arguments for "begin", "start", or "end".
[deliverable/binutils-gdb.git] / gdb / utils.c
index 37deb02c8e9397d65eda57016117fe21d1e37790..218faed0babed2b0f0d6643bd5bc55d324144ac4 100644 (file)
@@ -1124,6 +1124,30 @@ get_regcomp_error (int code, regex_t *rx)
   return result;
 }
 
+/* Compile a regexp and throw an exception on error.  This returns a
+   cleanup to free the resulting pattern on success.  If RX is NULL,
+   this does nothing and returns NULL.  */
+
+struct cleanup *
+compile_rx_or_error (regex_t *pattern, const char *rx, const char *message)
+{
+  int code;
+
+  if (!rx)
+    return NULL;
+
+  code = regcomp (pattern, rx, REG_NOSUB);
+  if (code != 0)
+    {
+      char *err = get_regcomp_error (code, pattern);
+
+      make_cleanup (xfree, err);
+      error (("%s: %s"), message, err);
+    }
+
+  return make_regfree_cleanup (pattern);
+}
+
 \f
 
 /* This function supports the query, nquery, and yquery functions.
This page took 0.023333 seconds and 4 git commands to generate.