From patchwork Sat Nov 2 02:56:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 840275 Delivered-To: patch@linaro.org Received: by 2002:adf:a38c:0:b0:37d:45d0:187 with SMTP id l12csp1158344wrb; Fri, 1 Nov 2024 19:58:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWtiQjcqco0MJxTZn2d2rpv3J7+fu61EkRy8Ys1sg6mpHjuXtI3xPZuS2Mszlb7TxIG2IYUOg==@linaro.org X-Google-Smtp-Source: AGHT+IEIsO5fCTNrFfP8c0VJPDpyHnZzruXR7Ky8cBki4GSivYDEiW0aWHm1QOsM2SslPQsLlo/6 X-Received: by 2002:a05:620a:3955:b0:7b1:48d1:574d with SMTP id af79cd13be357-7b2f3cf9e5dmr1496011685a.8.1730516295637; Fri, 01 Nov 2024 19:58:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1730516295; cv=pass; d=google.com; s=arc-20240605; b=GW938/mQcsyoxHOhPURAAGTzyuWGQ+SroX2Stizb6jNI8tu8ca94ib9FzCzVFfCpKG Q8F3wG8KIwDWXPsDnMx2a4xTQjPHAFcGH94o/QndvKXAb3W9ZN2kqqpMQEgfjqPJXZpd fQD3epkxShBBwPpD8CrxFOdUz8ohjW8e32DABXOHfTEYY9P5QGOtN5BGQEhULuAbBQ3I 7kfHoHM/U07oTBnMvFQyCHTMJPkJEu5CNy+mhKI+KGJJGu8AikblMRFlC4+CrFmQ2zYV QnA112xpBeQXUEEdA0rxxlBFmHZl6ijpGrilnl1sKyhYVX21BO3XNoUsd8iSuR2PaNRY QehQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=1eQqNcBj1MQz2Sf2r0uuvgO3/g229SbHldgXqqPTm7k=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=ZL8Rj2Bj5xMpvzGMP9LYr09JPw2yOAcYf8csIXodPxVoT0RMGs8KfP45NkA71ly6rC 2bKdIPRP48yE3oZMtP2sBeQaPT0+vV1CsHoAzL62d//6nT0Gh0vbFPvOftsS9vKzbtLs RAVGA7T39zn1TOTDeMZ2BmHNk+LPRFXf5a3vpv6io+U0p2Ss8/gB9ZJy6qXn25NAu9YD DqDSwezoobqLc95uutZSJf93efj1LkVGKhu99xGekkSeodeZaGkz3XDXmtK4Cec/wCVD dRgE1EGhqkux6y/Lpu0VCWoEkRSOpKyNRfg3Z66wRVAiHY/oUm1yu0CKYdYajzirU/wx y8mw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AvdmcZGR; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id af79cd13be357-7b2f3ab2150si655599685a.542.2024.11.01.19.58.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:58:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AvdmcZGR; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 50AB43857BA7 for ; Sat, 2 Nov 2024 02:58:15 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id C4D953858428 for ; Sat, 2 Nov 2024 02:56:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4D953858428 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4D953858428 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::530 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516215; cv=none; b=nVNg+cOBo+Ac9CtKOTCB8wdRI9ribBHQ8ysOi0t3k9uGyuCyxuYy68OPBB/TXjv7Z/80dzPDxzYW4RssaTmgQla8Evij4813d0Ze9eZr+Lf95VqVYceu9D7CmT1loSR/5THY/9eicBhRdzP/PnKhuIgiSqPN9b2eYwu+awdGf1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516215; c=relaxed/simple; bh=XasmZICvVOXT3tJNDECChC1zwk8I0AB4IAIXQArU9R4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=M7ryXsp6CfOZ48+6KfBF2UlxPZWpp5+HOvpX+C2xJs511dZ31JVqEpBMUaPUF42v8Sm1b3JMXOT9CXtlDmr2RsxX5Sbx7CzqmFYTYqPAoLm7eS8DAI0lLdGmdtpvblKO8cP6aUR8tMtpKPiGfeeJInd++X5h2vqpNIwt+rZzVwY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-7ea7ad1e01fso1821698a12.0 for ; Fri, 01 Nov 2024 19:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730516212; x=1731121012; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=1eQqNcBj1MQz2Sf2r0uuvgO3/g229SbHldgXqqPTm7k=; b=AvdmcZGRx6KDJJkS9mbSHZUEqE45orTWP8dSC15+cTIGeI4AevkRRwykXKRmnJVPgZ Qt8KsqV31or0H1AiBqKItayCsGgT8xbdswcK7RQYcmSB7UX41otzJFyyQ/uo+zS+0B5x z4WIZePmtycBt2ZNxeWK56qPtJlwyBcS7m3Woh1YxGH9bQVK6PmCIYjl2le/2RMeR1lV W8uHS95JmGSt1G5XXpaDqbwDXaZh6WYjWQoR3iWjAUD5LaqK9bO8Nb4Zbl2pqLInGXDa Z9K9ByEMhW0FDbbqCqv/CySRkwQbjKVPLvst8fnZoaR8dKpX6FjH101k6NRlHK12cdix XjpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730516212; x=1731121012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1eQqNcBj1MQz2Sf2r0uuvgO3/g229SbHldgXqqPTm7k=; b=GJI3LYoocoQuLsnLdW4OwBYg1Ewcw4dMAM3gQFiLclPiBU2GCj1an9YZZsVs/R0vlQ njzThNPCBoGb6xhiExoYCK/gVhgwmIpdRhhynGjUZloRDpWmcl/Dn+iH9+hyn2E5vfuY 5pK4FNGNMF+3xH2QkgcplkAFXwV+3rYQ9C3Ep+tXeKbUFYNARSCNF7UXEW1Vwfi16BhM 4VLlF1zpu+nwss/dSfyex+3NxbsC5J81xZnKl5rR8aMC1qTrWcR72ajW0rer13hHvy8u W7USRfjTVeRAVZHH8g62jPCxlrf/Bw7wNVEmEgt+Nz6srXt7jA5zzoKIODjU24eeGg9h P9vQ== X-Gm-Message-State: AOJu0YyqRwlQOBcGFjUM9HcdswpjQL+OmLaCH5GXv1K6+rrGoCJImRoJ ZzaQenFBw+KFJasn+4p/TnhFSNK9S9oDEL61YWgkzs6xv5wqWX7Th2eTYOnggoNwmCcS3nrM3yC d X-Received: by 2002:a17:902:d492:b0:20b:5ef8:10a6 with SMTP id d9443c01a7336-211056b23d9mr124045795ad.8.1730516211625; Fri, 01 Nov 2024 19:56:51 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:f214:b4dc:314a:c1ee]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211056ee412sm27794985ad.40.2024.11.01.19.56.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:56:51 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [RFC PATCH v4 04/15] GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg Date: Fri, 1 Nov 2024 23:56:24 -0300 Message-ID: <20241102025635.586759-5-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241102025635.586759-1-thiago.bauermann@linaro.org> References: <20241102025635.586759-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patch=linaro.org@sourceware.org The goal is to ensure that it is available in frame_unwind_got_bytes () to make sure that the provided buf isn't larger than the size of the register being provisioned. In the process, regcache's cached_reg_t::data also needed to be converted to a gdb::byte_vector, so that the register contents' size can be tracked. --- gdb/frame-unwind.c | 18 +++++++++++++++--- gdb/frame-unwind.h | 2 +- gdb/jit.c | 2 +- gdb/python/py-unwind.c | 7 ++++--- gdb/regcache.h | 2 +- gdb/remote.c | 11 +++++------ gdb/trad-frame.h | 10 +++++++--- 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c index fecd1070e912..ad8ebb29d736 100644 --- a/gdb/frame-unwind.c +++ b/gdb/frame-unwind.c @@ -313,14 +313,26 @@ frame_unwind_got_constant (const frame_info_ptr &frame, int regnum, } struct value * -frame_unwind_got_bytes (const frame_info_ptr &frame, int regnum, const gdb_byte *buf) +frame_unwind_got_bytes (const frame_info_ptr &frame, int regnum, + gdb::array_view buf) { struct gdbarch *gdbarch = frame_unwind_arch (frame); struct value *reg_val; reg_val = value::zero (register_type (gdbarch, regnum), not_lval); - memcpy (reg_val->contents_raw ().data (), buf, - register_size (gdbarch, regnum)); + gdb::array_view val_contents = reg_val->contents_raw (); + + /* The value's contents buffer is zeroed on allocation so if buf is + smaller, the remaining space will be filled with zero. + + This can happen when unwinding through signal frames. For example, if + an AArch64 program doesn't use SVE, then the Linux kernel will only + save in the signal frame the first 128 bits of the vector registers, + which is their minimum size, even if the vector length says they're + bigger. */ + gdb_assert (buf.size () <= val_contents.size ()); + + memcpy (val_contents.data (), buf.data (), buf.size ()); return reg_val; } diff --git a/gdb/frame-unwind.h b/gdb/frame-unwind.h index 53fcd6869e95..36e7fbdb4f9c 100644 --- a/gdb/frame-unwind.h +++ b/gdb/frame-unwind.h @@ -226,7 +226,7 @@ value *frame_unwind_got_constant (const frame_info_ptr &frame, int regnum, inside BUF. */ value *frame_unwind_got_bytes (const frame_info_ptr &frame, int regnum, - const gdb_byte *buf); + gdb::array_view buf); /* Return a value which indicates that FRAME's saved version of REGNUM has a known constant (computed) value of ADDR. Convert the diff --git a/gdb/jit.c b/gdb/jit.c index ed3b26cd4bd1..e068b0a4b572 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -1094,7 +1094,7 @@ jit_frame_prev_register (const frame_info_ptr &this_frame, void **cache, int reg return frame_unwind_got_optimized (this_frame, reg); gdbarch = priv->regcache->arch (); - gdb_byte *buf = (gdb_byte *) alloca (register_size (gdbarch, reg)); + gdb::byte_vector buf (register_size (gdbarch, reg)); enum register_status status = priv->regcache->cooked_read (reg, buf); if (status == REG_VALID) diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 68deaf98d81f..c1a01bf7cfe4 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -812,7 +812,7 @@ pyuw_prev_register (const frame_info_ptr &this_frame, void **cache_ptr, for (; reg_info < reg_info_end; ++reg_info) { if (regnum == reg_info->num) - return frame_unwind_got_bytes (this_frame, regnum, reg_info->data.get ()); + return frame_unwind_got_bytes (this_frame, regnum, reg_info->data); } return frame_unwind_got_optimized (this_frame, regnum); @@ -936,8 +936,9 @@ pyuw_sniffer (const struct frame_unwind *self, const frame_info_ptr &this_frame, cached_reg_t *cached = new (&cached_frame->reg[i]) cached_reg_t (); cached->num = reg->number; - cached->data.reset ((gdb_byte *) xmalloc (data_size)); - memcpy (cached->data.get (), value->contents ().data (), data_size); + cached->data.resize (data_size); + gdb::array_view contents = value->contents (); + cached->data.assign (contents.begin (), contents.end ()); } } diff --git a/gdb/regcache.h b/gdb/regcache.h index 65e9f7bb79da..739172a249b8 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -177,7 +177,7 @@ using register_read_ftype struct cached_reg_t { int num; - gdb::unique_xmalloc_ptr data; + gdb::byte_vector data; cached_reg_t () = default; cached_reg_t (cached_reg_t &&rhs) = default; diff --git a/gdb/remote.c b/gdb/remote.c index 6ffc51e4e2f5..2da2c5a4789a 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -8225,13 +8225,12 @@ Packet: '%s'\n"), hex_string (pnum), p, buf); cached_reg.num = reg->regnum; - cached_reg.data.reset ((gdb_byte *) - xmalloc (register_size (event->arch, - reg->regnum))); + cached_reg.data.resize (register_size (event->arch, + reg->regnum)); p = p1 + 1; - fieldsize = hex2bin (p, cached_reg.data.get (), - register_size (event->arch, reg->regnum)); + fieldsize = hex2bin (p, cached_reg.data.data (), + cached_reg.data.size ()); p += 2 * fieldsize; if (fieldsize < register_size (event->arch, reg->regnum)) warning (_("Remote reply is too short: %s"), buf); @@ -8572,7 +8571,7 @@ remote_target::process_stop_reply (stop_reply_up stop_reply, for (cached_reg_t ® : stop_reply->regcache) { - regcache->raw_supply (reg.num, reg.data.get ()); + regcache->raw_supply (reg.num, reg.data); rs->last_seen_expedited_registers.insert (reg.num); } } diff --git a/gdb/trad-frame.h b/gdb/trad-frame.h index ca8792baa17d..ef84a24c0bc7 100644 --- a/gdb/trad-frame.h +++ b/gdb/trad-frame.h @@ -122,6 +122,7 @@ struct trad_frame_saved_reg m_kind = trad_frame_saved_reg_kind::VALUE_BYTES; m_reg.value_bytes = data; + m_reg.bytes_len = bytes.size (); } /* Getters */ @@ -144,10 +145,10 @@ struct trad_frame_saved_reg return m_reg.addr; } - const gdb_byte *value_bytes () const + gdb::array_view value_bytes () const { gdb_assert (m_kind == trad_frame_saved_reg_kind::VALUE_BYTES); - return m_reg.value_bytes; + return { m_reg.value_bytes, m_reg.bytes_len }; } /* Convenience functions, return true if the register has been @@ -185,7 +186,10 @@ struct trad_frame_saved_reg LONGEST value; int realreg; LONGEST addr; - const gdb_byte *value_bytes; + struct { + const gdb_byte *value_bytes; + size_t bytes_len; + }; } m_reg; };