From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 4/7] Don't use struct buffer in handle_qxfer_threads
Date: Fri, 16 Dec 2022 16:50:14 -0700 [thread overview]
Message-ID: <20221216235017.3722833-5-tom@tromey.com> (raw)
In-Reply-To: <20221216235017.3722833-1-tom@tromey.com>
This changes handle_qxfer_threads, in gdbserver, to use std::string
rather than struct buffer.
---
gdbserver/server.cc | 45 +++++++++++++++++----------------------------
1 file changed, 17 insertions(+), 28 deletions(-)
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 0f053559b77..902a2a94618 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1633,7 +1633,7 @@ handle_qxfer_statictrace (const char *annex,
Emit the XML to describe the thread of INF. */
static void
-handle_qxfer_threads_worker (thread_info *thread, struct buffer *buffer)
+handle_qxfer_threads_worker (thread_info *thread, std::string *buffer)
{
ptid_t ptid = ptid_of (thread);
char ptid_s[100];
@@ -1652,34 +1652,34 @@ handle_qxfer_threads_worker (thread_info *thread, struct buffer *buffer)
write_ptid (ptid_s, ptid);
- buffer_xml_printf (buffer, "<thread id=\"%s\"", ptid_s);
+ string_xml_appendf (*buffer, "<thread id=\"%s\"", ptid_s);
if (core != -1)
{
sprintf (core_s, "%d", core);
- buffer_xml_printf (buffer, " core=\"%s\"", core_s);
+ string_xml_appendf (*buffer, " core=\"%s\"", core_s);
}
if (name != NULL)
- buffer_xml_printf (buffer, " name=\"%s\"", name);
+ string_xml_appendf (*buffer, " name=\"%s\"", name);
if (handle_status)
{
char *handle_s = (char *) alloca (handle_len * 2 + 1);
bin2hex (handle, handle_s, handle_len);
- buffer_xml_printf (buffer, " handle=\"%s\"", handle_s);
+ string_xml_appendf (*buffer, " handle=\"%s\"", handle_s);
}
- buffer_xml_printf (buffer, "/>\n");
+ string_xml_appendf (*buffer, "/>\n");
}
/* Helper for handle_qxfer_threads. Return true on success, false
otherwise. */
static bool
-handle_qxfer_threads_proper (struct buffer *buffer)
+handle_qxfer_threads_proper (std::string *buffer)
{
- buffer_grow_str (buffer, "<threads>\n");
+ *buffer += "<threads>\n";
/* The target may need to access memory and registers (e.g. via
libthread_db) to fetch thread properties. Even if don't need to
@@ -1699,7 +1699,7 @@ handle_qxfer_threads_proper (struct buffer *buffer)
if (non_stop)
target_unpause_all (true);
- buffer_grow_str0 (buffer, "</threads>\n");
+ *buffer += "</threads>\n";
return true;
}
@@ -1710,8 +1710,7 @@ handle_qxfer_threads (const char *annex,
gdb_byte *readbuf, const gdb_byte *writebuf,
ULONGEST offset, LONGEST len)
{
- static char *result = 0;
- static unsigned int result_length = 0;
+ static std::string result;
if (writebuf != NULL)
return -2;
@@ -1721,37 +1720,27 @@ handle_qxfer_threads (const char *annex,
if (offset == 0)
{
- struct buffer buffer;
/* When asked for data at offset 0, generate everything and store into
'result'. Successive reads will be served off 'result'. */
- if (result)
- free (result);
-
- buffer_init (&buffer);
-
- bool res = handle_qxfer_threads_proper (&buffer);
+ result.clear ();
- result = buffer_finish (&buffer);
- result_length = strlen (result);
- buffer_free (&buffer);
+ bool res = handle_qxfer_threads_proper (&result);
if (!res)
return -1;
}
- if (offset >= result_length)
+ if (offset >= result.length ())
{
/* We're out of data. */
- free (result);
- result = NULL;
- result_length = 0;
+ result.clear ();
return 0;
}
- if (len > result_length - offset)
- len = result_length - offset;
+ if (len > result.length () - offset)
+ len = result.length () - offset;
- memcpy (readbuf, result + offset, len);
+ memcpy (readbuf, result.c_str () + offset, len);
return len;
}
--
2.38.1
next prev parent reply other threads:[~2022-12-16 23:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-16 23:50 [PATCH 0/7] Remove struct buffer Tom Tromey
2022-12-16 23:50 ` [PATCH 1/7] Remove struct buffer from tracefile-tfile.c Tom Tromey
2022-12-16 23:50 ` [PATCH 2/7] Don't use struct buffer in handle_qxfer_traceframe_info Tom Tromey
2022-12-16 23:50 ` [PATCH 3/7] Don't use struct buffer in handle_qxfer_btrace Tom Tromey
2022-12-16 23:50 ` Tom Tromey [this message]
2022-12-16 23:50 ` [PATCH 5/7] Don't use struct buffer in event-top.c Tom Tromey
2022-12-16 23:50 ` [PATCH 6/7] Don't use struct buffer in top.c Tom Tromey
2022-12-16 23:50 ` [PATCH 7/7] Remove struct buffer Tom Tromey
2023-02-24 19:04 ` [PATCH 0/7] " 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=20221216235017.3722833-5-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).