public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Remove struct buffer
@ 2022-12-16 23:50 Tom Tromey
  2022-12-16 23:50 ` [PATCH 1/7] Remove struct buffer from tracefile-tfile.c Tom Tromey
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Tom Tromey @ 2022-12-16 23:50 UTC (permalink / raw)
  To: gdb-patches

Here's a series to remove struct buffer.

Regression tested on x86-64 Fedora 36.

Let me know what you think.

Tom



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/7] Remove struct buffer from tracefile-tfile.c
  2022-12-16 23:50 [PATCH 0/7] Remove struct buffer Tom Tromey
@ 2022-12-16 23:50 ` Tom Tromey
  2022-12-16 23:50 ` [PATCH 2/7] Don't use struct buffer in handle_qxfer_traceframe_info Tom Tromey
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-12-16 23:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes tracefile-tfile.c to use std::string rather than struct
buffer.
---
 gdb/tracefile-tfile.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 3266f357a27..831c510648c 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -31,7 +31,6 @@
 #include "remote.h"
 #include "xml-tdesc.h"
 #include "target-descriptions.h"
-#include "gdbsupport/buffer.h"
 #include "gdbsupport/pathstuff.h"
 #include <algorithm>
 
@@ -425,7 +424,7 @@ static off_t trace_frames_offset;
 static off_t cur_offset;
 static int cur_data_size;
 int trace_regblock_size;
-static struct buffer trace_tdesc;
+static std::string trace_tdesc;
 
 static void tfile_append_tdesc_line (const char *line);
 static void tfile_interp_line (char *line,
@@ -487,7 +486,7 @@ tfile_target_open (const char *arg, int from_tty)
   trace_fd = scratch_chan;
 
   /* Make sure this is clear.  */
-  buffer_free (&trace_tdesc);
+  trace_tdesc.clear ();
 
   bytes = 0;
   /* Read the file header and test for validity.  */
@@ -626,7 +625,7 @@ tfile_target::close ()
   trace_fd = -1;
   xfree (trace_filename);
   trace_filename = NULL;
-  buffer_free (&trace_tdesc);
+  trace_tdesc.clear ();
 
   trace_reset_local_state ();
 }
@@ -922,16 +921,16 @@ tfile_xfer_partial_features (const char *annex,
   if (readbuf == NULL)
     error (_("tfile_xfer_partial: tdesc is read-only"));
 
-  if (trace_tdesc.used_size == 0)
+  if (trace_tdesc.empty ())
     return TARGET_XFER_E_IO;
 
-  if (offset >= trace_tdesc.used_size)
+  if (offset >= trace_tdesc.length ())
     return TARGET_XFER_EOF;
 
-  if (len > trace_tdesc.used_size - offset)
-    len = trace_tdesc.used_size - offset;
+  if (len > trace_tdesc.length () - offset)
+    len = trace_tdesc.length () - offset;
 
-  memcpy (readbuf, trace_tdesc.buffer + offset, len);
+  memcpy (readbuf, trace_tdesc.c_str () + offset, len);
   *xfered_len = len;
 
   return TARGET_XFER_OK;
@@ -1128,8 +1127,8 @@ tfile_target::traceframe_info ()
 static void
 tfile_append_tdesc_line (const char *line)
 {
-  buffer_grow_str (&trace_tdesc, line);
-  buffer_grow_str (&trace_tdesc, "\n");
+  trace_tdesc += line;
+  trace_tdesc += "\n";
 }
 
 void _initialize_tracefile_tfile ();
-- 
2.38.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/7] Don't use struct buffer in handle_qxfer_traceframe_info
  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 ` Tom Tromey
  2022-12-16 23:50 ` [PATCH 3/7] Don't use struct buffer in handle_qxfer_btrace Tom Tromey
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-12-16 23:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes handle_qxfer_traceframe_info, in gdbserver, to use
std::string rather than struct buffer.
---
 gdbserver/server.cc     | 27 ++++++++-------------------
 gdbserver/tracepoint.cc | 20 ++++++++++----------
 gdbserver/tracepoint.h  |  2 +-
 3 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index aaef38e0062..58aeafe11d5 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1764,8 +1764,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;
@@ -1775,35 +1774,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 d82b8e2c3ce..252f07c581a 100644
--- a/gdbserver/tracepoint.cc
+++ b/gdbserver/tracepoint.cc
@@ -5388,13 +5388,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)
     {
@@ -5407,9 +5407,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':
@@ -5417,7 +5417,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':
@@ -5439,7 +5439,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;
 
@@ -5453,10 +5453,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 bbffb6228f4..923ef8230ba 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.  */
-- 
2.38.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/7] Don't use struct buffer in handle_qxfer_btrace
  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 ` Tom Tromey
  2022-12-16 23:50 ` [PATCH 4/7] Don't use struct buffer in handle_qxfer_threads Tom Tromey
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-12-16 23:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes handle_qxfer_btrace and handle_qxfer_btrace_conf, in
gdbserver, to use std::string rather than struct buffer.
---
 gdbserver/linux-low.cc | 72 +++++++++++++++++++++---------------------
 gdbserver/linux-low.h  |  4 +--
 gdbserver/server.cc    | 32 +++++++++----------
 gdbserver/target.cc    |  6 ++--
 gdbserver/target.h     |  9 +++---
 5 files changed, 61 insertions(+), 62 deletions(-)

diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 5e412315e6d..b6ee30a54bd 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -6742,38 +6742,38 @@ linux_process_target::disable_btrace (btrace_target_info *tinfo)
 /* Encode an Intel Processor Trace configuration.  */
 
 static void
-linux_low_encode_pt_config (struct buffer *buffer,
+linux_low_encode_pt_config (std::string *buffer,
 			    const struct btrace_data_pt_config *config)
 {
-  buffer_grow_str (buffer, "<pt-config>\n");
+  *buffer += "<pt-config>\n";
 
   switch (config->cpu.vendor)
     {
     case CV_INTEL:
-      buffer_xml_printf (buffer, "<cpu vendor=\"GenuineIntel\" family=\"%u\" "
-			 "model=\"%u\" stepping=\"%u\"/>\n",
-			 config->cpu.family, config->cpu.model,
-			 config->cpu.stepping);
+      string_xml_appendf (*buffer, "<cpu vendor=\"GenuineIntel\" family=\"%u\" "
+			  "model=\"%u\" stepping=\"%u\"/>\n",
+			  config->cpu.family, config->cpu.model,
+			  config->cpu.stepping);
       break;
 
     default:
       break;
     }
 
-  buffer_grow_str (buffer, "</pt-config>\n");
+  *buffer += "</pt-config>\n";
 }
 
 /* Encode a raw buffer.  */
 
 static void
-linux_low_encode_raw (struct buffer *buffer, const gdb_byte *data,
+linux_low_encode_raw (std::string *buffer, const gdb_byte *data,
 		      unsigned int size)
 {
   if (size == 0)
     return;
 
   /* We use hex encoding - see gdbsupport/rsp-low.h.  */
-  buffer_grow_str (buffer, "<raw>\n");
+  *buffer += "<raw>\n";
 
   while (size-- > 0)
     {
@@ -6782,17 +6782,17 @@ linux_low_encode_raw (struct buffer *buffer, const gdb_byte *data,
       elem[0] = tohex ((*data >> 4) & 0xf);
       elem[1] = tohex (*data++ & 0xf);
 
-      buffer_grow (buffer, elem, 2);
+      buffer->append (elem);
     }
 
-  buffer_grow_str (buffer, "</raw>\n");
+  *buffer += "</raw>\n";
 }
 
 /* See to_read_btrace target method.  */
 
 int
 linux_process_target::read_btrace (btrace_target_info *tinfo,
-				   buffer *buffer,
+				   std::string *buffer,
 				   enum btrace_read_type type)
 {
   struct btrace_data btrace;
@@ -6802,9 +6802,9 @@ linux_process_target::read_btrace (btrace_target_info *tinfo,
   if (err != BTRACE_ERR_NONE)
     {
       if (err == BTRACE_ERR_OVERFLOW)
-	buffer_grow_str0 (buffer, "E.Overflow.");
+	*buffer += "E.Overflow.";
       else
-	buffer_grow_str0 (buffer, "E.Generic Error.");
+	*buffer += "E.Generic Error.";
 
       return -1;
     }
@@ -6812,36 +6812,36 @@ linux_process_target::read_btrace (btrace_target_info *tinfo,
   switch (btrace.format)
     {
     case BTRACE_FORMAT_NONE:
-      buffer_grow_str0 (buffer, "E.No Trace.");
+      *buffer += "E.No Trace.";
       return -1;
 
     case BTRACE_FORMAT_BTS:
-      buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n");
-      buffer_grow_str (buffer, "<btrace version=\"1.0\">\n");
+      *buffer += "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n";
+      *buffer += "<btrace version=\"1.0\">\n";
 
       for (const btrace_block &block : *btrace.variant.bts.blocks)
-	buffer_xml_printf (buffer, "<block begin=\"0x%s\" end=\"0x%s\"/>\n",
-			   paddress (block.begin), paddress (block.end));
+	string_xml_appendf (*buffer, "<block begin=\"0x%s\" end=\"0x%s\"/>\n",
+			    paddress (block.begin), paddress (block.end));
 
-      buffer_grow_str0 (buffer, "</btrace>\n");
+      *buffer += "</btrace>\n";
       break;
 
     case BTRACE_FORMAT_PT:
-      buffer_grow_str (buffer, "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n");
-      buffer_grow_str (buffer, "<btrace version=\"1.0\">\n");
-      buffer_grow_str (buffer, "<pt>\n");
+      *buffer += "<!DOCTYPE btrace SYSTEM \"btrace.dtd\">\n";
+      *buffer += "<btrace version=\"1.0\">\n";
+      *buffer += "<pt>\n";
 
       linux_low_encode_pt_config (buffer, &btrace.variant.pt.config);
 
       linux_low_encode_raw (buffer, btrace.variant.pt.data,
 			    btrace.variant.pt.size);
 
-      buffer_grow_str (buffer, "</pt>\n");
-      buffer_grow_str0 (buffer, "</btrace>\n");
+      *buffer += "</pt>\n";
+      *buffer += "</btrace>\n";
       break;
 
     default:
-      buffer_grow_str0 (buffer, "E.Unsupported Trace Format.");
+      *buffer += "E.Unsupported Trace Format.";
       return -1;
     }
 
@@ -6852,12 +6852,12 @@ linux_process_target::read_btrace (btrace_target_info *tinfo,
 
 int
 linux_process_target::read_btrace_conf (const btrace_target_info *tinfo,
-					buffer *buffer)
+					std::string *buffer)
 {
   const struct btrace_config *conf;
 
-  buffer_grow_str (buffer, "<!DOCTYPE btrace-conf SYSTEM \"btrace-conf.dtd\">\n");
-  buffer_grow_str (buffer, "<btrace-conf version=\"1.0\">\n");
+  *buffer += "<!DOCTYPE btrace-conf SYSTEM \"btrace-conf.dtd\">\n";
+  *buffer += "<btrace-conf version=\"1.0\">\n";
 
   conf = linux_btrace_conf (tinfo);
   if (conf != NULL)
@@ -6868,20 +6868,20 @@ linux_process_target::read_btrace_conf (const btrace_target_info *tinfo,
 	  break;
 
 	case BTRACE_FORMAT_BTS:
-	  buffer_xml_printf (buffer, "<bts");
-	  buffer_xml_printf (buffer, " size=\"0x%x\"", conf->bts.size);
-	  buffer_xml_printf (buffer, " />\n");
+	  string_xml_appendf (*buffer, "<bts");
+	  string_xml_appendf (*buffer, " size=\"0x%x\"", conf->bts.size);
+	  string_xml_appendf (*buffer, " />\n");
 	  break;
 
 	case BTRACE_FORMAT_PT:
-	  buffer_xml_printf (buffer, "<pt");
-	  buffer_xml_printf (buffer, " size=\"0x%x\"", conf->pt.size);
-	  buffer_xml_printf (buffer, "/>\n");
+	  string_xml_appendf (*buffer, "<pt");
+	  string_xml_appendf (*buffer, " size=\"0x%x\"", conf->pt.size);
+	  string_xml_appendf (*buffer, "/>\n");
 	  break;
 	}
     }
 
-  buffer_grow_str0 (buffer, "</btrace-conf>\n");
+  *buffer += "</btrace-conf>\n";
   return 0;
 }
 #endif /* HAVE_LINUX_BTRACE */
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 1594f063f47..c046b93abf4 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -282,11 +282,11 @@ class linux_process_target : public process_stratum_target
 
   int disable_btrace (btrace_target_info *tinfo) override;
 
-  int read_btrace (btrace_target_info *tinfo, buffer *buf,
+  int read_btrace (btrace_target_info *tinfo, std::string *buf,
 		   enum btrace_read_type type) override;
 
   int read_btrace_conf (const btrace_target_info *tinfo,
-			buffer *buf) override;
+			std::string *buf) override;
 #endif
 
   bool supports_range_stepping () override;
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 58aeafe11d5..0f053559b77 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1819,7 +1819,7 @@ handle_qxfer_btrace (const char *annex,
 		     ULONGEST offset, LONGEST len)
 {
   client_state &cs = get_client_state ();
-  static struct buffer cache;
+  static std::string cache;
   struct thread_info *thread;
   enum btrace_read_type type;
   int result;
@@ -1861,13 +1861,13 @@ handle_qxfer_btrace (const char *annex,
 
   if (offset == 0)
     {
-      buffer_free (&cache);
+      cache.clear ();
 
       try
 	{
 	  result = target_read_btrace (thread->btrace, &cache, type);
 	  if (result != 0)
-	    memcpy (cs.own_buf, cache.buffer, cache.used_size);
+	    memcpy (cs.own_buf, cache.c_str (), cache.length ());
 	}
       catch (const gdb_exception_error &exception)
 	{
@@ -1878,16 +1878,16 @@ handle_qxfer_btrace (const char *annex,
       if (result != 0)
 	return -3;
     }
-  else if (offset > cache.used_size)
+  else if (offset > cache.length ())
     {
-      buffer_free (&cache);
+      cache.clear ();
       return -3;
     }
 
-  if (len > cache.used_size - offset)
-    len = cache.used_size - offset;
+  if (len > cache.length () - offset)
+    len = cache.length () - offset;
 
-  memcpy (readbuf, cache.buffer + offset, len);
+  memcpy (readbuf, cache.c_str () + offset, len);
 
   return len;
 }
@@ -1900,7 +1900,7 @@ handle_qxfer_btrace_conf (const char *annex,
 			  ULONGEST offset, LONGEST len)
 {
   client_state &cs = get_client_state ();
-  static struct buffer cache;
+  static std::string cache;
   struct thread_info *thread;
   int result;
 
@@ -1932,13 +1932,13 @@ handle_qxfer_btrace_conf (const char *annex,
 
   if (offset == 0)
     {
-      buffer_free (&cache);
+      cache.clear ();
 
       try
 	{
 	  result = target_read_btrace_conf (thread->btrace, &cache);
 	  if (result != 0)
-	    memcpy (cs.own_buf, cache.buffer, cache.used_size);
+	    memcpy (cs.own_buf, cache.c_str (), cache.length ());
 	}
       catch (const gdb_exception_error &exception)
 	{
@@ -1949,16 +1949,16 @@ handle_qxfer_btrace_conf (const char *annex,
       if (result != 0)
 	return -3;
     }
-  else if (offset > cache.used_size)
+  else if (offset > cache.length ())
     {
-      buffer_free (&cache);
+      cache.clear ();
       return -3;
     }
 
-  if (len > cache.used_size - offset)
-    len = cache.used_size - offset;
+  if (len > cache.length () - offset)
+    len = cache.length () - offset;
 
-  memcpy (readbuf, cache.buffer + offset, len);
+  memcpy (readbuf, cache.c_str () + offset, len);
 
   return len;
 }
diff --git a/gdbserver/target.cc b/gdbserver/target.cc
index c06a67600b1..08e935ff334 100644
--- a/gdbserver/target.cc
+++ b/gdbserver/target.cc
@@ -715,15 +715,15 @@ process_stratum_target::disable_btrace (btrace_target_info *tinfo)
 
 int
 process_stratum_target::read_btrace (btrace_target_info *tinfo,
-			     buffer *buffer,
-			     enum btrace_read_type type)
+				     std::string *buffer,
+				     enum btrace_read_type type)
 {
   error (_("Target does not support branch tracing."));
 }
 
 int
 process_stratum_target::read_btrace_conf (const btrace_target_info *tinfo,
-					  buffer *buffer)
+					  std::string *buffer)
 {
   error (_("Target does not support branch tracing."));
 }
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 18ab969dda7..9b1a73c07a2 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -33,7 +33,6 @@
 #include "gdbsupport/byte-vector.h"
 
 struct emit_ops;
-struct buffer;
 struct process_info;
 
 /* This structure describes how to resume a particular thread (or all
@@ -403,14 +402,14 @@ class process_stratum_target
   /* Read branch trace data into buffer.
      Return 0 on success; print an error message into BUFFER and return -1,
      otherwise.  */
-  virtual int read_btrace (btrace_target_info *tinfo, buffer *buf,
+  virtual int read_btrace (btrace_target_info *tinfo, std::string *buf,
 			   enum btrace_read_type type);
 
   /* Read the branch trace configuration into BUFFER.
      Return 0 on success; print an error message into BUFFER and return -1
      otherwise.  */
   virtual int read_btrace_conf (const btrace_target_info *tinfo,
-				buffer *buf);
+				std::string *buf);
 
   /* Return true if target supports range stepping.  */
   virtual bool supports_range_stepping ();
@@ -636,7 +635,7 @@ target_disable_btrace (struct btrace_target_info *tinfo)
 
 static inline int
 target_read_btrace (struct btrace_target_info *tinfo,
-		    struct buffer *buffer,
+		    std::string *buffer,
 		    enum btrace_read_type type)
 {
   return the_target->read_btrace (tinfo, buffer, type);
@@ -644,7 +643,7 @@ target_read_btrace (struct btrace_target_info *tinfo,
 
 static inline int
 target_read_btrace_conf (struct btrace_target_info *tinfo,
-			 struct buffer *buffer)
+			 std::string *buffer)
 {
   return the_target->read_btrace_conf (tinfo, buffer);
 }
-- 
2.38.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/7] Don't use struct buffer in handle_qxfer_threads
  2022-12-16 23:50 [PATCH 0/7] Remove struct buffer Tom Tromey
                   ` (2 preceding siblings ...)
  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
  2022-12-16 23:50 ` [PATCH 5/7] Don't use struct buffer in event-top.c Tom Tromey
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-12-16 23:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/7] Don't use struct buffer in event-top.c
  2022-12-16 23:50 [PATCH 0/7] Remove struct buffer Tom Tromey
                   ` (3 preceding siblings ...)
  2022-12-16 23:50 ` [PATCH 4/7] Don't use struct buffer in handle_qxfer_threads Tom Tromey
@ 2022-12-16 23:50 ` Tom Tromey
  2022-12-16 23:50 ` [PATCH 6/7] Don't use struct buffer in top.c Tom Tromey
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-12-16 23:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes event-top.c to use std::string rather than struct buffer.
This isn't completely ideal, in that it requires a copy of the string
to be made.
---
 gdb/event-top.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index fa86a89e4a1..73ac3e077eb 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -36,7 +36,6 @@
 #include "gdbcmd.h"		/* for dont_repeat() */
 #include "annotate.h"
 #include "maint.h"
-#include "gdbsupport/buffer.h"
 #include "ser-event.h"
 #include "gdbsupport/gdb_select.h"
 #include "gdbsupport/gdb-sigmask.h"
@@ -864,12 +863,9 @@ void
 gdb_readline_no_editing_callback (gdb_client_data client_data)
 {
   int c;
-  char *result;
-  struct buffer line_buffer;
+  std::string line_buffer;
   struct ui *ui = current_ui;
 
-  buffer_init (&line_buffer);
-
   FILE *stream = ui->instream != nullptr ? ui->instream : ui->stdin_stream;
   gdb_assert (stream != nullptr);
 
@@ -889,32 +885,28 @@ gdb_readline_no_editing_callback (gdb_client_data client_data)
 
       if (c == EOF)
 	{
-	  if (line_buffer.used_size > 0)
+	  if (!line_buffer.empty ())
 	    {
 	      /* The last line does not end with a newline.  Return it, and
 		 if we are called again fgetc will still return EOF and
 		 we'll return NULL then.  */
 	      break;
 	    }
-	  xfree (buffer_finish (&line_buffer));
 	  ui->input_handler (NULL);
 	  return;
 	}
 
       if (c == '\n')
 	{
-	  if (line_buffer.used_size > 0
-	      && line_buffer.buffer[line_buffer.used_size - 1] == '\r')
-	    line_buffer.used_size--;
+	  if (!line_buffer.empty () && line_buffer.back () == '\r')
+	    line_buffer.pop_back ();
 	  break;
 	}
 
-      buffer_grow_char (&line_buffer, c);
+      line_buffer += c;
     }
 
-  buffer_grow_char (&line_buffer, '\0');
-  result = buffer_finish (&line_buffer);
-  ui->input_handler (gdb::unique_xmalloc_ptr<char> (result));
+  ui->input_handler (make_unique_xstrdup (line_buffer.c_str ()));
 }
 \f
 
-- 
2.38.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/7] Don't use struct buffer in top.c
  2022-12-16 23:50 [PATCH 0/7] Remove struct buffer Tom Tromey
                   ` (4 preceding siblings ...)
  2022-12-16 23:50 ` [PATCH 5/7] Don't use struct buffer in event-top.c Tom Tromey
@ 2022-12-16 23:50 ` 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
  7 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-12-16 23:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes top.c to use std::string rather than struct buffer.  Like
