From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 6/6] Use std::string in print_one_catch_syscall
Date: Mon, 4 Oct 2021 18:14:53 -0600 [thread overview]
Message-ID: <20211005001453.2957929-7-tom@tromey.com> (raw)
In-Reply-To: <20211005001453.2957929-1-tom@tromey.com>
This changes print_one_catch_syscall to use std::string, removing a
bit of manual memory management.
---
gdb/break-catch-syscall.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 32736f024ad..3d3b275c31e 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -250,28 +250,24 @@ print_one_catch_syscall (struct breakpoint *b,
if (!c->syscalls_to_be_caught.empty ())
{
- char *text = xstrprintf ("%s", "");
+ std::string text;
+ bool first = true;
for (int iter : c->syscalls_to_be_caught)
{
- char *previous_text = text;
struct syscall s;
get_syscall_by_number (gdbarch, iter, &s);
+ if (!first)
+ text += ", ";
+ first = false;
+
if (s.name != NULL)
- text = xstrprintf ("%s%s, ", text, s.name);
+ text += s.name;
else
- text = xstrprintf ("%s%d, ", text, iter);
-
- /* We have to xfree previous_text because xstrprintf dynamically
- allocates new space for text on every call. */
- xfree (previous_text);
+ text += std::to_string (iter);
}
- /* Remove the last comma. */
- text[strlen (text) - 2] = '\0';
- uiout->field_string ("what", text);
- /* xfree last text. */
- xfree (text);
+ uiout->field_string ("what", text.c_str ());
}
else
uiout->field_string ("what", "<any syscall>", metadata_style.style ());
--
2.31.1
next prev parent reply other threads:[~2021-10-05 0:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 0:14 [PATCH 0/6] Remove some uses of xfree Tom Tromey
2021-10-05 0:14 ` [PATCH 1/6] Use unique_xmalloc_ptr in solib_catchpoint Tom Tromey
2021-10-05 0:14 ` [PATCH 2/6] Use unique_xmalloc_ptr in exec_catchpoint Tom Tromey
2021-10-05 0:14 ` [PATCH 3/6] Use unique_xmalloc_ptr in watchpoint Tom Tromey
2021-10-05 0:14 ` [PATCH 4/6] Use unique_xmalloc_ptr in bp_location Tom Tromey
2021-10-05 0:14 ` [PATCH 5/6] Use unique_xmalloc_ptr in breakpoing Tom Tromey
2021-10-05 0:14 ` Tom Tromey [this message]
2021-10-05 18:13 ` [PATCH 0/6] Remove some uses of xfree Bruno Larsen
2021-10-20 17:00 ` Tom Tromey
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=20211005001453.2957929-7-tom@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).