]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use unique_xmalloc_ptr in linespec_location_spec
authorTom Tromey <tom@tromey.com>
Sun, 10 Dec 2023 14:22:07 +0000 (07:22 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 13 Dec 2023 21:12:52 +0000 (14:12 -0700)
This changes linespec_location_spec to use unique_xmalloc_ptr,
removing some manual memory management.

Reviewed-By: John Baldwin <jhb@FreeBSD.org>
gdb/breakpoint.c
gdb/linespec.c
gdb/location.c
gdb/location.h

index 699919e32b3d5deffe06d938e63e5e19e2ba1ed7..957bef290f2b3de39a5a94f8fd61a541373d42b6 100644 (file)
@@ -8835,7 +8835,8 @@ parse_breakpoint_sals (location_spec *locspec,
 
   if (locspec->type () == LINESPEC_LOCATION_SPEC)
     {
-      const char *spec = as_linespec_location_spec (locspec)->spec_string;
+      const char *spec
+       = as_linespec_location_spec (locspec)->spec_string.get ();
 
       if (spec == NULL)
        {
@@ -8886,7 +8887,7 @@ parse_breakpoint_sals (location_spec *locspec,
       const char *spec = NULL;
 
       if (locspec->type () == LINESPEC_LOCATION_SPEC)
-       spec = as_linespec_location_spec (locspec)->spec_string;
+       spec = as_linespec_location_spec (locspec)->spec_string.get ();
 
       if (!cursal.symtab
          || (spec != NULL
@@ -12474,7 +12475,7 @@ strace_marker_create_sals_from_location_spec (location_spec *locspec,
   struct linespec_sals lsal;
   const char *arg_start, *arg;
 
-  arg = arg_start = as_linespec_location_spec (locspec)->spec_string;
+  arg = arg_start = as_linespec_location_spec (locspec)->spec_string.get ();
   lsal.sals = decode_static_tracepoint_spec (&arg);
 
   std::string str (arg_start, arg - arg_start);
@@ -12541,7 +12542,7 @@ std::vector<symtab_and_line>
 static_marker_tracepoint::decode_location_spec (location_spec *locspec,
                                                program_space *search_pspace)
 {
-  const char *s = as_linespec_location_spec (locspec)->spec_string;
+  const char *s = as_linespec_location_spec (locspec)->spec_string.get ();
 
   std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
   if (sals.size () > static_trace_marker_id_idx)
index 2aa0181981272f20e1d53f9d61c21b3d8e18066a..1643174de886fa3eac0997b0e34ea04143b9bb0a 100644 (file)
@@ -3072,7 +3072,8 @@ location_spec_to_sals (linespec_parser *parser,
       {
        const linespec_location_spec *ls = as_linespec_location_spec (locspec);
        PARSER_STATE (parser)->is_linespec = 1;
-       result = parse_linespec (parser, ls->spec_string, ls->match_type);
+       result = parse_linespec (parser, ls->spec_string.get (),
+                                ls->match_type);
       }
       break;
 
index 236bf3bb6f84f63ff52553cc2cc92a912b267810..df9a7d575dad784d36e17d6208d18f73929675b4 100644 (file)
@@ -83,15 +83,10 @@ linespec_location_spec::linespec_location_spec
         breakpoint setting code, where spec_string being nullptr means
         to use the default breakpoint location.  */
       if ((p - orig) > 0)
-       spec_string = savestring (orig, p - orig);
+       spec_string.reset (savestring (orig, p - orig));
     }
 }
 
-linespec_location_spec::~linespec_location_spec ()
-{
-  xfree (spec_string);
-}
-
 location_spec_up
 linespec_location_spec::clone () const
 {
@@ -108,7 +103,7 @@ linespec_location_spec::linespec_location_spec
   (const linespec_location_spec &other)
   : location_spec (other),
     match_type (other.match_type),
-    spec_string (maybe_xstrdup (other.spec_string))
+    spec_string (maybe_xstrdup (other.spec_string.get ()))
 {
 }
 
@@ -118,9 +113,9 @@ linespec_location_spec::compute_string () const
   if (spec_string != nullptr)
     {
       if (match_type == symbol_name_match_type::FULL)
-       return std::string ("-qualified ") + spec_string;
+       return std::string ("-qualified ") + spec_string.get ();
       else
-       return spec_string;
+       return spec_string.get ();
     }
   return {};
 }
index c2083ae7fc7803de514e26337914caba4085227e..e39a948f68032adef5fbd418473cf2a30c8d293e 100644 (file)
@@ -149,8 +149,6 @@ struct linespec_location_spec : public location_spec
   linespec_location_spec (const char **linespec,
                          symbol_name_match_type match_type);
 
-  ~linespec_location_spec ();
-
   location_spec_up clone () const override;
 
   bool empty_p () const override;
@@ -159,7 +157,7 @@ struct linespec_location_spec : public location_spec
   symbol_name_match_type match_type;
 
   /* The linespec.  */
-  char *spec_string = nullptr;
+  gdb::unique_xmalloc_ptr<char> spec_string;
 
 protected:
   linespec_location_spec (const linespec_location_spec &other);