the event-top.c change, this is not completely ideal in that it
requires a copy of the string.
---
 gdb/top.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/gdb/top.c b/gdb/top.c
index 45e65beb3b3..b2624134c8a 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -50,7 +50,6 @@
 #include "maint.h"
 #include "filenames.h"
 #include "frame.h"
-#include "gdbsupport/buffer.h"
 #include "gdbsupport/gdb_select.h"
 #include "gdbsupport/scope-exit.h"
 #include "gdbarch.h"
@@ -883,18 +882,16 @@ save_command_line (const char *cmd)
 
    A NULL return means end of file.  */
 
-static char *
+static gdb::unique_xmalloc_ptr<char>
 gdb_readline_no_editing (const char *prompt)
 {
-  struct buffer line_buffer;
+  std::string line_buffer;
   struct ui *ui = current_ui;
   /* Read from stdin if we are executing a user defined command.  This
      is the right thing for prompt_for_continue, at least.  */
   FILE *stream = ui->instream != NULL ? ui->instream : stdin;
   int fd = fileno (stream);
 
-  buffer_init (&line_buffer);
-
   if (prompt != NULL)
     {
       /* Don't use a _filtered function here.  It causes the assumed
@@ -929,28 +926,25 @@ gdb_readline_no_editing (const char *prompt)
 
       if (c == EOF)
 	{
-	  if (line_buffer.used_size > 0)
+	  if (!line_buffer.empty ())
 	    /* The last line does not end with a newline.  Return it, and
 	       if we are called again fgetc will still return EOF and
 	       we'll return NULL then.  */
 	    break;
-	  xfree (buffer_finish (&line_buffer));
 	  return NULL;
 	}
 
       if (c == '\n')
 	{
-	  if (line_buffer.used_size > 0
-	      && line_buffer.buffer[line_buffer.used_size - 1] == '\r')
-	    line_buffer.used_size--;
+	  if (!line_buffer.empty () && line_buffer.back () == '\r')
+	    line_buffer.pop_back ();
 	  break;
 	}
 
-      buffer_grow_char (&line_buffer, c);
+      line_buffer += c;
     }
 
