gdb: convert callback_handler_installed from int to bool
[binutils-gdb.git] / gdb / location.c
index f8369bf8318eba6a93b95c28d5e8d0dba77452b3..0459980ab8c072de4716e6fed358eae4341b6cce 100644 (file)
@@ -71,6 +71,12 @@ protected:
   {
   }
 
+  event_location (enum event_location_type t, std::string &&str)
+    : type (t),
+      as_string (std::move (str))
+  {
+  }
+
   explicit event_location (const event_location *to_clone)
     : type (to_clone->type),
       as_string (to_clone->as_string)
@@ -85,17 +91,9 @@ protected:
 /* A probe.  */
 struct event_location_probe : public event_location
 {
-  explicit event_location_probe (const char *probe)
-    : event_location (PROBE_LOCATION),
-      addr_string (probe == nullptr
-                  ? nullptr
-                  : xstrdup (probe))
-  {
-  }
-
-  ~event_location_probe ()
+  explicit event_location_probe (std::string &&probe)
+    : event_location (PROBE_LOCATION, std::move (probe))
   {
-    xfree (addr_string);
   }
 
   event_location_up clone () const override
@@ -105,24 +103,19 @@ struct event_location_probe : public event_location
 
   bool empty_p () const override
   {
-    return addr_string == nullptr;
+    return false;
   }
 
-  char *addr_string;
-
 protected:
 
   explicit event_location_probe (const event_location_probe *to_clone)
-    : event_location (to_clone),
-      addr_string (to_clone->addr_string == nullptr
-                  ? nullptr
-                  : xstrdup (to_clone->addr_string))
+    : event_location (to_clone)
   {
   }
 
   std::string compute_string () const override
   {
-    return addr_string;
+    return std::move (as_string);
   }
 };
 
@@ -141,6 +134,11 @@ struct event_location_linespec : public event_location
 
        linespec_lex_to_end (linespec);
        p = remove_trailing_whitespace (orig, *linespec);
+
+       /* If there is no valid linespec then this will leave the
+          spec_string as nullptr.  This behaviour is relied on in the
+          breakpoint setting code, where spec_string being nullptr means
+          to use the default breakpoint location.  */
        if ((p - orig) > 0)
          linespec_location.spec_string = savestring (orig, p - orig);
       }
@@ -357,9 +355,9 @@ get_address_string_location (const struct event_location *location)
 /* See description in location.h.  */
 
 event_location_up
-new_probe_location (const char *probe)
+new_probe_location (std::string &&probe)
 {
-  return event_location_up (new event_location_probe (probe));
+  return event_location_up (new event_location_probe (std::move (probe)));
 }
 
 /* See description in location.h.  */
@@ -368,7 +366,7 @@ const char *
 get_probe_location (const struct event_location *location)
 {
   gdb_assert (location->type == PROBE_LOCATION);
-  return ((event_location_probe *) location)->addr_string;
+  return location->to_string ();
 }
 
 /* See description in location.h.  */
@@ -454,7 +452,7 @@ explicit_to_string_internal (bool as_linespec,
                  explicit_loc->line_offset.offset);
     }
 
-  return std::move (buf.string ());
+  return buf.release ();
 }
 
 /* See description in location.h.  */