public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/3] gdb: use std::string for internalvar::name
Date: Mon, 13 Feb 2023 23:21:38 -0500	[thread overview]
Message-ID: <20230214042139.73638-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230214042139.73638-1-simon.marchi@efficios.com>

Change internalvar::name to std::string, automating memory management.

Change-Id: I814d61361663e7becb8f3fb5f58c0180cdc414bc
---
 gdb/value.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/value.c b/gdb/value.c
index e884913abe5a..68499896af8c 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1829,7 +1829,7 @@ union internalvar_data
 
 struct internalvar
 {
-  char *name;
+  std::string name;
 
   /* We support various different kinds of content of an internal variable.
      enum internalvar_kind specifies the kind, and union internalvar_data
@@ -1893,7 +1893,7 @@ struct internalvar *
 lookup_only_internalvar (const char *name)
 {
   for (internalvar_up &var : internalvars)
-    if (strcmp (var->name, name) == 0)
+    if (var->name == name)
       return var.get ();
 
   return NULL;
@@ -1910,8 +1910,8 @@ complete_internalvar (completion_tracker &tracker, const char *name)
   len = strlen (name);
 
   for (internalvar_up &var : internalvars)
-    if (strncmp (var->name, name, len) == 0)
-      tracker.add_completion (make_unique_xstrdup (var->name));
+    if (strncmp (var->name.c_str (), name, len) == 0)
+      tracker.add_completion (make_unique_xstrdup (var->name.c_str ()));
 }
 
 /* Create an internal variable with name NAME and with a void value.
@@ -1923,7 +1923,7 @@ create_internalvar (const char *name)
   internalvars.emplace_back (new internalvar);
   internalvar *var = internalvars.back ().get ();
 
-  var->name = xstrdup (name);
+  var->name = name;
   var->kind = INTERNALVAR_VOID;
 
   return var;
@@ -1994,7 +1994,7 @@ value_of_internalvar (struct gdbarch *gdbarch, struct internalvar *var)
 
   /* If there is a trace state variable of the same name, assume that
      is what we really want to see.  */
-  tsv = find_trace_state_variable (var->name);
+  tsv = find_trace_state_variable (var->name.c_str ());
   if (tsv)
     {
       tsv->value_known = target_get_trace_state_variable_value (tsv->number,
@@ -2147,7 +2147,7 @@ set_internalvar (struct internalvar *var, struct value *val)
   union internalvar_data new_data = { 0 };
 
   if (var->kind == INTERNALVAR_FUNCTION && var->u.fn.canonical)
-    error (_("Cannot overwrite convenience function %s"), var->name);
+    error (_("Cannot overwrite convenience function %s"), var->name.c_str ());
 
   /* Prepare new contents.  */
   switch (check_typedef (val->type ())->code ())
@@ -2259,7 +2259,7 @@ clear_internalvar (struct internalvar *var)
 const char *
 internalvar_name (const struct internalvar *var)
 {
-  return var->name;
+  return var->name.c_str ();
 }
 
 static struct internal_function *
@@ -2444,7 +2444,7 @@ show_convenience (const char *ignore, int from_tty)
 	{
 	  varseen = 1;
 	}
-      gdb_printf (("$%s = "), var->name);
+      gdb_printf (("$%s = "), var->name.c_str ());
 
       try
 	{
-- 
2.39.1


  reply	other threads:[~2023-02-14  4:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14  4:21 [PATCH 1/3] gdb: store internalvars in an std::vector Simon Marchi
2023-02-14  4:21 ` Simon Marchi [this message]
2023-02-14  4:21 ` [PATCH 3/3] gdb: keep internalvars sorted Simon Marchi
2023-02-14 10:54 ` [PATCH 1/3] gdb: store internalvars in an std::vector Lancelot SIX
2023-02-14 18:41   ` Simon Marchi

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=20230214042139.73638-2-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.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).