2016-03-29 Don Breazeal <donb@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / location.c
index 49067b996bd6eb34c4da923c3c8c6502555c5135..bbd26963f05e228856ad85f127730df3e86ab349 100644 (file)
@@ -1,5 +1,5 @@
 /* Data structures and API for event locations in GDB.
-   Copyright (C) 2013-2015 Free Software Foundation, Inc.
+   Copyright (C) 2013-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -36,7 +36,7 @@ struct event_location
 {
   /* The type of this breakpoint specification.  */
   enum event_location_type type;
-#define EL_TYPE(PTR) (PTR)->type
+#define EL_TYPE(P) (P)->type
 
   union
   {
@@ -44,22 +44,22 @@ struct event_location
        This representation is used by both "normal" linespecs and
        probes.  */
     char *addr_string;
-#define EL_LINESPEC(PTR) ((PTR)->u.addr_string)
-#define EL_PROBE(PTR) ((PTR)->u.addr_string)
+#define EL_LINESPEC(P) ((P)->u.addr_string)
+#define EL_PROBE(P) ((P)->u.addr_string)
 
     /* An address in the inferior.  */
     CORE_ADDR address;
-#define EL_ADDRESS(PTR) (PTR)->u.address
+#define EL_ADDRESS(P) (P)->u.address
 
     /* An explicit location.  */
     struct explicit_location explicit_loc;
-#define EL_EXPLICIT(PTR) (&((PTR)->u.explicit_loc))
+#define EL_EXPLICIT(P) (&((P)->u.explicit_loc))
   } u;
 
   /* Cached string representation of this location.  This is used, e.g., to
      save stop event locations to file.  Malloc'd.  */
   char *as_string;
-#define EL_STRING(PTR) ((PTR)->as_string)
+#define EL_STRING(P) ((P)->as_string)
 };
 
 /* See description in location.h.  */
@@ -113,13 +113,16 @@ get_linespec_location (const struct event_location *location)
 /* See description in location.h.  */
 
 struct event_location *
-new_address_location (CORE_ADDR addr)
+new_address_location (CORE_ADDR addr, const char *addr_string,
+                     int addr_string_len)
 {
   struct event_location *location;
 
   location = XCNEW (struct event_location);
   EL_TYPE (location) = ADDRESS_LOCATION;
   EL_ADDRESS (location) = addr;
+  if (addr_string != NULL)
+    EL_STRING (location) = xstrndup (addr_string, addr_string_len);
   return location;
 }
 
@@ -134,6 +137,15 @@ get_address_location (const struct event_location *location)
 
 /* See description in location.h.  */
 
+const char *
+get_address_string_location (const struct event_location *location)
+{
+  gdb_assert (EL_TYPE (location) == ADDRESS_LOCATION);
+  return EL_STRING (location);
+}
+
+/* See description in location.h.  */
+
 struct event_location *
 new_probe_location (const char *probe)
 {
@@ -510,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);
@@ -622,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);
-      *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);
        }
     }
 
@@ -675,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)
 {
This page took 0.027313 seconds and 4 git commands to generate.