From patchwork Sat Nov 2 02:56:22 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: 840273 Delivered-To: patch@linaro.org Received: by 2002:adf:a38c:0:b0:37d:45d0:187 with SMTP id l12csp1158221wrb; Fri, 1 Nov 2024 19:57:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW+D9EakoNKLKDupjLDOWT4swSEfEA4RNveDEEbP1TXfXTbBIhEyJTxjBL2kn0fOfLjM6IoMQ==@linaro.org X-Google-Smtp-Source: AGHT+IGj3F39fcpfBknsId+83iGCa6aXZn+imMw6zmkrybDfTKUvHL43MjVDlATTE+T1YAukN4Yz X-Received: by 2002:a05:620a:28cf:b0:7b1:8dcd:b7a6 with SMTP id af79cd13be357-7b2fb9582c3mr824202885a.8.1730516246011; Fri, 01 Nov 2024 19:57:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1730516245; cv=pass; d=google.com; s=arc-20240605; b=Ie0/cjCiG3zhPl8ORdbn7ofYMoSFWZnf/b/mRxTBCqIw7sUVXSvOkPl8TVukLdyigi 7Op4BFl8uxXQ0KY3T5jWj1L80qThysQ2kTmNTNWPp75ZSIWfmd8bO7dZQq856KKKsC/b DylsPbi4//XDjUaCBcgHMGHyYLlU/auOizFu2T6feFzyiY3La4KmE/IF3x65Vjsxn9lt RzXYkBdYgbHUx+te4AiBjqTq+5nByzcu9/cCAl46LQMCSh1uCIYuC/noLto5VSLxjFmy DVDrWlIQa+whlu5tgAFu5DsVzGQsLxJnh7mKfnYWoICnFuwoGSzZNu25cWrrYPn+NuAg gtkw== 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=OjXzt0ucyiIABJ/qp8lzbeE5zXEHcul8QSmCZaiXmdY=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=CKY0G76s469ohx3n3pQ0al+8INSVSaxw68aWRpL0KEHo8AUmqUDi7GBofuCuRT9dTr zDpOVrB3s5hy4cMn9LEdWwn1l61T78D288EHYbNazjyptiyaBcDmzbNynJtvJsHqM/gw lXdUHCa9fivn1X3bowoumT1cMYXsvmned5v3s9Qodie4Dwt06ZFSxz7ansciOn8PcD5F Exo31vpZsZrUbx8VMxhFSw74e3WBVFWJuwTI078khflfsW61J6hHf/n/HbcXT7kbP/qg dfw7SWvCUUqc4O+BvKb9UMVNKGmZup67/ejZlL/J4Qs/1c3u8P0ZKO9XKFzm3YUcZYD7 1g8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rg1DwZ7n; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id af79cd13be357-7b2f3aae2desi553475185a.531.2024.11.01.19.57.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:57:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rg1DwZ7n; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 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 51E533857C4F for ; Sat, 2 Nov 2024 02:57:25 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 66A263858C32 for ; Sat, 2 Nov 2024 02:56:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66A263858C32 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 66A263858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516209; cv=none; b=f7BdCNuq3GLTVIzG3CdC36uzo0tjogf1gHCoyH7s+HPMuGKXErVJxT3qVqRH/j5slIWuhQpfsjZQlHrrWybTV8PJc0gnr2z6BdgXAf5iEfiSt0PWilLol4jFQRCMRHAxtvID1/6yZCTcGxFfA0ABQrWr1KvkkDEJ3W2f0oPOxPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516209; c=relaxed/simple; bh=REue7UjN0DvJvB+GZaIK/039jpSDYPp5/5Y/ykhXV/I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=k2W/xJyDjQZ7/dkS9GS4i5NOX3OUmAfWnsRtVFoJOOM1Q36VjLdosGrRvNaz2NP5AF0SgWpX9GPPgiBej8dCN9jRGeB7pfWytSNUesvOqvSqxS7jMbxD2sX5fUy+uttObgEDsRCHYvZhwWQH4+N2l63Tk1rlB25fBijc6OTdsxo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-71e4244fdc6so2084460b3a.0 for ; Fri, 01 Nov 2024 19:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730516205; x=1731121005; 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=OjXzt0ucyiIABJ/qp8lzbeE5zXEHcul8QSmCZaiXmdY=; b=Rg1DwZ7n2SSNThuoXTce0Eex+/2e4Wv1Q/laAmjn8y3QnvIYE18jhBEgGBAF1JaUDs 3Nnx9fOqtnsFgdfQppjYAca18bGSDSiXCmNgE1jLZjiQEy79MlvYX9KnUBmAwIaoQnVR UTmWxTqD95pFyTEFPRTeIXXNrbpR8+fAtIP7BymWA3HhgRmGTLdoXuuCFQDHEikPAXk1 oyJEnq668e/R7n+k7uLOmJFR3YYBeR2FeWNGlbb0q3m3aYSjgvVrTl2509EVKJYOrCVW nhBryU/ioFcpmBspQCXvcFA9YPOTrknnG6d4t4MLTwObf+ADT5Ojwqjd1dgRhwaGh3Ql /xNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730516205; x=1731121005; 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=OjXzt0ucyiIABJ/qp8lzbeE5zXEHcul8QSmCZaiXmdY=; b=RVfl9fzORJwiSL1fsceb8MMHhu7DUi2RzwuJJjk2AncEz7q0YihFLpo8CaXCtaMsUz 4P19ld7mTB9EXhSxXg7R/0S/3vhSv05ZqNOi1l0j/4auZCBiyEhGpy2TMRaGPBaWRw5/ 57cl1zos2hrJDNpFdhy+a94J3q//fZ1qP1nEZWW8KdqS6cW2tTwQPPNp/Jp+NQ3IsyqE 6IEoXfPaelHXZbZjoRUp9kiVIA71G6tWUZ//8LyY/GqduJymJd6jvpMTx+rOJQzvgSuV KuETb40YUMoPkGtubYZn1axqQRunBRffDd52GkWzoKQZ+MIjBgRTTRvXOMhpYMB0C96U A4NA== X-Gm-Message-State: AOJu0YwxrVEFgwIkG29NpUHiu43PGeoqFT0Pd0z0MJ5rHipc7QU8Srna eVXKT5kXIw5cwNbqdybSlA95THzBm7Cj3hwG+dpcXLaK0BdzKhMMWRTU2j5bHQ7tmyjjd4PQ+17 4 X-Received: by 2002:a05:6a21:1743:b0:1cf:2853:bc6c with SMTP id adf61e73a8af0-1dba55ab0e3mr7349945637.33.1730516205341; Fri, 01 Nov 2024 19:56:45 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:f214:b4dc:314a:c1ee]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7ee452b1643sm3160799a12.38.2024.11.01.19.56.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:56:44 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [RFC PATCH v4 02/15] GDB: Use gdb::array_view for buffers used in register reading and unwinding Date: Fri, 1 Nov 2024 23:56:22 -0300 Message-ID: <20241102025635.586759-3-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 This allows checking the size of the given buffer. Changes frame_register_unwind (), frame_unwind_register (), get_frame_register () and deprecated_frame_register_read (). --- gdb/frame.c | 24 ++++++++++++++---------- gdb/frame.h | 8 ++++---- gdb/mips-tdep.c | 19 +++++++++++++------ gdb/stack.c | 2 +- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/gdb/frame.c b/gdb/frame.c index a6900b280724..2c1ea012191b 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1112,7 +1112,7 @@ frame_save_as_regcache (const frame_info_ptr &this_frame) { auto cooked_read = [this_frame] (int regnum, gdb::array_view buf) { - if (!deprecated_frame_register_read (this_frame, regnum, buf.data ())) + if (!deprecated_frame_register_read (this_frame, regnum, buf)) return REG_UNAVAILABLE; else return REG_VALID; @@ -1177,7 +1177,8 @@ void frame_register_unwind (const frame_info_ptr &next_frame, int regnum, int *optimizedp, int *unavailablep, enum lval_type *lvalp, CORE_ADDR *addrp, - int *realnump, gdb_byte *bufferp) + int *realnump, + std::optional> bufferp) { struct value *value; @@ -1204,11 +1205,13 @@ frame_register_unwind (const frame_info_ptr &next_frame, int regnum, if (bufferp) { + gdb_assert (bufferp->size () >= value->type ()->length ()); + if (!*optimizedp && !*unavailablep) - memcpy (bufferp, value->contents_all ().data (), + memcpy (bufferp->data (), value->contents_all ().data (), value->type ()->length ()); else - memset (bufferp, 0, value->type ()->length ()); + memset (bufferp->data (), 0, value->type ()->length ()); } /* Dispose of the new value. This prevents watchpoints from @@ -1217,7 +1220,8 @@ frame_register_unwind (const frame_info_ptr &next_frame, int regnum, } void -frame_unwind_register (const frame_info_ptr &next_frame, int regnum, gdb_byte *buf) +frame_unwind_register (const frame_info_ptr &next_frame, int regnum, + gdb::array_view buf) { int optimized; int unavailable; @@ -1238,7 +1242,7 @@ frame_unwind_register (const frame_info_ptr &next_frame, int regnum, gdb_byte *b void get_frame_register (const frame_info_ptr &frame, - int regnum, gdb_byte *buf) + int regnum, gdb::array_view buf) { frame_unwind_register (frame_info_ptr (frame->next), regnum, buf); } @@ -1447,7 +1451,7 @@ put_frame_register (const frame_info_ptr &next_frame, int regnum, gdb_assert (buf.size () == size); frame_register_unwind (next_frame, regnum, &optim, &unavail, &lval, &addr, - &realnum, nullptr); + &realnum); if (optim) error (_("Attempt to assign to a register that was not saved.")); switch (lval) @@ -1482,7 +1486,7 @@ put_frame_register (const frame_info_ptr &next_frame, int regnum, bool deprecated_frame_register_read (const frame_info_ptr &frame, int regnum, - gdb_byte *myaddr) + gdb::array_view myaddr) { int optimized; int unavailable; @@ -1541,7 +1545,7 @@ get_frame_register_bytes (const frame_info_ptr &next_frame, int regnum, int realnum; frame_register_unwind (next_frame, regnum, optimizedp, unavailablep, - &lval, &addr, &realnum, buffer.data ()); + &lval, &addr, &realnum, buffer); if (*optimizedp || *unavailablep) return false; } @@ -2159,7 +2163,7 @@ frame_register_unwind_location (const frame_info_ptr &initial_this_frame, int unavailable; frame_register_unwind (this_frame, regnum, optimizedp, &unavailable, - lvalp, addrp, realnump, NULL); + lvalp, addrp, realnump); if (*optimizedp) break; diff --git a/gdb/frame.h b/gdb/frame.h index e784c17b4807..23a3ade69c92 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -692,7 +692,7 @@ extern void frame_register_unwind (const frame_info_ptr &frame, int regnum, int *optimizedp, int *unavailablep, enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, - gdb_byte *valuep); + std::optional> valuep = {}); /* Fetch a register from this, or unwind a register from the next frame. Note that the get_frame methods are wrappers to @@ -701,9 +701,9 @@ extern void frame_register_unwind (const frame_info_ptr &frame, int regnum, do return a lazy value. */ extern void frame_unwind_register (const frame_info_ptr &next_frame, - int regnum, gdb_byte *buf); + int regnum, gdb::array_view buf); extern void get_frame_register (const frame_info_ptr &frame, - int regnum, gdb_byte *buf); + int regnum, gdb::array_view buf); struct value *frame_unwind_register_value (const frame_info_ptr &next_frame, int regnum); @@ -889,7 +889,7 @@ extern void print_frame_info (const frame_print_options &fp_opts, extern frame_info_ptr block_innermost_frame (const struct block *); extern bool deprecated_frame_register_read (const frame_info_ptr &frame, int regnum, - gdb_byte *buf); + gdb::array_view buf); /* From stack.c. */ diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index c00efbd02ad0..24970c7637ad 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -951,14 +951,17 @@ mips_register_to_value (const frame_info_ptr &frame, int regnum, if (mips_convert_register_float_case_p (gdbarch, regnum, type)) { - get_frame_register (frame, regnum + 0, to + 4); - get_frame_register (frame, regnum + 1, to + 0); + gdb::array_view first_half = gdb::make_array_view (to, 4); + gdb::array_view second_half = gdb::make_array_view (to + 4, 4); - if (!get_frame_register_bytes (next_frame, regnum + 0, 0, { to + 4, 4 }, + get_frame_register (frame, regnum + 0, second_half); + get_frame_register (frame, regnum + 1, first_half); + + if (!get_frame_register_bytes (next_frame, regnum + 0, 0, second_half, optimizedp, unavailablep)) return 0; - if (!get_frame_register_bytes (next_frame, regnum + 1, 0, { to + 0, 4 }, + if (!get_frame_register_bytes (next_frame, regnum + 1, 0, first_half, optimizedp, unavailablep)) return 0; *optimizedp = *unavailablep = 0; @@ -6257,8 +6260,10 @@ mips_read_fp_register_single (const frame_info_ptr &frame, int regno, struct gdbarch *gdbarch = get_frame_arch (frame); int raw_size = register_size (gdbarch, regno); gdb_byte *raw_buffer = (gdb_byte *) alloca (raw_size); + gdb::array_view raw_view = gdb::make_array_view (raw_buffer, + raw_size); - if (!deprecated_frame_register_read (frame, regno, raw_buffer)) + if (!deprecated_frame_register_read (frame, regno, raw_view)) error (_("can't read register %d (%s)"), regno, gdbarch_register_name (gdbarch, regno)); if (raw_size == 8) @@ -6295,7 +6300,9 @@ mips_read_fp_register_double (const frame_info_ptr &frame, int regno, { /* We have a 64-bit value for this register, and we should use all 64 bits. */ - if (!deprecated_frame_register_read (frame, regno, rare_buffer)) + gdb::array_view rare_view = gdb::make_array_view (rare_buffer, + raw_size); + if (!deprecated_frame_register_read (frame, regno, rare_view)) error (_("can't read register %d (%s)"), regno, gdbarch_register_name (gdbarch, regno)); } diff --git a/gdb/stack.c b/gdb/stack.c index 4a3e7e4ff006..b585e6e636d5 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1750,7 +1750,7 @@ info_frame_command_core (const frame_info_ptr &fi, bool selected_frame_p) /* Find out the location of the saved register without fetching the corresponding value. */ frame_register_unwind (fi, i, &optimized, &unavailable, - &lval, &addr, &realnum, NULL); + &lval, &addr, &realnum); /* For moment, only display registers that were saved on the stack. */ if (!optimized && !unavailable && lval == lval_memory)