From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/2] Use make_unique_xstrdup in tracepoint
Date: Thu, 15 Jan 2026 10:33:19 -0700 [thread overview]
Message-ID: <20260115-xstrdup-v1-2-72e13ba99851@adacore.com> (raw)
In-Reply-To: <20260115-xstrdup-v1-0-72e13ba99851@adacore.com>
This changes the tracepoint code to use make_unique_xstrdup (and
make_unique_xstrndup). This meant changing the types of some members
of uploaded_tp -- but it seems to me that using array types there did
not add any value.
---
gdb/tracepoint.c | 10 ++++------
gdb/tracepoint.h | 12 ++++++------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index a70edaeb262..2b6fbcbf5ae 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3414,7 +3414,7 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
p++; /* skip a colon */
if (piece == 'T')
{
- gdb::unique_xmalloc_ptr<char[]> cond;
+ gdb::unique_xmalloc_ptr<char> cond;
enabled = (*p++ == 'E');
p++; /* skip a colon */
@@ -3442,9 +3442,7 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
p++;
p = unpack_varlen_hex (p, &xlen);
p++; /* skip a comma */
- cond.reset ((char *) xmalloc (2 * xlen + 1));
- strncpy (&cond[0], p, 2 * xlen);
- cond[2 * xlen] = '\0';
+ cond = make_unique_xstrndup (p, 2 * xlen);
p += 2 * xlen;
}
else
@@ -3486,9 +3484,9 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
buf[end] = '\0';
if (startswith (srctype, "at:"))
- utp->at_string.reset (xstrdup (buf));
+ utp->at_string = make_unique_xstrdup (buf);
else if (startswith (srctype, "cond:"))
- utp->cond_string.reset (xstrdup (buf));
+ utp->cond_string = make_unique_xstrdup (buf);
else if (startswith (srctype, "cmd:"))
utp->cmd_strings.emplace_back (xstrdup (buf));
}
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index 8503789a14b..247723aa7ee 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -177,21 +177,21 @@ struct uploaded_tp
int orig_size = 0;
/* String that is the encoded form of the tracepoint's condition. */
- gdb::unique_xmalloc_ptr<char[]> cond;
+ gdb::unique_xmalloc_ptr<char> cond;
/* Vectors of strings that are the encoded forms of a tracepoint's
actions. */
- std::vector<gdb::unique_xmalloc_ptr<char[]>> actions;
- std::vector<gdb::unique_xmalloc_ptr<char[]>> step_actions;
+ std::vector<gdb::unique_xmalloc_ptr<char>> actions;
+ std::vector<gdb::unique_xmalloc_ptr<char>> step_actions;
/* The original string defining the location of the tracepoint. */
- gdb::unique_xmalloc_ptr<char[]> at_string;
+ gdb::unique_xmalloc_ptr<char> at_string;
/* The original string defining the tracepoint's condition. */
- gdb::unique_xmalloc_ptr<char[]> cond_string;
+ gdb::unique_xmalloc_ptr<char> cond_string;
/* List of original strings defining the tracepoint's actions. */
- std::vector<gdb::unique_xmalloc_ptr<char[]>> cmd_strings;
+ std::vector<gdb::unique_xmalloc_ptr<char>> cmd_strings;
/* The tracepoint's current hit count. */
int hit_count = 0;
--
2.52.0
next prev parent reply other threads:[~2026-01-15 17:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 17:33 [PATCH 0/2] More uses of make_unique_xstrdup Tom Tromey
2026-01-15 17:33 ` [PATCH 1/2] Use make_unique_xstrdup in more places Tom Tromey
2026-01-15 17:33 ` Tom Tromey [this message]
2026-01-15 17:39 ` [PATCH 0/2] More uses of make_unique_xstrdup Guinevere Larsen
2026-01-15 18:01 ` Simon Marchi
2026-01-15 18:16 ` Guinevere Larsen
2026-01-16 14:14 ` Andrew Burgess
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=20260115-xstrdup-v1-2-72e13ba99851@adacore.com \
--to=tromey@adacore.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