From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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); } -- 2.38.1