From patchwork Fri Dec 16 23:50:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62035 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16EBD383816E for ; Fri, 16 Dec 2022 23:51:26 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from progateway7-pub.mail.pro1.eigbox.com (gproxy5-pub.mail.unifiedlayer.com [67.222.38.55]) by sourceware.org (Postfix) with ESMTPS id 92E1638378F8 for ; Fri, 16 Dec 2022 23:50:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 92E1638378F8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway7.mail.pro1.eigbox.com (Postfix) with ESMTP id 6D04D10049640 for ; Fri, 16 Dec 2022 23:50:32 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 6KTIpEaPgLBzM6KTIpk6Ts; Fri, 16 Dec 2022 23:50:32 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=LcX5VhTi c=1 sm=1 tr=0 ts=639d0448 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=sHyYjHe8cH0A:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=mDV3o1hIAAAA:8 a=FJTyTDewS6_zLerGOMkA:9 a=_FVE-zBwftR9WsbkzFJk:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=GYJSxUnCFfREYY+OusZ/518XmB+Rdfn5i8KqtBnEGNE=; b=wAAiLhMEiXwvyDUz9dpT9I4S/M rLqPMh2mTDGYT37MdAaWB9LCHQkXTItGBxVZgKwyNd06CRyPqEobYm1rFUbNtTCey7gH9JlrYGzS1 DsUUQrGVI5tM1SnM2HgsfWySz; Received: from 97-122-76-186.hlrn.qwest.net ([97.122.76.186]:49920 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1p6KTI-002Lmq-7I; Fri, 16 Dec 2022 16:50:32 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 7/7] Remove struct buffer Date: Fri, 16 Dec 2022 16:50:17 -0700 Message-Id: <20221216235017.3722833-8-tom@tromey.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221216235017.3722833-1-tom@tromey.com> References: <20221216235017.3722833-1-tom@tromey.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.76.186 X-Source-L: No X-Exim-ID: 1p6KTI-002Lmq-7I X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-76-186.hlrn.qwest.net (localhost.localdomain) [97.122.76.186]:49920 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3028.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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 #include "gdbsupport/xml-utils.h" -#include "gdbsupport/buffer.h" #include #include #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 #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 . */ - -#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 . */ - -#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 */