aboutsummaryrefslogtreecommitdiff
path: root/gdbserver
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-12-16 07:49:01 -0700
committerTom Tromey <tom@tromey.com>2023-02-24 11:52:48 -0700
commitc9d9117a12be1ff0d86a6d5bd0c9380ee5107858 (patch)
treeea6a5a145aacb7198d5c5d69c5a0dbb6ae78e25d /gdbserver
parent588d3013543f8aa0105838edde410a1936b6765c (diff)
downloadgdb-c9d9117a12be1ff0d86a6d5bd0c9380ee5107858.zip
gdb-c9d9117a12be1ff0d86a6d5bd0c9380ee5107858.tar.gz
gdb-c9d9117a12be1ff0d86a6d5bd0c9380ee5107858.tar.bz2
Don't use struct buffer in handle_qxfer_traceframe_info
This changes handle_qxfer_traceframe_info, in gdbserver, to use std::string rather than struct buffer.
Diffstat (limited to 'gdbserver')
-rw-r--r--gdbserver/server.cc27
-rw-r--r--gdbserver/tracepoint.cc20
-rw-r--r--gdbserver/tracepoint.h2
3 files changed, 19 insertions, 30 deletions
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 46dfe70..443c11f 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1770,8 +1770,7 @@ handle_qxfer_traceframe_info (const char *annex,
ULONGEST offset, LONGEST len)
{
client_state &cs = get_client_state ();
- static char *result = 0;
- static unsigned int result_length = 0;
+ static std::string result;
if (writebuf != NULL)
return -2;
@@ -1781,35 +1780,25 @@ handle_qxfer_traceframe_info (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'. */
- free (result);
+ result.clear ();
- buffer_init (&buffer);
-
- traceframe_read_info (cs.current_traceframe, &buffer);
-
- result = buffer_finish (&buffer);
- result_length = strlen (result);
- buffer_free (&buffer);
+ traceframe_read_info (cs.current_traceframe, &result);
}
- 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;
}
diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
index b59077a..3f60989 100644
--- a/gdbserver/tracepoint.cc
+++ b/gdbserver/tracepoint.cc
@@ -5390,13 +5390,13 @@ traceframe_read_sdata (int tfnum, ULONGEST offset,
}
/* Callback for traceframe_walk_blocks. Builds a traceframe-info
- object. DATA is pointer to a struct buffer holding the
- traceframe-info object being built. */
+ object. DATA is pointer to a string holding the traceframe-info
+ object being built. */
static int
build_traceframe_info_xml (char blocktype, unsigned char *dataptr, void *data)
{
- struct buffer *buffer = (struct buffer *) data;
+ std::string *buffer = (std::string *) data;
switch (blocktype)
{
@@ -5409,9 +5409,9 @@ build_traceframe_info_xml (char blocktype, unsigned char *dataptr, void *data)
dataptr += sizeof (maddr);
memcpy (&mlen, dataptr, sizeof (mlen));
dataptr += sizeof (mlen);
- buffer_xml_printf (buffer,
- "<memory start=\"0x%s\" length=\"0x%s\"/>\n",
- paddress (maddr), phex_nz (mlen, sizeof (mlen)));
+ string_xml_appendf (*buffer,
+ "<memory start=\"0x%s\" length=\"0x%s\"/>\n",
+ paddress (maddr), phex_nz (mlen, sizeof (mlen)));
break;
}
case 'V':
@@ -5419,7 +5419,7 @@ build_traceframe_info_xml (char blocktype, unsigned char *dataptr, void *data)
int vnum;
memcpy (&vnum, dataptr, sizeof (vnum));
- buffer_xml_printf (buffer, "<tvar id=\"%d\"/>\n", vnum);
+ string_xml_appendf (*buffer, "<tvar id=\"%d\"/>\n", vnum);
break;
}
case 'R':
@@ -5441,7 +5441,7 @@ build_traceframe_info_xml (char blocktype, unsigned char *dataptr, void *data)
BUFFER. */
int
-traceframe_read_info (int tfnum, struct buffer *buffer)
+traceframe_read_info (int tfnum, std::string *buffer)
{
struct traceframe *tframe;
@@ -5455,10 +5455,10 @@ traceframe_read_info (int tfnum, struct buffer *buffer)
return 1;
}
- buffer_grow_str (buffer, "<traceframe-info>\n");
+ *buffer += "<traceframe-info>\n";
traceframe_walk_blocks (tframe->data, tframe->data_size,
tfnum, build_traceframe_info_xml, buffer);
- buffer_grow_str0 (buffer, "</traceframe-info>\n");
+ *buffer += "</traceframe-info>\n";
return 0;
}
diff --git a/gdbserver/tracepoint.h b/gdbserver/tracepoint.h
index a30f540..060d44d 100644
--- a/gdbserver/tracepoint.h
+++ b/gdbserver/tracepoint.h
@@ -95,7 +95,7 @@ int traceframe_read_sdata (int tfnum, ULONGEST offset,
unsigned char *buf, ULONGEST length,
ULONGEST *nbytes);
-int traceframe_read_info (int tfnum, struct buffer *buffer);
+int traceframe_read_info (int tfnum, std::string *buffer);
/* If a thread is determined to be collecting a fast tracepoint, this
structure holds the collect status. */