public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] Use unique_xmalloc_ptr in linespec_location_spec
Date: Sun, 10 Dec 2023 08:20:24 -0700	[thread overview]
Message-ID: <20231210-location-stuff-v1-1-9b6ae74fe5b0@tromey.com> (raw)
In-Reply-To: <20231210-location-stuff-v1-0-9b6ae74fe5b0@tromey.com>

This changes linespec_location_spec to use unique_xmalloc_ptr,
removing some manual memory management.
---
 gdb/breakpoint.c |  9 +++++----
 gdb/linespec.c   |  3 ++-
 gdb/location.c   | 13 ++++---------
 gdb/location.h   |  4 +---
 4 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 699919e32b3..957bef290f2 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -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)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 2aa01819812..1643174de88 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -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;
 
diff --git a/gdb/location.c b/gdb/location.c
index 236bf3bb6f8..df9a7d575da 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -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 {};
 }
diff --git a/gdb/location.h b/gdb/location.h
index c2083ae7fc7..e39a948f680 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -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);

-- 
2.43.0


  reply	other threads:[~2023-12-10 15:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-10 15:20 [PATCH 0/2] Use unique_xmalloc_ptr in location.[ch] Tom Tromey
2023-12-10 15:20 ` Tom Tromey [this message]
2023-12-10 15:20 ` [PATCH 2/2] Use unique_xmalloc_ptr in explicit_location_spec Tom Tromey
2023-12-12 23:52 ` [PATCH 0/2] Use unique_xmalloc_ptr in location.[ch] John Baldwin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231210-location-stuff-v1-1-9b6ae74fe5b0@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).