aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-12-16 12:50:29 -0700
committerTom Tromey <tom@tromey.com>2023-02-24 11:53:03 -0700
commit147699fd6991ae67fc22ca543a28f85a242fc930 (patch)
tree6b0db9f0536b143faf89940d3f0e9fa500bd08ae /gdbsupport
parent1293ecd838c82e86f6c81d4518f5c662f8eaa0b9 (diff)
downloadgdb-147699fd6991ae67fc22ca543a28f85a242fc930.zip
gdb-147699fd6991ae67fc22ca543a28f85a242fc930.tar.gz
gdb-147699fd6991ae67fc22ca543a28f85a242fc930.tar.bz2
Remove struct buffer
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.
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/Makefile.am1
-rw-r--r--gdbsupport/Makefile.in4
-rw-r--r--gdbsupport/buffer.cc178
-rw-r--r--gdbsupport/buffer.h68
4 files changed, 1 insertions, 250 deletions
diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am
index 83eb6c3..00524e9 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 6db7644..89ed110 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) \
@@ -369,7 +369,6 @@ noinst_LIBRARIES = libgdbsupport.a
libgdbsupport_a_SOURCES = \
agent.cc \
btrace-common.cc \
- buffer.cc \
cleanups.cc \
common-debug.cc \
common-exceptions.cc \
@@ -478,7 +477,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 da6f3af6..0000000
--- a/gdbsupport/buffer.cc
+++ /dev/null
@@ -1,178 +0,0 @@
-/* A simple growing buffer for GDB.
-
- Copyright (C) 2009-2023 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 7323c3a..0000000
--- a/gdbsupport/buffer.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* A simple growing buffer for GDB.
-
- Copyright (C) 2009-2023 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 */