From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6F45C3858281 for ; Mon, 27 Feb 2023 21:29:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F45C3858281 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677533388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WH5KrFp9VG4nUuZgWLYrrKVGOhIaCxfaqNEErIvIEZE=; b=AraHEzp0qh8p8J2TA6i3MQXIRrEE2Aho1z1Uv04mj2L+9J2xeoqedpx5/G1xK9wDA1qsXV OardW8X9VXGRKxw0XGYS0cOiVvNWKpQHgb5sJNuhm0DpLciQWZEhWwwJNB/Y3qmfKrpbGU ZMRThfVLpcGLukhAKT69rwlEDYvbsMM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-641-GIObEo-qPUqqwE6HpVBfQw-1; Mon, 27 Feb 2023 16:29:47 -0500 X-MC-Unique: GIObEo-qPUqqwE6HpVBfQw-1 Received: by mail-wm1-f69.google.com with SMTP id az12-20020a05600c600c00b003e8910ec2fdso2859005wmb.6 for ; Mon, 27 Feb 2023 13:29:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677533385; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WH5KrFp9VG4nUuZgWLYrrKVGOhIaCxfaqNEErIvIEZE=; b=AbB+tlUurK8qn+CIT9wpZaWScY48BT/aut0zO7VlMCAFiC8b/UaA4gnsROvyhLBy0N HXrFY4bZCj1qR7zb1tCyVaKA/9B8DOu/v2omZhK74Q3gYYZeLkT3mBhC8kNE4b46pDYs gU5Bsdc620jJ129ghNWWhfivtOzmj/XdFN8AhiDAgveOu0R2yTDYjsXPTV1nls+Zanus 0vR1X4HVOidAopxiL12jRCmuMt5nISPJizMpwvtRfYPCcy2S9LiPXbuV966yPqhZtNRA LsrHmMLmMQNxzI8Q+DDXNOLUpiVvb6+MC22rvhF7jEwsxYrd01VXw6oNVv5HNHp65Txk p1MA== X-Gm-Message-State: AO0yUKXKk1YJO32xM1x74Wp4V0lekycfkbdgLWzZaQgEarjvA5ULP5n9 kI1vrNgSV7CCqX1+IMNRvdTzUZUF1UB/BoO37PkiV2JyHStzdxJEJI5qWKOCe59d5AP8z4lm7DB xm4VMwbrbqgpiqkRFKeR0hvYb6iwo1sQLhENnbJ6tci7Gp+lC9EiESG9CzNQn3ebc96fMzFN4eA K2olo= X-Received: by 2002:a05:600c:1708:b0:3ea:c100:f18d with SMTP id c8-20020a05600c170800b003eac100f18dmr424396wmn.9.1677533385581; Mon, 27 Feb 2023 13:29:45 -0800 (PST) X-Google-Smtp-Source: AK7set/f4bNgDzJCV/JQo99HpoGO+4N/Bv3hPpoglc1WTzGhVbu9g/CC2sExpa6JANQomsWcy5mpcA== X-Received: by 2002:a05:600c:1708:b0:3ea:c100:f18d with SMTP id c8-20020a05600c170800b003eac100f18dmr424378wmn.9.1677533385283; Mon, 27 Feb 2023 13:29:45 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id z19-20020a05600c0a1300b003e4326a6d53sm13857747wmp.35.2023.02.27.13.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 13:29:44 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 11/13] gdb: remove some uses of alloca from remote.c Date: Mon, 27 Feb 2023 21:29:24 +0000 Message-Id: <4818cb026330713c1cbce9ff36a77fa6a3ec3618.1677533215.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: Remove some of the uses of alloca from remote.c and replace them with either gdb::byte_vector or std::vector. In one case I've used std::vector because this handles automatically zeroing the contents, and this allows me to remove an associated memset. There are other uses of alloca in this file (remote.c), but these are all for types other than gdb_byte so need replacing with something other than gdb::byte_vector. There should be no user visible changes after this commit. --- gdb/remote.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index ba7a7520cb4..3f0552e7c9e 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -8554,7 +8554,6 @@ remote_target::fetch_register_using_p (struct regcache *regcache, struct gdbarch *gdbarch = regcache->arch (); struct remote_state *rs = get_remote_state (); char *buf, *p; - gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum)); int i; if (m_features.packet_support (PACKET_p) == PACKET_DISABLE) @@ -8593,6 +8592,7 @@ remote_target::fetch_register_using_p (struct regcache *regcache, } /* Otherwise, parse and supply the value. */ + gdb::byte_vector regp (register_size (gdbarch, reg->regnum)); p = buf; i = 0; while (p[0] != 0) @@ -8603,7 +8603,7 @@ remote_target::fetch_register_using_p (struct regcache *regcache, regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]); p += 2; } - regcache->raw_supply (reg->regnum, regp); + regcache->raw_supply (reg->regnum, regp.data ()); return 1; } @@ -8862,7 +8862,7 @@ remote_target::store_register_using_P (const struct regcache *regcache, struct remote_state *rs = get_remote_state (); /* Try storing a single register. */ char *buf = rs->buf.data (); - gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum)); + gdb::byte_vector regp (register_size (gdbarch, reg->regnum)); char *p; if (m_features.packet_support (PACKET_P) == PACKET_DISABLE) @@ -8873,8 +8873,8 @@ remote_target::store_register_using_P (const struct regcache *regcache, xsnprintf (buf, get_remote_packet_size (), "P%s=", phex_nz (reg->pnum, 0)); p = buf + strlen (buf); - regcache->raw_collect (reg->regnum, regp); - bin2hex (regp, p, register_size (gdbarch, reg->regnum)); + regcache->raw_collect (reg->regnum, regp.data ()); + bin2hex (regp.data (), p, register_size (gdbarch, reg->regnum)); putpkt (rs->buf); getpkt (&rs->buf, 0); @@ -8900,30 +8900,26 @@ remote_target::store_registers_using_G (const struct regcache *regcache) { struct remote_state *rs = get_remote_state (); remote_arch_state *rsa = rs->get_remote_arch_state (regcache->arch ()); - gdb_byte *regs; - char *p; - /* Extract all the registers in the regcache copying them into a - local buffer. */ - { - int i; + /* Extract all the registers in the REGCACHE copying them into a local + buffer REGS. - regs = (gdb_byte *) alloca (rsa->sizeof_g_packet); - memset (regs, 0, rsa->sizeof_g_packet); - for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++) - { - struct packet_reg *r = &rsa->regs[i]; + Use std::vector here (instead of gdb::byte_vector) because + we want the contents to be zero initialized. */ + std::vector regs (rsa->sizeof_g_packet); + for (int i = 0; i < gdbarch_num_regs (regcache->arch ()); i++) + { + struct packet_reg *r = &rsa->regs[i]; - if (r->in_g_packet) - regcache->raw_collect (r->regnum, regs + r->offset); - } - } + if (r->in_g_packet) + regcache->raw_collect (r->regnum, regs.data () + r->offset); + } /* Command describes registers byte by byte, each byte encoded as two hex characters. */ - p = rs->buf.data (); + char *p = rs->buf.data (); *p++ = 'G'; - bin2hex (regs, p, rsa->sizeof_g_packet); + bin2hex (regs.data (), p, rsa->sizeof_g_packet); putpkt (rs->buf); getpkt (&rs->buf, 0); if (packet_check_result (rs->buf) == PACKET_ERROR) -- 2.25.4