gdb/MAINTAINERS: add Luis Machado as global maintainer
[binutils-gdb.git] / gdb / location.c
index 4d0b60ff9c7075a7b0d42e893bfa9a5549c769c1..236bf3bb6f84f63ff52553cc2cc92a912b267810 100644 (file)
@@ -1,5 +1,5 @@
 /* Data structures and API for location specs in GDB.
-   Copyright (C) 2013-2022 Free Software Foundation, Inc.
+   Copyright (C) 2013-2023 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -18,6 +18,7 @@
 
 #include "defs.h"
 #include "gdbsupport/gdb_assert.h"
+#include "gdbsupport/gdb-checked-static-cast.h"
 #include "location.h"
 #include "symtab.h"
 #include "language.h"
@@ -60,7 +61,7 @@ probe_location_spec::empty_p () const
 
 std::string probe_location_spec::compute_string () const
 {
-  return std::move (as_string);
+  return std::move (m_as_string);
 }
 
 /* A "normal" linespec.  */
@@ -131,7 +132,7 @@ address_location_spec::address_location_spec (CORE_ADDR addr,
     address (addr)
 {
   if (addr_string != nullptr)
-    as_string = std::string (addr_string, addr_string_len);
+    m_as_string = std::string (addr_string, addr_string_len);
 }
 
 location_spec_up
@@ -206,14 +207,6 @@ explicit_location_spec::compute_string () const
 
 /* See description in location.h.  */
 
-enum location_spec_type
-location_spec_type (const location_spec *locspec)
-{
-  return locspec->type;
-}
-
-/* See description in location.h.  */
-
 location_spec_up
 new_linespec_location_spec (const char **linespec,
                            symbol_name_match_type match_type)
@@ -227,8 +220,8 @@ new_linespec_location_spec (const char **linespec,
 const linespec_location_spec *
 as_linespec_location_spec (const location_spec *locspec)
 {
-  gdb_assert (locspec->type == LINESPEC_LOCATION_SPEC);
-  return static_cast<const linespec_location_spec *> (locspec);
+  gdb_assert (locspec->type () == LINESPEC_LOCATION_SPEC);
+  return gdb::checked_static_cast<const linespec_location_spec *> (locspec);
 }
 
 /* See description in location.h.  */
@@ -246,8 +239,8 @@ new_address_location_spec (CORE_ADDR addr, const char *addr_string,
 const address_location_spec *
 as_address_location_spec (const location_spec *locspec)
 {
-  gdb_assert (locspec->type == ADDRESS_LOCATION_SPEC);
-  return static_cast<const address_location_spec *> (locspec);
+  gdb_assert (locspec->type () == ADDRESS_LOCATION_SPEC);
+  return gdb::checked_static_cast<const address_location_spec *> (locspec);
 }
 
 /* See description in location.h.  */
@@ -263,8 +256,8 @@ new_probe_location_spec (std::string &&probe)
 const probe_location_spec *
 as_probe_location_spec (const location_spec *locspec)
 {
-  gdb_assert (locspec->type == PROBE_LOCATION_SPEC);
-  return static_cast<const probe_location_spec *> (locspec);
+  gdb_assert (locspec->type () == PROBE_LOCATION_SPEC);
+  return gdb::checked_static_cast<const probe_location_spec *> (locspec);
 }
 
 /* See description in location.h.  */
@@ -272,8 +265,8 @@ as_probe_location_spec (const location_spec *locspec)
 const explicit_location_spec *
 as_explicit_location_spec (const location_spec *locspec)
 {
-  gdb_assert (locspec->type == EXPLICIT_LOCATION_SPEC);
-  return static_cast<const explicit_location_spec *> (locspec);
+  gdb_assert (locspec->type () == EXPLICIT_LOCATION_SPEC);
+  return gdb::checked_static_cast<const explicit_location_spec *> (locspec);
 }
 
 /* See description in location.h.  */
@@ -281,8 +274,8 @@ as_explicit_location_spec (const location_spec *locspec)
 explicit_location_spec *
 as_explicit_location_spec (location_spec *locspec)
 {
-  gdb_assert (locspec->type == EXPLICIT_LOCATION_SPEC);
-  return static_cast<explicit_location_spec *> (locspec);
+  gdb_assert (locspec->type () == EXPLICIT_LOCATION_SPEC);
+  return gdb::checked_static_cast<explicit_location_spec *> (locspec);
 }
 
 /* Return a string representation of the explicit location spec in
@@ -353,22 +346,6 @@ explicit_location_spec::to_linespec () const
   return explicit_to_string_internal (true, this);
 }
 
-/* See description in location.h.  */
-
-location_spec_up
-copy_location_spec (const location_spec *src)
-{
-  return src->clone ();
-}
-
-/* See description in location.h.  */
-
-const char *
-location_spec_to_string (struct location_spec *locspec)
-{
-  return locspec->to_string ();
-}
-
 /* Find an instance of the quote character C in the string S that is
    outside of all single- and double-quoted strings (i.e., any quoting
    other than C).  */
@@ -863,7 +840,7 @@ string_to_location_spec (const char **stringp,
 
       /* If the user really specified a location spec, then we're
         done.  */
-      if (!location_spec_empty_p (locspec.get ()))
+      if (!locspec->empty_p ())
        return locspec;
 
       /* Otherwise, the user _only_ specified optional flags like
@@ -872,8 +849,7 @@ string_to_location_spec (const char **stringp,
         linespec parsing below and discard the explicit location
         spec.  */
       explicit_location_spec *xloc
-       = dynamic_cast<explicit_location_spec *> (locspec.get ());
-      gdb_assert (xloc != nullptr);
+       = gdb::checked_static_cast<explicit_location_spec *> (locspec.get ());
       match_type = xloc->func_name_match_type;
     }
 
@@ -881,20 +857,3 @@ string_to_location_spec (const char **stringp,
      spec.  */
   return string_to_location_spec_basic (stringp, language, match_type);
 }
-
-/* See description in location.h.  */
-
-int
-location_spec_empty_p (const location_spec *locspec)
-{
-  return locspec->empty_p ();
-}
-
-/* See description in location.h.  */
-
-void
-set_location_spec_string (struct location_spec *locspec,
-                         std::string &&string)
-{
-  locspec->as_string = std::move (string);
-}