From patchwork Fri Dec 16 23:50:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62033 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 28EAE382FAF5 for ; Fri, 16 Dec 2022 23:51:21 +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 7DD9138369DE for ; Fri, 16 Dec 2022 23:50:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7DD9138369DE 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 cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway7.mail.pro1.eigbox.com (Postfix) with ESMTP id 74C3C10048ECC for ; Fri, 16 Dec 2022 23:50:31 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 6KTHp948qR8oI6KTHpfMW7; Fri, 16 Dec 2022 23:50:31 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=DseTREz+ c=1 sm=1 tr=0 ts=639d0447 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=fOZgNBgWbKeGMVsnxmUA:9 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=fiLBGErizK7ZPNWrGm8ZLhF22TzkNbUB8MKgiFrMlNY=; b=Ym+l/mYMG/4N41pYMjzNo9u8xn 3zQXmUqGRS4JV23WISDZ80snFLxVtpZd2Osekya+f5Q6HkUy6Lo+xwN1vRAieEClAu+6ir1A7Dbi9 ZnMU8qiKnC/wdCgXuU8CT5N+3; 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 1p6KTH-002Lmq-5n; Fri, 16 Dec 2022 16:50:31 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/7] Remove struct buffer from tracefile-tfile.c Date: Fri, 16 Dec 2022 16:50:11 -0700 Message-Id: <20221216235017.3722833-2-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: 1p6KTH-002Lmq-5n 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: 2 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, 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" 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 @@ -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 (); From patchwork Fri Dec 16 23:50:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62034 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 8BBE938330A2 for ; Fri, 16 Dec 2022 23:51:23 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy3-pub.mail.unifiedlayer.com (gproxy3-pub.mail.unifiedlayer.com [69.89.30.42]) by sourceware.org (Postfix) with ESMTPS id 88A9E38378F4 for ; Fri, 16 Dec 2022 23:50:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 88A9E38378F4 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 cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway5.mail.pro1.eigbox.com (Postfix) with ESMTP id B94C310047B11 for ; Fri, 16 Dec 2022 23:50:31 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 6KTHpxzIndq8T6KTHp2Gug; Fri, 16 Dec 2022 23:50:31 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=bNfTnNyZ c=1 sm=1 tr=0 ts=639d0447 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=nhUq8SdgGP2KS3tbw_EA:9 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=h89IUkCDYbJCYQh86OqIPIrdUngiQAavz48cp3DTjSU=; b=F0o4iX2KU8yHV50kIZyZAsDSD5 hH9jOXJYNfUEs+Ecar0Sb86bLSKTQoZhMapICQpY4Clh+ahJYOyCt9f2i3Rm/jDC3SoyH9M80u/3N 31SWsdxiQOy+pzKbcBWq/sMDx; 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 1p6KTH-002Lmq-AY; Fri, 16 Dec 2022 16:50:31 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/7] Don't use struct buffer in handle_qxfer_traceframe_info Date: Fri, 16 Dec 2022 16:50:12 -0700 Message-Id: <20221216235017.3722833-3-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: 1p6KTH-002Lmq-AY 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: 3 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, 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" 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, - "\n", - paddress (maddr), phex_nz (mlen, sizeof (mlen))); + string_xml_appendf (*buffer, + "\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, "\n", vnum); + string_xml_appendf (*buffer, "\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, "\n"); + *buffer += "\n"; traceframe_walk_blocks (tframe->data, tframe->data_size, tfnum, build_traceframe_info_xml, buffer); - buffer_grow_str0 (buffer, "\n"); + *buffer += "\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. */ From patchwork Fri Dec 16 23:50:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62032 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 EE7F2383589E for ; Fri, 16 Dec 2022 23:50:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id BF1A738378C7 for ; Fri, 16 Dec 2022 23:50:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BF1A738378C7 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 progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id 192F510048918 for ; Fri, 16 Dec 2022 23:50:32 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 6KTHpEaPTLBzM6KTHpk6Tg; Fri, 16 Dec 2022 23:50:31 +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=FZFwN0MM0v3j6DLvTXoA:9 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=PjTWrW0dfOyUCMVnHvDWnU70EVa3E1dB/PTXRIyHVYw=; b=SWNQluwVdsPvuP4OugmYdUIb5V YSF0+m0Clf+CSFLl3pXrDimbcsv+Pkx1nbnyLGu9SeajhtTkPiZeHa4rpuIg9fbATmJP8vHsZ+O66 GkB9zrZT3MX4zq6DXJSuPBH85; 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 1p6KTH-002Lmq-GC; Fri, 16 Dec 2022 16:50:31 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/7] Don't use struct buffer in handle_qxfer_btrace Date: Fri, 16 Dec 2022 16:50:13 -0700 Message-Id: <20221216235017.3722833-4-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: 1p6KTH-002Lmq-GC 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: 4 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, 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" 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, "\n"); + *buffer += "\n"; switch (config->cpu.vendor) { case CV_INTEL: - buffer_xml_printf (buffer, "\n", - config->cpu.family, config->cpu.model, - config->cpu.stepping); + string_xml_appendf (*buffer, "\n", + config->cpu.family, config->cpu.model, + config->cpu.stepping); break; default: break; } - buffer_grow_str (buffer, "\n"); + *buffer += "\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, "\n"); + *buffer += "\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, "\n"); + *buffer += "\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, "\n"); - buffer_grow_str (buffer, "\n"); + *buffer += "\n"; + *buffer += "\n"; for (const btrace_block &block : *btrace.variant.bts.blocks) - buffer_xml_printf (buffer, "\n", - paddress (block.begin), paddress (block.end)); + string_xml_appendf (*buffer, "\n", + paddress (block.begin), paddress (block.end)); - buffer_grow_str0 (buffer, "\n"); + *buffer += "\n"; break; case BTRACE_FORMAT_PT: - buffer_grow_str (buffer, "\n"); - buffer_grow_str (buffer, "\n"); - buffer_grow_str (buffer, "\n"); + *buffer += "\n"; + *buffer += "\n"; + *buffer += "\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, "\n"); - buffer_grow_str0 (buffer, "\n"); + *buffer += "\n"; + *buffer += "\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, "\n"); - buffer_grow_str (buffer, "\n"); + *buffer += "\n"; + *buffer += "\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.size); - buffer_xml_printf (buffer, " />\n"); + string_xml_appendf (*buffer, "bts.size); + string_xml_appendf (*buffer, " />\n"); break; case BTRACE_FORMAT_PT: - buffer_xml_printf (buffer, "pt.size); - buffer_xml_printf (buffer, "/>\n"); + string_xml_appendf (*buffer, "pt.size); + string_xml_appendf (*buffer, "/>\n"); break; } } - buffer_grow_str0 (buffer, "\n"); + *buffer += "\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); } From patchwork Fri Dec 16 23:50:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62038 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 7B7F23831E68 for ; Fri, 16 Dec 2022 23:52:14 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from qproxy2-pub.mail.unifiedlayer.com (qproxy2-pub.mail.unifiedlayer.com [69.89.16.161]) by sourceware.org (Postfix) with ESMTPS id 4000838378D0 for ; Fri, 16 Dec 2022 23:51:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4000838378D0 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 gproxy4-pub.mail.unifiedlayer.com (gproxy4-pub.mail.unifiedlayer.com [69.89.23.142]) by qproxy2.mail.unifiedlayer.com (Postfix) with ESMTP id 4C3FC8034407 for ; Fri, 16 Dec 2022 23:51:43 +0000 (UTC) Received: from cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id 02B1910046FD7 for ; Fri, 16 Dec 2022 23:50:33 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 6KTIpxzJBdq8T6KTIp2Gv4; Fri, 16 Dec 2022 23:50:32 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=bNfTnNyZ c=1 sm=1 tr=0 ts=639d0449 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=S6_QSMFA2EAgCqZMrJAA:9 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=JcHsvQH7jdiRqGk9Zz8GEd7PYfd1ciGPiTdmbZDQWtM=; b=i8hXt5B3tYxPbK746Itfmtk8gj DMSCzOSsf/Zcmn0LvR6hTvmMIaf/zgvd/T2ZSGGsxd6JPw2W6pZ9vGvMRdf1+ZoAU/l8+TaGvZrKw FDxAT8d7sNvp13SyTXoCyV7j9; 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 1p6KTH-002Lmq-OC; Fri, 16 Dec 2022 16:50:31 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 4/7] Don't use struct buffer in handle_qxfer_threads Date: Fri, 16 Dec 2022 16:50:14 -0700 Message-Id: <20221216235017.3722833-5-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: 1p6KTH-002Lmq-OC 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: 5 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, 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" 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, "\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, "\n"); + *buffer += "\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, "\n"); + *buffer += "\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; } From patchwork Fri Dec 16 23:50:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62036 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 791EE382E475 for ; Fri, 16 Dec 2022 23:51:42 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id C6EDD38362FC for ; Fri, 16 Dec 2022 23:50:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C6EDD38362FC 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 cmgw15.mail.unifiedlayer.com (unknown [10.0.90.130]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 35918100400D6 for ; Fri, 16 Dec 2022 23:50:32 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 6KTIpHZrxPmV96KTIpN1M4; Fri, 16 Dec 2022 23:50:32 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=Z4EpoFdA 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=8-cbgDhxwsnNjlxz6vYA:9 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=BPhAVHTJqZss23YYZdgdNW3rVEIwBSJxPA2fz8e6PVU=; b=eVR90Gqt7k7XBadp+kTcn1UjPo em97s3HA9uYNrw64fDQGeWjYcriWh5uu7DhTvI2rE90nQoFRCUtVzyy83yyzDHDSWB0SaRb8v5/Zq uPOiXM6+5eh7QxloYW1kV3fxl; 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 1p6KTH-002Lmq-TR; Fri, 16 Dec 2022 16:50:31 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 5/7] Don't use struct buffer in event-top.c Date: Fri, 16 Dec 2022 16:50:15 -0700 Message-Id: <20221216235017.3722833-6-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: 1p6KTH-002Lmq-TR 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: 6 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, 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" 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 (result)); + ui->input_handler (make_unique_xstrdup (line_buffer.c_str ())); } From patchwork Fri Dec 16 23:50:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62037 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 C1DD8383487E for ; Fri, 16 Dec 2022 23:51:46 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id D0BC0383557F for ; Fri, 16 Dec 2022 23:50:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D0BC0383557F 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 cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 3EF7C100400DB for ; Fri, 16 Dec 2022 23:50:32 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 6KTIpxzIzdq8T6KTIp2Gus; Fri, 16 Dec 2022 23:50:32 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=bNfTnNyZ 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=lsDJFVu-zTrl8t9VFacA:9 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=CvEER/ikZW12mHRZrI3zXKKPvrtW1YPNX3GXzyQxrNY=; b=dBbd33qidgSerIfvUiKVMcu9aC K8DrLdpKFxu7cXbFLBL4LKKbfMuzIR6udvU3s+ScyRK3XgohWpxmL0qMtTUGPRpQTOjs1z3exrz+q V/2pLrHIagN0wp0z7EbS/+EcL; 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-2E; Fri, 16 Dec 2022 16:50:32 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 6/7] Don't use struct buffer in top.c Date: Fri, 16 Dec 2022 16:50:16 -0700 Message-Id: <20221216235017.3722833-7-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-2E 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: 7 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, 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" 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 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 (), 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 */