-  buffer_grow_char (&line_buffer, '\0');
-  return buffer_finish (&line_buffer);
+  return make_unique_xstrdup (line_buffer.c_str ());
 }
 
 /* Variables which control command line editing and history
@@ -1406,7 +1400,7 @@ command_line_input (std::string &cmd_line_buffer, const char *prompt_arg,
 	}
       else
 	{
-	  rl.reset (gdb_readline_no_editing (prompt));
+	  rl = gdb_readline_no_editing (prompt);
 	}
 
       cmd = handle_line_of_input (cmd_line_buffer, rl.get (),
-- 
2.38.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/7] Remove struct buffer
  2022-12-16 23:50 [PATCH 0/7] Remove struct buffer Tom Tromey
                   ` (5 preceding siblings ...)
  2022-12-16 23:50 ` [PATCH 6/7] Don't use struct buffer in top.c Tom Tromey
@ 2022-12-16 23:50 ` Tom Tromey
  2023-02-24 19:04 ` [PATCH 0/7] " Tom Tromey
  7 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-12-16 23:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I've long wanted to remove 'struct buffer', and thanks to Simon's
earlier patch, I was finally able to do so.  My feeling has been that
gdb already has several decent structures available for growing
strings: std::string of course, but also obstack and even objalloc
from BFD and dyn-string from libiberty.  The previous patches in this
series removed all the uses of struct buffer, so this one can remove
the code and the remaining #includes.
---
 gdb/linux-nat.c        |   1 -
 gdb/nat/linux-osdata.c |   1 -
 gdb/nat/linux-ptrace.c |   1 -
 gdb/nat/linux-ptrace.h |   2 -
 gdb/top.h              |   1 -
 gdbserver/server.h     |   1 -
 gdbsupport/Makefile.am |   1 -
 gdbsupport/Makefile.in |   4 +-
 gdbsupport/buffer.cc   | 178 -----------------------------------------
 gdbsupport/buffer.h    |  68 ----------------
 10 files changed, 1 insertion(+), 257 deletions(-)
 delete mode 100644 gdbsupport/buffer.cc
 delete mode 100644 gdbsupport/buffer.h

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index a244e03737e..2494c4caaf2 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -60,7 +60,6 @@
 #include "symfile.h"
 #include "gdbsupport/agent.h"
 #include "tracepoint.h"
-#include "gdbsupport/buffer.h"
 #include "target-descriptions.h"
 #include "gdbsupport/filestuff.h"
 #include "objfiles.h"
diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c
index 73a05256026..fda37aa00a1 100644
--- a/gdb/nat/linux-osdata.c
+++ b/gdb/nat/linux-osdata.c
@@ -33,7 +33,6 @@
 #include <arpa/inet.h>
 
 #include "gdbsupport/xml-utils.h"
-#include "gdbsupport/buffer.h"
 #include <dirent.h>
 #include <sys/stat.h>
 #include "gdbsupport/filestuff.h"
diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c
index 5b3086e76a6..a2823fd3a68 100644
--- a/gdb/nat/linux-ptrace.c
+++ b/gdb/nat/linux-ptrace.c
@@ -20,7 +20,6 @@
 #include "linux-ptrace.h"
 #include "linux-procfs.h"
 #include "linux-waitpid.h"
-#include "gdbsupport/buffer.h"
 #ifdef HAVE_SYS_PROCFS_H
 #include <sys/procfs.h>
 #endif
diff --git a/gdb/nat/linux-ptrace.h b/gdb/nat/linux-ptrace.h
index 4694046e1e8..d0872c7f525 100644
--- a/gdb/nat/linux-ptrace.h
+++ b/gdb/nat/linux-ptrace.h
@@ -18,8 +18,6 @@
 #ifndef NAT_LINUX_PTRACE_H
 #define NAT_LINUX_PTRACE_H
 
-struct buffer;
-
 #include "nat/gdb_ptrace.h"
 #include "gdbsupport/gdb_wait.h"
 
diff --git a/gdb/top.h b/gdb/top.h
index cbe50432c60..c1e84964cf5 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -20,7 +20,6 @@
 #ifndef TOP_H
 #define TOP_H
 
-#include "gdbsupport/buffer.h"
 #include "gdbsupport/event-loop.h"
 #include "gdbsupport/next-iterator.h"
 #include "value.h"
diff --git a/gdbserver/server.h b/gdbserver/server.h
index 6c64fe1ad80..620fc1bfed3 100644
--- a/gdbserver/server.h
+++ b/gdbserver/server.h
@@ -52,7 +52,6 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap);
 #  define PROG "gdbserver"
 #endif
 
-#include "gdbsupport/buffer.h"
 #include "gdbsupport/xml-utils.h"
 #include "regcache.h"
 #include "gdbsupport/gdb_signals.h"
diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am
index 1416027e1c9..5968b43cf69 100644
--- a/gdbsupport/Makefile.am
+++ b/gdbsupport/Makefile.am
@@ -42,7 +42,6 @@ endif
 libgdbsupport_a_SOURCES = \
     agent.cc \
     btrace-common.cc \
-    buffer.cc \
     cleanups.cc \
     common-debug.cc \
     common-exceptions.cc \
diff --git a/gdbsupport/Makefile.in b/gdbsupport/Makefile.in
index 6aadae41031..2e17861735a 100644
--- a/gdbsupport/Makefile.in
+++ b/gdbsupport/Makefile.in
@@ -147,7 +147,7 @@ libgdbsupport_a_LIBADD =
 @HAVE_PIPE_OR_PIPE2_TRUE@am__objects_1 = event-pipe.$(OBJEXT)
 @SELFTEST_TRUE@am__objects_2 = selftest.$(OBJEXT)
 am_libgdbsupport_a_OBJECTS = agent.$(OBJEXT) btrace-common.$(OBJEXT) \
-	buffer.$(OBJEXT) cleanups.$(OBJEXT) common-debug.$(OBJEXT) \
+	cleanups.$(OBJEXT) common-debug.$(OBJEXT) \
 	common-exceptions.$(OBJEXT) common-inferior.$(OBJEXT) \
 	common-regcache.$(OBJEXT) common-utils.$(OBJEXT) \
 	environ.$(OBJEXT) errors.$(OBJEXT) event-loop.$(OBJEXT) \
@@ -366,7 +366,6 @@ noinst_LIBRARIES = libgdbsupport.a
 libgdbsupport_a_SOURCES = \
     agent.cc \
     btrace-common.cc \
-    buffer.cc \
     cleanups.cc \
     common-debug.cc \
     common-exceptions.cc \
@@ -475,7 +474,6 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/agent.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/btrace-common.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cleanups.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/common-debug.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/common-exceptions.Po@am__quote@
diff --git a/gdbsupport/buffer.cc b/gdbsupport/buffer.cc
deleted file mode 100644
index fcf5990713b..00000000000
--- a/gdbsupport/buffer.cc
+++ /dev/null
@@ -1,178 +0,0 @@
-/* A simple growing buffer for GDB.
-  
-   Copyright (C) 2009-2022 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#include "common-defs.h"
-#include "xml-utils.h"
-#include "buffer.h"
-#include "inttypes.h"
-void
-buffer_grow (struct buffer *buffer, const char *data, size_t size)
-{
-  char *new_buffer;
-  size_t new_buffer_size;
-
-  if (size == 0)
-    return;
-
-  new_buffer_size = buffer->buffer_size;
-
-  if (new_buffer_size == 0)
-    new_buffer_size = 1;
-
-  while (buffer->used_size + size > new_buffer_size)
-    new_buffer_size *= 2;
-  new_buffer = (char *) xrealloc (buffer->buffer, new_buffer_size);
-  memcpy (new_buffer + buffer->used_size, data, size);
-  buffer->buffer = new_buffer;
-  buffer->buffer_size = new_buffer_size;
-  buffer->used_size += size;
-}
-
-void
-buffer_free (struct buffer *buffer)
-{
-  if (!buffer)
-    return;
-
-  xfree (buffer->buffer);
-  buffer->buffer = NULL;
-  buffer->buffer_size = 0;
-  buffer->used_size = 0;
-}
-
-void
-buffer_init (struct buffer *buffer)
-{
-  memset (buffer, 0, sizeof (*buffer));
-}
-
-char*
-buffer_finish (struct buffer *buffer)
-{
-  char *ret = buffer->buffer;
-  buffer->buffer = NULL;
-  buffer->buffer_size = 0;
-  buffer->used_size = 0;
-  return ret;
-}
-
-void
-buffer_xml_printf (struct buffer *buffer, const char *format, ...)
-{
-  va_list ap;
-  const char *f;
-  const char *prev;
-  int percent = 0;
-
-  va_start (ap, format);
-
-  prev = format;
-  for (f = format; *f; f++)
-    {
-      if (percent)
-	{
-	  char buf[32];
-	  char *str = buf;
-	  const char *f_old = f;
-	  
-	  switch (*f)
-	    {
-	    case 's':
-	      str = va_arg (ap, char *);
-	      break;
-	    case 'd':
-	      sprintf (str, "%d", va_arg (ap, int));
-	      break;
-	    case 'u':
-	      sprintf (str, "%u", va_arg (ap, unsigned int));
-	      break;
-	    case 'x':
-	      sprintf (str, "%x", va_arg (ap, unsigned int));
-	      break;
-	    case 'o':
-	      sprintf (str, "%o", va_arg (ap, unsigned int));
-	      break;
-	    case 'l':
-	      f++;
-	      switch (*f)
-		{
-		case 'd':
-		  sprintf (str, "%ld", va_arg (ap, long));
-		  break;
-		case 'u':
-		  sprintf (str, "%lu", va_arg (ap, unsigned long));
-		  break;
-		case 'x':
-		  sprintf (str, "%lx", va_arg (ap, unsigned long));
-		  break;
-		case 'o':
-		  sprintf (str, "%lo", va_arg (ap, unsigned long));
-		  break;
-		case 'l':
-		  f++;
-		  switch (*f)
-		    {
-		    case 'd':
-		      sprintf (str, "%" PRId64,
-			       (int64_t) va_arg (ap, long long));
-		      break;
-		    case 'u':
-		      sprintf (str, "%" PRIu64,
-			       (uint64_t) va_arg (ap, unsigned long long));
-		      break;
-		    case 'x':
-		      sprintf (str, "%" PRIx64,
-			       (uint64_t) va_arg (ap, unsigned long long));
-		      break;
-		    case 'o':
-		      sprintf (str, "%" PRIo64,
-			       (uint64_t) va_arg (ap, unsigned long long));
-		      break;
-		    default:
-		      str = 0;
-		      break;
-		    }
-		  break;
-		default:
-		  str = 0;
-		  break;
-		}
-	      break;
-	    default:
-	      str = 0;
-	      break;
-	    }
-
-	  if (str)
-	    {
-	      buffer_grow (buffer, prev, f_old - prev - 1);
-	      std::string p = xml_escape_text (str);
-	      buffer_grow_str (buffer, p.c_str ());
-	      prev = f + 1;
-	    }
-	  percent = 0;
-	}
-      else if (*f == '%')
-	percent = 1;
-    }
-
-  buffer_grow_str (buffer, prev);
-  va_end (ap);
-}
-
diff --git a/gdbsupport/buffer.h b/gdbsupport/buffer.h
deleted file mode 100644
index 9dac63fd478..00000000000
--- a/gdbsupport/buffer.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* A simple growing buffer for GDB.
-  
-   Copyright (C) 2009-2022 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef COMMON_BUFFER_H
-#define COMMON_BUFFER_H
-
-struct buffer
-{
-  char *buffer;
-  size_t buffer_size; /* allocated size */
-  size_t used_size; /* actually used size */
-};
-
-/* Append DATA of size SIZE to the end of BUFFER.  Grows the buffer to
-   accommodate the new data.  */
-void buffer_grow (struct buffer *buffer, const char *data, size_t size);
-
-/* Append C to the end of BUFFER.  Grows the buffer to accommodate the
-   new data.  */
-
-static inline void
-buffer_grow_char (struct buffer *buffer, char c)
-{
-  buffer_grow (buffer, &c, 1);
-}
-
-/* Release any memory held by BUFFER.  */
-void buffer_free (struct buffer *buffer);
-
-/* Initialize BUFFER.  BUFFER holds no memory afterwards.  */
-void buffer_init (struct buffer *buffer);
-
-/* Return a pointer into BUFFER data, effectively transferring
-   ownership of the buffer memory to the caller.  Calling buffer_free
-   afterwards has no effect on the returned data.  */
-char* buffer_finish (struct buffer *buffer);
-
-/* Simple printf to buffer function.  Current implemented formatters:
-   %s - grow an xml escaped text in BUFFER.
-   %d - grow an signed integer in BUFFER.
-   %u - grow an unsigned integer in BUFFER.
-   %x - grow an unsigned integer formatted in hexadecimal in BUFFER.
-   %o - grow an unsigned integer formatted in octal in BUFFER.  */
-void buffer_xml_printf (struct buffer *buffer, const char *format, ...)
-  ATTRIBUTE_PRINTF (2, 3);
-
-#define buffer_grow_str(BUFFER,STRING)		\
-  buffer_grow (BUFFER, STRING, strlen (STRING))
-#define buffer_grow_str0(BUFFER,STRING)			\
-  buffer_grow (BUFFER, STRING, strlen (STRING) + 1)
-
-#endif /* COMMON_BUFFER_H */
-- 
2.38.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7] Remove struct buffer
  2022-12-16 23:50 [PATCH 0/7] Remove struct buffer Tom Tromey
                   ` (6 preceding siblings ...)
  2022-12-16 23:50 ` [PATCH 7/7] Remove struct buffer Tom Tromey
@ 2023-02-24 19:04 ` Tom Tromey
  7 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2023-02-24 19:04 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> Here's a series to remove struct buffer.
Tom> Regression tested on x86-64 Fedora 36.

I'm checking this in now.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-02-24 19:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 4/7] Don't use struct buffer in handle_qxfer_threads Tom Tromey
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

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).