]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Refactor string_to_event_location for legacy linespec support.
authorKeith Seitz <keiths@redhat.com>
Tue, 9 Feb 2016 18:02:53 +0000 (10:02 -0800)
committerKeith Seitz <keiths@redhat.com>
Tue, 9 Feb 2016 18:02:53 +0000 (10:02 -0800)
This patch refactors string_to_event_location, breaking it into two
separate functions:

1) string_to_event_location_basic
A "basic" string parser that implements support for "legacy" linespecs
(linespec, address, and probe locations).  This function is intended to
be used by any UI wishing/needing to support this legacy behavior.

2) string_to_event_location
This is now intended as a CLI-only function which adds explicit location
parsing in a CLI-appropriate manner (in the form of traditional option/value
pairs).

Together these patches serve to simplify string-to-event location parsing
for all existing non-CLI interfaces (MI, guile, and python).

gdb/ChangeLog

* location.c (string_to_explicit_location): Note that "-p" is
reserved for probe locations and return NULL for any input
that starts with that.
(string_to_event_location): Move "legacy" linespec code to ...
(string_to_event_location_basic): ... here.
* location.h (string_to_event_location): Update comment.
(string_to_event_location_basic): New function.

gdb/ChangeLog
gdb/location.c
gdb/location.h

index 2d4713fcfe650b476e0c1d7083c61a4c79f550c4..1077d605bbba5422dc193b56e174573ec1a1fb8c 100644 (file)
@@ -1,3 +1,13 @@
+2016-02-09  Keith Seitz  <keiths@redhat.com>
+
+       * location.c (string_to_explicit_location): Note that "-p" is
+       reserved for probe locations and return NULL for any input
+       that starts with that.
+       (string_to_event_location): Move "legacy" linespec code to ...
+       (string_to_event_location_basic): ... here.
+       * location.h (string_to_event_location): Update comment.
+       (string_to_event_location_basic): New function.
+
 2016-02-09  Simon Marchi  <simon.marchi@ericsson.com>
 
        * configure.ac: Use AC_CONFIG_FILES instead of passing arguments
index e43ebf19feb0c3882098db0d16c16b76dce69e27..bbd26963f05e228856ad85f127730df3e86ab349 100644 (file)
@@ -522,11 +522,13 @@ string_to_explicit_location (const char **argp,
   struct event_location *location;
 
   /* It is assumed that input beginning with '-' and a non-digit
-     character is an explicit location.  */
+     character is an explicit location.  "-p" is reserved, though,
+     for probe locations.  */
   if (argp == NULL
       || *argp == '\0'
       || *argp[0] != '-'
-      || !isalpha ((*argp)[1]))
+      || !isalpha ((*argp)[1])
+      || ((*argp)[0] == '-' && (*argp)[1] == 'p'))
     return NULL;
 
   location = new_explicit_location (NULL);
@@ -634,51 +636,36 @@ string_to_explicit_location (const char **argp,
 /* See description in location.h.  */
 
 struct event_location *
-string_to_event_location (char **stringp,
-                         const struct language_defn *language)
+string_to_event_location_basic (char **stringp,
+                               const struct language_defn *language)
 {
   struct event_location *location;
+  const char *arg, *orig, *cs;
 
-  /* First, check if the string is an address location.  */
-  if (*stringp != NULL && **stringp == '*')
+  /* Try the input as a probe spec.  */
+  cs = *stringp;
+  if (cs != NULL && probe_linespec_to_ops (&cs) != NULL)
     {
-      const char *arg, *orig;
-      CORE_ADDR addr;
-
-      orig = arg = *stringp;
-      addr = linespec_expression_to_pc (&arg);
-      location = new_address_location (addr, orig, arg - orig);
-      *stringp += arg - orig;
+      location = new_probe_location (*stringp);
+      *stringp += strlen (*stringp);
     }
   else
     {
-      const char *cs;
-
-      /* Next, try the input as a probe spec.  */
-      cs = *stringp;
-      if (cs != NULL && probe_linespec_to_ops (&cs) != NULL)
-       {
-         location = new_probe_location (*stringp);
-         *stringp += strlen (*stringp);
-       }
-      else
+      /* Try an address location.  */
+      if (*stringp != NULL && **stringp == '*')
        {
          const char *arg, *orig;
+         CORE_ADDR addr;
 
-         /* Next, try an explicit location.  */
          orig = arg = *stringp;
-         location = string_to_explicit_location (&arg, language, 0);
-         if (location != NULL)
-           {
-             /* It was a valid explicit location.  Advance STRINGP to
-                the end of input.  */
-             *stringp += arg - orig;
-           }
-         else
-           {
-             /* Everything else is a linespec.  */
-             location = new_linespec_location (stringp);
-           }
+         addr = linespec_expression_to_pc (&arg);
+         location = new_address_location (addr, orig, arg - orig);
+         *stringp += arg - orig;
+       }
+      else
+       {
+         /* Everything else is a linespec.  */
+         location = new_linespec_location (stringp);
        }
     }
 
@@ -687,6 +674,34 @@ string_to_event_location (char **stringp,
 
 /* See description in location.h.  */
 
+struct event_location *
+string_to_event_location (char **stringp,
+                         const struct language_defn *language)
+{
+  struct event_location *location;
+  const char *arg, *orig;
+
+  /* Try an explicit location.  */
+  orig = arg = *stringp;
+  location = string_to_explicit_location (&arg, language, 0);
+  if (location != NULL)
+    {
+      /* It was a valid explicit location.  Advance STRINGP to
+        the end of input.  */
+      *stringp += arg - orig;
+    }
+  else
+    {
+      /* Everything else is a "basic" linespec, address, or probe
+        location.  */
+      location = string_to_event_location_basic (stringp, language);
+    }
+
+  return location;
+}
+
+/* See description in location.h.  */
+
 int
 event_location_empty_p (const struct event_location *location)
 {
index b2cf45e495c8bf8fb9260c971b0c2441bda0e5fa..8b19f34ad4471f65d382add3a29d5a991639f904 100644 (file)
@@ -207,12 +207,24 @@ extern struct event_location *
    but invalid, input, e.g., if it is called with missing argument parameters
    or invalid options.
 
-   The return result must be freed with delete_event_location.  */
+   The return result must be freed with delete_event_location.
+
+   This function is intended to be used by CLI commands and will parse
+   explicit locations in a CLI-centric way.  Other interfaces should use
+   string_to_event_location_basic if they want to maintain support for
+   legacy specifications of probe, address, and linespec locations.  */
 
 extern struct event_location *
   string_to_event_location (char **argp,
                            const struct language_defn *langauge);
 
+/* Like string_to_event_location, but does not attempt to parse explicit
+   locations.  */
+
+extern struct event_location *
+  string_to_event_location_basic (char **argp,
+                                 const struct language_defn *language);
+
 /* Attempt to convert the input string in *ARGP into an explicit location.
    ARGP is advanced past any processed input.  Returns an event_location
    (malloc'd) if an explicit location was successfully found in *ARGP,